Skip to content

Commit

Permalink
Added: Single Notification for Env-Vars Update & Set Vars on Launch C…
Browse files Browse the repository at this point in the history
…ommand
  • Loading branch information
Sewer56 committed Nov 28, 2022
1 parent 9ce3d90 commit 767372e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
35 changes: 23 additions & 12 deletions source/Reloaded.Mod.Launcher.Lib/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,31 @@ private static void SetLoaderPaths(LoaderConfig config, string launcherDirectory
// Update Environment Variables
Task.Run(() =>
{
// In case of first time use, so variables propagate to child processes.
Environment.SetEnvironmentVariable("RELOADEDII_LOADER64", config.LoaderPath64, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("RELOADEDII_LOADER32", config.LoaderPath32, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("RELOADEDII_LAUNCHER", config.LauncherPath, EnvironmentVariableTarget.Process);

// DO NOT CHANGE, BREAKS BACKCOMPAT
// THIS IS SLOW, RUN THIS SECOND
Environment.SetEnvironmentVariable("RELOADEDIIMODS", config.GetModConfigDirectory(), EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable("RELOADEDII_LOADER64", config.LoaderPath64, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable("RELOADEDII_LOADER32", config.LoaderPath32, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable("RELOADEDII_LAUNCHER", config.LauncherPath, EnvironmentVariableTarget.User);

RegisterLoaderPaths(config);
});
}

internal static void RegisterLoaderPaths(LoaderConfig config, bool onlyEssentialVars = false)
{
// In case user before changes are propagated.
Environment.SetEnvironmentVariable("RELOADEDII_LOADER64", config.LoaderPath64, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("RELOADEDII_LOADER32", config.LoaderPath32, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("RELOADEDII_LAUNCHER", config.LauncherPath, EnvironmentVariableTarget.Process);

// DO NOT CHANGE THIS METHOD, BREAKS BACKCOMPAT
// THIS IS SLOW, RUN THIS SECOND
// Get the user classes subkey.
using (var environmentKey = Registry.CurrentUser.OpenSubKey("Environment", true))
{
environmentKey.SetValue("RELOADEDII_LOADER64", config.LoaderPath64);
environmentKey.SetValue("RELOADEDII_LOADER32", config.LoaderPath32);
environmentKey.SetValue("RELOADEDII_LAUNCHER", config.LauncherPath);
}

// Fires WM_SETTINGCHANGE indirectly.
if (!onlyEssentialVars)
Environment.SetEnvironmentVariable("RELOADEDIIMODS", config.GetModConfigDirectory(), EnvironmentVariableTarget.User);
}

/// <summary>
/// Checks for mod loader updates.
Expand Down
1 change: 1 addition & 0 deletions source/Reloaded.Mod.Launcher.Lib/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private static void LaunchApplicationAndExit(string applicationToLaunch)
// Acquire arguments
var loaderConfig = IoC.Get<LoaderConfig>();
loaderConfig.UpdatePaths(Paths.CurrentProgramFolder, Resources.ErrorLoaderNotFound.Get());
Setup.RegisterLoaderPaths(loaderConfig, true);
IConfig<LoaderConfig>.ToPath(loaderConfig, Paths.LoaderConfigPath);

_commandLineArguments.TryGetValue(Constants.ParameterArguments, out var arguments);
Expand Down

0 comments on commit 767372e

Please sign in to comment.