From dcb92a466dbc1684d2dc6d827b894fa83d2d693b Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 28 Nov 2017 20:57:34 +0000 Subject: [PATCH 1/9] Add new base path for user data and config Refactor more path resolution to Platform2.cpp --- src/openrct2/PlatformEnvironment.cpp | 90 ++++++++++------- src/openrct2/PlatformEnvironment.h | 4 +- src/openrct2/core/FileIndex.hpp | 1 + src/openrct2/core/Path.cpp | 5 + src/openrct2/core/Path.hpp | 1 + src/openrct2/platform/Platform2.cpp | 139 ++++++++++++++++++++++++++- src/openrct2/platform/Platform2.h | 12 +++ 7 files changed, 215 insertions(+), 37 deletions(-) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index c21f6c1810..a8be259eae 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -21,11 +21,11 @@ #include "core/Path.hpp" #include "core/String.hpp" #include "OpenRCT2.h" +#include "platform/platform.h" +#include "platform/Platform2.h" #include "PlatformEnvironment.h" #include "Version.h" -#include "platform/platform.h" - using namespace OpenRCT2; class PlatformEnvironment final : public IPlatformEnvironment @@ -36,7 +36,7 @@ private: public: PlatformEnvironment(DIRBASE_VALUES basePaths) { - for (sint32 i = 0; i < 4; i++) + for (sint32 i = 0; i < DIRBASE_COUNT; i++) { _basePath[i] = basePaths[i]; } @@ -59,6 +59,7 @@ public: break; case DIRBASE::OPENRCT2: case DIRBASE::USER: + case DIRBASE::CONFIG: directoryName = DirectoryNamesOpenRCT2[(size_t)did]; break; } @@ -68,21 +69,10 @@ public: std::string GetFilePath(PATHID pathid) const override { - const utf8 * fileName = FileNames[(size_t)pathid]; - const utf8 * basePath = _basePath[(size_t)DIRBASE::USER].c_str(); - if (pathid == PATHID::MP_DAT) - { - basePath = _basePath[(size_t)DIRBASE::RCT1].c_str(); - } - else if (pathid == PATHID::SCORES_RCT2) - { - basePath = _basePath[(size_t)DIRBASE::RCT2].c_str(); - } - - utf8 path[260]; - String::Set(path, sizeof(path), basePath); - Path::Append(path, sizeof(path), fileName); - return std::string(path); + auto dirbase = GetDefaultBaseDirectory(pathid); + auto basePath = GetDirectoryPath(dirbase); + auto fileName = FileNames[(size_t)pathid]; + return Path::Combine(basePath, fileName); } void SetBasePath(DIRBASE base, const std::string &path) override @@ -94,6 +84,30 @@ private: static const char * DirectoryNamesRCT2[]; static const char * DirectoryNamesOpenRCT2[]; static const char * FileNames[]; + + static DIRBASE GetDefaultBaseDirectory(PATHID pathid) + { + switch (pathid) + { + case PATHID::CONFIG: + case PATHID::CONFIG_KEYBOARD: + return DIRBASE::CONFIG; + case PATHID::CACHE_OBJECTS: + case PATHID::CACHE_TRACKS: + case PATHID::CACHE_SCENARIOS: + return DIRBASE::CACHE; + case PATHID::MP_DAT: + return DIRBASE::RCT1; + case PATHID::SCORES_RCT2: + return DIRBASE::RCT2; + case PATHID::NETWORK_GROUPS: + case PATHID::NETWORK_SERVERS: + case PATHID::NETWORK_USERS: + case PATHID::SCORES: + case PATHID::SCORES_LEGACY: + return DIRBASE::USER; + } + } }; IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment(DIRBASE_VALUES basePaths) @@ -103,32 +117,36 @@ IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment(DIRBASE_VALUES basePa IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment() { - utf8 userPath[MAX_PATH]; - platform_resolve_openrct_data_path(); platform_resolve_user_data_path(); - platform_get_user_directory(userPath, nullptr, sizeof(userPath)); - if (!platform_ensure_directory_exists(userPath)) - { - Console::Error::WriteLine("Could not create user directory '%s' (do you have write access to your documents folder?)", userPath); - return nullptr; - } - platform_get_exe_path(gExePath, sizeof(gExePath)); - log_verbose("Setting exe path to %s", gExePath); - config_set_defaults(); if (!config_open_default()) { config_save_default(); } - utf8 path[260]; - std::string basePaths[4]; + std::string basePaths[DIRBASE_COUNT]; basePaths[(size_t)DIRBASE::RCT1] = String::ToStd(gConfigGeneral.rct1_path); basePaths[(size_t)DIRBASE::RCT2] = String::ToStd(gConfigGeneral.rct2_path); - platform_get_openrct_data_path(path, sizeof(path)); - basePaths[(size_t)DIRBASE::OPENRCT2] = std::string(path); - platform_get_user_directory(path, nullptr, sizeof(path)); - basePaths[(size_t)DIRBASE::USER] = std::string(path); + basePaths[(size_t)DIRBASE::OPENRCT2] = Platform::GetInstallPath(); + basePaths[(size_t)DIRBASE::USER] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_DATA), "openrct2"); + basePaths[(size_t)DIRBASE::CONFIG] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CONFIG), "openrct2"); + basePaths[(size_t)DIRBASE::CACHE] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CACHE), "openrct2"); + + // Override paths that have been specified via the command line + if (!String::IsNullOrEmpty(gCustomRCT2DataPath)) + { + basePaths[(size_t)DIRBASE::RCT2] = gCustomRCT2DataPath; + } + if (!String::IsNullOrEmpty(gCustomOpenrctDataPath)) + { + basePaths[(size_t)DIRBASE::OPENRCT2] = gCustomOpenrctDataPath; + } + if (!String::IsNullOrEmpty(gCustomUserDataPath)) + { + basePaths[(size_t)DIRBASE::USER] = gCustomUserDataPath; + basePaths[(size_t)DIRBASE::CONFIG] = gCustomUserDataPath; + basePaths[(size_t)DIRBASE::CACHE] = gCustomUserDataPath; + } IPlatformEnvironment * env = OpenRCT2::CreatePlatformEnvironment(basePaths); @@ -137,6 +155,8 @@ IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment() log_verbose("DIRBASE::RCT2 : %s", env->GetDirectoryPath(DIRBASE::RCT2).c_str()); log_verbose("DIRBASE::OPENRCT2: %s", env->GetDirectoryPath(DIRBASE::OPENRCT2).c_str()); log_verbose("DIRBASE::USER : %s", env->GetDirectoryPath(DIRBASE::USER).c_str()); + log_verbose("DIRBASE::CONFIG : %s", env->GetDirectoryPath(DIRBASE::CONFIG).c_str()); + log_verbose("DIRBASE::CACHE : %s", env->GetDirectoryPath(DIRBASE::CACHE).c_str()); return env; } diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h index 54b97dbeac..de4b9894b8 100644 --- a/src/openrct2/PlatformEnvironment.h +++ b/src/openrct2/PlatformEnvironment.h @@ -29,8 +29,10 @@ namespace OpenRCT2 RCT2, // Base directory for original RollerCoaster Tycoon 2 content. OPENRCT2, // Base directory for OpenRCT2 installation. USER, // Base directory for OpenRCT2 user content. + CONFIG, // Base directory for OpenRCT2 configuration. + CACHE, // Base directory for OpenRCT2 cache files. }; - constexpr sint32 DIRBASE_COUNT = 4; + constexpr sint32 DIRBASE_COUNT = 6; using DIRBASE_VALUES = std::string[DIRBASE_COUNT]; enum class DIRID diff --git a/src/openrct2/core/FileIndex.hpp b/src/openrct2/core/FileIndex.hpp index 8ab8db2074..91ad4b0638 100644 --- a/src/openrct2/core/FileIndex.hpp +++ b/src/openrct2/core/FileIndex.hpp @@ -253,6 +253,7 @@ private: try { log_verbose("FileIndex:Writing index: '%s'", _indexPath.c_str()); + Path::CreateDirectory(Path::GetDirectory(_indexPath)); auto fs = FileStream(_indexPath, FILE_MODE_WRITE); // Write header diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 002d293190..a5849fc64d 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -79,6 +79,11 @@ namespace Path return buffer; } + void CreateDirectory(const std::string &path) + { + platform_ensure_directory_exists(path.c_str()); + } + std::string GetFileName(const std::string &path) { return GetFileName(path.c_str()); diff --git a/src/openrct2/core/Path.hpp b/src/openrct2/core/Path.hpp index 4c055fb48d..e5c4292263 100644 --- a/src/openrct2/core/Path.hpp +++ b/src/openrct2/core/Path.hpp @@ -33,6 +33,7 @@ namespace Path std::string GetDirectory(const std::string &path); utf8 * GetDirectory(const utf8 * path); utf8 * GetDirectory(utf8 * buffer, size_t bufferSize, const utf8 * path); + void CreateDirectory(const std::string &path); std::string GetFileName(const std::string &path); const utf8 * GetFileName(const utf8 * path); std::string GetFileNameWithoutExtension(const std::string &path); diff --git a/src/openrct2/platform/Platform2.cpp b/src/openrct2/platform/Platform2.cpp index 758b00b90c..47bf8312d5 100644 --- a/src/openrct2/platform/Platform2.cpp +++ b/src/openrct2/platform/Platform2.cpp @@ -14,8 +14,18 @@ *****************************************************************************/ #pragma endregion -#include "Platform2.h" +#include +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #include +#else + #include +#endif + +#include "../core/Path.hpp" +#include "../core/String.hpp" +#include "Platform2.h" #include "platform.h" namespace Platform @@ -24,4 +34,131 @@ namespace Platform { return platform_get_ticks(); } + + std::string GetEnvironmentVariable(const std::string &name) + { +#ifdef _WIN32 + auto wname = String::ToUtf16(name); + wchar_t wvalue[MAX_PATH]; + GetEnvironmentVariableW(wname.c_str(), wvalue, sizeof(wvalue)); + return String::ToUtf8(wvalue); +#else + return String::ToStd(getenv(name.c_str())); +#endif + } + + static std::string GetEnvironmentPath(const char * name) + { + auto value = getenv(name); + if (value == nullptr) + { + return std::string(); + } + else + { + auto colon = std::strchr(value, ':'); + if (colon == nullptr) + { + return std::string(value); + } + else + { + return std::string(value, colon); + } + } + } + +#ifdef _WIN32 + std::string GetFolderPath(SPECIAL_FOLDER folder) + { + switch (folder) + { + // We currently store everything under Documents/OpenRCT2 + case SPECIAL_FOLDER::USER_CACHE: + case SPECIAL_FOLDER::USER_CONFIG: + case SPECIAL_FOLDER::USER_DATA: + { + wchar_t wpath[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, nullptr, 0, wpath))) + { + return ToUtf8(std::wstring(wpath)); + } + else + { + return GetFolderPath(SPECIAL_FOLDER::USER_HOME); + } + } + case SPECIAL_FOLDER::USER_HOME: + { + wchar_t wpath[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PROFILE | CSIDL_FLAG_CREATE, nullptr, 0, wpath))) + { + return ToUtf8(std::wstring(wpath)); + } + else + { + // Try default environment variables + auto homedrive = GetEnvironmentVariable("HOMEDRIVE"); + auto homepath = GetEnvironmentVariable("HOMEPATH"); + if (!homedrive.empty() && !homepath.empty()) + { + return Path::Combine(homedrive, homepath); + } + else + { + return "C:\\"; + } + } + } + } + + } +#else + std::string GetFolderPath(SPECIAL_FOLDER folder) + { + switch (folder) + { + case SPECIAL_FOLDER::USER_CACHE: + { + auto path = GetEnvironmentPath("XDG_CACHE_HOME"); + if (path.empty()) + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + path = Path::Combine(home, ".cache"); + } + return path; + } + case SPECIAL_FOLDER::USER_CONFIG: + { + auto path = GetEnvironmentPath("XDG_CONFIG_HOME"); + if (path.empty()) + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + path = Path::Combine(home, ".config"); + } + return path; + } + case SPECIAL_FOLDER::USER_DATA: + { + auto path = GetEnvironmentPath("XDG_DATA_HOME"); + if (path.empty()) + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + path = Path::Combine(home, ".local/share"); + } + return path; + } + case SPECIAL_FOLDER::USER_HOME: + return getpwuid(getuid())->pw_dir; + } + } +#endif + + std::string GetInstallPath() + { + utf8 path[260]; + platform_resolve_openrct_data_path(); + platform_get_openrct_data_path(path, sizeof(path)); + return path; + } } diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index fce41f87b9..5e0dc72319 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -18,11 +18,23 @@ #ifdef __cplusplus +#include #include "../common.h" +enum class SPECIAL_FOLDER +{ + USER_CACHE, + USER_CONFIG, + USER_DATA, + USER_HOME, +}; + namespace Platform { uint32 GetTicks(); + std::string GetEnvironmentVariable(const std::string &name); + std::string GetFolderPath(SPECIAL_FOLDER folder); + std::string GetInstallPath(); } #endif From 66a6aa95f631304047cf8409a12864d89949b3c6 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 28 Nov 2017 21:54:25 +0000 Subject: [PATCH 2/9] Redirect platform_get_user_directory to IPlatformEnvironment - Remove old code for getting user directory, redirect to IPlatformEnvironment. - Fix config loading so that it uses path straight from IPlatformEnvironment. - Add more special folder implementation in Platform2. --- src/openrct2/Context.cpp | 20 ++++++++ src/openrct2/Context.h | 1 + src/openrct2/PlatformEnvironment.cpp | 37 ++++++++++----- src/openrct2/cmdline/RootCommands.cpp | 15 ++---- src/openrct2/config/Config.cpp | 20 +++----- src/openrct2/config/Config.h | 1 - src/openrct2/platform/Platform2.cpp | 28 +++++++---- src/openrct2/platform/android.c | 4 -- src/openrct2/platform/linux.c | 30 ------------ src/openrct2/platform/platform.h | 2 - src/openrct2/platform/posix.c | 67 --------------------------- src/openrct2/platform/windows.c | 46 ------------------ 12 files changed, 76 insertions(+), 195 deletions(-) diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 6910b22b99..afb9d261b8 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -158,6 +158,11 @@ namespace OpenRCT2 return _uiContext; } + IPlatformEnvironment * GetPlatformEnvironment() override + { + return _env; + } + sint32 RunOpenRCT2(int argc, const char * * argv) override { if (Initialise()) @@ -1133,4 +1138,19 @@ extern "C" { return GetContext()->GetUiContext()->SetClipboardText(target); } + + /** + * This function is deprecated. + * Use IPlatformEnvironment instad. + */ + void platform_get_user_directory(utf8 * outPath, const utf8 * subDirectory, size_t outSize) + { + auto env = GetContext()->GetPlatformEnvironment(); + auto path = env->GetDirectoryPath(DIRBASE::USER); + if (!String::IsNullOrEmpty(subDirectory)) + { + path = Path::Combine(path, subDirectory); + } + String::Set(outPath, outSize, path.c_str()); + } } diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 87d8457f49..83961191e3 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -94,6 +94,7 @@ namespace OpenRCT2 virtual Audio::IAudioContext * GetAudioContext() abstract; virtual Ui::IUiContext * GetUiContext() abstract; + virtual IPlatformEnvironment * GetPlatformEnvironment() abstract; virtual sint32 RunOpenRCT2(int argc, const char * * argv) abstract; diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index a8be259eae..9c34a46600 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -115,22 +115,25 @@ IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment(DIRBASE_VALUES basePa return new PlatformEnvironment(basePaths); } +static std::string GetOpenRCT2DirectoryName() +{ +#if defined(__ANDROID__) + return "openrct2-user"; +#else + return "OpenRCT2"; +#endif +} + IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment() { - platform_resolve_user_data_path(); - config_set_defaults(); - if (!config_open_default()) - { - config_save_default(); - } + auto subDirectory = GetOpenRCT2DirectoryName(); + // Set default paths std::string basePaths[DIRBASE_COUNT]; - basePaths[(size_t)DIRBASE::RCT1] = String::ToStd(gConfigGeneral.rct1_path); - basePaths[(size_t)DIRBASE::RCT2] = String::ToStd(gConfigGeneral.rct2_path); basePaths[(size_t)DIRBASE::OPENRCT2] = Platform::GetInstallPath(); - basePaths[(size_t)DIRBASE::USER] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_DATA), "openrct2"); - basePaths[(size_t)DIRBASE::CONFIG] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CONFIG), "openrct2"); - basePaths[(size_t)DIRBASE::CACHE] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CACHE), "openrct2"); + basePaths[(size_t)DIRBASE::USER] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_DATA), subDirectory); + basePaths[(size_t)DIRBASE::CONFIG] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CONFIG), subDirectory); + basePaths[(size_t)DIRBASE::CACHE] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CACHE), subDirectory); // Override paths that have been specified via the command line if (!String::IsNullOrEmpty(gCustomRCT2DataPath)) @@ -148,7 +151,17 @@ IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment() basePaths[(size_t)DIRBASE::CACHE] = gCustomUserDataPath; } - IPlatformEnvironment * env = OpenRCT2::CreatePlatformEnvironment(basePaths); + auto env = OpenRCT2::CreatePlatformEnvironment(basePaths); + + // Now load the config so we can get the RCT1 and RCT2 paths + auto configPath = env->GetFilePath(PATHID::CONFIG); + config_set_defaults(); + if (!config_open(configPath.c_str())) + { + config_save(configPath.c_str()); + } + env->SetBasePath(DIRBASE::RCT1, String::ToStd(gConfigGeneral.rct1_path)); + env->SetBasePath(DIRBASE::RCT2, String::ToStd(gConfigGeneral.rct2_path)); // Log base paths log_verbose("DIRBASE::RCT1 : %s", env->GetDirectoryPath(DIRBASE::RCT1).c_str()); diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index de0dba64eb..414484a7f4 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -361,20 +361,13 @@ static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator) return EXITCODE_FAIL; } - // Check user path that will contain the config - utf8 userPath[MAX_PATH]; - platform_resolve_user_data_path(); - platform_get_user_directory(userPath, nullptr, sizeof(userPath)); - if (!platform_ensure_directory_exists(userPath)) { - Console::Error::WriteLine("Unable to access or create directory '%s'.", userPath); - return EXITCODE_FAIL; - } - // Update RCT2 path in config + auto env = OpenRCT2::CreatePlatformEnvironment(); + auto configPath = env->GetFilePath(OpenRCT2::PATHID::CONFIG); config_set_defaults(); - config_open_default(); + config_open(configPath.c_str()); String::DiscardDuplicate(&gConfigGeneral.rct2_path, path); - if (config_save_default()) + if (config_save(configPath.c_str())) { Console::WriteFormat("Updating RCT2 path to '%s'.", path); Console::WriteLine(); diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 6db32d749a..c911c8e24f 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -27,6 +27,7 @@ #include "../interface/window.h" #include "../network/network.h" #include "../OpenRCT2.h" +#include "../PlatformEnvironment.h" #include "../ui/UiContext.h" #include "Config.h" #include "IniReader.hpp" @@ -665,7 +666,12 @@ extern "C" } config_release(); - return Config::ReadFile(path); + auto result = Config::ReadFile(path); + if (result) + { + currency_load_custom_currency_config(); + } + return result; } bool config_save(const utf8 * path) @@ -707,18 +713,6 @@ extern "C" Path::Append(outPath, size, "config.ini"); } - bool config_open_default() - { - utf8 path[MAX_PATH]; - config_get_default_path(path, sizeof(path)); - if (config_open(path)) - { - currency_load_custom_currency_config(); - return true; - } - return false; - } - bool config_save_default() { utf8 path[MAX_PATH]; diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index 495bc9427c..75877d80b9 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -251,7 +251,6 @@ extern "C" void config_get_default_path(utf8 *outPath, size_t size); void config_set_defaults(); void config_release(); - bool config_open_default(); bool config_save_default(); bool config_find_or_browse_install_directory(); #ifdef __cplusplus diff --git a/src/openrct2/platform/Platform2.cpp b/src/openrct2/platform/Platform2.cpp index 47bf8312d5..e5ab67e23e 100644 --- a/src/openrct2/platform/Platform2.cpp +++ b/src/openrct2/platform/Platform2.cpp @@ -68,11 +68,11 @@ namespace Platform } } -#ifdef _WIN32 std::string GetFolderPath(SPECIAL_FOLDER folder) { switch (folder) { +#if defined(_WIN32) // We currently store everything under Documents/OpenRCT2 case SPECIAL_FOLDER::USER_CACHE: case SPECIAL_FOLDER::USER_CONFIG: @@ -110,14 +110,24 @@ namespace Platform } } } - } - - } +#elif defined (__ANDROID__) + // Andorid builds currently only read from /sdcard/openrct2* + case SPECIAL_FOLDER::USER_CACHE: + case SPECIAL_FOLDER::USER_CONFIG: + case SPECIAL_FOLDER::USER_DATA: + case SPECIAL_FOLDER::USER_HOME: + return "/sdcard"; +#elif defined (__MACOS__) + // macOS stores everything in ~/Library/Application Support/OpenRCT2 + case SPECIAL_FOLDER::USER_CACHE: + case SPECIAL_FOLDER::USER_CONFIG: + case SPECIAL_FOLDER::USER_DATA: + case SPECIAL_FOLDER::USER_HOME: + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + return Path::Combine(home, "/Library/Application Support"); + } #else - std::string GetFolderPath(SPECIAL_FOLDER folder) - { - switch (folder) - { case SPECIAL_FOLDER::USER_CACHE: { auto path = GetEnvironmentPath("XDG_CACHE_HOME"); @@ -150,9 +160,9 @@ namespace Platform } case SPECIAL_FOLDER::USER_HOME: return getpwuid(getuid())->pw_dir; +#endif } } -#endif std::string GetInstallPath() { diff --git a/src/openrct2/platform/android.c b/src/openrct2/platform/android.c index 383bf33ef2..84de7d0cc4 100644 --- a/src/openrct2/platform/android.c +++ b/src/openrct2/platform/android.c @@ -29,10 +29,6 @@ void platform_get_exe_path(utf8 *outPath, size_t outSize) safe_strcpy(outPath, "/sdcard/openrct2", outSize); } -void platform_posix_sub_user_data_path(char *buffer, size_t size, const char *homedir) { - safe_strcpy(buffer, "/sdcard/openrct2-user/", size); -} - #ifndef NO_TTF bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size) { diff --git a/src/openrct2/platform/linux.c b/src/openrct2/platform/linux.c index a221346833..90d951809f 100644 --- a/src/openrct2/platform/linux.c +++ b/src/openrct2/platform/linux.c @@ -78,36 +78,6 @@ void platform_get_exe_path(utf8 *outPath, size_t outSize) safe_strcpy(outPath, exePath, outSize); } -/** - * Default directory fallback is: - * - (command line argument) - * - $XDG_CONFIG_HOME/OpenRCT2 - * - /home/[uid]/.config/OpenRCT2 - */ -void platform_posix_sub_user_data_path(char *buffer, size_t size, const char *homedir) { - const char *configdir = getenv("XDG_CONFIG_HOME"); - log_verbose("configdir = '%s'", configdir); - if (configdir == NULL) - { - log_verbose("configdir was null, used getuid, now is = '%s'", homedir); - if (homedir == NULL) - { - log_fatal("Couldn't find user data directory"); - exit(-1); - return; - } - - safe_strcpy(buffer, homedir, size); - safe_strcat_path(buffer, ".config", size); - } - else - { - safe_strcpy(buffer, configdir, size); - } - safe_strcat_path(buffer, "OpenRCT2", size); - path_end_with_separator(buffer, size); -} - /** * Default directory fallback is: * - (command line argument) diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index 6413612ea5..eb9b7a387e 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -120,7 +120,6 @@ bool platform_file_move(const utf8 *srcPath, const utf8 *dstPath); bool platform_file_delete(const utf8 *path); uint32 platform_get_ticks(); void platform_sleep(uint32 ms); -void platform_resolve_user_data_path(); void platform_resolve_openrct_data_path(); void platform_get_openrct_data_path(utf8 *outPath, size_t outSize); void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory, size_t outSize); @@ -167,7 +166,6 @@ void core_init(); #endif // _WIN32 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) || defined(__ANDROID__) - void platform_posix_sub_user_data_path(char *buffer, size_t size, const char *homedir); void platform_posix_sub_resolve_openrct_data_path(utf8 *out, size_t size); #endif diff --git a/src/openrct2/platform/posix.c b/src/openrct2/platform/posix.c index 219a10225b..cbf852a886 100644 --- a/src/openrct2/platform/posix.c +++ b/src/openrct2/platform/posix.c @@ -683,54 +683,6 @@ static wchar_t *regular_to_wchar(const char* src) return w_buffer; } -/** - * Default directory fallback is: - * - (command line argument) - * - - */ -void platform_resolve_user_data_path() -{ - - if (gCustomUserDataPath[0] != 0) { - if (!platform_ensure_directory_exists(gCustomUserDataPath)) { - log_error("Failed to create directory \"%s\", make sure you have permissions.", gCustomUserDataPath); - return; - } - char *path; - if ((path = realpath(gCustomUserDataPath, NULL)) == NULL) { - log_error("Could not resolve path \"%s\"", gCustomUserDataPath); - return; - } - - safe_strcpy(_userDataDirectoryPath, path, MAX_PATH); - free(path); - - // Ensure path ends with separator - path_end_with_separator(_userDataDirectoryPath, MAX_PATH); - log_verbose("User data path resolved to: %s", _userDataDirectoryPath); - if (!platform_directory_exists(_userDataDirectoryPath)) { - log_error("Custom user data directory %s does not exist", _userDataDirectoryPath); - } - return; - } - - char buffer[MAX_PATH]; - log_verbose("buffer = '%s'", buffer); - - const char *homedir = getpwuid(getuid())->pw_dir; - platform_posix_sub_user_data_path(buffer, MAX_PATH, homedir); - - log_verbose("OpenRCT2 user data directory = '%s'", buffer); - sint32 len = strnlen(buffer, MAX_PATH); - wchar_t *w_buffer = regular_to_wchar(buffer); - w_buffer[len] = '\0'; - utf8 *path = widechar_to_utf8(w_buffer); - free(w_buffer); - safe_strcpy(_userDataDirectoryPath, path, MAX_PATH); - free(path); - log_verbose("User data path resolved to: %s", _userDataDirectoryPath); -} - void platform_get_openrct_data_path(utf8 *outPath, size_t outSize) { safe_strcpy(outPath, _openrctDataDirectoryPath, outSize); @@ -778,25 +730,6 @@ void platform_resolve_openrct_data_path() log_verbose("Trying to use OpenRCT2 data in %s", _openrctDataDirectoryPath); } -void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory, size_t outSize) -{ - char buffer[MAX_PATH]; - safe_strcpy(buffer, _userDataDirectoryPath, sizeof(buffer)); - if (subDirectory != NULL && subDirectory[0] != 0) { - log_verbose("adding subDirectory '%s'", subDirectory); - safe_strcat_path(buffer, subDirectory, sizeof(buffer)); - path_end_with_separator(buffer, sizeof(buffer)); - } - sint32 len = strnlen(buffer, MAX_PATH); - wchar_t *w_buffer = regular_to_wchar(buffer); - w_buffer[len] = '\0'; - utf8 *path = widechar_to_utf8(w_buffer); - free(w_buffer); - safe_strcpy(outPath, path, outSize); - free(path); - log_verbose("outPath + subDirectory = '%s'", buffer); -} - time_t platform_file_get_modified_time(const utf8* path){ struct stat buf; if (stat(path, &buf) == 0) { diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index 95dfc2fa2a..72b6c23c90 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -460,52 +460,6 @@ void platform_get_changelog_path(utf8 *outPath, size_t outSize) safe_strcat_path(outPath, "changelog.txt", outSize); } -/** - * Default directory fallback is: - * - (command line argument) - * - C:\Users\%USERNAME%\OpenRCT2 (as from SHGetFolderPathW) - */ -void platform_resolve_user_data_path() -{ - wchar_t wOutPath[MAX_PATH]; - - if (gCustomUserDataPath[0] != 0) { - wchar_t *customUserDataPathW = utf8_to_widechar(gCustomUserDataPath); - if (GetFullPathNameW(customUserDataPathW, countof(wOutPath), wOutPath, NULL) == 0) { - log_fatal("Unable to resolve path '%s'.", gCustomUserDataPath); - exit(-1); - } - utf8 *outPathTemp = widechar_to_utf8(wOutPath); - safe_strcpy(_userDataDirectoryPath, outPathTemp, sizeof(_userDataDirectoryPath)); - free(outPathTemp); - free(customUserDataPathW); - - path_end_with_separator(_userDataDirectoryPath, sizeof(_userDataDirectoryPath)); - return; - } - - if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, wOutPath))) { - utf8 *outPathTemp = widechar_to_utf8(wOutPath); - safe_strcpy(_userDataDirectoryPath, outPathTemp, sizeof(_userDataDirectoryPath)); - free(outPathTemp); - - safe_strcat_path(_userDataDirectoryPath, "OpenRCT2", sizeof(_userDataDirectoryPath)); - path_end_with_separator(_userDataDirectoryPath, sizeof(_userDataDirectoryPath)); - } else { - log_fatal("Unable to resolve user data path."); - exit(-1); - } -} - -void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory, size_t outSize) -{ - safe_strcpy(outPath, _userDataDirectoryPath, outSize); - if (subDirectory != NULL && subDirectory[0] != 0) { - safe_strcat_path(outPath, subDirectory, outSize); - path_end_with_separator(outPath, outSize); - } -} - bool platform_get_steam_path(utf8 * outPath, size_t outSize) { wchar_t * wSteamPath; From 679aae801dad8a665ce653ad3e6f6af039d8e5ff Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 28 Nov 2017 22:46:37 +0000 Subject: [PATCH 3/9] Fix GetFolderPath for Windows --- src/openrct2/PlatformEnvironment.cpp | 1 + src/openrct2/platform/Platform2.cpp | 39 +++++++++++++++++++++------- src/openrct2/platform/platform.h | 1 + src/openrct2/util/util.c | 4 +++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 9c34a46600..57ca672e14 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -105,6 +105,7 @@ private: case PATHID::NETWORK_USERS: case PATHID::SCORES: case PATHID::SCORES_LEGACY: + default: return DIRBASE::USER; } } diff --git a/src/openrct2/platform/Platform2.cpp b/src/openrct2/platform/Platform2.cpp index e5ab67e23e..f7bac368a1 100644 --- a/src/openrct2/platform/Platform2.cpp +++ b/src/openrct2/platform/Platform2.cpp @@ -18,6 +18,8 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include + #include + #undef GetEnvironmentVariable #else #include #endif @@ -25,6 +27,7 @@ #include "../core/Path.hpp" #include "../core/String.hpp" +#include "../core/Util.hpp" #include "Platform2.h" #include "platform.h" @@ -38,10 +41,22 @@ namespace Platform std::string GetEnvironmentVariable(const std::string &name) { #ifdef _WIN32 + std::wstring result; auto wname = String::ToUtf16(name); - wchar_t wvalue[MAX_PATH]; - GetEnvironmentVariableW(wname.c_str(), wvalue, sizeof(wvalue)); - return String::ToUtf8(wvalue); + wchar_t wvalue[256]; + auto valueSize = GetEnvironmentVariableW(wname.c_str(), wvalue, (DWORD)Util::CountOf(wvalue)); + if (valueSize < Util::CountOf(wvalue)) + { + result = wvalue; + } + else + { + auto wlvalue = new wchar_t[valueSize]; + GetEnvironmentVariableW(wname.c_str(), wlvalue, valueSize); + result = wlvalue; + delete wlvalue; + } + return String::ToUtf8(result); #else return String::ToStd(getenv(name.c_str())); #endif @@ -78,10 +93,12 @@ namespace Platform case SPECIAL_FOLDER::USER_CONFIG: case SPECIAL_FOLDER::USER_DATA: { - wchar_t wpath[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, nullptr, 0, wpath))) + wchar_t * wpath = nullptr; + if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, nullptr, &wpath))) { - return ToUtf8(std::wstring(wpath)); + auto path = String::ToUtf8(std::wstring(wpath)); + CoTaskMemFree(wpath); + return path; } else { @@ -90,10 +107,12 @@ namespace Platform } case SPECIAL_FOLDER::USER_HOME: { - wchar_t wpath[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PROFILE | CSIDL_FLAG_CREATE, nullptr, 0, wpath))) + wchar_t * wpath = nullptr; + if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Profile, KF_FLAG_CREATE, nullptr, &wpath))) { - return ToUtf8(std::wstring(wpath)); + auto path = String::ToUtf8(std::wstring(wpath)); + CoTaskMemFree(wpath); + return path; } else { @@ -161,6 +180,8 @@ namespace Platform case SPECIAL_FOLDER::USER_HOME: return getpwuid(getuid())->pw_dir; #endif + default: + return std::string(); } } diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index eb9b7a387e..78ed6fb748 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -153,6 +153,7 @@ void core_init(); #define WIN32_LEAN_AND_MEAN #endif #include + #undef CreateDirectory #undef CreateWindow #undef GetMessage diff --git a/src/openrct2/util/util.c b/src/openrct2/util/util.c index dadc9f3bed..273132fda6 100644 --- a/src/openrct2/util/util.c +++ b/src/openrct2/util/util.c @@ -385,6 +385,10 @@ char *safe_strcat(char *destination, const char *source, size_t size) char *safe_strcat_path(char *destination, const char *source, size_t size) { path_end_with_separator(destination, size); + if (source[0] == *PATH_SEPARATOR) + { + source = source + 1; + } return safe_strcat(destination, source, size); } From ea356cd2b9e24aad031ba1726166dcfb2b6b50c4 Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 29 Nov 2017 00:09:13 +0000 Subject: [PATCH 4/9] Fix mingw --- src/openrct2/platform/Platform2.cpp | 93 +++++++++++++++++++++-------- src/openrct2/platform/windows.c | 1 - 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/openrct2/platform/Platform2.cpp b/src/openrct2/platform/Platform2.cpp index f7bac368a1..974c12745a 100644 --- a/src/openrct2/platform/Platform2.cpp +++ b/src/openrct2/platform/Platform2.cpp @@ -20,6 +20,10 @@ #include #include #undef GetEnvironmentVariable + + #if !defined(__MINGW32__) && ((NTDDI_VERSION >= NTDDI_VISTA) && !defined(_USING_V110_SDK71_) && !defined(_ATL_XP_TARGETING)) + #define __USE_SHGETKNOWNFOLDERPATH__ + #endif #else #include #endif @@ -62,6 +66,7 @@ namespace Platform #endif } +#ifndef _WIN32 static std::string GetEnvironmentPath(const char * name) { auto value = getenv(name); @@ -82,6 +87,50 @@ namespace Platform } } } +#endif + + static std::string GetHomePathViaEnvironment() + { +#ifdef _WIN32 + std::string result; + auto homedrive = GetEnvironmentVariable("HOMEDRIVE"); + auto homepath = GetEnvironmentVariable("HOMEPATH"); + if (!homedrive.empty() && !homepath.empty()) + { + result = Path::Combine(homedrive, homepath); + } + return result; +#else + return GetEnvironmentVariable("HOME"); +#endif + } + +#ifdef _WIN32 +#ifdef __USE_SHGETKNOWNFOLDERPATH__ + static std::string WIN32_GetKnownFolderPath(REFKNOWNFOLDERID rfid) + { + std::string path; + wchar_t * wpath = nullptr; + if (SUCCEEDED(SHGetKnownFolderPath(rfid, KF_FLAG_CREATE, nullptr, &wpath))) + { + path = String::ToUtf8(std::wstring(wpath)); + } + CoTaskMemFree(wpath); + return path; + } +#else + static std::string WIN32_GetFolderPath(int nFolder) + { + std::string path; + wchar_t wpath[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPathW(nullptr, nFolder | CSIDL_FLAG_CREATE, nullptr, 0, wpath))) + { + path = String::ToUtf8(std::wstring(wpath)); + } + return path; + } +#endif +#endif std::string GetFolderPath(SPECIAL_FOLDER folder) { @@ -93,41 +142,33 @@ namespace Platform case SPECIAL_FOLDER::USER_CONFIG: case SPECIAL_FOLDER::USER_DATA: { - wchar_t * wpath = nullptr; - if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, nullptr, &wpath))) +#ifdef __USE_SHGETKNOWNFOLDERPATH__ + auto path = WIN32_GetKnownFolderPath(FOLDERID_Documents); +#else + auto path = WIN32_GetFolderPath(CSIDL_PERSONAL); +#endif + if (path.empty()) { - auto path = String::ToUtf8(std::wstring(wpath)); - CoTaskMemFree(wpath); - return path; - } - else - { - return GetFolderPath(SPECIAL_FOLDER::USER_HOME); + path = GetFolderPath(SPECIAL_FOLDER::USER_HOME); } + return path; } case SPECIAL_FOLDER::USER_HOME: { - wchar_t * wpath = nullptr; - if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Profile, KF_FLAG_CREATE, nullptr, &wpath))) +#ifdef __USE_SHGETKNOWNFOLDERPATH__ + auto path = WIN32_GetKnownFolderPath(FOLDERID_Profile); +#else + auto path = WIN32_GetFolderPath(CSIDL_PROFILE); +#endif + if (path.empty()) { - auto path = String::ToUtf8(std::wstring(wpath)); - CoTaskMemFree(wpath); - return path; - } - else - { - // Try default environment variables - auto homedrive = GetEnvironmentVariable("HOMEDRIVE"); - auto homepath = GetEnvironmentVariable("HOMEPATH"); - if (!homedrive.empty() && !homepath.empty()) + path = GetHomePathViaEnvironment(); + if (path.empty()) { - return Path::Combine(homedrive, homepath); - } - else - { - return "C:\\"; + path = "C:\\"; } } + return path; } #elif defined (__ANDROID__) // Andorid builds currently only read from /sdcard/openrct2* diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index 72b6c23c90..24c549aa38 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -48,7 +48,6 @@ // The name of the mutex used to prevent multiple instances of the game from running #define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX" -static utf8 _userDataDirectoryPath[MAX_PATH] = { 0 }; static utf8 _openrctDataDirectoryPath[MAX_PATH] = { 0 }; #define OPENRCT2_DLL_MODULE_NAME "openrct2.dll" From bbc389d18e9f6c60b60daf7f8f270e9f83afe3c1 Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 29 Nov 2017 18:05:51 +0000 Subject: [PATCH 5/9] Fix remaining code issues --- src/openrct2/platform/Platform2.cpp | 21 ++++++++++++++++++--- src/openrct2/platform/macos.m | 20 -------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/openrct2/platform/Platform2.cpp b/src/openrct2/platform/Platform2.cpp index 974c12745a..988d45ee00 100644 --- a/src/openrct2/platform/Platform2.cpp +++ b/src/openrct2/platform/Platform2.cpp @@ -171,7 +171,7 @@ namespace Platform return path; } #elif defined (__ANDROID__) - // Andorid builds currently only read from /sdcard/openrct2* + // Android builds currently only read from /sdcard/openrct2* case SPECIAL_FOLDER::USER_CACHE: case SPECIAL_FOLDER::USER_CONFIG: case SPECIAL_FOLDER::USER_DATA: @@ -185,7 +185,7 @@ namespace Platform case SPECIAL_FOLDER::USER_HOME: { auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - return Path::Combine(home, "/Library/Application Support"); + return Path::Combine(home, "Library/Application Support"); } #else case SPECIAL_FOLDER::USER_CACHE: @@ -219,7 +219,22 @@ namespace Platform return path; } case SPECIAL_FOLDER::USER_HOME: - return getpwuid(getuid())->pw_dir; + { + std::string path; + auto pw = getpwuid(getuid()); + if (pw != nullptr) + { + path = pw->pw_dir; + } + else + { + path = GetHomePathViaEnvironment(); + } + if (path.empty()) + { + return "/"; + } + } #endif default: return std::string(); diff --git a/src/openrct2/platform/macos.m b/src/openrct2/platform/macos.m index b439b81463..d5fa987273 100644 --- a/src/openrct2/platform/macos.m +++ b/src/openrct2/platform/macos.m @@ -56,26 +56,6 @@ void platform_get_exe_path(utf8 *outPath, size_t outSize) safe_strcpy(outPath, exePath, outSize); } -/** - * Default directory fallback is: - * - (command line argument) - * - ~/Library/Application Support/OpenRCT2 - */ -void platform_posix_sub_user_data_path(char *buffer, size_t size, const char *homedir) { - if (homedir == NULL) - { - log_fatal("Couldn't find user data directory"); - exit(-1); - return; - } - - safe_strcpy(buffer, homedir, size); - safe_strcat_path(buffer, "Library", size); - safe_strcat_path(buffer, "Application Support", size); - safe_strcat_path(buffer, "OpenRCT2", size); - path_end_with_separator(buffer, size); -} - /** * Default directory fallback is: * - (command line argument) From 205fdaefa72944109a3915e879b1784157007872 Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 1 Dec 2017 00:54:03 +0000 Subject: [PATCH 6/9] Split up Platform2 by OS --- src/openrct2/platform/Platform.Android.cpp | 39 ++++++ src/openrct2/platform/Platform.Linux.cpp | 67 ++++++++++ src/openrct2/platform/Platform.Posix.cpp | 87 ++++++++++++ .../{Platform2.cpp => Platform.Win32.cpp} | 124 ++---------------- src/openrct2/platform/Platform.macOS.cpp | 44 +++++++ src/openrct2/platform/Platform2.h | 5 + 6 files changed, 253 insertions(+), 113 deletions(-) create mode 100644 src/openrct2/platform/Platform.Android.cpp create mode 100644 src/openrct2/platform/Platform.Linux.cpp create mode 100644 src/openrct2/platform/Platform.Posix.cpp rename src/openrct2/platform/{Platform2.cpp => Platform.Win32.cpp} (55%) create mode 100644 src/openrct2/platform/Platform.macOS.cpp diff --git a/src/openrct2/platform/Platform.Android.cpp b/src/openrct2/platform/Platform.Android.cpp new file mode 100644 index 0000000000..18f257f50f --- /dev/null +++ b/src/openrct2/platform/Platform.Android.cpp @@ -0,0 +1,39 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#ifdef __ANDROID__ + +#include "Platform2.h" + +namespace Platform +{ + std::string GetFolderPath(SPECIAL_FOLDER folder) + { + // Android builds currently only read from /sdcard/openrct2* + switch (folder) + { + case SPECIAL_FOLDER::USER_CACHE: + case SPECIAL_FOLDER::USER_CONFIG: + case SPECIAL_FOLDER::USER_DATA: + case SPECIAL_FOLDER::USER_HOME: + return "/sdcard"; + default: + return std::string(); + } + } +} + +#endif diff --git a/src/openrct2/platform/Platform.Linux.cpp b/src/openrct2/platform/Platform.Linux.cpp new file mode 100644 index 0000000000..c6e4f03878 --- /dev/null +++ b/src/openrct2/platform/Platform.Linux.cpp @@ -0,0 +1,67 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#ifdef __linux__ + +#include +#include "../core/Path.hpp" +#include "Platform2.h" + +namespace Platform +{ + std::string GetFolderPath(SPECIAL_FOLDER folder) + { + switch (folder) + { + case SPECIAL_FOLDER::USER_CACHE: + { + auto path = GetEnvironmentPath("XDG_CACHE_HOME"); + if (path.empty()) + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + path = Path::Combine(home, ".cache"); + } + return path; + } + case SPECIAL_FOLDER::USER_CONFIG: + { + auto path = GetEnvironmentPath("XDG_CONFIG_HOME"); + if (path.empty()) + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + path = Path::Combine(home, ".config"); + } + return path; + } + case SPECIAL_FOLDER::USER_DATA: + { + auto path = GetEnvironmentPath("XDG_DATA_HOME"); + if (path.empty()) + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + path = Path::Combine(home, ".local/share"); + } + return path; + } + case SPECIAL_FOLDER::USER_HOME: + return GetHomePath(); + default: + return std::string(); + } + } +} + +#endif diff --git a/src/openrct2/platform/Platform.Posix.cpp b/src/openrct2/platform/Platform.Posix.cpp new file mode 100644 index 0000000000..18b258cbae --- /dev/null +++ b/src/openrct2/platform/Platform.Posix.cpp @@ -0,0 +1,87 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) + +#include +#include +#include +#include "../core/String.hpp" +#include "Platform2.h" +#include "platform.h" + +namespace Platform +{ + uint32 GetTicks() + { + return platform_get_ticks(); + } + + std::string GetEnvironmentVariable(const std::string &name) + { + return String::ToStd(getenv(name.c_str())); + } + + std::string GetEnvironmentPath(const char * name) + { + auto value = getenv(name); + if (value == nullptr) + { + return std::string(); + } + else + { + auto colon = std::strchr(value, ':'); + if (colon == nullptr) + { + return std::string(value); + } + else + { + return std::string(value, colon); + } + } + } + + std::string GetHomePath() + { + std::string path; + auto pw = getpwuid(getuid()); + if (pw != nullptr) + { + path = pw->pw_dir; + } + else + { + path = GetEnvironmentVariable("HOME"); + } + if (path.empty()) + { + path = "/"; + } + return path; + } + + std::string GetInstallPath() + { + utf8 path[MAX_PATH]; + platform_resolve_openrct_data_path(); + platform_get_openrct_data_path(path, sizeof(path)); + return path; + } +} + +#endif diff --git a/src/openrct2/platform/Platform2.cpp b/src/openrct2/platform/Platform.Win32.cpp similarity index 55% rename from src/openrct2/platform/Platform2.cpp rename to src/openrct2/platform/Platform.Win32.cpp index 988d45ee00..3b94c7f818 100644 --- a/src/openrct2/platform/Platform2.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -14,21 +14,17 @@ *****************************************************************************/ #pragma endregion -#include #ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN - #include - #include - #undef GetEnvironmentVariable - #if !defined(__MINGW32__) && ((NTDDI_VERSION >= NTDDI_VISTA) && !defined(_USING_V110_SDK71_) && !defined(_ATL_XP_TARGETING)) - #define __USE_SHGETKNOWNFOLDERPATH__ - #endif -#else - #include +#define WIN32_LEAN_AND_MEAN +#include +#include +#undef GetEnvironmentVariable + +#if !defined(__MINGW32__) && ((NTDDI_VERSION >= NTDDI_VISTA) && !defined(_USING_V110_SDK71_) && !defined(_ATL_XP_TARGETING)) + #define __USE_SHGETKNOWNFOLDERPATH__ #endif - #include "../core/Path.hpp" #include "../core/String.hpp" #include "../core/Util.hpp" @@ -44,7 +40,6 @@ namespace Platform std::string GetEnvironmentVariable(const std::string &name) { -#ifdef _WIN32 std::wstring result; auto wname = String::ToUtf16(name); wchar_t wvalue[256]; @@ -58,40 +53,13 @@ namespace Platform auto wlvalue = new wchar_t[valueSize]; GetEnvironmentVariableW(wname.c_str(), wlvalue, valueSize); result = wlvalue; - delete wlvalue; + delete[] wlvalue; } return String::ToUtf8(result); -#else - return String::ToStd(getenv(name.c_str())); -#endif } -#ifndef _WIN32 - static std::string GetEnvironmentPath(const char * name) - { - auto value = getenv(name); - if (value == nullptr) - { - return std::string(); - } - else - { - auto colon = std::strchr(value, ':'); - if (colon == nullptr) - { - return std::string(value); - } - else - { - return std::string(value, colon); - } - } - } -#endif - static std::string GetHomePathViaEnvironment() { -#ifdef _WIN32 std::string result; auto homedrive = GetEnvironmentVariable("HOMEDRIVE"); auto homepath = GetEnvironmentVariable("HOMEPATH"); @@ -100,12 +68,8 @@ namespace Platform result = Path::Combine(homedrive, homepath); } return result; -#else - return GetEnvironmentVariable("HOME"); -#endif } -#ifdef _WIN32 #ifdef __USE_SHGETKNOWNFOLDERPATH__ static std::string WIN32_GetKnownFolderPath(REFKNOWNFOLDERID rfid) { @@ -129,14 +93,12 @@ namespace Platform } return path; } -#endif #endif std::string GetFolderPath(SPECIAL_FOLDER folder) { switch (folder) { -#if defined(_WIN32) // We currently store everything under Documents/OpenRCT2 case SPECIAL_FOLDER::USER_CACHE: case SPECIAL_FOLDER::USER_CONFIG: @@ -170,72 +132,6 @@ namespace Platform } return path; } -#elif defined (__ANDROID__) - // Android builds currently only read from /sdcard/openrct2* - case SPECIAL_FOLDER::USER_CACHE: - case SPECIAL_FOLDER::USER_CONFIG: - case SPECIAL_FOLDER::USER_DATA: - case SPECIAL_FOLDER::USER_HOME: - return "/sdcard"; -#elif defined (__MACOS__) - // macOS stores everything in ~/Library/Application Support/OpenRCT2 - case SPECIAL_FOLDER::USER_CACHE: - case SPECIAL_FOLDER::USER_CONFIG: - case SPECIAL_FOLDER::USER_DATA: - case SPECIAL_FOLDER::USER_HOME: - { - auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - return Path::Combine(home, "Library/Application Support"); - } -#else - case SPECIAL_FOLDER::USER_CACHE: - { - auto path = GetEnvironmentPath("XDG_CACHE_HOME"); - if (path.empty()) - { - auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - path = Path::Combine(home, ".cache"); - } - return path; - } - case SPECIAL_FOLDER::USER_CONFIG: - { - auto path = GetEnvironmentPath("XDG_CONFIG_HOME"); - if (path.empty()) - { - auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - path = Path::Combine(home, ".config"); - } - return path; - } - case SPECIAL_FOLDER::USER_DATA: - { - auto path = GetEnvironmentPath("XDG_DATA_HOME"); - if (path.empty()) - { - auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - path = Path::Combine(home, ".local/share"); - } - return path; - } - case SPECIAL_FOLDER::USER_HOME: - { - std::string path; - auto pw = getpwuid(getuid()); - if (pw != nullptr) - { - path = pw->pw_dir; - } - else - { - path = GetHomePathViaEnvironment(); - } - if (path.empty()) - { - return "/"; - } - } -#endif default: return std::string(); } @@ -243,9 +139,11 @@ namespace Platform std::string GetInstallPath() { - utf8 path[260]; + utf8 path[MAX_PATH]; platform_resolve_openrct_data_path(); platform_get_openrct_data_path(path, sizeof(path)); return path; } } + +#endif diff --git a/src/openrct2/platform/Platform.macOS.cpp b/src/openrct2/platform/Platform.macOS.cpp new file mode 100644 index 0000000000..25e5a9bd4c --- /dev/null +++ b/src/openrct2/platform/Platform.macOS.cpp @@ -0,0 +1,44 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#ifdef __MACOS__ + +#include "../core/Path.hpp" +#include "Platform2.h" + +namespace Platform +{ + std::string GetFolderPath(SPECIAL_FOLDER folder) + { + // macOS stores everything in ~/Library/Application Support/OpenRCT2 + switch (folder) + { + case SPECIAL_FOLDER::USER_CACHE: + case SPECIAL_FOLDER::USER_CONFIG: + case SPECIAL_FOLDER::USER_DATA: + { + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + return Path::Combine(home, "Library/Application Support"); + } + case SPECIAL_FOLDER::USER_HOME: + return GetHomePath(); + default: + return std::string(); + } + } +} + +#endif diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 5e0dc72319..16f5eb9575 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -35,6 +35,11 @@ namespace Platform std::string GetEnvironmentVariable(const std::string &name); std::string GetFolderPath(SPECIAL_FOLDER folder); std::string GetInstallPath(); + +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) + std::string GetEnvironmentPath(const char * name); + std::string GetHomePath(); +#endif } #endif From 3dfb4214f34c6d29203390cec50221bdc9d8d290 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Fri, 1 Dec 2017 11:09:44 +0100 Subject: [PATCH 7/9] Fix Xcode project --- OpenRCT2.xcodeproj/project.pbxproj | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index a6834358bd..7d20b3c72f 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -117,6 +117,12 @@ 4CB832A71EFBDCCE00B88761 /* land_tool.c in Sources */ = {isa = PBXBuildFile; fileRef = 4CB832A51EFBDCCE00B88761 /* land_tool.c */; }; 4CB832AB1EFFB8D100B88761 /* ttf_sdlport.c in Sources */ = {isa = PBXBuildFile; fileRef = 4CB832A81EFFB8D100B88761 /* ttf_sdlport.c */; }; 4CB832AC1EFFB8D100B88761 /* ttf.c in Sources */ = {isa = PBXBuildFile; fileRef = 4CB832A91EFFB8D100B88761 /* ttf.c */; }; + 4CE462431FD1612C0001CD98 /* android.c in Sources */ = {isa = PBXBuildFile; fileRef = 4CE462421FD1612B0001CD98 /* android.c */; }; + 4CE462451FD161360001CD98 /* Platform.Android.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE462441FD161360001CD98 /* Platform.Android.cpp */; }; + 4CE4624A1FD1613D0001CD98 /* Platform.Linux.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE462461FD1613D0001CD98 /* Platform.Linux.cpp */; }; + 4CE4624B1FD1613D0001CD98 /* Platform.macOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE462471FD1613D0001CD98 /* Platform.macOS.cpp */; }; + 4CE4624C1FD1613D0001CD98 /* Platform.Posix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE462481FD1613D0001CD98 /* Platform.Posix.cpp */; }; + 4CE4624D1FD1613D0001CD98 /* Platform.Win32.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE462491FD1613D0001CD98 /* Platform.Win32.cpp */; }; 4CF788C01F1B787700C611BF /* Painter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF788BE1F1B787700C611BF /* Painter.cpp */; }; 4CFBCD5E1F27CD8000D74FB6 /* SmallScenery.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CFBCD5D1F27CD8000D74FB6 /* SmallScenery.cpp */; }; 4CFE4E801F90A3F1005243C2 /* Peep.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CFE4E7B1F90A3F1005243C2 /* Peep.cpp */; }; @@ -392,7 +398,6 @@ F76C86A31EC4E88400FA49E2 /* Crash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F76C845A1EC4E7CC00FA49E2 /* Crash.cpp */; }; F76C86A51EC4E88400FA49E2 /* linux.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C845C1EC4E7CC00FA49E2 /* linux.c */; }; F76C86A61EC4E88400FA49E2 /* macos.m in Sources */ = {isa = PBXBuildFile; fileRef = F76C845D1EC4E7CC00FA49E2 /* macos.m */; }; - F76C86A81EC4E88400FA49E2 /* Platform2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F76C845F1EC4E7CC00FA49E2 /* Platform2.cpp */; }; F76C86AA1EC4E88400FA49E2 /* posix.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84611EC4E7CC00FA49E2 /* posix.c */; }; F76C86AB1EC4E88400FA49E2 /* shared.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84621EC4E7CC00FA49E2 /* shared.c */; }; F76C86AC1EC4E88400FA49E2 /* windows.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84631EC4E7CC00FA49E2 /* windows.c */; }; @@ -728,6 +733,12 @@ 4CB832A81EFFB8D100B88761 /* ttf_sdlport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttf_sdlport.c; sourceTree = ""; }; 4CB832A91EFFB8D100B88761 /* ttf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttf.c; sourceTree = ""; }; 4CB832AA1EFFB8D100B88761 /* ttf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ttf.h; sourceTree = ""; }; + 4CE462421FD1612B0001CD98 /* android.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = android.c; sourceTree = ""; }; + 4CE462441FD161360001CD98 /* Platform.Android.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Platform.Android.cpp; sourceTree = ""; }; + 4CE462461FD1613D0001CD98 /* Platform.Linux.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Platform.Linux.cpp; sourceTree = ""; }; + 4CE462471FD1613D0001CD98 /* Platform.macOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Platform.macOS.cpp; sourceTree = ""; }; + 4CE462481FD1613D0001CD98 /* Platform.Posix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Platform.Posix.cpp; sourceTree = ""; }; + 4CE462491FD1613D0001CD98 /* Platform.Win32.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Platform.Win32.cpp; sourceTree = ""; }; 4CF788BE1F1B787700C611BF /* Painter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Painter.cpp; sourceTree = ""; }; 4CF788BF1F1B787700C611BF /* Painter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Painter.h; sourceTree = ""; }; 4CFBCD5D1F27CD8000D74FB6 /* SmallScenery.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SmallScenery.cpp; sourceTree = ""; }; @@ -1286,7 +1297,6 @@ F76C845C1EC4E7CC00FA49E2 /* linux.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = linux.c; sourceTree = ""; }; F76C845D1EC4E7CC00FA49E2 /* macos.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = macos.m; sourceTree = ""; }; F76C845E1EC4E7CC00FA49E2 /* platform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = platform.h; sourceTree = ""; }; - F76C845F1EC4E7CC00FA49E2 /* Platform2.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Platform2.cpp; sourceTree = ""; }; F76C84601EC4E7CC00FA49E2 /* Platform2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Platform2.h; sourceTree = ""; }; F76C84611EC4E7CC00FA49E2 /* posix.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = posix.c; sourceTree = ""; }; F76C84621EC4E7CC00FA49E2 /* shared.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = shared.c; sourceTree = ""; }; @@ -2250,12 +2260,17 @@ F76C84591EC4E7CC00FA49E2 /* platform */ = { isa = PBXGroup; children = ( + 4CE462421FD1612B0001CD98 /* android.c */, F76C845A1EC4E7CC00FA49E2 /* Crash.cpp */, F76C845B1EC4E7CC00FA49E2 /* crash.h */, F76C845C1EC4E7CC00FA49E2 /* linux.c */, F76C845D1EC4E7CC00FA49E2 /* macos.m */, + 4CE462441FD161360001CD98 /* Platform.Android.cpp */, F76C845E1EC4E7CC00FA49E2 /* platform.h */, - F76C845F1EC4E7CC00FA49E2 /* Platform2.cpp */, + 4CE462461FD1613D0001CD98 /* Platform.Linux.cpp */, + 4CE462471FD1613D0001CD98 /* Platform.macOS.cpp */, + 4CE462481FD1613D0001CD98 /* Platform.Posix.cpp */, + 4CE462491FD1613D0001CD98 /* Platform.Win32.cpp */, F76C84601EC4E7CC00FA49E2 /* Platform2.h */, F76C84611EC4E7CC00FA49E2 /* posix.c */, F76C84621EC4E7CC00FA49E2 /* shared.c */, @@ -3185,6 +3200,7 @@ C666EE6B1F37ACB10061AA04 /* About.cpp in Sources */, C666ED771F33DBB20061AA04 /* ShortcutKeys.cpp in Sources */, 4C93F1AA1F8B748900A9330D /* SubmarineRide.cpp in Sources */, + 4CE462451FD161360001CD98 /* Platform.Android.cpp in Sources */, C666EE6C1F37ACB10061AA04 /* Changelog.cpp in Sources */, 4C93F1441F8B744400A9330D /* InvertedRollerCoaster.cpp in Sources */, C64644FC1F3FA4120026AC2D /* Footpath.cpp in Sources */, @@ -3199,6 +3215,8 @@ 4CB832AB1EFFB8D100B88761 /* ttf_sdlport.c in Sources */, C654DF371F69C0430040F43D /* Sign.cpp in Sources */, 4C93F1751F8B745700A9330D /* MiniHelicopters.cpp in Sources */, + 4CE462431FD1612C0001CD98 /* android.c in Sources */, + 4CE4624B1FD1613D0001CD98 /* Platform.macOS.cpp in Sources */, 4C93F1501F8B744400A9330D /* SideFrictionRollerCoaster.cpp in Sources */, 4C93F13D1F8B744400A9330D /* CompactInvertedCoaster.cpp in Sources */, C67CCD681FBBD138004FAE4C /* EditorMain.cpp in Sources */, @@ -3206,6 +3224,7 @@ C6E415511FAFD6DC00D4A52A /* RideConstruction.cpp in Sources */, C685E51B1F8907850090598F /* Guest.cpp in Sources */, C64644F91F3FA4120026AC2D /* EditorInventionsList.cpp in Sources */, + 4CE4624C1FD1613D0001CD98 /* Platform.Posix.cpp in Sources */, C6D2BEE61F9BAACE008B557C /* TrackList.cpp in Sources */, 4C93F1AB1F8B748900A9330D /* WaterCoaster.cpp in Sources */, 4C93F16D1F8B745700A9330D /* Dodgems.cpp in Sources */, @@ -3253,6 +3272,7 @@ C666EE771F37ACB10061AA04 /* SavePrompt.cpp in Sources */, 4C93F16C1F8B745700A9330D /* CrookedHouse.cpp in Sources */, 4C93F18A1F8B747A00A9330D /* Enterprise.cpp in Sources */, + 4CE4624A1FD1613D0001CD98 /* Platform.Linux.cpp in Sources */, C654DF391F69C0430040F43D /* TitleCommandEditor.cpp in Sources */, 4C93F13B1F8B744400A9330D /* BobsleighCoaster.cpp in Sources */, 4C93F1701F8B745700A9330D /* GhostTrain.cpp in Sources */, @@ -3264,6 +3284,7 @@ F76C88811EC5324E00FA49E2 /* DrawLineShader.cpp in Sources */, 4C93F13A1F8B744400A9330D /* AirPoweredVerticalCoaster.cpp in Sources */, 4C93F1421F8B744400A9330D /* InvertedHairpinCoaster.cpp in Sources */, + 4CE4624D1FD1613D0001CD98 /* Platform.Win32.cpp in Sources */, C67CCD661FBBCFDB004FAE4C /* EditorBottomToolbar.cpp in Sources */, C666EE731F37ACB10061AA04 /* MusicCredits.cpp in Sources */, 4C93F1511F8B744400A9330D /* StandUpRollerCoaster.cpp in Sources */, @@ -3471,7 +3492,6 @@ F76C86A31EC4E88400FA49E2 /* Crash.cpp in Sources */, F76C86A51EC4E88400FA49E2 /* linux.c in Sources */, F76C86A61EC4E88400FA49E2 /* macos.m in Sources */, - F76C86A81EC4E88400FA49E2 /* Platform2.cpp in Sources */, F76C86AA1EC4E88400FA49E2 /* posix.c in Sources */, F76C86AB1EC4E88400FA49E2 /* shared.c in Sources */, F76C86AC1EC4E88400FA49E2 /* windows.c in Sources */, From 8a62229a5b0090a1eac7f79ef86e6782bc97d9b5 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Fri, 1 Dec 2017 11:16:05 +0100 Subject: [PATCH 8/9] Fix build on Xcode --- src/openrct2/platform/Platform.macOS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/platform/Platform.macOS.cpp b/src/openrct2/platform/Platform.macOS.cpp index 25e5a9bd4c..9eeec5e7d0 100644 --- a/src/openrct2/platform/Platform.macOS.cpp +++ b/src/openrct2/platform/Platform.macOS.cpp @@ -14,7 +14,7 @@ *****************************************************************************/ #pragma endregion -#ifdef __MACOS__ +#if defined(__APPLE__) && defined(__MACH__) #include "../core/Path.hpp" #include "Platform2.h" From 11fac1bbf570f72abe5108ee353f83a8b821317a Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 1 Dec 2017 21:03:45 +0000 Subject: [PATCH 9/9] Change back to current directory structure --- src/openrct2/platform/Platform.Linux.cpp | 27 ++---------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/openrct2/platform/Platform.Linux.cpp b/src/openrct2/platform/Platform.Linux.cpp index c6e4f03878..ed3e105006 100644 --- a/src/openrct2/platform/Platform.Linux.cpp +++ b/src/openrct2/platform/Platform.Linux.cpp @@ -27,34 +27,11 @@ namespace Platform switch (folder) { case SPECIAL_FOLDER::USER_CACHE: - { - auto path = GetEnvironmentPath("XDG_CACHE_HOME"); - if (path.empty()) - { - auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - path = Path::Combine(home, ".cache"); - } - return path; - } case SPECIAL_FOLDER::USER_CONFIG: - { - auto path = GetEnvironmentPath("XDG_CONFIG_HOME"); - if (path.empty()) - { - auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - path = Path::Combine(home, ".config"); - } - return path; - } case SPECIAL_FOLDER::USER_DATA: { - auto path = GetEnvironmentPath("XDG_DATA_HOME"); - if (path.empty()) - { - auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); - path = Path::Combine(home, ".local/share"); - } - return path; + auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); + return Path::Combine(home, ".config"); } case SPECIAL_FOLDER::USER_HOME: return GetHomePath();