RCT2 Steam path locator: improve OS support

Now looks for RCT2 install within OS-specific steam install directories.
Also checks the registry in Windows in case Steam has a custom install
path.
This commit is contained in:
Robert Jordan 2017-10-24 12:36:40 -04:00 committed by Michael Steenbeek
parent d924d771a6
commit c9c0c07eca
6 changed files with 109 additions and 0 deletions

View File

@ -614,6 +614,17 @@ namespace Config
return location;
}
}
utf8 steamPath[2048] = { 0 };
if (platform_get_steam_path(steamPath, sizeof(steamPath)))
{
std::string location = Path::Combine(steamPath, "Rollercoaster Tycoon 2");
if (platform_original_game_data_exists(location.c_str()))
{
return location;
}
}
if (platform_original_game_data_exists(gExePath))
{
return gExePath;

View File

@ -34,6 +34,7 @@
#endif // NO_TTF
#include <fnmatch.h>
#include <locale.h>
#include <pwd.h>
#include "../config/Config.h"
#include "../localisation/language.h"
@ -253,6 +254,52 @@ void platform_get_changelog_path(utf8 *outPath, size_t outSize)
safe_strcat_path(outPath, "changelog.txt", outSize);
}
bool platform_get_steam_path(utf8 * outPath, size_t outSize)
{
const char * steamRoot = getenv("STEAMROOT");
if (steamRoot != NULL)
{
safe_strcpy(outPath, steamRoot, outSize);
safe_strcat_path(outPath, "steamapps/common", outSize);
return true;
}
char steamPath[1024] = { 0 };
const char * localSharePath = getenv("XDG_DATA_HOME");
if (localSharePath != NULL)
{
safe_strcpy(steamPath, localSharePath, sizeof(steamPath));
safe_strcat_path(steamPath, "Steam/steamapps/common", sizeof(steamPath));
if (platform_directory_exists(steamPath))
{
safe_strcpy(outPath, steamPath, outSize);
return true;
}
}
const char * homeDir = getpwuid(getuid())->pw_dir;
if (homeDir != NULL)
{
safe_strcpy(steamPath, homeDir, sizeof(steamPath));
safe_strcat_path(steamPath, ".local/share/Steam/steamapps/common", sizeof(steamPath));
if (platform_directory_exists(steamPath))
{
safe_strcpy(outPath, steamPath, outSize);
return true;
}
memset(steamPath, 0, sizeof(steamPath));
safe_strcpy(steamPath, homeDir, sizeof(steamPath));
safe_strcat_path(steamPath, ".steam/steam/steamapps/common", sizeof(steamPath));
if (platform_directory_exists(steamPath))
{
safe_strcpy(outPath, steamPath, outSize);
return true;
}
}
return false;
}
#ifndef NO_TTF
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size)
{

View File

@ -19,6 +19,7 @@
@import AppKit;
@import Foundation;
#include <mach-o/dyld.h>
#include <pwd.h>
#include "platform.h"
#include "../util/util.h"
#include "../localisation/language.h"
@ -215,4 +216,21 @@ void platform_get_changelog_path(utf8 *outPath, size_t outSize)
safe_strcat_path(outPath, "changelog.txt", outSize);
}
bool platform_get_steam_path(utf8 * outPath, size_t outSize)
{
char steamPath[1024] = { 0 };
const char * homeDir = getpwuid(getuid())->pw_dir;
if (homeDir != NULL)
{
safe_strcpy(steamPath, homeDir, sizeof(steamPath));
safe_strcat_path(steamPath, "Library/Application Support/Steam/steamapps/common", sizeof(steamPath));
if (platform_directory_exists(steamPath))
{
safe_strcpy(outPath, steamPath, outSize);
return true;
}
}
return false;
}
#endif

View File

@ -135,6 +135,7 @@ uint8 platform_get_locale_temperature_format();
uint8 platform_get_locale_date_format();
bool platform_process_is_elevated();
void platform_get_changelog_path(utf8 *outPath, size_t outSize);
bool platform_get_steam_path(utf8 * outPath, size_t outSize);
#ifndef NO_TTF
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size);

View File

@ -27,6 +27,7 @@
#include <libgen.h>
#include <locale.h>
#include <pwd.h>
#include <stdlib.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/time.h>

View File

@ -506,6 +506,37 @@ void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory, size_t
}
}
bool platform_get_steam_path(utf8 * outPath, size_t outSize)
{
wchar_t * wSteamPath;
HKEY hKey;
DWORD type, size;
LRESULT result;
if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", &hKey) != ERROR_SUCCESS)
return false;
// Get the size of the path first
if (RegQueryValueExW(hKey, L"SteamPath", 0, &type, NULL, &size) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return false;
}
wSteamPath = (wchar_t*)malloc(size);
result = RegQueryValueExW(hKey, L"SteamPath", 0, &type, (LPBYTE)wSteamPath, &size);
if (result == ERROR_SUCCESS)
{
utf8 * utf8SteamPath = widechar_to_utf8(wSteamPath);
safe_strcpy(outPath, utf8SteamPath, outSize);
safe_strcat_path(outPath, "steamapps\\common", outSize);
free(utf8SteamPath);
}
free(wSteamPath);
RegCloseKey(hKey);
return result == ERROR_SUCCESS;
}
/**
*
* rct2: 0x00407978