From 278ba8ef3faa7b236845e6338984f0e74a73fb97 Mon Sep 17 00:00:00 2001 From: naejadu Date: Tue, 7 Jun 2022 00:36:14 +0200 Subject: [PATCH] Check environment for the Path if run by first-time wizard Signed-off-by: Arne Babenhauserheide --- MachineConfig.cs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/MachineConfig.cs b/MachineConfig.cs index 7aa220d..ca5f88a 100755 --- a/MachineConfig.cs +++ b/MachineConfig.cs @@ -33,7 +33,7 @@ public static void CheckConfig(string pathConfig) { string line = lines[i]; - /* + /* ================================ * CHECK AND RUN JAVA COMMAND * */ @@ -62,7 +62,7 @@ public static void CheckConfig(string pathConfig) } - /* + /* ================================ * ENABLE OR DISABLE LAUNCH PARAMETERS FOR JAVA8 OR JAVA 9+ * */ @@ -98,6 +98,36 @@ public static void CheckConfig(string pathConfig) private static void GetJVMinfo(string pathJVM) { + + /* ================================ + * Only run if the installer started tray.exe with "-welcome" arg. + * If OS did not have Java installed, the Freenet installer installed a JVM. + * This JVM's java.exe can be found in PATH. + * Problem: Installer starts tray.exe with old environment variables, + * meaning PATH does not contain Java.exe at this point. + * This results in "JVM not found" error. + * Solution: Read environment variables again. + * + */ + foreach (var arg in Environment.GetCommandLineArgs()) + { + if( arg.Equals("-welcome") ) + { + string machineEnv = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine); + string currentEnv = System.Environment.GetEnvironmentVariable("Path"); + if( !machineEnv.Equals(currentEnv) ) + { + System.Environment.SetEnvironmentVariable("Path", machineEnv); + } + break; + } + } + + + /* ================================ + * RUN JAVA AND GET JVM INFO + * + */ using (System.Diagnostics.Process pProcess = new System.Diagnostics.Process()) { pProcess.StartInfo.FileName = pathJVM;