diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index c26cf6d5d..fcb4f218b 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -656,6 +656,8 @@ int main(int argc, char* argv[]) Settings::getInstance()->setInt("ScreenHeight", 720); #endif + bool migratedSettings {false}; + { if (!Settings::getInstance()->getBool("LegacyAppDataDirectory")) { // 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?"; } } + 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; if (Settings::getInstance()->getBool("LegacyAppDataDirectory")) 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?"; } } + 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 + 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: " << std::chrono::duration_cast( std::chrono::system_clock::now() - applicationStartTime) diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 0ef0208b0..65fe0766a 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -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() { const std::string upgradeMessage { @@ -146,6 +181,7 @@ void ViewController::unsafeUpgradeDialog() "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, nullptr, true, true, diff --git a/es-app/src/views/ViewController.h b/es-app/src/views/ViewController.h index 125ae9ad6..18e65adf7 100644 --- a/es-app/src/views/ViewController.h +++ b/es-app/src/views/ViewController.h @@ -34,6 +34,8 @@ public: // These functions are called from main(). void setMenuColors(); + void legacyAppDataDialog(); + void migratedAppDataFilesDialog(); void unsafeUpgradeDialog(); void invalidSystemsFileDialog(); void noGamesDialog();