Added automatic configuration file migration from the legacy application data directory structure

Also added instruction dialogs regarding the new directory structure and file migration
This commit is contained in:
Leon Styhre 2023-12-16 00:00:10 +01:00
parent 6b0bfbfc09
commit 873ec7ee20
3 changed files with 82 additions and 1 deletions

View file

@ -656,6 +656,8 @@ int main(int argc, char* argv[])
Settings::getInstance()->setInt("ScreenHeight", 720); Settings::getInstance()->setInt("ScreenHeight", 720);
#endif #endif
bool migratedSettings {false};
{ {
if (!Settings::getInstance()->getBool("LegacyAppDataDirectory")) { if (!Settings::getInstance()->getBool("LegacyAppDataDirectory")) {
// Create the settings folder in the application data directory. // Create the settings folder in the application data directory.
@ -668,11 +670,33 @@ int main(int argc, char* argv[])
LOG(LogError) << "Couldn't create directory, permission problems?"; LOG(LogError) << "Couldn't create directory, permission problems?";
} }
} }
std::filesystem::path settingsPathOld;
std::filesystem::path settingsPathNew;
settingsPathOld = Utils::FileSystem::getAppDataDirectory().append("es_settings.xml");
settingsPathNew = Utils::FileSystem::getAppDataDirectory()
.append("settings")
.append("es_settings.xml");
if (!Utils::FileSystem::existsSTD(settingsPathNew) &&
Utils::FileSystem::existsSTD(settingsPathOld)) {
Utils::FileSystem::renameFile(settingsPathOld.string(), settingsPathNew.string(),
false);
Settings::getInstance()->loadFile();
migratedSettings = true;
}
settingsPathOld = Utils::FileSystem::getAppDataDirectory().append("es_input.xml");
settingsPathNew =
Utils::FileSystem::getAppDataDirectory().append("settings").append("es_input.xml");
if (!Utils::FileSystem::existsSTD(settingsPathNew) &&
Utils::FileSystem::existsSTD(settingsPathOld)) {
Utils::FileSystem::renameFile(settingsPathOld.string(), settingsPathNew.string(),
false);
migratedSettings = true;
}
} }
} }
{ {
// Check if the configuration file exists, and if not, create it. // Check if the es_settings.xml file exists, and if not, create it.
std::filesystem::path settingsPath; std::filesystem::path settingsPath;
if (Settings::getInstance()->getBool("LegacyAppDataDirectory")) if (Settings::getInstance()->getBool("LegacyAppDataDirectory"))
settingsPath = Utils::FileSystem::getAppDataDirectory().append("es_settings.xml"); settingsPath = Utils::FileSystem::getAppDataDirectory().append("es_settings.xml");
@ -788,6 +812,17 @@ int main(int argc, char* argv[])
LOG(LogWarning) << "Couldn't create directory, permission problems?"; LOG(LogWarning) << "Couldn't create directory, permission problems?";
} }
} }
std::filesystem::path configPathOld {
Utils::FileSystem::getAppDataDirectory().append("es_controller_mappings.cfg")};
std::filesystem::path configPathNew {Utils::FileSystem::getAppDataDirectory()
.append("controllers")
.append("es_controller_mappings.cfg")};
if (!Utils::FileSystem::existsSTD(configPathNew) &&
Utils::FileSystem::existsSTD(configPathOld)) {
Utils::FileSystem::renameFile(configPathOld.string(), configPathNew.string(),
false);
migratedSettings = true;
}
} }
} }
@ -951,6 +986,14 @@ int main(int argc, char* argv[])
} }
#endif #endif
if (Settings::getInstance()->getBool("LegacyAppDataDirectory"))
ViewController::getInstance()->legacyAppDataDialog();
if (migratedSettings) {
LOG(LogInfo) << "Migrated settings from a legacy application data directory structure";
ViewController::getInstance()->migratedAppDataFilesDialog();
}
LOG(LogInfo) << "Application startup time: " LOG(LogInfo) << "Application startup time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>( << std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - applicationStartTime) std::chrono::system_clock::now() - applicationStartTime)

View file

@ -137,6 +137,41 @@ void ViewController::setMenuColors()
} }
} }
void ViewController::legacyAppDataDialog()
{
const std::string upgradeMessage {
"IN ES-DE 3.0 THE APPLICATION DATA DIRECTORY HAS CHANGED FROM \".emulationstation\" to "
"\"ES-DE\"\nPLEASE RENAME YOUR CURRENT DATA DIRECTORY:\n" +
Utils::FileSystem::getAppDataDirectory().string() + "\nTO THE FOLLOWING:\n" +
Utils::FileSystem::getAppDataDirectory().parent_path().append("ES-DE").string()};
mWindow->pushGui(new GuiMsgBox(
HelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "", nullptr, nullptr, true,
true,
(mRenderer->getIsVerticalOrientation() ?
0.85f :
0.55f * (1.778f / mRenderer->getScreenAspectRatio()))));
}
void ViewController::migratedAppDataFilesDialog()
{
const std::string message {"SETTINGS HAVE BEEN MIGRATED FROM A LEGACY APPLICATION DATA "
"DIRECTORY STRUCTURE, YOU NEED TO RESTART ES-DE TO APPLY "
"THE CONFIGURATION"};
mWindow->pushGui(new GuiMsgBox(
HelpStyle(), message.c_str(), "QUIT",
[] {
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
},
"", nullptr, "", nullptr, nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ?
0.65f :
0.55f * (1.778f / mRenderer->getScreenAspectRatio()))));
}
void ViewController::unsafeUpgradeDialog() void ViewController::unsafeUpgradeDialog()
{ {
const std::string upgradeMessage { const std::string upgradeMessage {
@ -146,6 +181,7 @@ void ViewController::unsafeUpgradeDialog()
"MAKE SURE TO ALWAYS FOLLOW THE UPGRADE INSTRUCTIONS IN THE " "MAKE SURE TO ALWAYS FOLLOW THE UPGRADE INSTRUCTIONS IN THE "
"README.TXT FILE THAT CAN BE FOUND IN THE EMULATIONSTATION-DE " "README.TXT FILE THAT CAN BE FOUND IN THE EMULATIONSTATION-DE "
"DIRECTORY."}; "DIRECTORY."};
mWindow->pushGui(new GuiMsgBox( mWindow->pushGui(new GuiMsgBox(
HelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "", nullptr, nullptr, true, HelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "", nullptr, nullptr, true,
true, true,

View file

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