Fix env variable remove on Windows

Removing env variable failed on uninstallation on Windows if the env
variable value had @TargetDir@ in path. File separators got changed
from Windows style to unix style.
Update documentation to inform users to use '\\' as separators when
setting a path as environment variable.

Tested with following values (component.addElevatedOperation(...)
in components.qs):
"@TargetDir@\\lib\\system\\qtplugins"
"not_a_path_but_variable_with_slash_\\qtplugins"
"not_a_path_but_variable_with_slash_/qtplugins"
"%SystemRoot%\\lib\\system\\qtplugins"
"12345"

Task-number: QTIFW-1148
Change-Id: Iaa48d890e70afdbe56bbf389dd4994d5ae91b316
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
This commit is contained in:
Johanna Äijälä 2019-10-10 12:09:43 +03:00
parent c706665c4f
commit 1b96174671
2 changed files with 14 additions and 2 deletions

View File

@ -188,6 +188,8 @@
persistently. This is currently only supported on Windows. persistently. This is currently only supported on Windows.
If \c system is set to \c true, the persistent variable is set If \c system is set to \c true, the persistent variable is set
system-wide, not only for the current user. system-wide, not only for the current user.
Note, if you set path to environment variable, use '\\' as separator, for example:
@Targetdir@\\lib\\system.
\row \row
\li RegisterFileType \li RegisterFileType
\li "RegisterFileType" \c extension \c command [\c description [\c contentType [\c icon]]]. \li "RegisterFileType" \c extension \c command [\c description [\c contentType [\c icon]]].

View File

@ -152,8 +152,18 @@ UpdateOperation::Error undoSetting(const QString &regPath,
SettingsType registry(regPath, QSettingsWrapper::NativeFormat); SettingsType registry(regPath, QSettingsWrapper::NativeFormat);
actual = registry.value(name).toString(); actual = registry.value(name).toString();
} }
if (actual != value) //key changed, don't undo
if (actual != value)
{
//For unknown reason paths with @TargetDir@ variable get modified
//so that Windows file separators get replaced with unix style separators,
//fix separators before matching to actual value in register
QString tempValue = value;
QString fixedValue = tempValue.replace(QLatin1Char('/'), QLatin1Char('\\'));
if (actual != fixedValue) //key changed, don't undo
return UpdateOperation::UserDefinedError; return UpdateOperation::UserDefinedError;
}
bool error = false; bool error = false;
if (handleRegExpandSz(regPath, name, oldValue, errorString, &error)) if (handleRegExpandSz(regPath, name, oldValue, errorString, &error))