From 3a6796ac9d5bf00ec3c18de5a80764750f3b154c Mon Sep 17 00:00:00 2001 From: Markus Hartung Date: Sun, 2 Jul 2017 21:51:53 +0200 Subject: [PATCH] Fix for some AppDomains that doesn't add trailing DirectorySeparatorChar. --- OpenRA.Game/Platform.cs | 16 ++++++++++++++-- OpenRA.Test/OpenRA.Game/PlatformTest.cs | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Platform.cs b/OpenRA.Game/Platform.cs index 91f16e9914..61b3d3fa8a 100644 --- a/OpenRA.Game/Platform.cs +++ b/OpenRA.Game/Platform.cs @@ -95,12 +95,24 @@ namespace OpenRA return dir + Path.DirectorySeparatorChar; } - public static string GameDir { get { return AppDomain.CurrentDomain.BaseDirectory; } } + public static string GameDir + { + get + { + var dir = AppDomain.CurrentDomain.BaseDirectory; + + // Add trailing DirectorySeparator for some buggy AppPool hosts + if (!dir.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) + dir += Path.DirectorySeparatorChar; + + return dir; + } + } /// Replaces special character prefixes with full paths. public static string ResolvePath(string path) { - path = path.TrimEnd(new char[] { ' ', '\t' }); + path = path.TrimEnd(' ', '\t'); // Paths starting with ^ are relative to the support dir if (path.StartsWith("^", StringComparison.Ordinal)) diff --git a/OpenRA.Test/OpenRA.Game/PlatformTest.cs b/OpenRA.Test/OpenRA.Game/PlatformTest.cs index fe357fa277..58152f043d 100644 --- a/OpenRA.Test/OpenRA.Game/PlatformTest.cs +++ b/OpenRA.Test/OpenRA.Game/PlatformTest.cs @@ -39,6 +39,9 @@ namespace OpenRA.Test Assert.That(Platform.ResolvePath("./testpath"), Is.EqualTo(Path.Combine(gameDir, "testpath"))); + Assert.That(Platform.ResolvePath(Path.Combine(".", "Foo.dll")), + Is.EqualTo(Path.Combine(gameDir, "Foo.dll"))); + Assert.That(Platform.ResolvePath("testpath"), Is.EqualTo("testpath")); }