private void CheckPathCasing(ResourcePath path) { // Run this inside the thread pool due to overhead. Task.Run(() => { var prevPath = GetPath(ResourcePath.Root); var diskPath = ResourcePath.Root; var mismatch = false; foreach (var segment in path.EnumerateSegments()) { var prevDir = new DirectoryInfo(prevPath); var found = false; foreach (var info in prevDir.GetFileSystemInfos()) { if (!string.Equals(info.Name, segment, StringComparison.InvariantCultureIgnoreCase)) { // Not the dir info for this path segment, ignore it. continue; } if (!string.Equals(info.Name, segment, StringComparison.InvariantCulture)) { // Segments match insensitively but not the other way around. Bad. mismatch = true; } diskPath /= info.Name; prevPath = Path.Combine(prevPath, info.Name); found = true; break; } if (!found) { // File doesn't exist. Let somebody else throw the exception. return; } } if (mismatch) { _sawmill.Warning("Path '{0}' has mismatching case from file on disk ('{1}'). " + "This can cause loading failures on certain file system configurations " + "and should be corrected.", path, diskPath); } }); }
private bool TryGetNodeAt(ResourcePath path, out INode node) { if (!path.IsRooted) { throw new ArgumentException("Path must be rooted", nameof(path)); } path = path.Clean(); if (path == ResourcePath.Root) { node = _rootDirectoryNode; return(true); } var directory = _rootDirectoryNode; var segments = path.EnumerateSegments().ToArray(); for (var i = 0; i < segments.Length; i++) { var segment = segments[i]; if (!directory.Children.TryGetValue(segment, out var child)) { node = default; return(false); } if (i == segments.Length - 1) { node = child; return(true); } directory = (DirectoryNode)child; } throw new InvalidOperationException("Unreachable."); }