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

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 ...@@ -961,21 +961,13 @@ int SettingsAccessor::firstSupportedVersion() const
return d->firstVersion(); return d->firstVersion();
} }
void SettingsAccessor::backupUserFile() const Utils::FileName SettingsAccessor::backupName(const QVariantMap &data) const
{ {
SettingsAccessorPrivate::Settings oldSettings; QString backupName = defaultFileName(m_userSuffix);
oldSettings.path = FileName::fromString(defaultFileName(m_userSuffix)); const QByteArray oldEnvironmentId = environmentIdFromMap(data);
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);
if (!oldEnvironmentId.isEmpty() && oldEnvironmentId != creatorId()) if (!oldEnvironmentId.isEmpty() && oldEnvironmentId != creatorId())
backupName += QLatin1String(".") + QString::fromLatin1(oldEnvironmentId).mid(1, 7); backupName += QLatin1String(".") + QString::fromLatin1(oldEnvironmentId).mid(1, 7);
const int oldVersion = versionFromMap(oldSettings.map); const int oldVersion = versionFromMap(data);
if (oldVersion != currentVersion()) { if (oldVersion != currentVersion()) {
VersionUpgrader *upgrader = d->upgrader(oldVersion); VersionUpgrader *upgrader = d->upgrader(oldVersion);
if (upgrader) if (upgrader)
...@@ -983,8 +975,22 @@ void SettingsAccessor::backupUserFile() const ...@@ -983,8 +975,22 @@ void SettingsAccessor::backupUserFile() const
else else
backupName += QLatin1String(".") + QString::number(oldVersion); backupName += QLatin1String(".") + QString::number(oldVersion);
} }
if (backupName != origName) return Utils::FileName::fromString(backupName);
QFile::copy(origName, 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 QVariantMap SettingsAccessor::readUserSettings(QWidget *parent) const
......
...@@ -114,6 +114,8 @@ protected: ...@@ -114,6 +114,8 @@ protected:
virtual bool isBetterMatch(const QVariantMap &origData, const QVariantMap &newData) const; 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; virtual IssueInfo findIssues(const QVariantMap &data, const Utils::FileName &path) const;
private: 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