Skip to content

Commit

Permalink
Changed: Always Update Loader Config on Boot from Shortcut
Browse files Browse the repository at this point in the history
Fixes booting from portable mode shortcuts after launching global version launcher.
  • Loading branch information
Sewer56 committed Mar 5, 2022
1 parent 2884987 commit 64c4ab0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
27 changes: 2 additions & 25 deletions source/Reloaded.Mod.Launcher.Lib/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,31 +269,8 @@ private static void SetLoaderPaths(LoaderConfig config, string launcherDirectory
if (String.IsNullOrEmpty(launcherDirectory))
throw new DllNotFoundException("The provided launcher directory is null or empty. This is a bug. Report this to the developer.");

// Loader configuration.
var loaderPath32 = Paths.GetLoaderPath32(launcherDirectory);
if (! File.Exists(loaderPath32))
throw new DllNotFoundException($"(x86) {Path.GetFileName(loaderPath32)} {Resources.ErrorLoaderNotFound.Get()}");

var loaderPath64 = Paths.GetLoaderPath64(launcherDirectory);
if (!File.Exists(loaderPath64))
throw new DllNotFoundException($"(x64) {Path.GetFileName(loaderPath64)} {Resources.ErrorLoaderNotFound.Get()}");

// Bootstrappers.
var bootstrapper32Path = Paths.GetBootstrapperPath32(launcherDirectory);
if (!File.Exists(bootstrapper32Path))
throw new DllNotFoundException($"{Path.GetFileName(bootstrapper32Path)} {Resources.ErrorLoaderNotFound.Get()}");

var bootstrapper64Path = Paths.GetBootstrapperPath64(launcherDirectory);
if (!File.Exists(bootstrapper64Path))
throw new DllNotFoundException($"{Path.GetFileName(bootstrapper64Path)} {Resources.ErrorLoaderNotFound.Get()}");

// Set to config.
config.LauncherPath = Process.GetCurrentProcess().MainModule!.FileName;
config.LoaderPath32 = loaderPath32;
config.LoaderPath64 = loaderPath64;
config.Bootstrapper32Path = bootstrapper32Path;
config.Bootstrapper64Path = bootstrapper64Path;

config.UpdatePaths(launcherDirectory, Resources.ErrorLoaderNotFound.Get());

// Update Environment Variables
Task.Run(() => Environment.SetEnvironmentVariable("RELOADEDIIMODS", config.GetModConfigDirectory(), EnvironmentVariableTarget.User));
}
Expand Down
7 changes: 6 additions & 1 deletion source/Reloaded.Mod.Launcher.Lib/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Reloaded.Mod.Launcher.Lib.Models.ViewModel.Dialog;
using Reloaded.Mod.Launcher.Lib.Static;
using Reloaded.Mod.Launcher.Lib.Utility;
using Reloaded.Mod.Loader.IO;
using Reloaded.Mod.Loader.IO.Config;
using Reloaded.Mod.Loader.Update.Providers.Web;

Expand Down Expand Up @@ -63,11 +64,15 @@ private static void KillProcessWithId(string processId)
private static void LaunchApplicationAndExit(string applicationToLaunch)
{
// Acquire arguments
var loaderConfig = IoC.Get<LoaderConfig>();
loaderConfig.UpdatePaths(Paths.CurrentProgramFolder, Resources.ErrorLoaderNotFound.Get());
IConfig<LoaderConfig>.ToPath(loaderConfig, Paths.LoaderConfigPath);

_commandLineArguments.TryGetValue(Constants.ParameterArguments, out var arguments);
arguments ??= "";
applicationToLaunch = Path.GetFullPath(applicationToLaunch);

var application = ApplicationConfig.GetAllApplications(IoC.Get<LoaderConfig>().GetApplicationConfigDirectory()).FirstOrDefault(x => ApplicationConfig.GetAbsoluteAppLocation(x) == applicationToLaunch);
var application = ApplicationConfig.GetAllApplications(loaderConfig.GetApplicationConfigDirectory()).FirstOrDefault(x => ApplicationConfig.GetAbsoluteAppLocation(x) == applicationToLaunch);
if (application != null)
arguments = $"{arguments} {application.Config.AppArguments}";

Expand Down
37 changes: 37 additions & 0 deletions source/Reloaded.Mod.Loader.IO/Config/LoaderConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,43 @@ private void ResetMissingDirectories()
}
}

/// <summary>
/// Updates the paths referenced in this config file.
/// </summary>
/// <param name="launcherDirectory">The directory in which the launcher is contained.</param>
/// <param name="dllNotFoundText">Error text to display when a DLL is not found.</param>
/// <exception cref="DllNotFoundException">A required DLL is not found.</exception>
public void UpdatePaths(string launcherDirectory, string dllNotFoundText = "")
{
if (String.IsNullOrEmpty(launcherDirectory))
throw new DllNotFoundException("The provided launcher directory is null or empty. This is a bug. Report this to the developer.");

// Loader configuration.
var loaderPath32 = Paths.GetLoaderPath32(launcherDirectory);
if (!File.Exists(loaderPath32))
throw new DllNotFoundException($"(x86) {Path.GetFileName(loaderPath32)} {dllNotFoundText}");

var loaderPath64 = Paths.GetLoaderPath64(launcherDirectory);
if (!File.Exists(loaderPath64))
throw new DllNotFoundException($"(x64) {Path.GetFileName(loaderPath64)} {dllNotFoundText}");

// Bootstrappers.
var bootstrapper32Path = Paths.GetBootstrapperPath32(launcherDirectory);
if (!File.Exists(bootstrapper32Path))
throw new DllNotFoundException($"{Path.GetFileName(bootstrapper32Path)} {dllNotFoundText}");

var bootstrapper64Path = Paths.GetBootstrapperPath64(launcherDirectory);
if (!File.Exists(bootstrapper64Path))
throw new DllNotFoundException($"{Path.GetFileName(bootstrapper64Path)} {dllNotFoundText}");

// Set to config.
LauncherPath = Process.GetCurrentProcess().MainModule!.FileName;
LoaderPath32 = loaderPath32;
LoaderPath64 = loaderPath64;
Bootstrapper32Path = bootstrapper32Path;
Bootstrapper64Path = bootstrapper64Path;
}

// Removes empty NuGet feeds.*
private void CleanEmptyFeeds()
{
Expand Down

0 comments on commit 64c4ab0

Please sign in to comment.