//
using System;
using System.IO;
+using Mono.XBuild.Utilities;
namespace Microsoft.Build.Internal
{
{
public static string NormalizeFilePath (string path)
{
+ if (MSBuildUtils.RunningOnWindows || string.IsNullOrWhiteSpace (path) || File.Exists (path) || Directory.Exists (path))
+ return path;
return path.Replace ('\\', Path.DirectorySeparatorChar);
}
+
+ public static string FindMatchingPath (string path)
+ {
+ if (MSBuildUtils.RunningOnWindows || string.IsNullOrWhiteSpace (path) || File.Exists (path) || Directory.Exists (path))
+ return path;
+ path = path.Replace ('\\', Path.DirectorySeparatorChar);
+ var file = Path.GetFileName (path);
+ var dir = FindMatchingPath (Path.GetDirectoryName (path));
+ if (Directory.Exists (dir)) {
+ foreach (FileSystemInfo e in new DirectoryInfo (dir.Length > 0 ? dir : ".").EnumerateFileSystemInfos ()) {
+ if (e.Name.Equals (file, StringComparison.OrdinalIgnoreCase))
+ return dir.Length > 0 ? Path.Combine (dir, e.Name) : e.Name;
+ }
+ }
+ // The directory part is still based on case insensitive match.
+ return dir.Length > 0 ? Path.Combine (dir, file) : file;
+ }
}
}