From 63c624b273f4cbe019894cbfd921a52d18c494d0 Mon Sep 17 00:00:00 2001
From: Heiko <61519853+htcfreek@users.noreply.github.com>
Date: Wed, 28 Jun 2023 11:44:13 +0200
Subject: [PATCH] [Run] Fix environment helper for nested environment variables
(#27034)
* Updates to EnvironmentHelper
* Revert "Updates to EnvironmentHelper"
This reverts commit 8af2441c3455a37d3abe5aa328c9d495ff4c97ad.
* Environment helper fix
* clean up usings
* fix spelling
* Update comment
* Update src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs
* Update src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs
---
.../PowerLauncher/Helper/EnvironmentHelper.cs | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs b/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs
index 272c73ee6e..37c5a2bc1a 100644
--- a/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs
+++ b/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs
@@ -68,12 +68,23 @@ namespace PowerLauncher.Helper
}
///
- /// This method updates the environment of PT Run's process when called. It is called when we receive a special WindowMessage.
+ /// This method is used as a function wrapper to do the update twice. We have to do it twice to get correct variable sets if they contain nested variables (e.g. PATH contains %JAVA_HOME%).
+ /// It is called when we receive a special WindowMessage.
///
internal static void UpdateEnvironment()
{
Stopwatch.Normal("EnvironmentHelper.UpdateEnvironment - Duration cost", () =>
{
+ ExecuteEnvironmentUpdate();
+ ExecuteEnvironmentUpdate();
+ });
+ }
+
+ ///
+ /// This method updates the environment of PT Run's process when called.
+ ///
+ private static void ExecuteEnvironmentUpdate()
+ {
// Caching existing process environment and getting updated environment variables
IDictionary oldProcessEnvironment = GetEnvironmentVariablesWithErrorLog(EnvironmentVariableTarget.Process);
var newEnvironment = new Dictionary(StringComparer.OrdinalIgnoreCase);
@@ -151,7 +162,6 @@ namespace PowerLauncher.Helper
Log.Error($"Failed to update the environment variable [{kv.Key}] for the PT Run process. Their name is null or empty. (The variable value has a length of [{varValueLength}].)", typeof(PowerLauncher.Helper.EnvironmentHelper));
}
}
- });
}
///