From 29445f65ce4db0fe5dd8b6de322d320c7c7fa37f Mon Sep 17 00:00:00 2001 From: yeranya <154719813+yeranya@users.noreply.github.com> Date: Fri, 29 Dec 2023 00:34:57 -0800 Subject: [PATCH 1/2] check 'User Shell Folders' key in addition to 'Shell Folders' --- src/GameStart.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index 6e49db9..74158f4 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -42,12 +42,14 @@ std::string GetGamePath() { if (Path.empty()) { sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)"; openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); - if (openRes != ERROR_SUCCESS) { - fatal("Cannot get Local Appdata directory!"); - } + if (openRes == ERROR_SUCCESS) goto GotAppDataDir; + openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk.insert(51, "User "), 0, KEY_ALL_ACCESS, &hKey); + if (openRes != ERROR_SUCCESS) fatal("Cannot get Local Appdata directory"); +GotAppDataDir: Path = QueryKey(hKey, 5); Path += "\\BeamNG.drive\\"; } + std::string Ver = CheckVer(GetGameDir()); Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1)); Path += Ver + "\\"; From a714dc318878ba08016d2c15a36394d1bd3e262c Mon Sep 17 00:00:00 2001 From: 20dka Date: Sun, 8 Sep 2024 16:42:03 +0200 Subject: [PATCH 2/2] fix windows build and implement suggestion from lionkor --- src/GameStart.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index 74158f4..d298f7f 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -42,10 +42,14 @@ std::string GetGamePath() { if (Path.empty()) { sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)"; openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); - if (openRes == ERROR_SUCCESS) goto GotAppDataDir; - openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk.insert(51, "User "), 0, KEY_ALL_ACCESS, &hKey); - if (openRes != ERROR_SUCCESS) fatal("Cannot get Local Appdata directory"); -GotAppDataDir: + if (openRes != ERROR_SUCCESS) { + sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders)"; + openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); + } + if (openRes != ERROR_SUCCESS) { + fatal("Cannot get Local Appdata directory"); + } + Path = QueryKey(hKey, 5); Path += "\\BeamNG.drive\\"; }