From de7a84e8edf344826106048cb3245392785d2d50 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 20 Nov 2020 17:39:06 +0000 Subject: [PATCH] Don't use Platform.ResolvePath when constructing hardcoded paths. --- OpenRA.Game/Game.cs | 10 +++++----- OpenRA.Game/Network/ReplayRecorder.cs | 2 +- OpenRA.Game/Platform.cs | 6 ------ OpenRA.Game/Scripting/ScriptContext.cs | 2 +- OpenRA.Game/Server/Server.cs | 10 +++++----- .../UtilityCommands/CheckRuntimeAssembliesCommand.cs | 2 +- .../Widgets/Logic/GameSaveBrowserLogic.cs | 8 ++++---- OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs | 2 +- OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs | 2 +- packaging/windows/WindowsLauncher.cs.in | 2 +- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index e35491ff7e..dcbe764045 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -262,7 +262,7 @@ namespace OpenRA public static void InitializeSettings(Arguments args) { - Settings = new Settings(Platform.ResolvePath(Path.Combine(Platform.SupportDirPrefix, "settings.yaml")), args); + Settings = new Settings(Path.Combine(Platform.SupportDir, "settings.yaml"), args); } public static RunStatus InitializeAndRun(string[] args) @@ -285,7 +285,7 @@ namespace OpenRA // Load the engine version as early as possible so it can be written to exception logs try { - EngineVersion = File.ReadAllText(Platform.ResolvePath(Path.Combine(".", "VERSION"))).Trim(); + EngineVersion = File.ReadAllText(Path.Combine(Platform.GameDir, "VERSION")).Trim(); } catch { } @@ -324,7 +324,7 @@ namespace OpenRA Settings.Game.Platform = p; try { - var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + p + ".dll")); + var rendererPath = Path.Combine(Platform.GameDir, "OpenRA.Platforms." + p + ".dll"); var assembly = Assembly.LoadFile(rendererPath); var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); @@ -423,7 +423,7 @@ namespace OpenRA ModData = new ModData(Mods[mod], Mods, true); - LocalPlayerProfile = new LocalPlayerProfile(Platform.ResolvePath(Path.Combine("^", Settings.Game.AuthProfile)), ModData.Manifest.Get()); + LocalPlayerProfile = new LocalPlayerProfile(Path.Combine(Platform.SupportDir, Settings.Game.AuthProfile), ModData.Manifest.Get()); if (!ModData.LoadScreen.BeforeLoad()) return; @@ -539,7 +539,7 @@ namespace OpenRA using (new PerfTimer("Renderer.SaveScreenshot")) { var mod = ModData.Manifest.Metadata; - var directory = Platform.ResolvePath(Platform.SupportDirPrefix, "Screenshots", ModData.Manifest.Id, mod.Version); + var directory = Path.Combine(Platform.SupportDir, "Screenshots", ModData.Manifest.Id, mod.Version); Directory.CreateDirectory(directory); var filename = TimestampedFilename(true); diff --git a/OpenRA.Game/Network/ReplayRecorder.cs b/OpenRA.Game/Network/ReplayRecorder.cs index 33e0075c08..d56386727a 100644 --- a/OpenRA.Game/Network/ReplayRecorder.cs +++ b/OpenRA.Game/Network/ReplayRecorder.cs @@ -44,7 +44,7 @@ namespace OpenRA.Network { var filename = chooseFilename(); var mod = Game.ModData.Manifest; - var dir = Platform.ResolvePath(Platform.SupportDirPrefix, "Replays", mod.Id, mod.Metadata.Version); + var dir = Path.Combine(Platform.SupportDir, "Replays", mod.Id, mod.Metadata.Version); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); diff --git a/OpenRA.Game/Platform.cs b/OpenRA.Game/Platform.cs index 484c3c87df..b8533bd3ac 100644 --- a/OpenRA.Game/Platform.cs +++ b/OpenRA.Game/Platform.cs @@ -203,12 +203,6 @@ namespace OpenRA return path; } - /// Replace special character prefixes with full paths. - public static string ResolvePath(params string[] path) - { - return ResolvePath(Path.Combine(path)); - } - /// /// Replace the full path prefix with the special notation characters ^ or . /// and transforms \ path separators to / on Windows diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index 2461cd0793..9457e490e1 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -162,7 +162,7 @@ namespace OpenRA.Scripting PlayerCommands = FilterCommands(world.Map.Rules.Actors["player"], knownPlayerCommands); runtime.Globals["GameDir"] = Platform.GameDir; - runtime.DoBuffer(File.Open(Platform.ResolvePath(".", "lua", "scriptwrapper.lua"), FileMode.Open, FileAccess.Read).ReadAllText(), "scriptwrapper.lua").Dispose(); + runtime.DoBuffer(File.Open(Path.Combine(Platform.GameDir, "lua", "scriptwrapper.lua"), FileMode.Open, FileAccess.Read).ReadAllText(), "scriptwrapper.lua").Dispose(); tick = (LuaFunction)runtime.Globals["Tick"]; // Register globals diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index b459fcd82d..154fa0ea31 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -531,7 +531,7 @@ namespace OpenRA.Server if (Type == ServerType.Dedicated) { - var motdFile = Platform.ResolvePath(Platform.SupportDirPrefix, "motd.txt"); + var motdFile = Path.Combine(Platform.SupportDir, "motd.txt"); if (!File.Exists(motdFile)) File.WriteAllText(motdFile, "Welcome, have fun and good luck!"); @@ -930,8 +930,8 @@ namespace OpenRA.Server while ((invalidIndex = filename.IndexOfAny(invalidChars)) != -1) filename = filename.Remove(invalidIndex, 1); - var baseSavePath = Platform.ResolvePath( - Platform.SupportDirPrefix, + var baseSavePath = Path.Combine( + Platform.SupportDir, "Saves", ModData.Manifest.Id, ModData.Manifest.Metadata.Version); @@ -958,8 +958,8 @@ namespace OpenRA.Server while ((invalidIndex = filename.IndexOfAny(invalidChars)) != -1) filename = filename.Remove(invalidIndex, 1); - var savePath = Platform.ResolvePath( - Platform.SupportDirPrefix, + var savePath = Path.Combine( + Platform.SupportDir, "Saves", ModData.Manifest.Id, ModData.Manifest.Metadata.Version, diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckRuntimeAssembliesCommand.cs b/OpenRA.Mods.Common/UtilityCommands/CheckRuntimeAssembliesCommand.cs index b8de7b08db..55858057df 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckRuntimeAssembliesCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckRuntimeAssembliesCommand.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.UtilityCommands .ToArray(); // Load the renderer assembly so we can check its dependencies - Assembly.LoadFile(Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms.Default.dll"))); + Assembly.LoadFile(Path.Combine(Platform.GameDir, "OpenRA.Platforms.Default.dll")); var missing = new List(); foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) diff --git a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs index f5f1dc7d78..e15273dc87 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var newTemplate = panel.Get("NEW_TEMPLATE"); var mod = modData.Manifest; - baseSavePath = Platform.ResolvePath(Platform.SupportDirPrefix, "Saves", mod.Id, mod.Metadata.Version); + baseSavePath = Path.Combine(Platform.SupportDir, "Saves", mod.Id, mod.Metadata.Version); // Avoid filename conflicts when creating new saves if (isSavePanel) @@ -304,8 +304,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic void Save(World world) { var filename = saveTextField.Text + ".orasav"; - var testPath = Platform.ResolvePath( - Platform.SupportDirPrefix, + var testPath = Path.Combine( + Platform.SupportDir, "Saves", modData.Manifest.Id, modData.Manifest.Metadata.Version, @@ -351,7 +351,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public static bool IsLoadPanelEnabled(Manifest mod) { - var baseSavePath = Platform.ResolvePath(Platform.SupportDirPrefix, "Saves", mod.Id, mod.Metadata.Version); + var baseSavePath = Path.Combine(Platform.SupportDir, "Saves", mod.Id, mod.Metadata.Version); if (!Directory.Exists(baseSavePath)) return false; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index a653f71efc..a5c9492756 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -264,7 +264,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (newsBG != null && Game.Settings.Game.FetchNews) { - var cacheFile = Platform.ResolvePath(Platform.SupportDirPrefix, webServices.GameNewsFileName); + var cacheFile = Path.Combine(Platform.SupportDir, webServices.GameNewsFileName); var currentNews = ParseNews(cacheFile); if (currentNews != null) DisplayNews(currentNews); diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 2a553a3c60..7debaa0298 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var template = panel.Get("REPLAY_TEMPLATE"); var mod = modData.Manifest; - var dir = Platform.ResolvePath(Platform.SupportDirPrefix, "Replays", mod.Id, mod.Metadata.Version); + var dir = Path.Combine(Platform.SupportDir, "Replays", mod.Id, mod.Metadata.Version); if (Directory.Exists(dir)) ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template)); diff --git a/packaging/windows/WindowsLauncher.cs.in b/packaging/windows/WindowsLauncher.cs.in index 53b87e5d42..2a370e928b 100644 --- a/packaging/windows/WindowsLauncher.cs.in +++ b/packaging/windows/WindowsLauncher.cs.in @@ -178,7 +178,7 @@ namespace OpenRA { try { - Process.Start(Platform.ResolvePath("^", "Logs")); + Process.Start(Path.Combine(Platform.SupportDir, "Logs")); } catch { } }