From 2a03448b3f4a544fd28cab7061e8b31d093cb7d0 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 06:31:03 +0200 Subject: [PATCH] Fix for custom document location --- src/GameStart.cpp | 15 +++++++++------ src/Security/BeamNG.cpp | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index fb9d5bc..2db479e 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -22,16 +22,19 @@ std::string GetGamePath(){ LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive"; LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); if (openRes != ERROR_SUCCESS){ - fatal("Please launch the game at least once"); + fatal("Please launch the game at least once!"); } Path = QueryKey(hKey,4); if(Path.empty()){ - size_t RS; - getenv_s(&RS, nullptr, 0, "USERPROFILE"); - std::string P(RS-1,0); - getenv_s(&RS, &P[0], RS, "USERPROFILE"); - Path = P + R"(\Documents\BeamNG.drive\)"; + 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 Documents directory!"); + } + Path = QueryKey(hKey,5); + Path += "\\"; return Path; } diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 6a99d90..ccf7144 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -117,6 +117,7 @@ std::string QueryKey(HKEY hKey,int ID){ case 2: if(key == "Name" && data == "BeamNG.drive")return data;break; case 3: if(key == "rootpath")return data;break; case 4: if(key == "userpath_override")return data; + case 5: if(key == "Personal")return data; default: break; } }