[PT Run] Fix crash in EnvHelper if no machine path var exists (#15540)

* addig if condition

* fix spelling
This commit is contained in:
Heiko
2022-01-17 23:56:39 +01:00
committed by GitHub
parent 5035dc6754
commit 8c24d7e942

View File

@@ -20,7 +20,7 @@ namespace PowerLauncher.Helper
public static class EnvironmentHelper public static class EnvironmentHelper
{ {
// The HashSet will contain the list of environment variables that will be skipped on update. // The HashSet will contain the list of environment variables that will be skipped on update.
private const string PathVariable = "Path"; private const string PathVariableName = "Path";
private static readonly HashSet<string> _protectedProcessVariables = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private static readonly HashSet<string> _protectedProcessVariables = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
/// <summary> /// <summary>
@@ -179,17 +179,27 @@ namespace PowerLauncher.Helper
string uVarValue = (string)uVar.Value; string uVarValue = (string)uVar.Value;
// The variable name of the path variable can be upper case, lower case ore mixed case. So we have to compare case insensitive. // The variable name of the path variable can be upper case, lower case ore mixed case. So we have to compare case insensitive.
if (!uVarKey.Equals(PathVariable, StringComparison.OrdinalIgnoreCase)) if (!uVarKey.Equals(PathVariableName, StringComparison.OrdinalIgnoreCase))
{ {
environment[uVarKey] = uVarValue; environment[uVarKey] = uVarValue;
} }
else else
{
// Checking if the list of (machine) variables contains a path variable
if (environment.ContainsKey(PathVariableName))
{ {
// When we merging the PATH variables we can't simply overwrite machine layer's value. The path variable must be joined by appending the user value to the machine value. // When we merging the PATH variables we can't simply overwrite machine layer's value. The path variable must be joined by appending the user value to the machine value.
// This is the official behavior and checked by trying it out on the physical machine. // This is the official behavior and checked by trying it out on the physical machine.
string newPathValue = environment[uVarKey].EndsWith(';') ? environment[uVarKey] + uVarValue : environment[uVarKey] + ';' + uVarValue; string newPathValue = environment[uVarKey].EndsWith(';') ? environment[uVarKey] + uVarValue : environment[uVarKey] + ';' + uVarValue;
environment[uVarKey] = newPathValue; environment[uVarKey] = newPathValue;
} }
else
{
// Log warning and only write user value into dictionary
Log.Warn("The List of machine variables doesn't contain a path variable! The merged list won't contain any machine paths in the path variable.", typeof(PowerLauncher.Helper.EnvironmentHelper));
environment[uVarKey] = uVarValue;
}
}
} }
} }
} }