fix config path

This commit is contained in:
Callow 2022-07-13 13:40:16 +03:00
parent 78cc285af2
commit d80d3d15d6
3 changed files with 15 additions and 4 deletions

View File

@ -62,6 +62,14 @@ namespace util
return (*c); return (*c);
} }
std::string GetModulePath(HMODULE hModule /*= nullptr*/)
{
char pathOut[MAX_PATH] = {};
GetModuleFileNameA(hModule, pathOut, MAX_PATH);
return std::filesystem::path(pathOut).parent_path().string();
}
std::optional<std::string> SelectDirectory(const char* title) std::optional<std::string> SelectDirectory(const char* title)
{ {
auto currPath = std::filesystem::current_path(); auto currPath = std::filesystem::current_path();

View File

@ -36,6 +36,8 @@ namespace util
std::string GetLastErrorAsString(DWORD errorId = 0); std::string GetLastErrorAsString(DWORD errorId = 0);
int64_t GetCurrentTimeMillisec(); int64_t GetCurrentTimeMillisec();
std::string GetModulePath(HMODULE hModule = nullptr);
std::vector<std::string> StringSplit(const std::string& delimiter, const std::string& content); std::vector<std::string> StringSplit(const std::string& delimiter, const std::string& content);
std::string SplitWords(const std::string& value); std::string SplitWords(const std::string& value);
std::string MakeCapital(std::string value); std::string MakeCapital(std::string value);

View File

@ -15,15 +15,16 @@ void Run(HMODULE* phModule)
{ {
ResourceLoader::SetModuleHandle(*phModule); ResourceLoader::SetModuleHandle(*phModule);
auto cheatDir = std::filesystem::path(util::GetModulePath(*phModule)).parent_path();
// Init config // Init config
std::string configPath = (std::filesystem::current_path() / "cfg.json").string(); config::Initialize((cheatDir / "cfg.json").string());
config::Initialize(configPath);
// Init logger // Init logger
auto& settings = cheat::feature::Settings::GetInstance(); auto& settings = cheat::feature::Settings::GetInstance();
if (settings.f_FileLogging) if (settings.f_FileLogging)
{ {
Logger::PrepareFileLogging((std::filesystem::current_path() / "logs").string()); Logger::PrepareFileLogging((cheatDir / "logs").string());
Logger::SetLevel(Logger::Level::Trace, Logger::LoggerType::FileLogger); Logger::SetLevel(Logger::Level::Trace, Logger::LoggerType::FileLogger);
} }
@ -55,5 +56,5 @@ void Run(HMODULE* phModule)
cheat::Init(); cheat::Init();
LOG_DEBUG("Config path is at %s", configPath.c_str()); LOG_DEBUG("Config path is at %s", (cheatDir / "cfg.json").string().c_str());
} }