From d6226ba7c998fdcc4b666da82bf3576252063c52 Mon Sep 17 00:00:00 2001 From: aemony Date: Fri, 19 Apr 2024 07:44:52 +0200 Subject: [PATCH] Added HKLM fallback to Steam's install path --- include/utility/registry.h | 10 ++++++++++ src/stores/Steam/steam_library.cpp | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/utility/registry.h b/include/utility/registry.h index 4e16b963..96a1290c 100644 --- a/include/utility/registry.h +++ b/include/utility/registry.h @@ -5,7 +5,17 @@ #include #include +#ifndef RRF_SUBKEY_WOW6464KEY +#define RRF_SUBKEY_WOW6464KEY 0x00010000 +#endif // !RRF_SUBKEY_WOW6464KEY +#ifndef RRF_SUBKEY_WOW6432KEY +#define RRF_SUBKEY_WOW6432KEY 0x00020000 +#endif // !RRF_SUBKEY_WOW6432KEY + +#ifndef RRF_WOW64_MASK +#define RRF_WOW64_MASK 0x00030000 +#endif // !RRF_WOW64_MASK struct SKIF_RegistrySettings { diff --git a/src/stores/Steam/steam_library.cpp b/src/stores/Steam/steam_library.cpp index 9960213e..40252c6a 100644 --- a/src/stores/Steam/steam_library.cpp +++ b/src/stores/Steam/steam_library.cpp @@ -372,6 +372,8 @@ SK_GetSteamDir (void) wszSteamPath [0] = L'?'; DWORD len = MAX_PATH; + + // Rely on HKCU path first and foremost LSTATUS status = RegGetValueW ( HKEY_CURRENT_USER, LR"(SOFTWARE\Valve\Steam\)", @@ -381,10 +383,26 @@ SK_GetSteamDir (void) wszSteamPath, (LPDWORD)&len ); + // Use the HKCU path if it exists + if (status == ERROR_SUCCESS && PathFileExists (wszSteamPath)) + return wszSteamPath; + + std::fill (std::begin (wszSteamPath), std::end(wszSteamPath), L'\0'); + + // In case of issues with the HKCU path, try the HKLM path + status = + RegGetValueW ( HKEY_LOCAL_MACHINE, + LR"(SOFTWARE\Valve\Steam\)", + L"InstallPath", + RRF_RT_REG_SZ | RRF_SUBKEY_WOW6432KEY, // Steam stores this path in the Wow6432Node key + nullptr, + wszSteamPath, + (LPDWORD)&len ); + if (status == ERROR_SUCCESS) return wszSteamPath; - else - return L""; + + return L""; } return wszSteamPath;