From 3a4bc871980e44a4460c722728e7fccb20898282 Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 1 Feb 2017 23:11:47 +0000 Subject: [PATCH 1/4] Allow control of assertion behaviour This allows tests to change the behaviour at runtime so that OpenRCT2 aborts instead of showing a message box. --- openrct2.common.props | 22 ++----- src/openrct2/core/Guard.cpp | 113 ++++++++++++++++++++++++++---------- src/openrct2/core/Guard.hpp | 10 ++++ test/tests/tests.cpp | 4 ++ 4 files changed, 100 insertions(+), 49 deletions(-) diff --git a/openrct2.common.props b/openrct2.common.props index bbdf78fe06..7400067710 100644 --- a/openrct2.common.props +++ b/openrct2.common.props @@ -2,8 +2,6 @@ ..\..\ - Debug - Release @@ -16,13 +14,13 @@ MultiByte $(SolutionDir)bin\ - $(SolutionDir)obj\$(ProjectName)\$(Config)_$(Platform)\ + $(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\ $(ProjectName) - + true - + false true @@ -56,7 +54,7 @@ /OPT:NOLBR /ignore:4099 %(AdditionalOptions) - + Disabled true @@ -68,7 +66,7 @@ UseFastLinkTimeCodeGeneration - + Full true @@ -85,16 +83,6 @@ true - - - __TEST__;%(PreprocessorDefinitions) - - - - - NDEBUG;__TEST__;%(PreprocessorDefinitions) - - diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 746c1a0780..0edfe9adc9 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -24,14 +24,14 @@ #undef GetMessage #endif +#include "../OpenRCT2.h" #include "Console.hpp" #include "Diagnostics.hpp" #include "Guard.hpp" +#include "String.hpp" extern "C" { - #include "../OpenRCT2.h" - void openrct2_assert(bool expression, const char * message, ...) { va_list args; @@ -44,6 +44,30 @@ extern "C" namespace Guard { + // The default behaviour when an assertion is raised. + static ASSERT_BEHAVIOUR _assertBehaviour = +#ifdef __WINDOWS__ + ASSERT_BEHAVIOUR::MESSAGE_BOX +#else + ASSERT_BEHAVIOUR::CASSERT +#endif + ; + +#ifdef __WINDOWS__ + static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage); + static void ForceCrash(); +#endif + + ASSERT_BEHAVIOUR GetAssertBehaviour() + { + return _assertBehaviour; + } + + void SetAssertBehaviour(ASSERT_BEHAVIOUR behaviour) + { + _assertBehaviour = behaviour; + } + void Assert(bool expression, const char * message, ...) { va_list args; @@ -56,47 +80,46 @@ namespace Guard { if (expression) return; + char version[128]; + openrct2_write_full_version_info(version, sizeof(version)); + Console::Error::WriteLine("An assertion failed, please report this to the OpenRCT2 developers."); + Console::Error::WriteLine("Version: %s", version); + + // This is never freed, but acceptable considering we are about to crash out + utf8 * formattedMessage = nullptr; if (message != nullptr) { - Console::Error::WriteLine("Assertion failed:"); - Console::Error::WriteLine_VA(message, args); + formattedMessage = String::Format_VA(message, args); + Console::Error::WriteLine(formattedMessage); } #ifdef DEBUG Debug::Break(); #endif -#ifdef __WINDOWS__ - char version[128]; - openrct2_write_full_version_info(version, sizeof(version)); - char buffer[512]; - strcpy(buffer, "An assertion failed, please report this to the OpenRCT2 developers.\r\n\r\nVersion: "); - strcat(buffer, version); - if (message != nullptr) - { - strcat(buffer, "\r\n"); - char *bufend = (char *)strchr(buffer, 0); - vsnprintf(bufend, sizeof(buffer) - (bufend - buffer), message, args); - } -#ifdef __TEST__ - // Abort if we are building for testing - abort(); -#else - // Show message box if we are not building for testing - sint32 result = MessageBoxA(nullptr, buffer, OPENRCT2_NAME, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION); - if (result == IDABORT) - { -#ifdef USE_BREAKPAD - // Force a crash that breakpad will handle allowing us to get a dump - *((void**)0) = 0; -#else + switch (_assertBehaviour) { + case ASSERT_BEHAVIOUR::ABORT: + abort(); + break; + default: + case ASSERT_BEHAVIOUR::CASSERT: assert(false); -#endif + break; +#ifdef __WINDOWS__ + case ASSERT_BEHAVIOUR::MESSAGE_BOX: + { + // Show message box if we are not building for testing + char buffer[512]; + GetAssertMessage(buffer, sizeof(buffer), formattedMessage); + sint32 result = MessageBoxA(nullptr, buffer, OPENRCT2_NAME, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION); + if (result == IDABORT) + { + ForceCrash(); + } + break; } #endif -#else - assert(false); -#endif + } } void Fail(const char * message, ...) @@ -111,4 +134,30 @@ namespace Guard { Assert_VA(false, message, args); } + +#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, "An assertion failed, please report this to the OpenRCT2 developers.\r\n\r\nVersion: "); + String::Append(buffer, bufferSize, version); + if (formattedMessage != nullptr) + { + String::Append(buffer, bufferSize, "\r\n"); + String::Append(buffer, bufferSize, formattedMessage); + } + } + + static void ForceCrash() + { +#ifdef USE_BREAKPAD + // Force a crash that breakpad will handle allowing us to get a dump + *((void**)0) = 0; +#else + assert(false); +#endif + } +#endif } diff --git a/src/openrct2/core/Guard.hpp b/src/openrct2/core/Guard.hpp index 905e5ccf8e..9c2c397fe8 100644 --- a/src/openrct2/core/Guard.hpp +++ b/src/openrct2/core/Guard.hpp @@ -27,11 +27,21 @@ void openrct2_assert(bool expression, const char * message, ...); #include +enum class ASSERT_BEHAVIOUR +{ + ABORT, + CASSERT, + MESSAGE_BOX, +}; + /** * Utility methods for asserting function parameters. */ namespace Guard { + ASSERT_BEHAVIOUR GetAssertBehaviour(); + void SetAssertBehaviour(ASSERT_BEHAVIOUR behaviour); + void Assert(bool expression, const char * message = nullptr, ...); void Assert_VA(bool expression, const char * message, va_list args); void Fail(const char * message = nullptr, ...); diff --git a/test/tests/tests.cpp b/test/tests/tests.cpp index 4190c4fa39..27c1a9bd5e 100644 --- a/test/tests/tests.cpp +++ b/test/tests/tests.cpp @@ -3,9 +3,13 @@ #ifdef _MSC_VER #include +#include int main(int argc, char * * argv) { + // Abort on an assertions so the tests do not hang + Guard::SetAssertBehaviour(ASSERT_BEHAVIOUR::ABORT); + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } From f59afb8c446d812901eba82a9f3144c1c0aa1954 Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 1 Feb 2017 23:16:22 +0000 Subject: [PATCH 2/4] Use constant for assertion message --- src/openrct2/core/Guard.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 0edfe9adc9..169883aa7d 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -44,6 +44,8 @@ extern "C" namespace Guard { + constexpr const utf8 * ASSERTION_MESSAGE = "An assertion failed, please report this to the OpenRCT2 developers."; + // The default behaviour when an assertion is raised. static ASSERT_BEHAVIOUR _assertBehaviour = #ifdef __WINDOWS__ @@ -82,7 +84,7 @@ namespace Guard char version[128]; openrct2_write_full_version_info(version, sizeof(version)); - Console::Error::WriteLine("An assertion failed, please report this to the OpenRCT2 developers."); + Console::Error::WriteLine(ASSERTION_MESSAGE); Console::Error::WriteLine("Version: %s", version); // This is never freed, but acceptable considering we are about to crash out @@ -141,7 +143,9 @@ namespace Guard char version[128]; openrct2_write_full_version_info(version, sizeof(version)); - String::Set(buffer, bufferSize, "An assertion failed, please report this to the OpenRCT2 developers.\r\n\r\nVersion: "); + String::Set(buffer, bufferSize, ASSERTION_MESSAGE); + String::Append(buffer, bufferSize, "\r\n\r\n"); + String::Append(buffer, bufferSize, "Version: "); String::Append(buffer, bufferSize, version); if (formattedMessage != nullptr) { From e649e7ad4a34120187e18f6ccf589f70c2a17bdc Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 3 Feb 2017 13:11:58 +0000 Subject: [PATCH 3/4] Move creation of version string to Version.cpp --- OpenRCT2.xcodeproj/project.pbxproj | 12 ++-- src/openrct2/OpenRCT2.cpp | 33 +---------- src/openrct2/Version.cpp | 85 +++++++++++++++++++++++++++ src/openrct2/{version.h => Version.h} | 51 +++++++++------- src/openrct2/cmdline/RootCommands.cpp | 1 + src/openrct2/common.h | 2 - src/openrct2/core/Guard.cpp | 13 ++-- src/openrct2/interface/console.c | 1 + src/openrct2/libopenrct2.vcxproj | 2 +- src/openrct2/network/http.cpp | 3 +- src/openrct2/network/network.h | 1 + src/openrct2/platform/crash.cpp | 1 + src/openrct2/platform/shared.c | 1 + src/openrct2/platform/windows.c | 8 ++- src/openrct2/version.c | 49 --------------- test/tests/CMakeLists.txt | 1 + 16 files changed, 141 insertions(+), 123 deletions(-) create mode 100644 src/openrct2/Version.cpp rename src/openrct2/{version.h => Version.h} (55%) delete mode 100644 src/openrct2/version.c 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) From e7b9500bb6048ae3fc5b0081367ac32e4dc63032 Mon Sep 17 00:00:00 2001 From: danidoedel Date: Sat, 4 Feb 2017 11:37:01 +0100 Subject: [PATCH 4/4] Update Xcode project --- OpenRCT2.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index c986458283..d4152b55b9 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 652076321E22EFE7000D0C04 /* Imaging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 652076301E22EFE7000D0C04 /* Imaging.cpp */; }; 652747EC1E41CE1B000F36FD /* SawyerEncoding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 652747EA1E41CE1B000F36FD /* SawyerEncoding.cpp */; }; 658F3D911E44A6C200388550 /* ParkImporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 658F3D8F1E44A6C200388550 /* ParkImporter.cpp */; }; + 656F6C8E1E45BFC200E0F770 /* Version.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 656F6C8C1E45BFC200E0F770 /* Version.cpp */; }; 791166FB1D7486EF005912EA /* NetworkServerAdvertiser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 791166F91D7486EF005912EA /* NetworkServerAdvertiser.cpp */; }; 85060FD31D8C17CC00DFA2B3 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = 8594C05F1D885CF600235E93 /* track_data_old.c */; }; 8594C0601D885CF600235E93 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = 8594C05F1D885CF600235E93 /* track_data_old.c */; }; @@ -466,7 +467,6 @@ 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.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 */; }; @@ -527,6 +527,8 @@ 652747EB1E41CE1B000F36FD /* SawyerEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SawyerEncoding.h; path = rct12/SawyerEncoding.h; sourceTree = ""; }; 658F3D8F1E44A6C200388550 /* ParkImporter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParkImporter.cpp; sourceTree = ""; }; 658F3D901E44A6C200388550 /* ParkImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParkImporter.h; sourceTree = ""; }; + 656F6C8C1E45BFC200E0F770 /* Version.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Version.cpp; sourceTree = ""; }; + 656F6C8D1E45BFC200E0F770 /* Version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Version.h; sourceTree = ""; }; 791166F91D7486EF005912EA /* NetworkServerAdvertiser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkServerAdvertiser.cpp; sourceTree = ""; }; 791166FA1D7486EF005912EA /* NetworkServerAdvertiser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkServerAdvertiser.h; sourceTree = ""; }; 8594C05F1D885CF600235E93 /* track_data_old.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = track_data_old.c; sourceTree = ""; }; @@ -897,7 +899,6 @@ 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 = ""; }; 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 +1213,6 @@ 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.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.cpp */, - D442718D1CC81B3200D84D28 /* Version.h */, + 656F6C8C1E45BFC200E0F770 /* Version.cpp */, + 656F6C8D1E45BFC200E0F770 /* Version.h */, ); name = Sources; path = src/openrct2; @@ -2787,7 +2787,6 @@ D44272931CC81B3200D84D28 /* top_toolbar.c in Sources */, D43407DA1D0E14BE00C2B3D4 /* FillRectShader.cpp in Sources */, D464FEBE1D31A66E00CBABAC /* MemoryStream.cpp in Sources */, - D4CA88661D4E64C800060C11 /* Version.cpp in Sources */, D44271F61CC81B3200D84D28 /* audio.c in Sources */, D442728A1CC81B3200D84D28 /* tile_inspector.c in Sources */, D43407D91D0E14BE00C2B3D4 /* DrawLineShader.cpp in Sources */, @@ -2900,6 +2899,7 @@ D44272041CC81B3200D84D28 /* Stopwatch.cpp in Sources */, D43407D81D0E14BE00C2B3D4 /* DrawImageShader.cpp in Sources */, 007A05D01CFB2C8B00F419C3 /* NetworkGroup.cpp in Sources */, + 656F6C8E1E45BFC200E0F770 /* Version.cpp in Sources */, C686F9491CDBC3B7009F9BFC /* chairlift.c in Sources */, C686F9501CDBC3B7009F9BFC /* log_flume.c in Sources */, D464FEE81D31A6AA00CBABAC /* FootpathObject.cpp in Sources */,