Commit acda3403 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

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: default avatarDaniel Teske <daniel.teske@digia.com>
parent 0addee8b
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment