From 1d7eb64fe0b813dcc646164dc3c324349959932e Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:42:49 +0200 Subject: [PATCH] Get localappdata via winapi instead of registry --- src/GameStart.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index 0dd553d..48c7d81 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -8,6 +8,7 @@ #if defined(_WIN32) #include +#include #elif defined(__linux__) #include "vdf_parser.hpp" #include @@ -40,17 +41,17 @@ std::string GetGamePath() { Path = QueryKey(hKey, 4); 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) { - sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders)"; - openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); + Path = ""; + char appDataPath[MAX_PATH]; + HRESULT result = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath); + if (SUCCEEDED(result)) { + Path = appDataPath; } - if (openRes != ERROR_SUCCESS) { + + if (Path.empty()) { fatal("Cannot get Local Appdata directory"); } - Path = QueryKey(hKey, 5); Path += "\\BeamNG.drive\\"; }