Fix for custom document location

This commit is contained in:
Anonymous275
2020-12-27 06:31:03 +02:00
parent 9734a7f3d5
commit 2a03448b3f
2 changed files with 10 additions and 6 deletions

View File

@@ -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;
}

View File

@@ -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;
}
}