Skip to content

Commit

Permalink
Use SHGetKnownFolderPath to obtain rerelease homedir
Browse files Browse the repository at this point in the history
  • Loading branch information
res2k committed Nov 24, 2024
1 parent a38e70e commit f6a9ab3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions inc/system/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ void Sys_BackTrace(void **output, size_t count, size_t offset);
extern cvar_t *sys_basedir;
extern cvar_t *sys_libdir;
extern cvar_t *sys_homedir;

#ifdef _WIN32
bool Sys_GetRereleaseHomeDir(char *path, size_t path_length);
#endif
2 changes: 1 addition & 1 deletion src/common/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -3980,7 +3980,7 @@ static void FS_FindBaseDir(void)
#ifdef _WIN32
if (com_rerelease->integer == RERELEASE_MODE_YES) {
char homedir[MAX_OSPATH];
if (ExpandEnvironmentStringsA("%userprofile%\\Saved Games\\NightDive Studios\\Quake II", homedir, sizeof(homedir) - 2)) {
if (Sys_GetRereleaseHomeDir(homedir, sizeof(homedir) - 2)) {
FS_NormalizePath(homedir);
Cvar_Set("homedir", homedir);
}
Expand Down
32 changes: 32 additions & 0 deletions src/windows/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma message("No Xbox support")
#endif

#if defined(_WIN32)
#include <Knownfolders.h>
#include <Shlobj.h>
#endif

HINSTANCE hGlobalInstance;

#if USE_WINSVC
Expand Down Expand Up @@ -1287,6 +1292,33 @@ const sys_getinstalledgamepath_func_t gamepath_funcs[] = {
NULL
};

// Locate rerelease home dir
bool Sys_GetRereleaseHomeDir(char *path, size_t path_length)
{
bool result = false;
PWSTR saved_games_path = NULL;
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_SavedGames, KF_FLAG_CREATE | KF_FLAG_INIT, NULL, &saved_games_path);
if (!SUCCEEDED(hr))
{
Com_WPrintf("Failed to retrieve Saved Games path (%.8x)\n", hr);
goto done;
}

if (WideCharToMultiByte(CP_UTF8, 0, saved_games_path, -1, path, (int)path_length, NULL, NULL) == 0)
{
DWORD err = GetLastError();
Com_WPrintf("Failed to convert Saved Games path (%d)\n", err);
goto done;
}

Q_strlcat(path, "\\NightDive Studios\\Quake II", path_length);
result = true;

done:
CoTaskMemFree(saved_games_path);
return result;
}

/*
========================================================================
Expand Down

0 comments on commit f6a9ab3

Please sign in to comment.