Exemplo n.º 1
0
        DriveEntry createDriveEntry(string path)
        {
            IFileProvider fileProvider = this.physicalProviderConstructor(path);
            DriveEntry    driveEntry   = new DriveEntry(path, fileProvider);

            AddDisposable(driveEntry);
            return(driveEntry);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Classifies <paramref name="path"/>, get-or-creates a matching <paramref name="fileProvider"/> to be returned and <paramref name="subpath"/> within that file provider.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="fileProvider"></param>
        /// <param name="subpath"></param>
        /// <returns>true if <paramref name="path"/> was successfully parsed</returns>
        bool GetFileProviderAndPath(string path, out IFileProvider fileProvider, out string subpath)
        {
            // Assert not disposding
            if (IsDisposing)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            // Match
            Match match        = Pattern.Match(path);
            Group relativepath = match.Groups["relativepath"];

            // Fix relative path to rooted path
            if (relativepath.Success)
            {
                if (path == ".")
                {
                    path = Directory.GetCurrentDirectory();
                }
                else
                {
                    path = Path.GetFullPath(path);
                }
                match = Pattern.Match(path);
            }

            // "C:\"
            Group windows_driveletter = match.Groups["windows_driveletter"], windows_path = match.Groups["windows_path"];

            if (windows_driveletter.Success)
            {
                DriveEntry driveEntry = entries.GetOrAdd(windows_driveletter.Value + "\\", entryConstructor);
                fileProvider = driveEntry.fileProvider;
                subpath      = windows_path.Success ? windows_path.Value : "";
                return(true);
            }

            // "/"
            Group unix_rooted_path = match.Groups["unix_rooted_path"];

            if (unix_rooted_path.Success)
            {
                DriveEntry driveEntry = entries.GetOrAdd("/", entryConstructor);
                fileProvider = driveEntry.fileProvider;
                subpath      = path;
                return(true);
            }

            // "\\server\share\path"
            Group share_server = match.Groups["share_server"], share_name = match.Groups["share_name"], share_path = match.Groups["share_path"];

            if (share_server.Success)
            {
                if (share_name.Success)
                {
                    string     driveName  = path.Substring(0, share_name.Index + share_name.Length);
                    DriveEntry driveEntry = entries.GetOrAdd(driveName, entryConstructor);
                    fileProvider = driveEntry.fileProvider;
                    subpath      = share_path.Success ? share_path.Value : "";
                    return(true);
                }
                else
                {
                    // "\\server"
                    string     driveName  = path.Substring(0, share_server.Index + share_server.Length);
                    DriveEntry driveEntry = entries.GetOrAdd(driveName, entryConstructor);
                    fileProvider = driveEntry.fileProvider;
                    subpath      = "";
                    return(true);
                }
            }

            fileProvider = null; subpath = null; return(false);
        }