Exemple #1
0
        // Token: 0x06001AF8 RID: 6904 RVA: 0x0005B24C File Offset: 0x0005944C
        private static string GetDemandDir(string fullPath, bool thisDirOnly)
        {
            fullPath = Path.RemoveLongPathPrefix(fullPath);
            string result;

            if (thisDirOnly)
            {
                if (fullPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) || fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal))
                {
                    result = fullPath + ".";
                }
                else
                {
                    result = fullPath + Path.DirectorySeparatorChar.ToString() + ".";
                }
            }
            else if (!fullPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) && !fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal))
            {
                result = fullPath + Path.DirectorySeparatorChar.ToString();
            }
            else
            {
                result = fullPath;
            }
            return(result);
        }
        internal static bool IsPathRooted(String path)
        {
            Contract.Requires(path != null);
            String tempPath = Path.RemoveLongPathPrefix(path);

            return(Path.IsPathRooted(tempPath));
        }
        private static String GetDemandDir(string fullPath, bool thisDirOnly)
        {
            String demandPath;

            fullPath = Path.RemoveLongPathPrefix(fullPath);
            if (thisDirOnly)
            {
                if (fullPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) ||
                    fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal))
                {
                    demandPath = fullPath + '.';
                }
                else
                {
                    demandPath = fullPath + Path.DirectorySeparatorChar + '.';
                }
            }
            else
            {
                if (!(fullPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) ||
                      fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal)))
                {
                    demandPath = fullPath + Path.DirectorySeparatorChar;
                }
                else
                {
                    demandPath = fullPath;
                }
            }
            return(demandPath);
        }
Exemple #4
0
 public static string GetDirectoryName(string path)
 {
     if (path != null)
     {
         Path.CheckInvalidPathChars(path, false);
         string str1 = Path.NormalizePath(path, false);
         if (path.Length > 0)
         {
             try
             {
                 string str2   = Path.RemoveLongPathPrefix(path);
                 int    length = 0;
                 while (length < str2.Length && (int)str2[length] != 63 && (int)str2[length] != 42)
                 {
                     ++length;
                 }
                 if (length > 0)
                 {
                     Path.GetFullPath(str2.Substring(0, length));
                 }
             }
             catch (SecurityException ex)
             {
                 if (path.IndexOf("~", StringComparison.Ordinal) != -1)
                 {
                     str1 = Path.NormalizePath(path, false, false);
                 }
             }
             catch (PathTooLongException ex)
             {
             }
             catch (NotSupportedException ex)
             {
             }
             catch (IOException ex)
             {
             }
             catch (ArgumentException ex)
             {
             }
         }
         path = str1;
         int rootLength = Path.GetRootLength(path);
         if (path.Length > rootLength)
         {
             int length = path.Length;
             if (length == rootLength)
             {
                 return((string)null);
             }
             do
             {
                 ;
             }while (length > rootLength && (int)path[--length] != (int)Path.DirectorySeparatorChar && (int)path[length] != (int)Path.AltDirectorySeparatorChar);
             return(path.Substring(0, length));
         }
     }
     return((string)null);
 }
Exemple #5
0
 internal static string TryRemoveLongPathPrefix(string path, out bool removed)
 {
     removed = Path.HasLongPathPrefix(path);
     if (!removed)
     {
         return(path);
     }
     return(Path.RemoveLongPathPrefix(path));
 }
 internal static String TryRemoveLongPathPrefix(String path, out bool removed)
 {
     Contract.Requires(path != null);
     removed = Path.HasLongPathPrefix(path);
     if (!removed)
     {
         return(path);
     }
     return(Path.RemoveLongPathPrefix(path));
 }
Exemple #7
0
        internal unsafe bool TryExpandShortFileName()
        {
            if (this.useStackAlloc)
            {
                this.NullTerminate();
                char *chPtr          = this.UnsafeGetArrayPtr();
                char *longPathBuffer = (char *)stackalloc byte[(((IntPtr)(Path.MaxPath + 1)) * 2)];
                int   len            = Win32Native.GetLongPathName(chPtr, longPathBuffer, Path.MaxPath);
                if (len >= Path.MaxPath)
                {
                    throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
                }
                if (len == 0)
                {
                    return(false);
                }
                Buffer.memcpy(longPathBuffer, 0, chPtr, 0, len);
                this.Length = len;
                this.NullTerminate();
                return(true);
            }
            StringBuilder stringBuilder = this.GetStringBuilder();
            string        str           = stringBuilder.ToString();
            string        path          = str;
            bool          flag          = false;

            if (path.Length > Path.MaxPath)
            {
                path = Path.AddLongPathPrefix(path);
                flag = true;
            }
            stringBuilder.Capacity = this.m_capacity;
            stringBuilder.Length   = 0;
            int num2 = Win32Native.GetLongPathName(path, stringBuilder, this.m_capacity);

            if (num2 == 0)
            {
                stringBuilder.Length = 0;
                stringBuilder.Append(str);
                return(false);
            }
            if (flag)
            {
                num2 -= 4;
            }
            if (num2 >= this.m_maxPath)
            {
                throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
            }
            stringBuilder = Path.RemoveLongPathPrefix(stringBuilder);
            this.Length   = stringBuilder.Length;
            return(true);
        }
Exemple #8
0
 private static string GetDemandDir(string fullPath, bool thisDirOnly)
 {
     fullPath = Path.RemoveLongPathPrefix(fullPath);
     if (thisDirOnly)
     {
         if (fullPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) || fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal))
         {
             return(fullPath + '.');
         }
         return(fullPath + Path.DirectorySeparatorChar + '.');
     }
     if (!fullPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) && !fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal))
     {
         return(fullPath + Path.DirectorySeparatorChar);
     }
     return(fullPath);
 }
Exemple #9
0
        internal unsafe bool TryExpandShortFileName()
        {
            if (doNotTryExpandShortFileName)
            {
                return(false);
            }

            if (useStackAlloc)
            {
                NullTerminate();
                char *buffer = UnsafeGetArrayPtr();
                char *shortFileNameBuffer = stackalloc char[Path.MaxPath + 1];

                int r = Win32Native.GetLongPathName(buffer, shortFileNameBuffer, Path.MaxPath);

                // If success, the return buffer length does not account for the terminating null character.
                // If in-sufficient buffer, the return buffer length does account for the path + the terminating null character.
                // If failure, the return buffer length is zero
                if (r >= Path.MaxPath)
                {
                    throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
                }

                if (r == 0)
                {
                    // Note: GetLongPathName will return ERROR_INVALID_FUNCTION on a
                    // path like \\.\PHYSICALDEVICE0 - some device driver doesn't
                    // support GetLongPathName on that string.  This behavior is
                    // by design, according to the Core File Services team.
                    // We also get ERROR_NOT_ENOUGH_QUOTA in SQL_CLR_STRESS runs
                    // intermittently on paths like D:\DOCUME~1\user\LOCALS~1\Temp\

                    // We do not need to call GetLongPathName if we know it will fail becasue the path does not exist:
                    int lastErr = Marshal.GetLastWin32Error();
                    if (lastErr == Win32Native.ERROR_FILE_NOT_FOUND || lastErr == Win32Native.ERROR_PATH_NOT_FOUND)
                    {
                        doNotTryExpandShortFileName = true;
                    }

                    return(false);
                }

                // Safe to copy as we have already done Path.MaxPath bound checking
                String.wstrcpy(buffer, shortFileNameBuffer, r);
                Length = r;
                // We should explicitly null terminate as in some cases the long version of the path
                // might actually be shorter than what we started with because of Win32's normalization
                // Safe to write directly as bufferLength is guaranteed to be < Path.MaxPath
                NullTerminate();
                return(true);
            }
            else
            {
                StringBuilder sb = GetStringBuilder();

                String origName    = sb.ToString();
                String tempName    = origName;
                bool   addedPrefix = false;
                if (tempName.Length > Path.MaxPath)
                {
                    tempName    = Path.AddLongPathPrefix(tempName);
                    addedPrefix = true;
                }
                sb.Capacity = m_capacity;
                sb.Length   = 0;
                int r = Win32Native.GetLongPathName(tempName, sb, m_capacity);

                if (r == 0)
                {
                    // Note: GetLongPathName will return ERROR_INVALID_FUNCTION on a
                    // path like \\.\PHYSICALDEVICE0 - some device driver doesn't
                    // support GetLongPathName on that string.  This behavior is
                    // by design, according to the Core File Services team.
                    // We also get ERROR_NOT_ENOUGH_QUOTA in SQL_CLR_STRESS runs
                    // intermittently on paths like D:\DOCUME~1\user\LOCALS~1\Temp\

                    // We do not need to call GetLongPathName if we know it will fail becasue the path does not exist:
                    int lastErr = Marshal.GetLastWin32Error();
                    if (Win32Native.ERROR_FILE_NOT_FOUND == lastErr || Win32Native.ERROR_PATH_NOT_FOUND == lastErr)
                    {
                        doNotTryExpandShortFileName = true;
                    }

                    sb.Length = 0;
                    sb.Append(origName);
                    return(false);
                }

                if (addedPrefix)
                {
                    r -= 4;
                }

                // If success, the return buffer length does not account for the terminating null character.
                // If in-sufficient buffer, the return buffer length does account for the path + the terminating null character.
                // If failure, the return buffer length is zero
                if (r >= m_maxPath)
                {
                    throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
                }


                sb     = Path.RemoveLongPathPrefix(sb);
                Length = sb.Length;
                return(true);
            }
        }
