From d37119655b63940be892798b3696e5f9a9565656 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 14 Aug 2018 16:54:39 +0000 Subject: [PATCH] Add Engine.SupportDir argument. --- OpenRA.Game/Game.cs | 4 ++++ OpenRA.Game/Platform.cs | 21 +++++++++++++++++++++ OpenRA.Server/Program.cs | 5 ++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index c6c1057836..93f4470a6f 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -258,6 +258,10 @@ namespace OpenRA static void Initialize(Arguments args) { + var supportDirArg = args.GetValue("Engine.SupportDir", null); + if (supportDirArg != null) + Platform.OverrideSupportDir(supportDirArg); + Console.WriteLine("Platform is {0}", Platform.CurrentPlatform); // Load the engine version as early as possible so it can be written to exception logs diff --git a/OpenRA.Game/Platform.cs b/OpenRA.Game/Platform.cs index 01288879e3..a15a588359 100644 --- a/OpenRA.Game/Platform.cs +++ b/OpenRA.Game/Platform.cs @@ -71,9 +71,30 @@ namespace OpenRA /// public static string SupportDir { get { return supportDir.Value; } } static Lazy supportDir = Exts.Lazy(GetSupportDir); + static string supportDirOverride; + + /// + /// Specify a custom support directory that already exists on the filesystem. + /// MUST be called before Platform.SupportDir is first accessed. + /// + public static void OverrideSupportDir(string path) + { + if (!Directory.Exists(path)) + throw new DirectoryNotFoundException(path); + + if (!path.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) && + !path.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal)) + path += Path.DirectorySeparatorChar; + + supportDirOverride = path; + } static string GetSupportDir() { + // Use the custom override if it has been defined + if (supportDirOverride != null) + return supportDirOverride; + // Use a local directory in the game root if it exists (shared with the system support dir) var localSupportDir = Path.Combine(GameDir, "Support"); if (Directory.Exists(localSupportDir)) diff --git a/OpenRA.Server/Program.cs b/OpenRA.Server/Program.cs index 458cfb5eb9..87c197e4e3 100644 --- a/OpenRA.Server/Program.cs +++ b/OpenRA.Server/Program.cs @@ -11,7 +11,6 @@ using System; using System.IO; -using System.Linq; using System.Net; using System.Threading; using OpenRA.Support; @@ -23,6 +22,10 @@ namespace OpenRA.Server static void Main(string[] args) { var arguments = new Arguments(args); + var supportDirArg = arguments.GetValue("Engine.SupportDir", null); + if (supportDirArg != null) + Platform.OverrideSupportDir(supportDirArg); + Log.AddChannel("debug", "dedicated-debug.log"); Log.AddChannel("perf", "dedicated-perf.log"); Log.AddChannel("server", "dedicated-server.log");