From 83603fcf45f96215d6896da2e9b9a9ba2f5bd42f Mon Sep 17 00:00:00 2001 From: lethosor Date: Fri, 11 Dec 2015 20:27:46 -0500 Subject: [PATCH] Add prerelease build flag and warning script --- CMakeLists.txt | 1 + library/CMakeLists.txt | 5 +++++ library/Core.cpp | 6 +++++ library/DFHackVersion.cpp | 9 ++++++++ library/LuaApi.cpp | 1 + library/include/DFHackVersion.h | 2 ++ scripts/gui/prerelease-warning.lua | 36 ++++++++++++++++++++++++++++++ 7 files changed, 60 insertions(+) create mode 100644 scripts/gui/prerelease-warning.lua diff --git a/CMakeLists.txt b/CMakeLists.txt index d85b97076..274b58fce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ endif() # set up versioning. set(DF_VERSION "0.42.02") SET(DFHACK_RELEASE "r0") +SET(DFHACK_PRERELEASE TRUE) set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 827a4eacd..5071d9e71 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -263,6 +263,11 @@ SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS DF_VERSION="${DF_VERSION}" DFHACK_RELEASE="${DFHACK_RELEASE}" ) +IF(DFHACK_PRERELEASE) + SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS + DFHACK_PRERELEASE=1 + ) +ENDIF() ADD_CUSTOM_TARGET(git-describe COMMAND ${CMAKE_COMMAND} diff --git a/library/Core.cpp b/library/Core.cpp index edb00c45e..bdbb5c3b2 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2057,6 +2057,12 @@ void Core::onStateChange(color_ostream &out, state_change_event event) break; } + if (event == SC_MAP_LOADED && Version::is_prerelease()) + { + runCommand(out, "gui/prerelease-warning"); + std::cerr << "loaded map in prerelease build" << std::endl; + } + EventManager::onStateChange(out, event); buildings_onStateChange(out, event); diff --git a/library/DFHackVersion.cpp b/library/DFHackVersion.cpp index d3200a42f..744f3183b 100644 --- a/library/DFHackVersion.cpp +++ b/library/DFHackVersion.cpp @@ -33,5 +33,14 @@ namespace DFHack { return false; #endif } + + bool is_prerelease() + { + #ifdef DFHACK_PRERELEASE + return true; + #else + return false; + #endif + } } } diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 72267a5bf..a3a9eb070 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1418,6 +1418,7 @@ static const LuaWrapper::FunctionReg dfhack_module[] = { WRAP_VERSION_FUNC(getGitDescription, git_description), WRAP_VERSION_FUNC(getGitCommit, git_commit), WRAP_VERSION_FUNC(isRelease, is_release), + WRAP_VERSION_FUNC(isPrerelease, is_prerelease), { NULL, NULL } }; diff --git a/library/include/DFHackVersion.h b/library/include/DFHackVersion.h index f035e616a..67bf35df1 100644 --- a/library/include/DFHackVersion.h +++ b/library/include/DFHackVersion.h @@ -7,6 +7,7 @@ namespace DFHack { const char *git_description(); const char *git_commit(); bool is_release(); + bool is_prerelease(); } } @@ -17,4 +18,5 @@ namespace DFHack { #define DFHACK_GIT_DESCRIPTION (DFHack::Version::git_description()) #define DFHACK_GIT_COMMIT (DFHack::Version::git_commit()) #define DFHACK_IS_RELEASE (DFHack::Version::is_release()) + #define DFHACK_IS_PRERELEASE (DFHack::Version::is_prerelease()) #endif diff --git a/scripts/gui/prerelease-warning.lua b/scripts/gui/prerelease-warning.lua new file mode 100644 index 000000000..53d612d41 --- /dev/null +++ b/scripts/gui/prerelease-warning.lua @@ -0,0 +1,36 @@ +-- Shows the warning about missing configuration file. +--[[=begin + +gui/prerelease-warning +====================== +Shows a warning on world load for pre-release builds. + +=end]] + +if not dfhack.isPrerelease() then qerror('not a prerelease build') end + +local gui = require 'gui' +local dlg = require 'gui.dialogs' + +local message = { + 'This is a prerelease build of DFHack. Some structures are likely', NEWLINE, + 'to be incorrect, resulting in crashes or save corruption', NEWLINE, + {pen=COLOR_LIGHTRED, text='Make backups of your saves and avoid saving if possible.'} +} + +dfhack.print('\n') + +for k,v in ipairs(message) do + if type(v) == 'table' then + dfhack.color(v.pen) + dfhack.print(v.text) + else + dfhack.color(COLOR_YELLOW) + dfhack.print(v) + end +end + +dfhack.color(COLOR_RESET) +dfhack.print('\n\n') + +dlg.showMessage('Warning', message, COLOR_YELLOW)