Refactor build information getters and remove the useless code.
Reviewed By: elexis, Stan Tested By: Stan Differential Revision: https://code.wildfiregames.com/D1348 This was SVN commit r22035.
This commit is contained in:
parent
276050bcad
commit
2d56e62e11
@ -224,3 +224,11 @@ function hideRemaining(parentName, start = 0)
|
||||
for (let i = start; i < objects.length; ++i)
|
||||
objects[i].hidden = true;
|
||||
}
|
||||
|
||||
function getBuildString()
|
||||
{
|
||||
return sprintf(translate("Build: %(buildDate)s (%(revision)s)"), {
|
||||
"buildDate": Engine.GetBuildDate(),
|
||||
"revision": Engine.GetBuildRevision()
|
||||
});
|
||||
}
|
||||
|
@ -193,14 +193,6 @@ function blendSubmenuIntoMain(topPosition, bottomPosition)
|
||||
Engine.GetGUIObjectByName("MainMenuPanelRightBorderBottom").size = "100%-2 " + (bottomPosition) + " 100% 100%";
|
||||
}
|
||||
|
||||
function getBuildString()
|
||||
{
|
||||
return sprintf(translate("Build: %(buildDate)s (%(revision)s)"), {
|
||||
"buildDate": Engine.GetBuildTimestamp(0),
|
||||
"revision": Engine.GetBuildTimestamp(2)
|
||||
});
|
||||
}
|
||||
|
||||
function exitGamePressed()
|
||||
{
|
||||
closeMenu();
|
||||
|
@ -1462,14 +1462,6 @@ function playAmbient()
|
||||
Engine.PlayAmbientSound(pickRandom(g_Ambient), true);
|
||||
}
|
||||
|
||||
function getBuildString()
|
||||
{
|
||||
return sprintf(translate("Build: %(buildDate)s (%(revision)s)"), {
|
||||
"buildDate": Engine.GetBuildTimestamp(0),
|
||||
"revision": Engine.GetBuildTimestamp(2)
|
||||
});
|
||||
}
|
||||
|
||||
function showTimeWarpMessageBox()
|
||||
{
|
||||
messageBox(
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -53,66 +53,35 @@ void JSI_Debug::DisplayErrorDialog(ScriptInterface::CxPrivate* UNUSED(pCxPrivate
|
||||
debug_DisplayError(msg.c_str(), DE_NO_DEBUG_INFO, NULL, NULL, NULL, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
// Return the date/time at which the current executable was compiled.
|
||||
// params: mode OR an integer specifying
|
||||
// what to display: -1 for "date time (svn revision)", 0 for date, 1 for time, 2 for svn revision
|
||||
// returns: string with the requested timestamp info
|
||||
// notes:
|
||||
// Return the date at which the current executable was compiled.
|
||||
// - Displayed on main menu screen; tells non-programmers which auto-build
|
||||
// they are running. Could also be determined via .EXE file properties,
|
||||
// but that's a bit more trouble.
|
||||
// - To be exact, the date/time returned is when scriptglue.cpp was
|
||||
// last compiled, but the auto-build does full rebuilds.
|
||||
std::wstring JSI_Debug::GetBuildDate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
||||
{
|
||||
UDate buildDate = g_L10n.ParseDateTime(__DATE__, "MMM d yyyy", icu::Locale::getUS());
|
||||
return wstring_from_utf8(g_L10n.LocalizeDateTime(buildDate, L10n::Date, icu::SimpleDateFormat::MEDIUM));
|
||||
}
|
||||
|
||||
double JSI_Debug::GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
||||
{
|
||||
UDate buildDate = g_L10n.ParseDateTime(__DATE__ " " __TIME__, "MMM d yyyy HH:mm:ss", icu::Locale::getUS());
|
||||
if (buildDate)
|
||||
return buildDate / 1000.0;
|
||||
return std::time(nullptr);
|
||||
}
|
||||
|
||||
// Return the revision number at which the current executable was compiled.
|
||||
// - svn revision is generated by calling svnversion and cached in
|
||||
// lib/svn_revision.cpp. it is useful to know when attempting to
|
||||
// reproduce bugs (the main EXE and PDB should be temporarily reverted to
|
||||
// that revision so that they match user-submitted crashdumps).
|
||||
std::wstring JSI_Debug::GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int mode)
|
||||
std::wstring JSI_Debug::GetBuildRevision(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
||||
{
|
||||
char buf[200];
|
||||
if (mode == -1) // Date, time and revision.
|
||||
{
|
||||
UDate dateTime = g_L10n.ParseDateTime(__DATE__ " " __TIME__, "MMM d yyyy HH:mm:ss", icu::Locale::getUS());
|
||||
std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::DateTime, icu::SimpleDateFormat::DATE_TIME);
|
||||
char svnRevision[32];
|
||||
sprintf_s(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision);
|
||||
if (strcmp(svnRevision, "custom build") == 0)
|
||||
{
|
||||
// Translation: First item is a date and time, item between parenthesis is the Subversion revision number of the current build.
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (custom build)").c_str(), dateTimeString.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Translation: First item is a date and time, item between parenthesis is the Subversion revision number of the current build.
|
||||
// dennis-ignore: *
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (%ls)").c_str(), dateTimeString.c_str(), svn_revision);
|
||||
}
|
||||
}
|
||||
else if (mode == 0) // Date.
|
||||
{
|
||||
UDate dateTime = g_L10n.ParseDateTime(__DATE__, "MMM d yyyy", icu::Locale::getUS());
|
||||
std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::Date, icu::SimpleDateFormat::MEDIUM);
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str());
|
||||
}
|
||||
else if (mode == 1) // Time.
|
||||
{
|
||||
UDate dateTime = g_L10n.ParseDateTime(__TIME__, "HH:mm:ss", icu::Locale::getUS());
|
||||
std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::Time, icu::SimpleDateFormat::MEDIUM);
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str());
|
||||
}
|
||||
else if (mode == 2) // Revision.
|
||||
{
|
||||
char svnRevision[32];
|
||||
sprintf_s(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision);
|
||||
if (strcmp(svnRevision, "custom build") == 0)
|
||||
{
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), "%s", g_L10n.Translate("custom build").c_str());
|
||||
}
|
||||
else
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), "%ls", svn_revision);
|
||||
}
|
||||
|
||||
return wstring_from_utf8(buf);
|
||||
std::wstring svnRevision(svn_revision);
|
||||
if (svnRevision == L"custom build")
|
||||
return wstring_from_utf8(g_L10n.Translate("custom build"));
|
||||
return svnRevision;
|
||||
}
|
||||
|
||||
void JSI_Debug::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
||||
@ -121,5 +90,7 @@ void JSI_Debug::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
||||
scriptInterface.RegisterFunction<int, &Crash>("Crash");
|
||||
scriptInterface.RegisterFunction<void, &DebugWarn>("DebugWarn");
|
||||
scriptInterface.RegisterFunction<void, std::wstring, &DisplayErrorDialog>("DisplayErrorDialog");
|
||||
scriptInterface.RegisterFunction<std::wstring, int, &GetBuildTimestamp>("GetBuildTimestamp");
|
||||
scriptInterface.RegisterFunction<std::wstring, &GetBuildDate>("GetBuildDate");
|
||||
scriptInterface.RegisterFunction<double, &GetBuildTimestamp>("GetBuildTimestamp");
|
||||
scriptInterface.RegisterFunction<std::wstring, &GetBuildRevision>("GetBuildRevision");
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -27,7 +27,9 @@ namespace JSI_Debug
|
||||
int Crash(ScriptInterface::CxPrivate* UNUSED(pCxPrivate));
|
||||
void DebugWarn(ScriptInterface::CxPrivate* UNUSED(pCxPrivate));
|
||||
void DisplayErrorDialog(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& msg);
|
||||
std::wstring GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int mode);
|
||||
std::wstring GetBuildDate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate));
|
||||
double GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate));
|
||||
std::wstring GetBuildRevision(ScriptInterface::CxPrivate* UNUSED(pCxPrivate));
|
||||
double GetMicroseconds(ScriptInterface::CxPrivate* UNUSED(pCxPrivate));
|
||||
|
||||
void RegisterScriptFunctions(const ScriptInterface& ScriptInterface);
|
||||
|
Loading…
Reference in New Issue
Block a user