Esempio n. 1
0
        public static bool IsValidRelativePath(string path, out string reason)
        {
            reason = string.Empty;
            if (path == null)
            {
                reason = "Input path string is null";
                return(false);
            }
            if (path.Length == 0)
            {
                reason = "Empty string for path";
                return(false);
            }

            if (!InternalStringHelper.CanOnlyBeARelativePath(path))
            {
                reason = "An absolute path was inputed where a relative path was expected.";
                return(false);
            }

            path = InternalStringHelper.NormalizePath(path);
            if (InternalStringHelper.ContainsInnerSpecialDir(path))
            {
                string unusedPath;
                if (!InternalStringHelper.TryResolveInnerSpecialDir(path, out unusedPath, out reason))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        }                               // special for empty

        protected FilePath(string path, bool isAbsolute) : base(path, isAbsolute)
        {
            if (!InternalStringHelper.HasParentDir(this.Path))
            {
                throw new ArgumentException(this.Path, @"The file path has no parent directory.");
            }
        }
Esempio n. 3
0
        protected static string GetAbsolutePathFrom(DirectoryPathAbsolute pathFrom, BasePath pathTo)
        {
            Debug.Assert(pathTo.IsRelativePath);
            // %HYYKA%

            /*if (pathTo.PathMode == PathMode.Absolute) {
             * throw new ArgumentException(@"Cannot call GetAbsolutePath() on a path already absolute.
             * PathFrom = """ + pathFrom.Path + @"""
             * PathTo   = """ + pathTo.Path + @"""");
             * }*/
            // Only work with Directory
            if (pathTo.IsFilePath)
            {
                pathTo = pathTo.ParentDirectoryPath;
            }
            return(InternalStringHelper.GetAbsolutePath(pathFrom.Path, pathTo.Path));
        }
Esempio n. 4
0
        public static bool IsValidAbsolutePath(string path, out string reason)
        {
            reason = string.Empty;

            if (path == null)
            {
                reason = "Input path string is null";
                return(false);
            }
            if (path.Length == 0)
            {
                reason = "Empty string for path";
                return(false);
            }

            if (InternalStringHelper.CanOnlyBeARelativePath(path))
            {
                reason = "A relative path was inputed where an absolute path was expected.";
                return(false);
            }

            if (InternalStringHelper.IsUniformRessourceLocatorPath(path))
            {
                reason = "URN (UniformRessourceLocator) paths are not supported.";
                return(false);
            }

            if (!InternalStringHelper.BeginsWithASingleLetterDrive(path))
            {
                reason = "The absolute path doesn't begin with a single letter drive followed by ':'.";
                return(false);
            }

            path = InternalStringHelper.NormalizePath(path);
            if (InternalStringHelper.ContainsInnerSpecialDir(path))
            {
                string unusedPath;
                if (!InternalStringHelper.TryResolveInnerSpecialDir(path, out unusedPath, out reason))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 5
0
        //
        //  Ctor
        //
        public BasePath(string path, bool isAbsolute)
        {
            if (path == null)
            {
                throw new ArgumentNullException("Input path string is null");
            }

            // No check fro empty paths
            if (path.Length == 0)
            {
                throw new ArgumentException(path, "Input path string is empty");
            }

            path = InternalStringHelper.NormalizePath(path);

            string errorReason;

            if (isAbsolute)
            {
                PathHelper.IsValidAbsolutePath(path, out errorReason);
            }
            else
            {
                PathHelper.IsValidRelativePath(path, out errorReason);
            }
            if (errorReason.Length > 0)
            {
                throw new ArgumentException(path, errorReason);
            }

            // Try remove eventual InnerSpecialDir
            if (InternalStringHelper.ContainsInnerSpecialDir(path))
            {
                InternalStringHelper.TryResolveInnerSpecialDir(path, out path, out errorReason);
            }
            Debug.Assert(errorReason.Length == 0); // The error test has already been done in IsValidXXXPath()
            Debug.Assert(path != null && path.Length > 0);

            m_Path = path;
        }
Esempio n. 6
0
        //
        //  Relative/absolute
        //
        protected static string GetPathRelative(DirectoryPathAbsolute pathFrom, BasePath pathTo)
        {
            Debug.Assert(pathTo.IsAbsolutePath);
            // %HYYKA%

            /*if (pathTo.PathMode == PathMode.Relative) {
             * throw new ArgumentException(@"Cannot input a relative path to GetPathRelativeTo().
             * PathFrom = """ + pathFrom.Path + @"""
             * PathTo   = """ + pathTo.Path + @"""");
             * }*/
            if (string.Compare(pathFrom.DriveProtected, pathTo.DriveProtected, true) != 0)
            {
                throw new ArgumentException(@"Cannot compute relative path from 2 paths that are not on the same drive 
PathFrom = """ + pathFrom.Path + @"""
PathTo   = """ + pathTo.Path + @"""");
            }
            // Only work with Directory
            if (pathTo.IsFilePath)
            {
                pathTo = pathTo.ParentDirectoryPath;
            }
            return(InternalStringHelper.GetPathRelativeTo(pathFrom.Path, pathTo.Path));
        }