diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index c3e728df0f..4aac25096b 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -243,7 +243,7 @@ namespace OpenRA public static void InitializeSettings(Arguments args) { - Settings = new Settings(Platform.ResolvePath(Path.Combine("^", "settings.yaml")), args); + Settings = new Settings(Platform.ResolvePath(Path.Combine(Platform.SupportDirPrefix, "settings.yaml")), args); } public static RunStatus InitializeAndRun(string[] args) @@ -528,7 +528,7 @@ namespace OpenRA ThreadPool.QueueUserWorkItem(_ => { var mod = ModData.Manifest.Metadata; - var directory = Platform.ResolvePath("^", "Screenshots", ModData.Manifest.Id, mod.Version); + var directory = Platform.ResolvePath(Platform.SupportDirPrefix, "Screenshots", ModData.Manifest.Id, mod.Version); Directory.CreateDirectory(directory); var filename = TimestampedFilename(true); diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index dcd7476c2e..195d7602ba 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -70,7 +70,7 @@ namespace OpenRA try { // HACK: If the path is inside the the support directory then we may need to create it - if (name.StartsWith("^", StringComparison.Ordinal)) + if (Platform.IsPathRelativeToSupportDirectory(name)) { // Assume that the path is a directory if there is not an existing file with the same name var resolved = Platform.ResolvePath(name); @@ -144,7 +144,7 @@ namespace OpenRA name = name.Substring(1); // Don't try to open the map directory in the support directory if it doesn't exist - if (name.StartsWith("^", StringComparison.Ordinal)) + if (Platform.IsPathRelativeToSupportDirectory(name)) { var resolved = Platform.ResolvePath(name); if (!Directory.Exists(resolved) || !File.Exists(resolved)) diff --git a/OpenRA.Game/Network/ReplayRecorder.cs b/OpenRA.Game/Network/ReplayRecorder.cs index 50741388c5..50162716b5 100644 --- a/OpenRA.Game/Network/ReplayRecorder.cs +++ b/OpenRA.Game/Network/ReplayRecorder.cs @@ -45,7 +45,7 @@ namespace OpenRA.Network { var filename = chooseFilename(); var mod = Game.ModData.Manifest; - var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.Metadata.Version); + var dir = Platform.ResolvePath(Platform.SupportDirPrefix, "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 16bc44ea28..b0747fb314 100644 --- a/OpenRA.Game/Platform.cs +++ b/OpenRA.Game/Platform.cs @@ -21,6 +21,7 @@ namespace OpenRA public static class Platform { + public const string SupportDirPrefix = "^"; public static PlatformType CurrentPlatform { get { return currentPlatform.Value; } } public static readonly Guid SessionGUID = Guid.NewGuid(); @@ -143,7 +144,7 @@ namespace OpenRA path = path.TrimEnd(' ', '\t'); // Paths starting with ^ are relative to the support dir - if (path.StartsWith("^", StringComparison.Ordinal)) + if (Platform.IsPathRelativeToSupportDirectory(path)) path = SupportDir + path.Substring(1); // Paths starting with . are relative to the game dir @@ -166,12 +167,17 @@ namespace OpenRA public static string UnresolvePath(string path) { if (path.StartsWith(SupportDir, StringComparison.Ordinal)) - path = "^" + path.Substring(SupportDir.Length); + path = Platform.SupportDirPrefix + path.Substring(SupportDir.Length); if (path.StartsWith(GameDir, StringComparison.Ordinal)) path = "./" + path.Substring(GameDir.Length); return path; } + + public static bool IsPathRelativeToSupportDirectory(string path) + { + return path.StartsWith(Platform.SupportDirPrefix, StringComparison.Ordinal); + } } } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index cc0db7906f..d75470969c 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -384,7 +384,7 @@ namespace OpenRA.Server if (Dedicated) { - var motdFile = Platform.ResolvePath("^", "motd.txt"); + var motdFile = Platform.ResolvePath(Platform.SupportDirPrefix, "motd.txt"); if (!File.Exists(motdFile)) File.WriteAllText(motdFile, "Welcome, have fun and good luck!"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index 8ea8205c32..586f631b38 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -289,7 +289,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (newsBG != null) { - var cacheFile = Platform.ResolvePath("^", "news.yaml"); + var cacheFile = Platform.ResolvePath(Platform.SupportDirPrefix, "news.yaml"); 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 080a68aa6c..157c06db21 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("^", "Replays", mod.Id, mod.Metadata.Version); + var dir = Platform.ResolvePath(Platform.SupportDirPrefix, "Replays", mod.Id, mod.Metadata.Version); if (Directory.Exists(dir)) ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template));