From ea903b13166b87b10ca051ad98226ea52fb2e9cf Mon Sep 17 00:00:00 2001 From: Camila Date: Tue, 27 Dec 2022 22:19:17 +0100 Subject: [PATCH] Backup all config files in the config folder if there was a version change of the client. Signed-off-by: Camila --- src/gui/application.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/gui/application.cpp b/src/gui/application.cpp index d6c6db292..3b47300ad 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -141,29 +141,31 @@ bool Application::configVersionMigration() // Did the client version change? // (The client version is adjusted further down) - bool versionChanged = configFile.clientVersionString() != MIRALL_VERSION_STRING; - - if (versionChanged) { - QDir directory(configFile.configPath()); - const auto anyConfigFileList = directory.entryInfoList({"*.cfg"}, QDir::Files); - for (const auto &file : anyConfigFileList) { - if (file.baseName() != APPLICATION_CONFIG_NAME) { - QFile::rename(file.canonicalFilePath(), configFile.configFile()); - break; - } - } - } + const auto versionChanged = configFile.clientVersionString() != MIRALL_VERSION_STRING; // We want to message the user either for destructive changes, // or if we're ignoring something and the client version changed. - bool warningMessage = !deleteKeys.isEmpty() || (!ignoreKeys.isEmpty() && versionChanged); + auto warningMessage = !deleteKeys.isEmpty() || (!ignoreKeys.isEmpty() && versionChanged); - if (!versionChanged && !warningMessage) + if (!versionChanged && !warningMessage) { return true; + } - const auto backupFile = configFile.backup(); + // back up all old config file + QStringList backupFilesList; + QDir directory(configFile.configPath()); + const auto anyConfigFileList = directory.entryInfoList({"*.cfg"}, QDir::Files); + for (const auto &file : anyConfigFileList) { + const auto fileName = file.fileName(); + backupFilesList.append(configFile.backup(fileName)); + if (file.baseName() != APPLICATION_CONFIG_NAME) { + if (!QFile::rename(fileName, configFile.configFile())) { + qCWarning(lcApplication) << "Failed to rename configuration file from" << file.baseName() << "to" << configFile.configFile(); + } + } + } - if (warningMessage) { + if (warningMessage || backupFilesList.count() > 0) { QString boldMessage; if (!deleteKeys.isEmpty()) { boldMessage = tr("Continuing will mean deleting these settings."); @@ -180,7 +182,7 @@ bool Application::configVersionMigration() "%1
" "
" "The current configuration file was already backed up to %2.") - .arg(boldMessage, backupFile)); + .arg(boldMessage, backupFilesList.join("
"))); box.addButton(tr("Quit"), QMessageBox::AcceptRole); auto continueBtn = box.addButton(tr("Continue"), QMessageBox::DestructiveRole); -- 2.30.2