Skip to content

Commit

Permalink
add setProcessDirectory() to set the current directory always to the …
Browse files Browse the repository at this point in the history
…exe directory
  • Loading branch information
gynt committed Dec 29, 2024
1 parent 9adba57 commit 8069892
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 25 additions & 6 deletions dll/core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -363,12 +375,6 @@ void Core::initialize() {
return;
}

this->setArgsFromCommandLine();
this->processEnvironmentVariables();
this->processCommandLineArguments();

this->createPIDFile();

if (!this->secureMode) {
int answer = MessageBoxA(
NULL,
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions dll/core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class Core

void createPIDFile();

bool setProcessDirectory();

Store* getModuleHashStore();

void log(int logLevel, std::string message);
Expand Down

0 comments on commit 8069892

Please sign in to comment.