Exemple #10
0
 internal static bool IsPathRooted(string path)
 {
     return(Path.IsPathRooted(Path.RemoveLongPathPrefix(path)));
 }
Exemple #11
0
        internal unsafe bool TryExpandShortFileName()
        {
            if (this.doNotTryExpandShortFileName)
            {
                return(false);
            }
            if (this.useStackAlloc)
            {
                this.NullTerminate();
                char *arrayPtr     = this.UnsafeGetArrayPtr();
                char *chPtr        = stackalloc char[Path.MaxPath + 1];
                int   longPathName = Win32Native.GetLongPathName(arrayPtr, chPtr, Path.MaxPath);
                if (longPathName >= Path.MaxPath)
                {
                    throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
                }
                if (longPathName == 0)
                {
                    switch (Marshal.GetLastWin32Error())
                    {
                    case 2:
                    case 3:
                        this.doNotTryExpandShortFileName = true;
                        break;
                    }
                    return(false);
                }
                string.wstrcpy(arrayPtr, chPtr, longPathName);
                this.Length = longPathName;
                this.NullTerminate();
                return(true);
            }
            StringBuilder stringBuilder = this.GetStringBuilder();
            string        @string       = stringBuilder.ToString();
            string        path          = @string;
            bool          flag          = false;

            if (path.Length > Path.MaxPath)
            {
                path = Path.AddLongPathPrefix(path);
                flag = true;
            }
            stringBuilder.Capacity = this.m_capacity;
            stringBuilder.Length   = 0;
            int longPathName1 = Win32Native.GetLongPathName(path, stringBuilder, this.m_capacity);

            if (longPathName1 == 0)
            {
                int lastWin32Error = Marshal.GetLastWin32Error();
                if (2 == lastWin32Error || 3 == lastWin32Error)
                {
                    this.doNotTryExpandShortFileName = true;
                }
                stringBuilder.Length = 0;
                stringBuilder.Append(@string);
                return(false);
            }
            if (flag)
            {
                longPathName1 -= 4;
            }
            if (longPathName1 >= this.m_maxPath)
            {
                throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
            }
            this.Length = Path.RemoveLongPathPrefix(stringBuilder).Length;
            return(true);
        }
 internal unsafe bool TryExpandShortFileName()
 {
     if (this.doNotTryExpandShortFileName)
     {
         return(false);
     }
     if (this.useStackAlloc)
     {
         this.NullTerminate();
         char *ptr          = this.UnsafeGetArrayPtr();
         char *ptr2         = stackalloc char[checked (unchecked ((UIntPtr)(Path.MaxPath + 1)) * 2)];
         int   longPathName = Win32Native.GetLongPathName(ptr, ptr2, Path.MaxPath);
         if (longPathName >= Path.MaxPath)
         {
             throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
         }
         if (longPathName == 0)
         {
             int lastWin32Error = Marshal.GetLastWin32Error();
             if (lastWin32Error == 2 || lastWin32Error == 3)
             {
                 this.doNotTryExpandShortFileName = true;
             }
             return(false);
         }
         string.wstrcpy(ptr, ptr2, longPathName);
         this.Length = longPathName;
         this.NullTerminate();
         return(true);
     }
     else
     {
         StringBuilder stringBuilder = this.GetStringBuilder();
         string        text          = stringBuilder.ToString();
         string        text2         = text;
         bool          flag          = false;
         if (text2.Length > Path.MaxPath)
         {
             text2 = Path.AddLongPathPrefix(text2);
             flag  = true;
         }
         stringBuilder.Capacity = this.m_capacity;
         stringBuilder.Length   = 0;
         int num = Win32Native.GetLongPathName(text2, stringBuilder, this.m_capacity);
         if (num == 0)
         {
             int lastWin32Error2 = Marshal.GetLastWin32Error();
             if (2 == lastWin32Error2 || 3 == lastWin32Error2)
             {
                 this.doNotTryExpandShortFileName = true;
             }
             stringBuilder.Length = 0;
             stringBuilder.Append(text);
             return(false);
         }
         if (flag)
         {
             num -= 4;
         }
         if (num >= this.m_maxPath)
         {
             throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
         }
         stringBuilder = Path.RemoveLongPathPrefix(stringBuilder);
         this.Length   = stringBuilder.Length;
         return(true);
     }
 }