From acda3403a5e20e3536c732e3a3a7c0eb80486f91 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 4 Apr 2013 16:21:04 +0200 Subject: [PATCH] SettingsAccessor: Backup old settings again. Back up when saving. That is more robust when several instances work with the same project at the same time. Change-Id: Id4bfd5eab4184934f66909dcf7a580fef1e104ae Reviewed-by: Daniel Teske --- .../projectexplorer/settingsaccessor.cpp | 24 +++++++++++++++++++ .../projectexplorer/settingsaccessor.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/plugins/projectexplorer/settingsaccessor.cpp b/src/plugins/projectexplorer/settingsaccessor.cpp index 3b35b6e445b..ef64b041fe8 100644 --- a/src/plugins/projectexplorer/settingsaccessor.cpp +++ b/src/plugins/projectexplorer/settingsaccessor.cpp @@ -611,6 +611,8 @@ bool SettingsAccessor::saveSettings(const QVariantMap &map) const if (map.isEmpty()) return false; + backupUserFile(); + SettingsData settings(map); settings.m_fileName = Utils::FileName::fromString(defaultFileName(m_userFileAcessor.suffix())); const QVariant &shared = m_project->property(SHARED_SETTINGS); @@ -686,6 +688,28 @@ int SettingsAccessor::currentVersion() const return m_lastVersion + 1; } +void SettingsAccessor::backupUserFile() const +{ + SettingsData oldSettings; + oldSettings.m_fileName = Utils::FileName::fromString(defaultFileName(m_userFileAcessor.suffix())); + if (!m_userFileAcessor.readFile(&oldSettings)) + return; + + // Do we need to do a backup? + const QString origName = oldSettings.fileName().toString(); + QString backupName = origName; + if (oldSettings.environmentId() != creatorId()) + backupName += QLatin1String(".") + QString::fromLatin1(oldSettings.environmentId()).mid(1, 7); + if (oldSettings.version() != currentVersion()) { + if (m_handlers.contains(oldSettings.version())) + backupName += QLatin1String(".") + m_handlers.value(oldSettings.version())->displayUserFileVersion(); + else + backupName += QLatin1String(".") + QString::number(oldSettings.version()); + } + if (backupName != origName) + QFile::copy(origName, backupName); +} + void SettingsAccessor::incrementVersion(SettingsAccessor::SettingsData &data) const { data.m_map = m_handlers.value(data.version())->update(m_project, data.m_map); diff --git a/src/plugins/projectexplorer/settingsaccessor.h b/src/plugins/projectexplorer/settingsaccessor.h index b324b6d7dbe..b11f7237669 100644 --- a/src/plugins/projectexplorer/settingsaccessor.h +++ b/src/plugins/projectexplorer/settingsaccessor.h @@ -63,6 +63,7 @@ private: QByteArray creatorId() const; QString defaultFileName(const QString &suffix) const; int currentVersion() const; + void backupUserFile() const; // The relevant data from the settings currently in use. class SettingsData