From b30cfe4adad3cf2023c20bf081fead5277aa6451 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 27 Jun 2017 18:16:00 +0000 Subject: [PATCH] Move launchPath argument from ExternalMods ctor to .Register. --- OpenRA.Game/ExternalMods.cs | 10 ++-------- OpenRA.Game/Game.cs | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/ExternalMods.cs b/OpenRA.Game/ExternalMods.cs index 0056671f17..6587b9b62a 100644 --- a/OpenRA.Game/ExternalMods.cs +++ b/OpenRA.Game/ExternalMods.cs @@ -38,15 +38,9 @@ namespace OpenRA { readonly Dictionary mods = new Dictionary(); readonly SheetBuilder sheetBuilder; - readonly string launchPath; - public ExternalMods(string launchPath) + public ExternalMods() { - // Process.Start requires paths to not be quoted, even if they contain spaces - if (launchPath.First() == '"' && launchPath.Last() == '"') - launchPath = launchPath.Substring(1, launchPath.Length - 2); - - this.launchPath = launchPath; sheetBuilder = new SheetBuilder(SheetType.BGRA, 256); // Load registered mods @@ -83,7 +77,7 @@ namespace OpenRA mods[ExternalMod.MakeKey(mod)] = mod; } - internal void Register(Manifest mod) + internal void Register(Manifest mod, string launchPath) { if (mod.Metadata.Hidden) return; diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 23c399bfd4..86e146c7c0 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -338,8 +338,21 @@ namespace OpenRA foreach (var mod in Mods) Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version); - var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location); - ExternalMods = new ExternalMods(launchPath); + ExternalMods = new ExternalMods(); + + Manifest currentMod; + if (modID != null && Mods.TryGetValue(modID, out currentMod)) + { + var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location); + + // Sanitize input from platform-specific launchers + // Process.Start requires paths to not be quoted, even if they contain spaces + if (launchPath.First() == '"' && launchPath.Last() == '"') + launchPath = launchPath.Substring(1, launchPath.Length - 2); + + ExternalMods.Register(Mods[modID], launchPath); + } + Console.WriteLine("External mods:"); foreach (var mod in ExternalMods) Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); @@ -385,7 +398,6 @@ namespace OpenRA Sound.StopVideo(); ModData = new ModData(Mods[mod], Mods, true); - ExternalMods.Register(ModData.Manifest); if (!ModData.LoadScreen.BeforeLoad()) return;