From ab9cce7fe7adba200744c5930600d3d1c43a9073 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 29 Jan 2018 13:05:13 +0100 Subject: Utils: use system case for environment variables on windows Match case of user changed environment variables to the already defined variables. Change-Id: Ic012d35faa0822df3523ab642491c9f19051853c Reviewed-by: Oswald Buddenhagen Reviewed-by: hjk --- src/libs/utils/environment.cpp | 7 ++++++- src/libs/utils/environment.h | 1 + src/libs/utils/environmentmodel.cpp | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp index 0705c30081..74534eeaf4 100644 --- a/src/libs/utils/environment.cpp +++ b/src/libs/utils/environment.cpp @@ -500,7 +500,7 @@ Environment::const_iterator Environment::constEnd() const Environment::const_iterator Environment::constFind(const QString &name) const { - return m_values.constFind(name); + return findKey(m_values, m_osType, name); } int Environment::size() const @@ -567,6 +567,11 @@ bool Environment::hasKey(const QString &key) const return m_values.contains(key); } +OsType Environment::osType() const +{ + return m_osType; +} + QString Environment::userName() const { return value(QString::fromLatin1(m_osType == OsTypeWindows ? "USERNAME" : "USER")); diff --git a/src/libs/utils/environment.h b/src/libs/utils/environment.h index e3a382daf0..4fed80a8bb 100644 --- a/src/libs/utils/environment.h +++ b/src/libs/utils/environment.h @@ -91,6 +91,7 @@ public: /// Return the Environment changes necessary to modify this into the other environment. QList diff(const Environment &other, bool checkAppendPrepend = false) const; bool hasKey(const QString &key) const; + OsType osType() const; QString userName() const; diff --git a/src/libs/utils/environmentmodel.cpp b/src/libs/utils/environmentmodel.cpp index 4191d3abee..fde8e7ad55 100644 --- a/src/libs/utils/environmentmodel.cpp +++ b/src/libs/utils/environmentmodel.cpp @@ -364,6 +364,13 @@ void EnvironmentModel::setUserChanges(QList list) name = name.trimmed(); if (name.startsWith(QLatin1String("export "))) name = name.mid(7).trimmed(); + if (d->m_baseEnvironment.osType() == OsTypeWindows) { + // Environment variable names are case-insensitive under windows, but we still + // want to preserve the case of pre-existing variables. + auto it = d->m_baseEnvironment.constFind(name); + if (it != d->m_baseEnvironment.constEnd()) + name = d->m_baseEnvironment.key(it); + } } d->updateResultEnvironment(); -- cgit v1.2.1