diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index fa9eee4bf4..c986458283 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -466,7 +466,7 @@ D4A8B4B41DB41873007A2F29 /* libpng16.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D4A8B4B31DB41873007A2F29 /* libpng16.dylib */; }; D4A8B4B51DB4188D007A2F29 /* libpng16.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D4A8B4B31DB41873007A2F29 /* libpng16.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; D4B21B6F1E343AF1004982C7 /* lightfx.c in Sources */ = {isa = PBXBuildFile; fileRef = D4B21B6D1E343AF1004982C7 /* lightfx.c */; }; - D4CA88661D4E64C800060C11 /* version.c in Sources */ = {isa = PBXBuildFile; fileRef = D4CA88651D4E64C800060C11 /* version.c */; }; + D4CA88661D4E64C800060C11 /* Version.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D4CA88651D4E64C800060C11 /* Version.cpp */; }; D4EC48E61C2637710024B507 /* g2.dat in Resources */ = {isa = PBXBuildFile; fileRef = D4EC48E31C2637710024B507 /* g2.dat */; }; D4EC48E71C2637710024B507 /* language in Resources */ = {isa = PBXBuildFile; fileRef = D4EC48E41C2637710024B507 /* language */; }; D4EC48E81C2637710024B507 /* title in Resources */ = {isa = PBXBuildFile; fileRef = D4EC48E51C2637710024B507 /* title */; }; @@ -897,7 +897,7 @@ D442718A1CC81B3200D84D28 /* sawyercoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sawyercoding.h; sourceTree = ""; }; D442718B1CC81B3200D84D28 /* util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = util.c; sourceTree = ""; }; D442718C1CC81B3200D84D28 /* util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = util.h; sourceTree = ""; }; - D442718D1CC81B3200D84D28 /* version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = version.h; sourceTree = ""; }; + D442718D1CC81B3200D84D28 /* Version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Version.h; sourceTree = ""; }; D442718F1CC81B3200D84D28 /* about.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = about.c; sourceTree = ""; }; D44271901CC81B3200D84D28 /* banner.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = banner.c; sourceTree = ""; }; D44271911CC81B3200D84D28 /* changelog.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = changelog.c; sourceTree = ""; }; @@ -1212,7 +1212,7 @@ D4A8B4B31DB41873007A2F29 /* libpng16.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libpng16.dylib; sourceTree = ""; }; D4B21B6D1E343AF1004982C7 /* lightfx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lightfx.c; sourceTree = ""; }; D4B21B6E1E343AF1004982C7 /* lightfx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lightfx.h; sourceTree = ""; }; - D4CA88651D4E64C800060C11 /* version.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = version.c; sourceTree = ""; }; + D4CA88651D4E64C800060C11 /* Version.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Version.cpp; sourceTree = ""; }; D4EC48E31C2637710024B507 /* g2.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = g2.dat; path = data/g2.dat; sourceTree = SOURCE_ROOT; }; D4EC48E41C2637710024B507 /* language */ = {isa = PBXFileReference; lastKnownFileType = folder; name = language; path = data/language; sourceTree = SOURCE_ROOT; }; D4EC48E51C2637710024B507 /* title */ = {isa = PBXFileReference; lastKnownFileType = folder; name = title; path = data/title; sourceTree = SOURCE_ROOT; }; @@ -1582,8 +1582,8 @@ D442716C1CC81B3200D84D28 /* rct2.h */, D433A5031E4A862F00D9A6DF /* rct12.h */, D44271851CC81B3200D84D28 /* sprites.h */, - D4CA88651D4E64C800060C11 /* version.c */, - D442718D1CC81B3200D84D28 /* version.h */, + D4CA88651D4E64C800060C11 /* Version.cpp */, + D442718D1CC81B3200D84D28 /* Version.h */, ); name = Sources; path = src/openrct2; @@ -2787,7 +2787,7 @@ D44272931CC81B3200D84D28 /* top_toolbar.c in Sources */, D43407DA1D0E14BE00C2B3D4 /* FillRectShader.cpp in Sources */, D464FEBE1D31A66E00CBABAC /* MemoryStream.cpp in Sources */, - D4CA88661D4E64C800060C11 /* version.c in Sources */, + D4CA88661D4E64C800060C11 /* Version.cpp in Sources */, D44271F61CC81B3200D84D28 /* audio.c in Sources */, D442728A1CC81B3200D84D28 /* tile_inspector.c in Sources */, D43407D91D0E14BE00C2B3D4 /* DrawLineShader.cpp in Sources */, diff --git a/src/openrct2/OpenRCT2.cpp b/src/openrct2/OpenRCT2.cpp index 534898ebfc..3be08f2754 100644 --- a/src/openrct2/OpenRCT2.cpp +++ b/src/openrct2/OpenRCT2.cpp @@ -28,6 +28,7 @@ #include "scenario/ScenarioRepository.h" #include "title/TitleScreen.h" #include "title/TitleSequenceManager.h" +#include "Version.h" extern "C" { @@ -44,7 +45,6 @@ extern "C" #include "platform/platform.h" #include "rct1.h" #include "rct2/interop.h" - #include "version.h" } // The game update inverval in milliseconds, (1000 / 40fps) = 25ms @@ -76,7 +76,6 @@ extern "C" namespace OpenRCT2 { static IPlatformEnvironment * _env = nullptr; - static std::string _versionInfo; static bool _isWindowMinimised; static uint32 _isWindowMinimisedLastCheckTick; static uint32 _lastTick; @@ -85,7 +84,6 @@ namespace OpenRCT2 /** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to false. */ static bool _finished; - static void SetVersionInfoString(); static bool ShouldRunVariableFrame(); static void RunGameLoop(); static void RunFixedFrame(); @@ -98,11 +96,7 @@ extern "C" { void openrct2_write_full_version_info(utf8 * buffer, size_t bufferSize) { - if (OpenRCT2::_versionInfo.empty()) - { - OpenRCT2::SetVersionInfoString(); - } - String::Set(buffer, bufferSize, OpenRCT2::_versionInfo.c_str()); + String::Set(buffer, bufferSize, Version::GetInfo().c_str()); } static void openrct2_set_exe_path() @@ -380,29 +374,6 @@ namespace OpenRCT2 return env; } - static void SetVersionInfoString() - { - utf8 buffer[256]; - size_t bufferSize = sizeof(buffer); - String::Set(buffer, bufferSize, OPENRCT2_NAME ", v" OPENRCT2_VERSION); - if (!String::IsNullOrEmpty(gGitBranch)) - { - String::AppendFormat(buffer, bufferSize, "-%s", gGitBranch); - } - if (!String::IsNullOrEmpty(gCommitSha1Short)) - { - String::AppendFormat(buffer, bufferSize, " build %s", gCommitSha1Short); - } - if (!String::IsNullOrEmpty(gBuildServer)) - { - String::AppendFormat(buffer, bufferSize, " provided by %s", gBuildServer); - } - #ifdef DEBUG - String::AppendFormat(buffer, bufferSize, " (DEBUG)", gBuildServer); - #endif - _versionInfo = buffer; - } - /** * Run the main game loop until the finished flag is set. */ diff --git a/src/openrct2/Version.cpp b/src/openrct2/Version.cpp new file mode 100644 index 0000000000..fd54151ae9 --- /dev/null +++ b/src/openrct2/Version.cpp @@ -0,0 +1,85 @@ +#pragma region Copyright (c) 2014-2016 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 + +#include +#include "core/String.hpp" +#include "Version.h" + +#ifdef OPENRCT2_BUILD_INFO_HEADER +#include OPENRCT2_BUILD_INFO_HEADER +#endif + +#ifdef OPENRCT2_BUILD_NUMBER + const char *gBuildNumber = OPENRCT2_BUILD_NUMBER; +#else + const char *gBuildNumber = ""; +#endif + +#ifdef OPENRCT2_BUILD_SERVER + const char *gBuildServer = OPENRCT2_BUILD_SERVER; +#else + const char *gBuildServer = ""; +#endif + +#ifdef OPENRCT2_BRANCH + const char *gGitBranch = OPENRCT2_BRANCH; +#else + const char *gGitBranch = ""; +#endif + +#ifdef OPENRCT2_COMMIT_SHA1 + const char *gCommitSha1 = OPENRCT2_COMMIT_SHA1; +#else + const char *gCommitSha1 = ""; +#endif + +#ifdef OPENRCT2_COMMIT_SHA1_SHORT + const char *gCommitSha1Short = OPENRCT2_COMMIT_SHA1_SHORT; +#else + const char *gCommitSha1Short = ""; +#endif + +namespace Version +{ + static std::string _info; + + std::string GetInfo() + { + if (_info.empty()) + { + utf8 buffer[256]; + size_t bufferSize = sizeof(buffer); + String::Set(buffer, bufferSize, OPENRCT2_NAME ", v" OPENRCT2_VERSION); + if (!String::IsNullOrEmpty(gGitBranch)) + { + String::AppendFormat(buffer, bufferSize, "-%s", gGitBranch); + } + if (!String::IsNullOrEmpty(gCommitSha1Short)) + { + String::AppendFormat(buffer, bufferSize, " build %s", gCommitSha1Short); + } + if (!String::IsNullOrEmpty(gBuildServer)) + { + String::AppendFormat(buffer, bufferSize, " provided by %s", gBuildServer); + } +#ifdef DEBUG + String::AppendFormat(buffer, bufferSize, " (DEBUG)", gBuildServer); +#endif + _info = std::string(buffer); + } + return _info; + } +} diff --git a/src/openrct2/version.h b/src/openrct2/Version.h similarity index 55% rename from src/openrct2/version.h rename to src/openrct2/Version.h index 2c14d74a40..0a474bf7eb 100644 --- a/src/openrct2/version.h +++ b/src/openrct2/Version.h @@ -14,61 +14,68 @@ *****************************************************************************/ #pragma endregion -#ifndef _VERSION_H_ -#define _VERSION_H_ +#pragma once #include "common.h" -#define OPENRCT2_NAME "OpenRCT2" -#define OPENRCT2_VERSION "0.0.7" +#define OPENRCT2_NAME "OpenRCT2" +#define OPENRCT2_VERSION "0.0.7" #if defined(__amd64__) || defined(_M_AMD64) - #define OPENRCT2_ARCHITECTURE "x86-64" + #define OPENRCT2_ARCHITECTURE "x86-64" #elif defined(__i386__) || defined(_M_IX86) - #define OPENRCT2_ARCHITECTURE "x86" + #define OPENRCT2_ARCHITECTURE "x86" #elif defined(__aarch64__) - #define OPENRCT2_ARCHITECTURE "AArch64" + #define OPENRCT2_ARCHITECTURE "AArch64" #elif defined(__arm__) || defined(_M_ARM) - #define OPENRCT2_ARCHITECTURE "ARMv7" + #define OPENRCT2_ARCHITECTURE "ARMv7" #elif defined(__powerpc__) || defined(_M_PPC) - #define OPENRCT2_ARCHITECTURE "PowerPC" + #define OPENRCT2_ARCHITECTURE "PowerPC" #endif #ifndef OPENRCT2_ARCHITECTURE - #error "OPENRCT2_ARCHITECTURE is undefined. Please add identification." + #error "OPENRCT2_ARCHITECTURE is undefined. Please add identification." #endif // Platform #ifdef __WINDOWS__ - #define OPENRCT2_PLATFORM "Windows" + #define OPENRCT2_PLATFORM "Windows" #endif #ifdef __LINUX__ - #define OPENRCT2_PLATFORM "Linux" + #define OPENRCT2_PLATFORM "Linux" #endif #ifdef __MACOSX__ - #define OPENRCT2_PLATFORM "macOS" + #define OPENRCT2_PLATFORM "macOS" #endif #ifdef __FREEBSD__ - #define OPENRCT2_PLATFORM "FreeBSD" + #define OPENRCT2_PLATFORM "FreeBSD" #endif #ifndef OPENRCT2_PLATFORM - #error Unknown platform! + #error Unknown platform! #endif -#define OPENRCT2_TIMESTAMP __DATE__ " " __TIME__ +#define OPENRCT2_TIMESTAMP __DATE__ " " __TIME__ #ifdef __cplusplus extern "C" { #endif - // The following constants are for automated build servers - extern const char *gBuildNumber; - extern const char *gBuildServer; - extern const char *gGitBranch; - extern const char *gCommitSha1; - extern const char *gCommitSha1Short; + // The following constants are for automated build servers + extern const char *gBuildNumber; + extern const char *gBuildServer; + extern const char *gGitBranch; + extern const char *gCommitSha1; + extern const char *gCommitSha1Short; #ifdef __cplusplus } #endif +#ifdef __cplusplus + +#include + +namespace Version +{ + std::string GetInfo(); +} #endif diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index 44f02193ac..62fb60ffb3 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -31,6 +31,7 @@ extern "C" #include "../network/network.h" #include "../object/ObjectRepository.h" #include "../OpenRCT2.h" +#include "../Version.h" #include "CommandLine.hpp" #ifdef USE_BREAKPAD diff --git a/src/openrct2/common.h b/src/openrct2/common.h index e0bdd02cdb..e33c5f5df8 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -142,8 +142,6 @@ char *strndup(const char *src, size_t size); #define MAP_ANONYMOUS MAP_ANON #endif -#include "version.h" - #define OPENRCT2_MASTER_SERVER_URL "https://servers.openrct2.website" // Time (represented as number of 100-nanosecond intervals since 0001-01-01T00:00:00Z) diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 169883aa7d..94083328c9 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -18,13 +18,15 @@ #include #include +#include "../common.h" + #ifdef __WINDOWS__ #define WIN32_LEAN_AND_MEAN #include #undef GetMessage #endif -#include "../OpenRCT2.h" +#include "../Version.h" #include "Console.hpp" #include "Diagnostics.hpp" #include "Guard.hpp" @@ -82,10 +84,8 @@ namespace Guard { if (expression) return; - char version[128]; - openrct2_write_full_version_info(version, sizeof(version)); Console::Error::WriteLine(ASSERTION_MESSAGE); - Console::Error::WriteLine("Version: %s", version); + Console::Error::WriteLine("Version: %s", Version::GetInfo().c_str()); // This is never freed, but acceptable considering we are about to crash out utf8 * formattedMessage = nullptr; @@ -140,13 +140,10 @@ namespace Guard #ifdef __WINDOWS__ static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage) { - char version[128]; - openrct2_write_full_version_info(version, sizeof(version)); - String::Set(buffer, bufferSize, ASSERTION_MESSAGE); String::Append(buffer, bufferSize, "\r\n\r\n"); String::Append(buffer, bufferSize, "Version: "); - String::Append(buffer, bufferSize, version); + String::Append(buffer, bufferSize, Version::GetInfo().c_str()); if (formattedMessage != nullptr) { String::Append(buffer, bufferSize, "\r\n"); diff --git a/src/openrct2/interface/console.c b/src/openrct2/interface/console.c index 6ab38287fe..bd3aeedec7 100644 --- a/src/openrct2/interface/console.c +++ b/src/openrct2/interface/console.c @@ -35,6 +35,7 @@ #include "../rct2.h" #include "../util/sawyercoding.h" #include "../util/util.h" +#include "../Version.h" #include "../world/banner.h" #include "../world/climate.h" #include "../world/park.h" diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 37d047f3b1..132d355439 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -336,7 +336,7 @@ - + diff --git a/src/openrct2/network/http.cpp b/src/openrct2/network/http.cpp index de698abb8e..8d1aa14b81 100644 --- a/src/openrct2/network/http.cpp +++ b/src/openrct2/network/http.cpp @@ -26,10 +26,11 @@ void http_dispose() { } #else +#include "../core/Console.hpp" #include "../core/Math.hpp" #include "../core/Path.hpp" #include "../core/String.hpp" -#include "../core/Console.hpp" +#include "../Version.h" #ifdef __WINDOWS__ // cURL includes windows.h, but we don't need all of it. diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 1667d90f7a..1a6b0178b3 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -47,6 +47,7 @@ extern "C" { } #endif // __cplusplus +#include "../Version.h" #include "NetworkTypes.h" #ifndef DISABLE_NETWORK diff --git a/src/openrct2/platform/crash.cpp b/src/openrct2/platform/crash.cpp index 0fa6d81a54..19c6b7469d 100644 --- a/src/openrct2/platform/crash.cpp +++ b/src/openrct2/platform/crash.cpp @@ -39,6 +39,7 @@ extern "C" #include "../core/Console.hpp" #include "../core/Exception.hpp" #include "../rct2/S6Exporter.h" +#include "../Version.h" #define WSZ(x) L"" x diff --git a/src/openrct2/platform/shared.c b/src/openrct2/platform/shared.c index 3de9cc0ba0..69167de298 100644 --- a/src/openrct2/platform/shared.c +++ b/src/openrct2/platform/shared.c @@ -32,6 +32,7 @@ #include "../rct2.h" #include "../title/TitleScreen.h" #include "../util/util.h" +#include "../Version.h" #include "../world/climate.h" #include "platform.h" diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index 01b499b42c..55610b757c 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -30,10 +30,12 @@ #include #include #include -#include "../OpenRCT2.h" -#include "../localisation/language.h" -#include "../util/util.h" + #include "../config.h" +#include "../localisation/language.h" +#include "../OpenRCT2.h" +#include "../util/util.h" +#include "../Version.h" #include "platform.h" // Native resource IDs diff --git a/src/openrct2/version.c b/src/openrct2/version.c deleted file mode 100644 index 29ae37d999..0000000000 --- a/src/openrct2/version.c +++ /dev/null @@ -1,49 +0,0 @@ -#pragma region Copyright (c) 2014-2016 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 OPENRCT2_BUILD_INFO_HEADER -#include OPENRCT2_BUILD_INFO_HEADER -#endif - -#ifdef OPENRCT2_BUILD_NUMBER - const char *gBuildNumber = OPENRCT2_BUILD_NUMBER; -#else - const char *gBuildNumber = ""; -#endif - -#ifdef OPENRCT2_BUILD_SERVER - const char *gBuildServer = OPENRCT2_BUILD_SERVER; -#else - const char *gBuildServer = ""; -#endif - -#ifdef OPENRCT2_BRANCH - const char *gGitBranch = OPENRCT2_BRANCH; -#else - const char *gGitBranch = ""; -#endif - -#ifdef OPENRCT2_COMMIT_SHA1 - const char *gCommitSha1 = OPENRCT2_COMMIT_SHA1; -#else - const char *gCommitSha1 = ""; -#endif - -#ifdef OPENRCT2_COMMIT_SHA1_SHORT - const char *gCommitSha1Short = OPENRCT2_COMMIT_SHA1_SHORT; -#else - const char *gCommitSha1Short = ""; -#endif diff --git a/test/tests/CMakeLists.txt b/test/tests/CMakeLists.txt index e6f48fcd30..f92f61bae8 100644 --- a/test/tests/CMakeLists.txt +++ b/test/tests/CMakeLists.txt @@ -81,6 +81,7 @@ set(LANGUAGEPACK_TEST_SOURCES "../../src/openrct2/localisation/format_codes.c" "../../src/openrct2/localisation/utf8.c" "../../src/openrct2/util/util.c" + "../../src/openrct2/Version.cpp" ) add_executable(test_languagepack ${LANGUAGEPACK_TEST_SOURCES}) target_link_libraries(test_languagepack ${GTEST_LIBRARIES} dl z SDL2 SDL2_ttf ssl crypto)