Exemple #1
0
        internal static string InsecureGetFullPath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Trim().Length == 0)
            {
                string text = Locale.GetText("The specified path is not of a legal form (empty).");
                throw new ArgumentException(text);
            }
            if (Environment.IsRunningOnWindows)
            {
                path = Path.WindowsDriveAdjustment(path);
            }
            char c = path[path.Length - 1];

            if (path.Length >= 2 && Path.IsDsc(path[0]) && Path.IsDsc(path[1]))
            {
                if (path.Length == 2 || path.IndexOf(path[0], 2) < 0)
                {
                    throw new ArgumentException("UNC paths should be of the form \\\\server\\share.");
                }
                if (path[0] != Path.DirectorySeparatorChar)
                {
                    path = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
                }
                path = Path.CanonicalizePath(path);
            }
            else
            {
                if (!Path.IsPathRooted(path))
                {
                    path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorStr + path;
                }
                else if (Path.DirectorySeparatorChar == '\\' && path.Length >= 2 && Path.IsDsc(path[0]) && !Path.IsDsc(path[1]))
                {
                    string currentDirectory = Directory.GetCurrentDirectory();
                    if (currentDirectory[1] == Path.VolumeSeparatorChar)
                    {
                        path = currentDirectory.Substring(0, 2) + path;
                    }
                    else
                    {
                        path = currentDirectory.Substring(0, currentDirectory.IndexOf('\\', currentDirectory.IndexOf("\\\\") + 1));
                    }
                }
                path = Path.CanonicalizePath(path);
            }
            if (Path.IsDsc(c) && path[path.Length - 1] != Path.DirectorySeparatorChar)
            {
                path += Path.DirectorySeparatorChar;
            }
            string text2;

            if (MonoIO.RemapPath(path, out text2))
            {
                path = text2;
            }
            return(path);
        }
Exemple #2
0
        // insecure - do not call directly
        internal static string InsecureGetFullPath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.Trim().Length == 0)
            {
                string msg = Locale.GetText("The specified path is not of a legal form (empty).");
                throw new ArgumentException(msg);
            }

            // adjust for drives, i.e. a special case for windows
            if (Environment.IsRunningOnWindows)
            {
                path = WindowsDriveAdjustment(path);
            }

            // if the supplied path ends with a separator...
            char end = path [path.Length - 1];

            if (path.Length >= 2 &&
                IsDsc(path [0]) &&
                IsDsc(path [1]))
            {
                if (path.Length == 2 || path.IndexOf(path [0], 2) < 0)
                {
                    throw new ArgumentException("UNC paths should be of the form \\\\server\\share.");
                }

                if (path [0] != DirectorySeparatorChar)
                {
                    path = path.Replace(AltDirectorySeparatorChar, DirectorySeparatorChar);
                }

                path = CanonicalizePath(path);
            }
            else
            {
                if (!IsPathRooted(path))
                {
                    path = Directory.GetCurrentDirectory() + DirectorySeparatorStr + path;
                }
                else if (DirectorySeparatorChar == '\\' &&
                         path.Length >= 2 &&
                         IsDsc(path [0]) &&
                         !IsDsc(path [1]))                   // like `\abc\def'
                {
                    string current = Directory.GetCurrentDirectory();
                    if (current [1] == VolumeSeparatorChar)
                    {
                        path = current.Substring(0, 2) + path;
                    }
                    else
                    {
                        path = current.Substring(0, current.IndexOf('\\', current.IndexOf("\\\\") + 1));
                    }
                }
                path = CanonicalizePath(path);
            }

            // if the original ended with a [Alt]DirectorySeparatorChar then ensure the full path also ends with one
            if (IsDsc(end) && (path [path.Length - 1] != DirectorySeparatorChar))
            {
                path += DirectorySeparatorChar;
            }

            string newPath;

            if (MonoIO.RemapPath(path, out newPath))
            {
                path = newPath;
            }
            return(path);
        }