1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Upgrade platform_get_steam_dir()

This commit is contained in:
Gymnasiast
2022-01-10 13:28:23 +01:00
parent eb2b0c1537
commit 310ad1e400
11 changed files with 98 additions and 102 deletions

View File

@@ -652,8 +652,8 @@ namespace Config
}
}
utf8 steamPath[2048] = { 0 };
if (platform_get_steam_path(steamPath, sizeof(steamPath)))
auto steamPath = Platform::GetSteamPath();
if (!steamPath.empty())
{
std::string location = Path::Combine(steamPath, platform_get_rct1_steam_dir());
if (RCT1DataPresentAtLocation(location.c_str()))
@@ -701,8 +701,8 @@ namespace Config
}
}
utf8 steamPath[2048] = { 0 };
if (platform_get_steam_path(steamPath, sizeof(steamPath)))
auto steamPath = Platform::GetSteamPath();
if (!steamPath.empty())
{
std::string location = Path::Combine(steamPath, platform_get_rct2_steam_dir());
if (Platform::OriginalGameDataExists(location))

View File

@@ -42,11 +42,6 @@ float platform_get_default_scale()
return displayScale;
}
bool platform_get_steam_path(utf8* outPath, size_t outSize)
{
return false;
}
AndroidClassLoader::AndroidClassLoader()
{
log_info("Obtaining JNI class loader");

View File

@@ -34,52 +34,6 @@
# include <pwd.h>
bool platform_get_steam_path(utf8* outPath, size_t outSize)
{
const char* steamRoot = getenv("STEAMROOT");
if (steamRoot != nullptr)
{
safe_strcpy(outPath, steamRoot, outSize);
safe_strcat_path(outPath, "ubuntu12_32/steamapps/content", outSize);
return true;
}
char steamPath[1024] = { 0 };
const char* localSharePath = getenv("XDG_DATA_HOME");
if (localSharePath != nullptr)
{
safe_strcpy(steamPath, localSharePath, sizeof(steamPath));
safe_strcat_path(steamPath, "Steam/ubuntu12_32/steamapps/content", sizeof(steamPath));
if (Path::DirectoryExists(steamPath))
{
safe_strcpy(outPath, steamPath, outSize);
return true;
}
}
const char* homeDir = getpwuid(getuid())->pw_dir;
if (homeDir != nullptr)
{
safe_strcpy(steamPath, homeDir, sizeof(steamPath));
safe_strcat_path(steamPath, ".local/share/Steam/ubuntu12_32/steamapps/content", sizeof(steamPath));
if (Path::DirectoryExists(steamPath))
{
safe_strcpy(outPath, steamPath, outSize);
return true;
}
std::fill_n(steamPath, sizeof(steamPath), 0x00);
safe_strcpy(steamPath, homeDir, sizeof(steamPath));
safe_strcat_path(steamPath, ".steam/steam/ubuntu12_32/steamapps/content", sizeof(steamPath));
if (Path::DirectoryExists(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

@@ -70,6 +70,11 @@ namespace Platform
{
return MeasurementFormat::Metric;
}
std::string GetSteamPath()
{
return "";
}
} // namespace Platform
#endif

View File

@@ -271,6 +271,45 @@ namespace Platform
}
return MeasurementFormat::Metric;
}
std::string GetSteamPath()
{
const char* steamRoot = getenv("STEAMROOT");
if (steamRoot != nullptr)
{
return Path::Combine(steamRoot, "ubuntu12_32/steamapps/content");
}
const char* localSharePath = getenv("XDG_DATA_HOME");
if (localSharePath != nullptr)
{
auto steamPath = Path::Combine(localSharePath, "Steam/ubuntu12_32/steamapps/content");
if (Path::DirectoryExists(steamPath))
{
return steamPath;
}
}
const char* homeDir = getpwuid(getuid())->pw_dir;
if (homeDir == nullptr)
{
return "";
}
auto steamPath = Path::Combine(homeDir, ".local/share/Steam/ubuntu12_32/steamapps/content");
if (Path::DirectoryExists(steamPath))
{
return steamPath;
}
steamPath = Path::Combine(homeDir, ".steam/steam/ubuntu12_32/steamapps/content");
if (Path::DirectoryExists(steamPath))
{
return steamPath;
}
return "";
}
} // namespace Platform
#endif

View File

@@ -822,6 +822,36 @@ namespace Platform
}
return isElevated;
}
std::string GetSteamPath()
{
wchar_t* wSteamPath;
HKEY hKey;
DWORD type, size;
LRESULT result;
if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", &hKey) != ERROR_SUCCESS)
return "";
// Get the size of the path first
if (RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, nullptr, &size) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return "";
}
std::string outPath = "";
wSteamPath = reinterpret_cast<wchar_t*>(malloc(size));
result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, reinterpret_cast<LPBYTE>(wSteamPath), &size);
if (result == ERROR_SUCCESS)
{
auto utf8SteamPath = String::ToUtf8(wSteamPath);
outPath = Path::Combine(utf8SteamPath, "steamapps", "common");
}
free(wSteamPath);
RegCloseKey(hKey);
return outPath;
}
} // namespace Platform
#endif

View File

@@ -21,6 +21,7 @@
# include <Foundation/Foundation.h>
# include <mach-o/dyld.h>
# include <pwd.h>
namespace Platform
{
@@ -231,6 +232,24 @@ namespace Platform
return MeasurementFormat::Imperial;
}
}
std::string GetSteamPath()
{
const char* homeDir = getpwuid(getuid())->pw_dir;
if (homeDir == nullptr)
{
return "";
}
auto steamPath = Path::Combine(
homeDir, "Library/Application Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/steamapps");
if (Path::DirectoryExists(steamPath))
{
return steamPath;
}
return "";
}
}
#endif

View File

@@ -59,6 +59,7 @@ namespace Platform
std::string GetUsername();
std::string GetSteamPath();
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
std::string GetEnvironmentPath(const char* name);
std::string GetHomePath();

View File

@@ -96,35 +96,7 @@ int32_t platform_get_drives()
return GetLogicalDrives();
}
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", nullptr, &type, nullptr, &size) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return false;
}
wSteamPath = reinterpret_cast<wchar_t*>(malloc(size));
result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, reinterpret_cast<LPBYTE>(wSteamPath), &size);
if (result == ERROR_SUCCESS)
{
auto utf8SteamPath = String::ToUtf8(wSteamPath);
safe_strcpy(outPath, utf8SteamPath.c_str(), outSize);
safe_strcat_path(outPath, "steamapps\\common", outSize);
}
free(wSteamPath);
RegCloseKey(hKey);
return result == ERROR_SUCCESS;
}
std::string platform_get_rct1_steam_dir()
{

View File

@@ -46,22 +46,4 @@ bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size)
}
# endif // NO_TTF
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/Steam.AppBundle/Steam/Contents/MacOS/steamapps", sizeof(steamPath));
if (Path::DirectoryExists(steamPath))
{
safe_strcpy(outPath, steamPath, outSize);
return true;
}
}
return false;
}
#endif

View File

@@ -98,7 +98,6 @@ void platform_sleep(uint32_t ms);
void platform_get_user_directory(utf8* outPath, const utf8* subDirectory, size_t outSize);
bool platform_open_common_file_dialog(utf8* outFilename, file_dialog_desc* desc, size_t outSize);
utf8* platform_open_directory_browser(const utf8* title);
bool platform_get_steam_path(utf8* outPath, size_t outSize);
std::string platform_get_rct1_steam_dir();
std::string platform_get_rct2_steam_dir();