Пример #1
0
        private static void InternalDelete(string fullPath, string userPath, bool recursive)
        {
            string demandDir = LongPathDirectory.GetDemandDir(fullPath, !recursive);

            FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, demandDir, false, false);
            string text = Path.AddLongPathPrefix(fullPath);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA win32_FILE_ATTRIBUTE_DATA = default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
            int num = File.FillAttributeInfo(text, ref win32_FILE_ATTRIBUTE_DATA, false, true);

            if (num != 0)
            {
                if (num == 2)
                {
                    num = 3;
                }
                __Error.WinIOError(num, fullPath);
            }
            if ((win32_FILE_ATTRIBUTE_DATA.fileAttributes & 1024) != 0)
            {
                recursive = false;
            }
            LongPathDirectory.DeleteHelper(text, userPath, recursive, true);
        }
Пример #2
0
        private static void DeleteHelper(string fullPath, string userPath, bool recursive, bool throwOnTopLevelDirectoryNotFound)
        {
            Exception ex = null;

            if (recursive)
            {
                Win32Native.WIN32_FIND_DATA win32_FIND_DATA = default(Win32Native.WIN32_FIND_DATA);
                string fileName;
                if (fullPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
                {
                    fileName = fullPath + "*";
                }
                else
                {
                    fileName = fullPath + Path.DirectorySeparatorChar.ToString() + "*";
                }
                int num;
                using (SafeFindHandle safeFindHandle = Win32Native.FindFirstFile(fileName, ref win32_FIND_DATA))
                {
                    if (safeFindHandle.IsInvalid)
                    {
                        num = Marshal.GetLastWin32Error();
                        __Error.WinIOError(num, userPath);
                    }
                    for (;;)
                    {
                        bool flag = (win32_FIND_DATA.dwFileAttributes & 16) != 0;
                        if (!flag)
                        {
                            goto IL_180;
                        }
                        if (!win32_FIND_DATA.IsRelativeDirectory)
                        {
                            bool flag2 = (win32_FIND_DATA.dwFileAttributes & 1024) == 0;
                            if (flag2)
                            {
                                string fullPath2 = LongPath.InternalCombine(fullPath, win32_FIND_DATA.cFileName);
                                string userPath2 = LongPath.InternalCombine(userPath, win32_FIND_DATA.cFileName);
                                try
                                {
                                    LongPathDirectory.DeleteHelper(fullPath2, userPath2, recursive, false);
                                    goto IL_1BD;
                                }
                                catch (Exception ex2)
                                {
                                    if (ex == null)
                                    {
                                        ex = ex2;
                                    }
                                    goto IL_1BD;
                                }
                            }
                            if (win32_FIND_DATA.dwReserved0 == -1610612733)
                            {
                                string mountPoint = LongPath.InternalCombine(fullPath, win32_FIND_DATA.cFileName + Path.DirectorySeparatorChar.ToString());
                                if (!Win32Native.DeleteVolumeMountPoint(mountPoint))
                                {
                                    num = Marshal.GetLastWin32Error();
                                    if (num != 3)
                                    {
                                        try
                                        {
                                            __Error.WinIOError(num, win32_FIND_DATA.cFileName);
                                        }
                                        catch (Exception ex3)
                                        {
                                            if (ex == null)
                                            {
                                                ex = ex3;
                                            }
                                        }
                                    }
                                }
                            }
                            string path = LongPath.InternalCombine(fullPath, win32_FIND_DATA.cFileName);
                            if (!Win32Native.RemoveDirectory(path))
                            {
                                num = Marshal.GetLastWin32Error();
                                if (num != 3)
                                {
                                    try
                                    {
                                        __Error.WinIOError(num, win32_FIND_DATA.cFileName);
                                        goto IL_1BD;
                                    }
                                    catch (Exception ex4)
                                    {
                                        if (ex == null)
                                        {
                                            ex = ex4;
                                        }
                                        goto IL_1BD;
                                    }
                                    goto IL_180;
                                }
                            }
                        }
IL_1BD:
                        if (!Win32Native.FindNextFile(safeFindHandle, ref win32_FIND_DATA))
                        {
                            break;
                        }
                        continue;
IL_180:
                        string path2 = LongPath.InternalCombine(fullPath, win32_FIND_DATA.cFileName);
                        if (Win32Native.DeleteFile(path2))
                        {
                            goto IL_1BD;
                        }
                        num = Marshal.GetLastWin32Error();
                        if (num != 2)
                        {
                            try
                            {
                                __Error.WinIOError(num, win32_FIND_DATA.cFileName);
                            }
                            catch (Exception ex5)
                            {
                                if (ex == null)
                                {
                                    ex = ex5;
                                }
                            }
                            goto IL_1BD;
                        }
                        goto IL_1BD;
                    }
                    num = Marshal.GetLastWin32Error();
                }
                if (ex != null)
                {
                    throw ex;
                }
                if (num != 0 && num != 18)
                {
                    __Error.WinIOError(num, userPath);
                }
            }
            if (!Win32Native.RemoveDirectory(fullPath))
            {
                int num = Marshal.GetLastWin32Error();
                if (num == 2)
                {
                    num = 3;
                }
                if (num == 5)
                {
                    throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", new object[]
                    {
                        userPath
                    }));
                }
                if (num == 3 && !throwOnTopLevelDirectoryNotFound)
                {
                    return;
                }
                __Error.WinIOError(num, userPath);
            }
        }