Commit 3145b270 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Make detection of .user-file copying more robust

 * Create and store a UUID when starting the projectexplorer plugin
 * Check for this UUID when reading .user files:
    * Hostnames may change due to moving between dhcp networks, etc.
    * MAC addresses do not change when booting different OSes
 * Put UUID into .user file when writting it (instead of hostname).

Task-number: QTCREATORBUG-1820
parent eab55aac
......@@ -753,6 +753,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
d->m_projectExplorerSettings.showCompilerOutput = s->value("ProjectExplorer/Settings/ShowCompilerOutput", false).toBool();
d->m_projectExplorerSettings.cleanOldAppOutput = s->value("ProjectExplorer/Settings/CleanOldAppOutput", false).toBool();
d->m_projectExplorerSettings.useJom = s->value("ProjectExplorer/Settings/UseJom", true).toBool();
d->m_projectExplorerSettings.environmentId = QUuid(s->value("ProjectExplorer/Settings/EnvironmentId").toString());
if (d->m_projectExplorerSettings.environmentId.isNull())
d->m_projectExplorerSettings.environmentId = QUuid::createUuid();
connect(d->m_sessionManagerAction, SIGNAL(triggered()), this, SLOT(showSessionManager()));
......@@ -1000,6 +1003,7 @@ void ProjectExplorerPlugin::savePersistentSettings()
s->setValue("ProjectExplorer/Settings/ShowCompilerOutput", d->m_projectExplorerSettings.showCompilerOutput);
s->setValue("ProjectExplorer/Settings/CleanOldAppOutput", d->m_projectExplorerSettings.cleanOldAppOutput);
s->setValue("ProjectExplorer/Settings/UseJom", d->m_projectExplorerSettings.useJom);
s->setValue("ProjectExplorer/Settings/EnvironmentId", d->m_projectExplorerSettings.environmentId.toString());
......@@ -30,6 +30,8 @@
#include <QtCore/QUuid>
namespace ProjectExplorer {
namespace Internal {
......@@ -44,6 +46,10 @@ struct ProjectExplorerSettings
bool showCompilerOutput;
bool cleanOldAppOutput;
bool useJom;
// Add a UUid which is used to identify the development environment.
// This is used to warn the user when he is trying to open a .user file that was created
// somewhere else (which might lead to unexpected results).
QUuid environmentId;
inline bool operator==(const ProjectExplorerSettings &p1, const ProjectExplorerSettings &p2)
......@@ -32,6 +32,8 @@
#include "buildconfiguration.h"
#include "persistentsettings.h"
#include "project.h"
#include "projectexplorer.h"
#include "projectexplorersettings.h"
#include "target.h"
#include "toolchain.h"
......@@ -49,7 +51,7 @@ using namespace ProjectExplorer;
namespace {
const char * const USER_FILE_VERSION = "ProjectExplorer.Project.Updater.FileVersion";
const char * const USER_FILE_HOSTNAME = "ProjectExplorer.Project.Updater.Hostname";
const char * const USER_FILE_ENVIRONMENT_ID = "ProjectExplorer.Project.Updater.EnvironmentId";
const char * const WAS_UPDATED = "ProjectExplorer.Project.Updater.DidUpdate";
const char * const PROJECT_FILE_POSTFIX(".user");
......@@ -264,20 +266,22 @@ QVariantMap UserFileAccessor::restoreSettings(Project *project)
return QVariantMap();
// Verify hostname
const QString hostname = map.value(QLatin1String(USER_FILE_HOSTNAME)).toString();
if (!hostname.isEmpty() && hostname != QHostInfo::localHostName()) {
// Ask the user
// Verify environment Id:
QUuid fileEnvironmentId(map.value(QLatin1String(USER_FILE_ENVIRONMENT_ID)).toString());
if (!fileEnvironmentId.isNull()
&& fileEnvironmentId != ProjectExplorerPlugin::instance()->projectExplorerSettings().environmentId) {
// TODO tr, casing check
QMessageBox msgBox(QMessageBox::Question,
"Project Settings File from a different Host?"),
"Project Settings File from a different Environment?"),
"Qt Creator has found a .user settings file from a host %1. "
"The hostname for this computer is %2. \n\n"
"The .user settings files contain machine specific settings. "
"They should not be copied to a different environment. \n\n"
"Still load the settings file?").arg(hostname, QHostInfo::localHostName()),
"Qt Creator has found a .user settings file which was "
"created for another development setup, maybe "
"originating from another machine.\n\n"
"The .user settings files contain environment specific "
"settings. They should not be copied to a different "
"environment. \n\n"
"Do you still want to load the settings file?"),
QMessageBox::Yes | QMessageBox::No,
......@@ -315,7 +319,8 @@ bool UserFileAccessor::saveSettings(Project *project, const QVariantMap &map)
writer.saveValue(i.key(), i.value());
writer.saveValue(QLatin1String(USER_FILE_VERSION), m_lastVersion + 1);
writer.saveValue(QLatin1String(USER_FILE_HOSTNAME), QHostInfo::localHostName());
return>file()->fileName()), "QtCreatorProject");
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