Commit 150447dd authored by Tobias Hunger's avatar Tobias Hunger

SettingsAccessor: Introduce backupName()

Change-Id: Iac2e7f4b88f0df9e724f2c45516bf66c9715639d
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 8880112c
......@@ -961,21 +961,13 @@ int SettingsAccessor::firstSupportedVersion() const
return d->firstVersion();
}
void SettingsAccessor::backupUserFile() const
Utils::FileName SettingsAccessor::backupName(const QVariantMap &data) const
{
SettingsAccessorPrivate::Settings oldSettings;
oldSettings.path = FileName::fromString(defaultFileName(m_userSuffix));
oldSettings.map = readFile(oldSettings.path);
if (oldSettings.map.isEmpty())
return;
// Do we need to do a backup?
const QString origName = oldSettings.path.toString();
QString backupName = origName;
const QByteArray oldEnvironmentId = environmentIdFromMap(oldSettings.map);
QString backupName = defaultFileName(m_userSuffix);
const QByteArray oldEnvironmentId = environmentIdFromMap(data);
if (!oldEnvironmentId.isEmpty() && oldEnvironmentId != creatorId())
backupName += QLatin1String(".") + QString::fromLatin1(oldEnvironmentId).mid(1, 7);
const int oldVersion = versionFromMap(oldSettings.map);
const int oldVersion = versionFromMap(data);
if (oldVersion != currentVersion()) {
VersionUpgrader *upgrader = d->upgrader(oldVersion);
if (upgrader)
......@@ -983,8 +975,22 @@ void SettingsAccessor::backupUserFile() const
else
backupName += QLatin1String(".") + QString::number(oldVersion);
}
if (backupName != origName)
QFile::copy(origName, backupName);
return Utils::FileName::fromString(backupName);
}
void SettingsAccessor::backupUserFile() const
{
SettingsAccessorPrivate::Settings oldSettings;
oldSettings.path = FileName::fromString(defaultFileName(m_userSuffix));
oldSettings.map = readFile(oldSettings.path);
if (oldSettings.map.isEmpty())
return;
// Do we need to do a backup?
const QString origName = oldSettings.path.toString();
QString backupFileName = backupName(oldSettings.map).toString();
if (backupFileName != origName)
QFile::copy(origName, backupFileName);
}
QVariantMap SettingsAccessor::readUserSettings(QWidget *parent) const
......
......@@ -114,6 +114,8 @@ protected:
virtual bool isBetterMatch(const QVariantMap &origData, const QVariantMap &newData) const;
virtual Utils::FileName backupName(const QVariantMap &data) const;
virtual IssueInfo findIssues(const QVariantMap &data, const Utils::FileName &path) const;
private:
......
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