diff options
author | Tobias Hunger <tobias.hunger@nokia.com> | 2010-09-09 11:48:01 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@nokia.com> | 2010-09-13 18:17:50 +0200 |
commit | 6b3132a69bb198a6df7d3811d71695b90578c720 (patch) | |
tree | e9a5471d65c5ad16c47acb2860b5919eb2295ede | |
parent | 03c0060b960bb6e4c75540d69bbedf1ce7a3a1e1 (diff) | |
download | qt-creator-6b3132a69bb198a6df7d3811d71695b90578c720.tar.gz |
Provide more information when updating .user files
* Add more information into the updated map of .user-file data:
* Version from which we updated
* File name of the old .user-file we saved away
* Make the keys available to projects from as constants defined
in ProjectExplorer::Constants
-rw-r--r-- | src/plugins/projectexplorer/projectexplorerconstants.h | 6 | ||||
-rw-r--r-- | src/plugins/projectexplorer/userfileaccessor.cpp | 20 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index 64ba865db3..c92f1019f6 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -214,6 +214,12 @@ const char * const BUILDSTEPS_CLEAN = "ProjectExplorer.BuildSteps.Clean"; const char * const BUILDSTEPS_BUILD = "ProjectExplorer.BuildSteps.Build"; const char * const BUILDSTEPS_DEPLOY = "ProjectExplorer.BuildSteps.Deploy"; +// .user file accessor keys: +const char * const USERFILE_WAS_UPDATED_KEY = "ProjectExplorer.Project.Updater.DidUpdate"; +const char * const USERFILE_PREVIOUS_VERSION_KEY = "ProjectExplorer.Project.Updater.PreviousVersion"; +const char * const USERFILE_VERSION_KEY = "ProjectExplorer.Project.Updater.FileVersion"; +const char * const USERFILE_BACKUP_FILENAME_KEY = "ProjectExplorer.Project.Updater.PreviousVersion"; + // Deploy Configuration id: const char * const DEFAULT_DEPLOYCONFIGURATION_ID = "ProjectExplorer.DefaultDeployConfiguration"; diff --git a/src/plugins/projectexplorer/userfileaccessor.cpp b/src/plugins/projectexplorer/userfileaccessor.cpp index 948780e82b..9ecf0f18c6 100644 --- a/src/plugins/projectexplorer/userfileaccessor.cpp +++ b/src/plugins/projectexplorer/userfileaccessor.cpp @@ -34,6 +34,7 @@ #include "project.h" #include "projectexplorer.h" #include "projectexplorersettings.h" +#include "projectexplorerconstants.h" #include "target.h" #include "toolchain.h" @@ -50,9 +51,8 @@ using namespace ProjectExplorer; namespace { -const char * const USER_FILE_VERSION = "ProjectExplorer.Project.Updater.FileVersion"; -const char * const USER_FILE_ENVIRONMENT_ID = "ProjectExplorer.Project.Updater.EnvironmentId"; -const char * const WAS_UPDATED = "ProjectExplorer.Project.Updater.DidUpdate"; +const char * const USERFILE_ENVIRONMENT_ID_KEY = "ProjectExplorer.Project.Updater.EnvironmentId"; + const char * const PROJECT_FILE_POSTFIX(".user"); // Version 0 is used in Qt Creator 1.3.x and @@ -314,14 +314,14 @@ QVariantMap UserFileAccessor::restoreSettings(Project *project) QVariantMap map(reader.restoreValues()); // Get and verify file version: - const int fileVersion = map.value(QLatin1String(USER_FILE_VERSION), 0).toInt(); + const int fileVersion = map.value(QLatin1String(Constants::USERFILE_VERSION_KEY), 0).toInt(); if (fileVersion < m_firstVersion || fileVersion > m_lastVersion + 1) { qWarning() << "File version" << fileVersion << "is not supported."; return QVariantMap(); } // Verify environment Id: - QUuid fileEnvironmentId(map.value(QLatin1String(USER_FILE_ENVIRONMENT_ID)).toString()); + QUuid fileEnvironmentId(map.value(QLatin1String(USERFILE_ENVIRONMENT_ID_KEY)).toString()); if (!fileEnvironmentId.isNull() && fileEnvironmentId != ProjectExplorerPlugin::instance()->projectExplorerSettings().environmentId) { // TODO tr, casing check @@ -347,17 +347,19 @@ QVariantMap UserFileAccessor::restoreSettings(Project *project) // Do we need to do a update? if (fileVersion != m_lastVersion + 1) { - map.insert(QLatin1String(WAS_UPDATED), true); + map.insert(QLatin1String(Constants::USERFILE_WAS_UPDATED_KEY), true); const QString backupFileName = fileName + '.' + m_handlers.value(fileVersion)->displayUserFileVersion(); + map.insert(QLatin1String(Constants::USERFILE_BACKUP_FILENAME_KEY), backupFileName); QFile::remove(backupFileName); // Remove because copy doesn't overwrite QFile::copy(fileName, backupFileName); } + map.insert(QLatin1String(Constants::USERFILE_PREVIOUS_VERSION_KEY), fileVersion); // Update: for (int i = fileVersion; i <= m_lastVersion; ++i) map = m_handlers.value(i)->update(project, map); - map.insert(QLatin1String(USER_FILE_VERSION), m_lastVersion + 1); + map.insert(QLatin1String(Constants::USERFILE_VERSION_KEY), m_lastVersion + 1); return map; } @@ -372,8 +374,8 @@ bool UserFileAccessor::saveSettings(Project *project, const QVariantMap &map) for (QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i) writer.saveValue(i.key(), i.value()); - writer.saveValue(QLatin1String(USER_FILE_VERSION), m_lastVersion + 1); - writer.saveValue(QLatin1String(USER_FILE_ENVIRONMENT_ID), + writer.saveValue(QLatin1String(Constants::USERFILE_VERSION_KEY), m_lastVersion + 1); + writer.saveValue(QLatin1String(USERFILE_ENVIRONMENT_ID_KEY), ProjectExplorerPlugin::instance()->projectExplorerSettings().environmentId.toString()); return writer.save(fileNameFor(project->file()->fileName()), "QtCreatorProject"); |