Skip to content

Commit

Permalink
Added HKLM fallback to Steam's install path
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Apr 19, 2024
1 parent 5816a6a commit d6226ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions include/utility/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
#include <sstream>
#include <vector>

#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 {

Expand Down
22 changes: 20 additions & 2 deletions src/stores/Steam/steam_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\)",
Expand All @@ -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;
Expand Down

0 comments on commit d6226ba

Please sign in to comment.