fs: dedup functions, fix absolute paths in cfg

fixes #2

closes #12
This commit is contained in:
Vaxry
2025-04-14 21:03:10 +01:00
parent ab01c2c469
commit 1bdc60b8d2
5 changed files with 54 additions and 39 deletions

View File

@@ -2,18 +2,12 @@
#include <glaze/glaze.hpp>
#include "../helpers/FsUtils.hpp"
#include "../GlobalState.hpp"
static std::string readFileAsText(const std::string& path) {
std::ifstream ifs(path);
auto res = std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
if (res.back() == '\n')
res.pop_back();
return res;
}
CConfig::CConfig() {
auto json = glz::read_jsonc<SConfig>(readFileAsText(g_pGlobalState->cwd + "/" + g_pGlobalState->configPath));
auto json = glz::read_jsonc<SConfig>(
NFsUtils::readFileAsString(NFsUtils::isAbsolute(g_pGlobalState->configPath) ? g_pGlobalState->configPath : g_pGlobalState->cwd + "/" + g_pGlobalState->configPath).value());
if (!json.has_value())
throw std::runtime_error("No config / bad config format");