diff --git a/dll/core/Core.cpp b/dll/core/Core.cpp index 6fc8459..b51f7da 100644 --- a/dll/core/Core.cpp +++ b/dll/core/Core.cpp @@ -355,6 +355,18 @@ void Core::createPIDFile() { NULL); } +bool Core::setProcessDirectory() { + CHAR path[MAX_PATH]; + GetModuleFileNameA(NULL, path, MAX_PATH); + + std::filesystem::path p = std::filesystem::path(path); + auto folder = p.parent_path(); + + SetCurrentDirectoryA(folder.string().c_str()); + + return true; +} + void Core::initialize() { if (this->isInitialized) { @@ -363,12 +375,6 @@ void Core::initialize() { return; } - this->setArgsFromCommandLine(); - this->processEnvironmentVariables(); - this->processCommandLineArguments(); - - this->createPIDFile(); - if (!this->secureMode) { int answer = MessageBoxA( NULL, @@ -382,10 +388,23 @@ void Core::initialize() { } } + bool processDirectorySuccess = setProcessDirectory(); + + this->createPIDFile(); + + this->setArgsFromCommandLine(); + this->processEnvironmentVariables(); + this->processCommandLineArguments(); + initializeLogger(this->logLevel, this->consoleLogLevel); this->initializeConsole(); + if (!processDirectorySuccess) { + this->log(-1, "Failed to set process directory"); + } + this->log(0, "Current directory: " + std::filesystem::current_path().string()); + this->moduleHashStore = new Store(this->UCP_DIR / "extension-store.yml", this->secureMode); std::string error; diff --git a/dll/core/Core.h b/dll/core/Core.h index e3391fe..139b13e 100644 --- a/dll/core/Core.h +++ b/dll/core/Core.h @@ -98,6 +98,8 @@ class Core void createPIDFile(); + bool setProcessDirectory(); + Store* getModuleHashStore(); void log(int logLevel, std::string message);