Fix for some AppDomains that doesn't add trailing DirectorySeparatorChar.

This commit is contained in:
Markus Hartung
2017-07-02 21:51:53 +02:00
committed by Paul Chote
parent c2e36b8eeb
commit 3a6796ac9d
2 changed files with 17 additions and 2 deletions

View File

@@ -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;
}
}
/// <summary>Replaces special character prefixes with full paths.</summary>
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))

View File

@@ -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"));
}