/// <summary> /// Return the legacy drive letter (e.g. "C", "D") for the given path or null if one doesn't exist /// </summary> public static string GetDriveLetter(this IExtendedFileService extendedFileService, IFileService fileService, string path) { string pathCanonicalRoot = extendedFileService.GetCanonicalRoot(fileService, path); // We have to walk drives foreach (var drive in extendedFileService.GetLogicalDriveStrings()) { string driveCanonicalRoot = extendedFileService.GetCanonicalRoot(fileService, drive); if (String.Equals(pathCanonicalRoot, driveCanonicalRoot)) { return(drive); } } return(null); //int rootLength; //switch (Paths.GetPathFormat(path, out rootLength)) //{ // case PathFormat.UnknownFormat: // case PathFormat.CurrentDirectoryRelative: // case PathFormat.CurrentVolumeRelative: // case PathFormat.UniformNamingConvention: // case PathFormat.UniformNamingConventionExtended: // return null; // case PathFormat.DriveAbsolute: // case PathFormat.DriveRelative: // // Already in the "C:" form // return path.Substring(0, 1); // case PathFormat.Device: // case PathFormat.VolumeAbsoluteExtended: // // Get the DOS alias for this path // string root = path.Substring(0, rootLength); // string deviceAlias = fileService.QueryDosDeviceNames(root).FirstOrDefault(); // if (deviceAlias == null) return null; // // We have to walk drives // foreach (var drive in fileService.GetLogicalDriveStrings()) // { // string driveAlias = fileService.QueryDosDeviceNames(drive).FirstOrDefault(); // if (String.Equals(deviceAlias, driveAlias)) // { // return driveAlias; // } // } // break; //} //return null; }
/// <summary> /// Return the legacy drive letter (e.g. "C", "D") for the given path or null if one doesn't exist /// </summary> public static string GetDriveLetter(this IExtendedFileService extendedFileService, IFileService fileService, string path) { string pathCanonicalRoot = extendedFileService.GetCanonicalRoot(fileService, path); // We have to walk drives foreach (var drive in extendedFileService.GetLogicalDriveStrings()) { string driveCanonicalRoot = extendedFileService.GetCanonicalRoot(fileService, drive); if (string.Equals(pathCanonicalRoot, driveCanonicalRoot)) { return(drive); } } return(null); }
private string AddEntry(string directory, string canonicalRoot = null) { string root = Paths.GetRoot(directory); canonicalRoot = canonicalRoot ?? extendedFileService.GetCanonicalRoot(fileService, directory); // If the directory has vanished, walk up while (!fileService.DirectoryExists(directory) && !String.Equals((directory = Paths.GetDirectory(directory)), root, StringComparison.Ordinal)) { Debug.Assert(directory != null); } if (this.volumeDirectories.ContainsKey(canonicalRoot)) { this.volumeDirectories[canonicalRoot] = directory; } else { this.volumeDirectories.Add(canonicalRoot, directory); } return(canonicalRoot); }
private string AddEntry(string directory, string canonicalRoot = null) { string root = Paths.GetRoot(directory); canonicalRoot = canonicalRoot ?? _extendedFileService.GetCanonicalRoot(_fileService, directory); // Look for the highest level existing directory or use the root while (!_fileService.DirectoryExists(directory) && !string.Equals((directory = Paths.GetDirectory(directory)), root, StringComparison.Ordinal)) { Debug.Assert(directory != null); } if (_volumeDirectories.ContainsKey(canonicalRoot)) { _volumeDirectories[canonicalRoot] = directory; } else { _volumeDirectories.Add(canonicalRoot, directory); } return(canonicalRoot); }