Improve behaviour of Platform.UnresolvePath on Windows.
This commit is contained in:
@@ -144,7 +144,7 @@ namespace OpenRA
|
|||||||
path = path.TrimEnd(' ', '\t');
|
path = path.TrimEnd(' ', '\t');
|
||||||
|
|
||||||
// Paths starting with ^ are relative to the support dir
|
// Paths starting with ^ are relative to the support dir
|
||||||
if (Platform.IsPathRelativeToSupportDirectory(path))
|
if (IsPathRelativeToSupportDirectory(path))
|
||||||
path = SupportDir + path.Substring(1);
|
path = SupportDir + path.Substring(1);
|
||||||
|
|
||||||
// Paths starting with . are relative to the game dir
|
// Paths starting with . are relative to the game dir
|
||||||
@@ -163,21 +163,30 @@ namespace OpenRA
|
|||||||
return ResolvePath(path.Aggregate(Path.Combine));
|
return ResolvePath(path.Aggregate(Path.Combine));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Replace the full path prefix with the special notation characters ^ or .</summary>
|
/// <summary>
|
||||||
|
/// Replace the full path prefix with the special notation characters ^ or .
|
||||||
|
/// and transforms \ path separators to / on Windows
|
||||||
|
/// </summary>
|
||||||
public static string UnresolvePath(string path)
|
public static string UnresolvePath(string path)
|
||||||
{
|
{
|
||||||
if (path.StartsWith(SupportDir, StringComparison.Ordinal))
|
// Use a case insensitive comparison on windows to avoid problems
|
||||||
path = Platform.SupportDirPrefix + path.Substring(SupportDir.Length);
|
// with inconsistent drive letter case
|
||||||
|
var compare = CurrentPlatform == PlatformType.Windows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
|
||||||
|
if (path.StartsWith(SupportDir, compare))
|
||||||
|
path = SupportDirPrefix + path.Substring(SupportDir.Length);
|
||||||
|
|
||||||
if (path.StartsWith(GameDir, StringComparison.Ordinal))
|
if (path.StartsWith(GameDir, compare))
|
||||||
path = "./" + path.Substring(GameDir.Length);
|
path = "./" + path.Substring(GameDir.Length);
|
||||||
|
|
||||||
|
if (CurrentPlatform == PlatformType.Windows)
|
||||||
|
path = path.Replace('\\', '/');
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsPathRelativeToSupportDirectory(string path)
|
public static bool IsPathRelativeToSupportDirectory(string path)
|
||||||
{
|
{
|
||||||
return path.StartsWith(Platform.SupportDirPrefix, StringComparison.Ordinal);
|
return path.StartsWith(SupportDirPrefix, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user