Esempio n. 1
0
        public static Stream OpenAsyncRead(string fullPath)
        {
            Debug.Assert(PathUtilities.IsAbsolute(fullPath));

            return(RethrowExceptionsAsIOException(() => new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous)));
        }
Esempio n. 2
0
 public static string ResolveRelativePath(string path, string basePath, string baseDirectory)
 {
     Debug.Assert(baseDirectory == null || PathUtilities.IsAbsolute(baseDirectory));
     return(ResolveRelativePath(PathUtilities.GetPathKind(path), path, basePath, baseDirectory));
 }
Esempio n. 3
0
        private static string ResolveRelativePath(PathKind kind, string path, string basePath, string baseDirectory)
        {
            switch (kind)
            {
            case PathKind.Empty:
                return(null);

            case PathKind.Relative:
                baseDirectory = GetBaseDirectory(basePath, baseDirectory);
                if (baseDirectory == null)
                {
                    return(null);
                }

                // with no search paths relative paths are relative to the base directory:
                return(PathUtilities.CombinePathsUnchecked(baseDirectory, path));

            case PathKind.RelativeToCurrentDirectory:
                baseDirectory = GetBaseDirectory(basePath, baseDirectory);
                if (baseDirectory == null)
                {
                    return(null);
                }

                if (path.Length == 1)
                {
                    // "."
                    return(baseDirectory);
                }
                else
                {
                    // ".\path"
                    return(PathUtilities.CombinePathsUnchecked(baseDirectory, path));
                }

            case PathKind.RelativeToCurrentParent:
                baseDirectory = GetBaseDirectory(basePath, baseDirectory);
                if (baseDirectory == null)
                {
                    return(null);
                }

                // ".."
                return(PathUtilities.CombinePathsUnchecked(baseDirectory, path));

            case PathKind.RelativeToCurrentRoot:
                string baseRoot;
                if (basePath != null)
                {
                    baseRoot = PathUtilities.GetPathRoot(basePath);
                }
                else if (baseDirectory != null)
                {
                    baseRoot = PathUtilities.GetPathRoot(baseDirectory);
                }
                else
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(baseRoot))
                {
                    return(null);
                }

                Debug.Assert(PathUtilities.IsDirectorySeparator(path[0]));
                Debug.Assert(path.Length == 1 || !PathUtilities.IsDirectorySeparator(path[1]));
                return(PathUtilities.CombinePathsUnchecked(baseRoot, path.Substring(1)));

            case PathKind.RelativeToDriveDirectory:
                // drive relative paths not supported, can't resolve:
                return(null);

            case PathKind.Absolute:
                return(path);

            default:
                throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }