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 <oswald.buddenhagen@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
David Schulz
2018-01-29 13:05:13 +01:00
parent 88d65af7d3
commit ab9cce7fe7
3 changed files with 14 additions and 1 deletions

View File

@@ -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"));

View File

@@ -91,6 +91,7 @@ public:
/// Return the Environment changes necessary to modify this into the other environment.
QList<EnvironmentItem> diff(const Environment &other, bool checkAppendPrepend = false) const;
bool hasKey(const QString &key) const;
OsType osType() const;
QString userName() const;

View File

@@ -364,6 +364,13 @@ void EnvironmentModel::setUserChanges(QList<EnvironmentItem> 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();