Explicitly set working directory to executable directory on boot (#1430)

* Explicitly set working directory to executable directory on boot

* change to GetModuleFileNameW instead

* switch to pre-existing implementations of getting the executable path

* add argument to use current working directory

* use error code variant of current_path
This commit is contained in:
ĐeäTh 2025-03-24 19:34:37 +01:00 committed by GitHub
parent b76a44923d
commit 7f9ce5037e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -199,12 +199,14 @@ int main(int argc, char *argv[])
bool forceInstaller = false; bool forceInstaller = false;
bool forceDLCInstaller = false; bool forceDLCInstaller = false;
bool useDefaultWorkingDirectory = false;
const char *sdlVideoDriver = nullptr; const char *sdlVideoDriver = nullptr;
for (uint32_t i = 1; i < argc; i++) for (uint32_t i = 1; i < argc; i++)
{ {
forceInstaller = forceInstaller || (strcmp(argv[i], "--install") == 0); forceInstaller = forceInstaller || (strcmp(argv[i], "--install") == 0);
forceDLCInstaller = forceDLCInstaller || (strcmp(argv[i], "--install-dlc") == 0); forceDLCInstaller = forceDLCInstaller || (strcmp(argv[i], "--install-dlc") == 0);
useDefaultWorkingDirectory = useDefaultWorkingDirectory || (strcmp(argv[i], "--use-cwd") == 0);
if (strcmp(argv[i], "--sdl-video-driver") == 0) if (strcmp(argv[i], "--sdl-video-driver") == 0)
{ {
@ -215,6 +217,13 @@ int main(int argc, char *argv[])
} }
} }
if (!useDefaultWorkingDirectory)
{
// Set the current working directory to the executable's path.
std::error_code ec;
std::filesystem::current_path(os::process::GetExecutablePath().parent_path(), ec);
}
Config::Load(); Config::Load();
#if defined(_WIN32) && defined(UNLEASHED_RECOMP_D3D12) #if defined(_WIN32) && defined(UNLEASHED_RECOMP_D3D12)