From 558ff1fd934f7a9999fcf5e415078506d3d205a2 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 11 Nov 2018 15:26:46 +0200 Subject: [PATCH] SettingsAccessor: Relax old version validation for shared files Settings with older versions will not necessarily fail on upgrade. Let the upgrader assume they're using the oldest supported version, and continue from there. The logic with an appropriate message was already there, but it was never reached due to several bugs. Change-Id: Ie4d840a29d9aec7be7763111269f7bed81a8cbe3 Reviewed-by: Tobias Hunger --- src/libs/utils/settingsaccessor.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/settingsaccessor.cpp b/src/libs/utils/settingsaccessor.cpp index 09210c37669..998e78e58c8 100644 --- a/src/libs/utils/settingsaccessor.cpp +++ b/src/libs/utils/settingsaccessor.cpp @@ -535,6 +535,8 @@ SettingsAccessor::RestoreData UpgradingSettingsAccessor::validateVersionRange(const RestoreData &data) const { RestoreData result = data; + if (data.data.isEmpty()) + return result; const int version = versionFromMap(result.data); if (version < firstSupportedVersion() || version > currentVersion()) { Issue i(QApplication::translate("Utils::SettingsAccessor", "No Valid Settings Found"), @@ -548,7 +550,8 @@ UpgradingSettingsAccessor::validateVersionRange(const RestoreData &data) const return result; } - if (result.path != baseFilePath() && version < currentVersion()) { + if (result.path != baseFilePath() && !result.path.endsWith(".shared") + && version < currentVersion()) { Issue i(QApplication::translate("Utils::SettingsAccessor", "Using Old Settings"), QApplication::translate("Utils::SettingsAccessor", "

The versioned backup \"%1\" of the settings " @@ -578,6 +581,7 @@ UpgradingSettingsAccessor::validateVersionRange(const RestoreData &data) const .arg(applicationDisplayName).arg(result.path.toUserOutput()), Issue::Type::WARNING); i.defaultButton = QMessageBox::No; i.escapeButton = QMessageBox::No; + i.buttons.clear(); i.buttons.insert(QMessageBox::Yes, Continue); i.buttons.insert(QMessageBox::No, DiscardAndContinue); result.issue = i; @@ -615,6 +619,7 @@ SettingsAccessor::RestoreData MergingSettingsAccessor::readData(const FileName & RestoreData secondaryData = m_secondaryAccessor ? m_secondaryAccessor->readData(m_secondaryAccessor->baseFilePath(), parent) : RestoreData(); + secondaryData.data = preprocessReadSettings(secondaryData.data); int secondaryVersion = versionFromMap(secondaryData.data); if (secondaryVersion == -1) secondaryVersion = currentVersion(); // No version information, use currentVersion since @@ -635,10 +640,12 @@ SettingsAccessor::RestoreData MergingSettingsAccessor::readData(const FileName & "Do you want to try loading it anyway?") .arg(secondaryData.path.toUserOutput()) .arg(applicationDisplayName), Issue::Type::WARNING); + secondaryData.issue->buttons.clear(); secondaryData.issue->buttons.insert(QMessageBox::Yes, Continue); secondaryData.issue->buttons.insert(QMessageBox::No, DiscardAndContinue); secondaryData.issue->defaultButton = QMessageBox::No; secondaryData.issue->escapeButton = QMessageBox::No; + setVersionInMap(secondaryData.data, std::max(secondaryVersion, firstSupportedVersion())); } if (secondaryData.hasIssue()) {