コード例 #1
0
ファイル: PathHelper.cs プロジェクト: xj42/ChapterGrabber
        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);
        }
コード例 #2
0
ファイル: PathHelper.cs プロジェクト: xj42/ChapterGrabber
        //----------------------------------------
        //
        // Path String Validity
        //
        //----------------------------------------
        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);
        }
コード例 #3
0
ファイル: BasePath.cs プロジェクト: xj42/ChapterGrabber
        //
        //  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;
        }