From cb44dc5c2114cc2341ba9aca48b832f14eded248 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 21 Jan 2018 02:13:32 +0000 Subject: [PATCH] Fix changelog --- src/openrct2-ui/windows/Changelog.cpp | 23 +++++++++++++----- src/openrct2/PlatformEnvironment.cpp | 9 ++++++++ src/openrct2/PlatformEnvironment.h | 4 +++- src/openrct2/platform/Android.cpp | 5 ---- src/openrct2/platform/Linux.cpp | 27 ---------------------- src/openrct2/platform/Platform.Android.cpp | 5 ++++ src/openrct2/platform/Platform.Linux.cpp | 19 +++++++++++++++ src/openrct2/platform/Platform.Win32.cpp | 5 ++++ src/openrct2/platform/Platform.macOS.cpp | 5 ++++ src/openrct2/platform/Platform2.h | 1 + src/openrct2/platform/Windows.cpp | 6 ----- src/openrct2/platform/platform.h | 1 - 12 files changed, 64 insertions(+), 46 deletions(-) diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 2624113cca..c818c3ca18 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -17,15 +17,18 @@ #include #include #include -#include #include #include #include +#include #include +#include #include #include #include +using namespace OpenRCT2; + enum { WIDX_BACKGROUND, WIDX_TITLE, @@ -198,17 +201,25 @@ static void window_changelog_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, } } +static std::string GetChangelogPath() +{ + auto env = GetContext()->GetPlatformEnvironment(); + return env->GetFilePath(PATHID::CHANGELOG); +} + static std::string GetChangelogText() { - utf8 path[MAX_PATH]; - platform_get_changelog_path(path, sizeof(path)); - + auto path = GetChangelogPath(); #if defined(_WIN32) && !defined(__MINGW32__) auto pathW = String::ToUtf16(path); - auto fs = std::ifstream(pathW, std::ios::out | std::ios::app); + auto fs = std::ifstream(pathW, std::ios::in); #else - auto fs = std::ifstream(path, std::ios::out | std::ios::app); + auto fs = std::ifstream(path, std::ios::in); #endif + if (!fs.is_open()) + { + throw std::runtime_error("Unable to open " + path); + } return std::string((std::istreambuf_iterator(fs)), std::istreambuf_iterator()); } diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 7850f7bdc7..40b865ebc8 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -99,6 +99,8 @@ private: return DIRBASE::RCT1; case PATHID::SCORES_RCT2: return DIRBASE::RCT2; + case PATHID::CHANGELOG: + return DIRBASE::DOCUMENTATION; case PATHID::NETWORK_GROUPS: case PATHID::NETWORK_SERVERS: case PATHID::NETWORK_USERS: @@ -134,6 +136,7 @@ IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment() 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); + basePaths[(size_t)DIRBASE::DOCUMENTATION] = Platform::GetDocsPath(); // Override paths that have been specified via the command line if (!String::IsNullOrEmpty(gCustomRCT2DataPath)) @@ -151,6 +154,11 @@ IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment() basePaths[(size_t)DIRBASE::CACHE] = gCustomUserDataPath; } + if (basePaths[(size_t)DIRBASE::DOCUMENTATION].empty()) + { + basePaths[(size_t)DIRBASE::DOCUMENTATION] = basePaths[(size_t)DIRBASE::OPENRCT2]; + } + auto env = OpenRCT2::CreatePlatformEnvironment(basePaths); // Now load the config so we can get the RCT1 and RCT2 paths @@ -225,5 +233,6 @@ const char * PlatformEnvironment::FileNames[] = "highscores.dat", // SCORES "scores.dat", // SCORES (LEGACY) "Saved Games" PATH_SEPARATOR "scores.dat", // SCORES (RCT2) + "changelog.txt" // CHANGELOG }; // clang-format on diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h index de4b9894b8..32989f0ae0 100644 --- a/src/openrct2/PlatformEnvironment.h +++ b/src/openrct2/PlatformEnvironment.h @@ -31,8 +31,9 @@ namespace OpenRCT2 USER, // Base directory for OpenRCT2 user content. CONFIG, // Base directory for OpenRCT2 configuration. CACHE, // Base directory for OpenRCT2 cache files. + DOCUMENTATION, // Base directory for OpenRCT2 doc files. }; - constexpr sint32 DIRBASE_COUNT = 6; + constexpr sint32 DIRBASE_COUNT = 7; using DIRBASE_VALUES = std::string[DIRBASE_COUNT]; enum class DIRID @@ -67,6 +68,7 @@ namespace OpenRCT2 SCORES, // Scenario scores (highscores.dat). SCORES_LEGACY, // Scenario scores, legacy (scores.dat). SCORES_RCT2, // Scenario scores, rct2 (\Saved Games\scores.dat). + CHANGELOG, // Notable changes to the game between versions, distributed with the game. }; /** diff --git a/src/openrct2/platform/Android.cpp b/src/openrct2/platform/Android.cpp index d3429d1566..a80b562a08 100644 --- a/src/openrct2/platform/Android.cpp +++ b/src/openrct2/platform/Android.cpp @@ -69,11 +69,6 @@ float platform_get_default_scale() { return displayScale; } -void platform_get_changelog_path(utf8 *outPath, size_t outSize) -{ - STUB(); -} - bool platform_get_steam_path(utf8 * outPath, size_t outSize) { return false; diff --git a/src/openrct2/platform/Linux.cpp b/src/openrct2/platform/Linux.cpp index fda75ca297..8b2cd88d45 100644 --- a/src/openrct2/platform/Linux.cpp +++ b/src/openrct2/platform/Linux.cpp @@ -108,27 +108,6 @@ void platform_posix_sub_resolve_openrct_data_path(utf8 *out, size_t size) { } } -/** -* Default directory fallback is: -* - /doc -* - /usr/share/doc/openrct2 -*/ -static void platform_posix_sub_resolve_openrct_doc_path(utf8 *out, size_t size) { - static const utf8 *searchLocations[] = { - "./doc", - "/usr/share/doc/openrct2", - }; - for (auto searchLocation : searchLocations) - { - log_verbose("Looking for OpenRCT2 doc path at %s", searchLocation); - if (platform_directory_exists(searchLocation)) - { - safe_strcpy(out, searchLocation, size); - return; - } - } -} - uint16 platform_get_locale_language(){ const char *langString = setlocale(LC_MESSAGES, ""); if(langString != NULL){ @@ -218,12 +197,6 @@ uint8 platform_get_locale_measurement_format(){ return MEASUREMENT_FORMAT_METRIC; } -void platform_get_changelog_path(utf8 *outPath, size_t outSize) -{ - platform_posix_sub_resolve_openrct_doc_path(outPath, outSize); - safe_strcat_path(outPath, "changelog.txt", outSize); -} - bool platform_get_steam_path(utf8 * outPath, size_t outSize) { const char * steamRoot = getenv("STEAMROOT"); diff --git a/src/openrct2/platform/Platform.Android.cpp b/src/openrct2/platform/Platform.Android.cpp index 18f257f50f..bdabd83035 100644 --- a/src/openrct2/platform/Platform.Android.cpp +++ b/src/openrct2/platform/Platform.Android.cpp @@ -34,6 +34,11 @@ namespace Platform return std::string(); } } + + std::string GetDocsPath() + { + return std::string(); + } } #endif diff --git a/src/openrct2/platform/Platform.Linux.cpp b/src/openrct2/platform/Platform.Linux.cpp index 3414dc1a6a..9db7b69b65 100644 --- a/src/openrct2/platform/Platform.Linux.cpp +++ b/src/openrct2/platform/Platform.Linux.cpp @@ -18,6 +18,7 @@ #include #include "../core/Path.hpp" +#include "platform.h" #include "Platform2.h" namespace Platform @@ -44,6 +45,24 @@ namespace Platform return std::string(); } } + + std::string GetDocsPath() + { + static const utf8 * searchLocations[] = + { + "./doc", + "/usr/share/doc/openrct2", + }; + for (auto searchLocation : searchLocations) + { + log_verbose("Looking for OpenRCT2 doc path at %s", searchLocation); + if (platform_directory_exists(searchLocation)) + { + return searchLocation; + } + } + return std::string(); + } } #endif diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 4586b9ea19..048f8170bb 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -147,6 +147,11 @@ namespace Platform return path; } + std::string GetDocsPath() + { + return std::string(); + } + static SYSTEMTIME TimeToSystemTime(std::time_t timestamp) { LONGLONG ll = Int32x32To64(timestamp, 10000000) + 116444736000000000; diff --git a/src/openrct2/platform/Platform.macOS.cpp b/src/openrct2/platform/Platform.macOS.cpp index 9eeec5e7d0..d82b28dc2f 100644 --- a/src/openrct2/platform/Platform.macOS.cpp +++ b/src/openrct2/platform/Platform.macOS.cpp @@ -39,6 +39,11 @@ namespace Platform return std::string(); } } + + std::string GetDocsPath() + { + return std::string(); + } } #endif diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 9ae79139e1..38cdcefa77 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -36,6 +36,7 @@ namespace Platform std::string GetEnvironmentVariable(const std::string &name); std::string GetFolderPath(SPECIAL_FOLDER folder); std::string GetInstallPath(); + std::string GetDocsPath(); #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) std::string GetEnvironmentPath(const char * name); diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index 31f78e1d65..c816d0f9c1 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -244,12 +244,6 @@ void platform_get_openrct_data_path(utf8 *outPath, size_t outSize) safe_strcpy(outPath, _openrctDataDirectoryPath, outSize); } -void platform_get_changelog_path(utf8 *outPath, size_t outSize) -{ - safe_strcpy(outPath, gExePath, outSize); - safe_strcat_path(outPath, "changelog.txt", outSize); -} - bool platform_get_steam_path(utf8 * outPath, size_t outSize) { wchar_t * wSteamPath; diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index a4491413ae..a761d9454a 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -127,7 +127,6 @@ uint8 platform_get_locale_measurement_format(); 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