1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-12 02:22:26 +01:00

Move creation of version string to Version.cpp

This commit is contained in:
Ted John
2017-02-03 13:11:58 +00:00
parent f59afb8c44
commit e649e7ad4a
16 changed files with 141 additions and 123 deletions

View File

@@ -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 = "<group>"; };
D442718B1CC81B3200D84D28 /* util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = util.c; sourceTree = "<group>"; };
D442718C1CC81B3200D84D28 /* util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = util.h; sourceTree = "<group>"; };
D442718D1CC81B3200D84D28 /* version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = version.h; sourceTree = "<group>"; };
D442718D1CC81B3200D84D28 /* Version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Version.h; sourceTree = "<group>"; };
D442718F1CC81B3200D84D28 /* about.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = about.c; sourceTree = "<group>"; };
D44271901CC81B3200D84D28 /* banner.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = banner.c; sourceTree = "<group>"; };
D44271911CC81B3200D84D28 /* changelog.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = changelog.c; sourceTree = "<group>"; };
@@ -1212,7 +1212,7 @@
D4A8B4B31DB41873007A2F29 /* libpng16.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libpng16.dylib; sourceTree = "<group>"; };
D4B21B6D1E343AF1004982C7 /* lightfx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lightfx.c; sourceTree = "<group>"; };
D4B21B6E1E343AF1004982C7 /* lightfx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lightfx.h; sourceTree = "<group>"; };
D4CA88651D4E64C800060C11 /* version.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = version.c; sourceTree = "<group>"; };
D4CA88651D4E64C800060C11 /* Version.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Version.cpp; sourceTree = "<group>"; };
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 */,

View File

@@ -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.
*/

85
src/openrct2/Version.cpp Normal file
View File

@@ -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 <string>
#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;
}
}

View File

@@ -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 <string>
namespace Version
{
std::string GetInfo();
}
#endif

View File

@@ -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

View File

@@ -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)

View File

@@ -18,13 +18,15 @@
#include <stdarg.h>
#include <stdio.h>
#include "../common.h"
#ifdef __WINDOWS__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#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");

View File

@@ -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"

View File

@@ -336,7 +336,7 @@
<ClCompile Include="world\particle.c" />
<ClCompile Include="util\sawyercoding.c" />
<ClCompile Include="util\util.c" />
<ClCompile Include="version.c" />
<ClCompile Include="Version.cpp" />
<ClCompile Include="windows\about.c" />
<ClCompile Include="windows\banner.c" />
<ClCompile Include="windows\cheats.c" />

View File

@@ -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.

View File

@@ -47,6 +47,7 @@ extern "C" {
}
#endif // __cplusplus
#include "../Version.h"
#include "NetworkTypes.h"
#ifndef DISABLE_NETWORK

View File

@@ -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

View File

@@ -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"

View File

@@ -30,10 +30,12 @@
#include <shlobj.h>
#include <SDL_syswm.h>
#include <sys/stat.h>
#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

View File

@@ -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

View File

@@ -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)