(Windows) Added a warning dialog on startup if an unsafe upgrade of the portable release has been made

This commit is contained in:
Leon Styhre 2023-07-31 17:42:38 +02:00
parent 66555101bf
commit 868c89cecf
3 changed files with 47 additions and 7 deletions

View file

@ -33,7 +33,6 @@
#include "SystemData.h"
#include "guis/GuiDetectDevice.h"
#include "guis/GuiLaunchScreen.h"
#include "guis/GuiMsgBox.h"
#include "utils/FileSystemUtil.h"
#include "utils/PlatformUtil.h"
#include "utils/StringUtil.h"
@ -825,6 +824,31 @@ int main(int argc, char* argv[])
ViewController::getInstance()->updateAvailableDialog();
#endif
#if defined(_WIN64)
if (Settings::getInstance()->getBool("PortableMode")) {
// If it's the portable Windows release then create a release file, and check if there
// are any release files from different versions than the one currently running.
// If this is the case an unsafe upgrade has taken place, probably by simply unpacking
// the new release on top of the old one.
bool releaseFileExists {true};
const std::string releaseFile {"r" + std::to_string(PROGRAM_RELEASE_NUMBER) + ".rel"};
if (!Utils::FileSystem::exists(Utils::FileSystem::getExePath() + "/" + releaseFile)) {
releaseFileExists = Utils::FileSystem::createEmptyFile(
Utils::FileSystem::getExePath() + "/" + releaseFile);
}
if (releaseFileExists) {
for (auto& file : Utils::FileSystem::getMatchingFiles(
Utils::FileSystem::getExePath() + "/*.rel")) {
if (Utils::FileSystem::getFileName(file) != releaseFile) {
LOG(LogWarning) << "It seems as if an unsafe upgrade has been made";
ViewController::getInstance()->unsafeUpgradeDialog();
break;
}
}
}
}
#endif
LOG(LogInfo) << "Application startup time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - applicationStartTime)

View file

@ -137,14 +137,29 @@ void ViewController::setMenuColors()
}
}
void ViewController::unsafeUpgradeDialog()
{
std::string upgradeMessage {"IT SEEMS AS IF AN UNSAFE UPGRADE HAS BEEN MADE, POSSIBLY BY "
"UNPACKING THE NEW RELEASE ON TOP OF THE OLD ONE? THIS MAY CAUSE "
"VARIOUS PROBLEMS, SOME OF WHICH MAY NOT BE APPARENT IMMEDIATELY. "
"MAKE SURE TO ALWAYS FOLLOW THE UPGRADE INSTRUCTIONS IN THE "
"README.TXT FILE THAT CAN BE FOUND IN THE EMULATIONSTATION-DE "
"DIRECTORY."};
mWindow->pushGui(new GuiMsgBox(
HelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "", nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.85f :
0.55f * (1.778f / mRenderer->getScreenAspectRatio()))));
}
void ViewController::invalidSystemsFileDialog()
{
std::string errorMessage = "COULDN'T PARSE THE SYSTEMS CONFIGURATION FILE. "
"IF YOU HAVE A CUSTOMIZED es_systems.xml FILE, THEN "
"SOMETHING IS LIKELY WRONG WITH YOUR XML SYNTAX. "
"IF YOU DON'T HAVE A CUSTOM SYSTEMS FILE, THEN THE "
"EMULATIONSTATION INSTALLATION IS BROKEN. SEE THE "
"APPLICATION LOG FILE es_log.txt FOR ADDITIONAL INFO";
const std::string errorMessage {"COULDN'T PARSE THE SYSTEMS CONFIGURATION FILE. "
"IF YOU HAVE A CUSTOMIZED es_systems.xml FILE, THEN "
"SOMETHING IS LIKELY WRONG WITH YOUR XML SYNTAX. "
"IF YOU DON'T HAVE A CUSTOM SYSTEMS FILE, THEN THE "
"EMULATIONSTATION INSTALLATION IS BROKEN. SEE THE "
"APPLICATION LOG FILE es_log.txt FOR ADDITIONAL INFO"};
mWindow->pushGui(new GuiMsgBox(
HelpStyle(), errorMessage.c_str(), "QUIT",

View file

@ -34,6 +34,7 @@ public:
// These functions are called from main().
void setMenuColors();
void unsafeUpgradeDialog();
void invalidSystemsFileDialog();
void noGamesDialog();
void invalidAlternativeEmulatorDialog();