From cbea08e1fe32a16c5cbd055591d2e147eaf75415 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 11 Mar 2021 21:33:41 +0000 Subject: [PATCH] Fix non-relative path handling in install logic. --- .../Installation/InstallFromDiscLogic.cs | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs index c8c6e2b829..3051e69fc5 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs @@ -268,11 +268,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic case "delete": { - var sourcePath = Path.Combine(path, i.Value.Value); - - // Try as an absolute path - if (!File.Exists(sourcePath)) - sourcePath = Platform.ResolvePath(i.Value.Value); + // Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected disc path + var sourcePath = i.Value.Value.StartsWith("^") ? Platform.ResolvePath(i.Value.Value) : Path.Combine(path, i.Value.Value); Log.Write("debug", "Deleting {0}", sourcePath); File.Delete(sourcePath); @@ -325,11 +322,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic static void ExtractFromPackage(ExtractionType type, string path, MiniYaml actionYaml, List extractedFiles, Action updateMessage) { - var sourcePath = Path.Combine(path, actionYaml.Value); - - // Try as an absolute path - if (!File.Exists(sourcePath)) - sourcePath = Platform.ResolvePath(actionYaml.Value); + // Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected disc path + var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : Path.Combine(path, actionYaml.Value); using (var source = File.OpenRead(sourcePath)) { @@ -384,11 +378,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic static void ExtractFromMSCab(string path, MiniYaml actionYaml, List extractedFiles, Action updateMessage) { - var sourcePath = Path.Combine(path, actionYaml.Value); - - // Try as an absolute path - if (!File.Exists(sourcePath)) - sourcePath = Platform.ResolvePath(actionYaml.Value); + // Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected disc path + var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : Path.Combine(path, actionYaml.Value); using (var source = File.OpenRead(sourcePath)) { @@ -418,11 +409,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic static void ExtractFromISCab(string path, MiniYaml actionYaml, List extractedFiles, Action updateMessage) { - var sourcePath = Path.Combine(path, actionYaml.Value); - - // Try as an absolute path - if (!File.Exists(sourcePath)) - sourcePath = Platform.ResolvePath(actionYaml.Value); + // Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected disc path + var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : Path.Combine(path, actionYaml.Value); var volumeNode = actionYaml.Nodes.FirstOrDefault(n => n.Key == "Volumes"); if (volumeNode == null)