コード例 #1
0
        private static void InternalDelete(string fullPath, string userPath, bool recursive)
        {
            string demandDir = GetDemandDir(fullPath, !recursive);

            new FileIOPermission(FileIOPermissionAccess.Write, new string[] { demandDir }, false, false).Demand();
            string path = Path.AddLongPathPrefix(fullPath);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int errorCode = File.FillAttributeInfo(path, ref data, false, true);

            switch (errorCode)
            {
            case 0:
                goto Label_0051;

            case 2:
                errorCode = 3;
                break;
            }
            __Error.WinIOError(errorCode, fullPath);
Label_0051:
            if ((data.fileAttributes & 0x400) != 0)
            {
                recursive = false;
            }
            DeleteHelper(path, userPath, recursive);
        }
コード例 #2
0
        // Called from DirectoryInfo as well.  FullPath is fully qualified,
        // while the user path is used for feedback in exceptions.
        internal static void Delete(String fullPath, String userPath, bool recursive)
        {
            // Do not recursively delete through reparse points.  Perhaps in a
            // future version we will add a new flag to control this behavior,
            // but for now we're much safer if we err on the conservative side.
            // This applies to symbolic links and mount points.
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int dataInitialised = File.FillAttributeInfo(fullPath, ref data, false, true);

            if (dataInitialised != 0)
            {
                // Ensure we throw a DirectoryNotFoundException.
                if (dataInitialised == Win32Native.ERROR_FILE_NOT_FOUND)
                {
                    dataInitialised = Win32Native.ERROR_PATH_NOT_FOUND;
                }
                __Error.WinIOError(dataInitialised, fullPath);
            }

            if (((FileAttributes)data.fileAttributes & FileAttributes.ReparsePoint) != 0)
            {
                recursive = false;
            }

            DeleteHelper(fullPath, userPath, recursive, true);
        }
コード例 #3
0
        internal static long GetLength(string path)
        {
            string path1 = LongPath.NormalizePath(path);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[1] {
                path1
            }, 0 != 0, 0 != 0).Demand();
            string path2 = Path.AddLongPathPrefix(path1);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA fileAttributeData = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            // ISSUE: explicit reference operation
            // ISSUE: variable of a reference type
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA& data = @fileAttributeData;
            int num1      = 0;
            int num2      = 1;
            int errorCode = File.FillAttributeInfo(path2, data, num1 != 0, num2 != 0);

            if (errorCode != 0)
            {
                __Error.WinIOError(errorCode, path);
            }
            if ((fileAttributeData.fileAttributes & 16) != 0)
            {
                __Error.WinIOError(2, path);
            }
            return((long)fileAttributeData.fileSizeHigh << 32 | (long)fileAttributeData.fileSizeLow & (long)uint.MaxValue);
        }
コード例 #4
0
        // Determine whether path describes an existing directory
        // on disk, avoiding security checks.
        internal static bool InternalExists(String path, out int lastError)
        {
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            lastError = File.FillAttributeInfo(path, ref data, false, true);

            return((lastError == 0) && (data.fileAttributes != -1) &&
                   ((data.fileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY) != 0));
        }
コード例 #5
0
ファイル: directory.cs プロジェクト: SSCLI/sscli_20021101
        // Determine whether path describes an existing directory
        // on disk, avoiding security checks.
        internal static bool InternalExists(String path)
        {
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int dataInitialised = File.FillAttributeInfo(path, ref data, false);

            if (dataInitialised != 0)
            {
                return(false);
            }

            return(data.fileAttributes != -1 && (data.fileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY) != 0);
        }
コード例 #6
0
        public static FileAttributes GetAttributes(string path)
        {
            string fullPathInternal = Path.GetFullPathInternal(path);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[] { fullPathInternal }, false, false).Demand();
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int errorCode = FillAttributeInfo(fullPathInternal, ref data, false, true);

            if (errorCode != 0)
            {
                __Error.WinIOError(errorCode, fullPathInternal);
            }
            return((FileAttributes)data.fileAttributes);
        }
コード例 #7
0
        public static DateTime GetLastWriteTimeUtc(string path)
        {
            string fullPathInternal = Path.GetFullPathInternal(path);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[] { fullPathInternal }, false, false).Demand();
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int errorCode = FillAttributeInfo(fullPathInternal, ref data, false, false);

            if (errorCode != 0)
            {
                __Error.WinIOError(errorCode, fullPathInternal);
            }
            long fileTime = (data.ftLastWriteTimeHigh << 0x20) | data.ftLastWriteTimeLow;

            return(DateTime.FromFileTimeUtc(fileTime));
        }
コード例 #8
0
        internal static DateTimeOffset GetLastWriteTime(string path)
        {
            string text = LongPath.NormalizePath(path);

            FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, text, false, false);
            string path2 = Path.AddLongPathPrefix(text);

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

            if (num != 0)
            {
                __Error.WinIOError(num, text);
            }
            DateTime dateTime = DateTime.FromFileTimeUtc(win32_FILE_ATTRIBUTE_DATA.ftLastWriteTime.ToTicks()).ToLocalTime();

            return(new DateTimeOffset(dateTime).ToLocalTime());
        }
コード例 #9
0
        internal static DateTimeOffset GetCreationTime(string path)
        {
            string str = LongPath.NormalizePath(path);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[] { str }, false, false).Demand();
            string str2 = Path.AddLongPathPrefix(str);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int errorCode = File.FillAttributeInfo(str2, ref data, false, false);

            if (errorCode != 0)
            {
                __Error.WinIOError(errorCode, str);
            }
            long           fileTime = (data.ftCreationTimeHigh << 0x20) | data.ftCreationTimeLow;
            DateTimeOffset offset   = new DateTimeOffset(DateTime.FromFileTimeUtc(fileTime).ToLocalTime());

            return(offset.ToLocalTime());
        }
コード例 #10
0
        internal static long GetLength(string path)
        {
            string str = LongPath.NormalizePath(path);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[] { str }, false, false).Demand();
            string str2 = Path.AddLongPathPrefix(str);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            int errorCode = File.FillAttributeInfo(str2, ref data, false, true);

            if (errorCode != 0)
            {
                __Error.WinIOError(errorCode, path);
            }
            if ((data.fileAttributes & 0x10) != 0)
            {
                __Error.WinIOError(2, path);
            }
            return((data.fileSizeHigh << 0x20) | (data.fileSizeLow & ((long)0xffffffffL)));
        }
コード例 #11
0
        internal static long GetLength(string path)
        {
            string text = LongPath.NormalizePath(path);

            FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, text, false, false);
            string path2 = Path.AddLongPathPrefix(text);

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

            if (num != 0)
            {
                __Error.WinIOError(num, path);
            }
            if ((win32_FILE_ATTRIBUTE_DATA.fileAttributes & 16) != 0)
            {
                __Error.WinIOError(2, path);
            }
            return((long)win32_FILE_ATTRIBUTE_DATA.fileSizeHigh << 32 | ((long)win32_FILE_ATTRIBUTE_DATA.fileSizeLow & (long)((ulong)-1)));
        }
コード例 #12
0
        internal static DateTimeOffset GetLastWriteTime(string path)
        {
            string str = LongPath.NormalizePath(path);

            new FileIOPermission(FileIOPermissionAccess.Read, new string[1] {
                str
            }, 0 != 0, 0 != 0).Demand();
            string path1 = Path.AddLongPathPrefix(str);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA fileAttributeData = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
            // ISSUE: explicit reference operation
            // ISSUE: variable of a reference type
            Win32Native.WIN32_FILE_ATTRIBUTE_DATA& data = @fileAttributeData;
            int num1      = 0;
            int num2      = 0;
            int errorCode = File.FillAttributeInfo(path1, data, num1 != 0, num2 != 0);

            if (errorCode != 0)
            {
                __Error.WinIOError(errorCode, str);
            }
            return(new DateTimeOffset(DateTime.FromFileTimeUtc((long)fileAttributeData.ftLastWriteTimeHigh << 32 | (long)fileAttributeData.ftLastWriteTimeLow).ToLocalTime()).ToLocalTime());
        }
コード例 #13
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);
        }
コード例 #14
0
ファイル: FileSystemInfo.cs プロジェクト: E024/NativeSharp
 internal void InitializeFrom(Win32Native.WIN32_FIND_DATA findData)
 {
     _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
     _data.PopulateFrom(findData);
     _dataInitialised = 0;
 }
コード例 #15
0
 internal static bool InternalExists(string path)
 {
     Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
     return(((FillAttributeInfo(path, ref data, false, true) == 0) && (data.fileAttributes != -1)) && ((data.fileAttributes & 0x10) == 0));
 }
コード例 #16
0
        internal static int FillAttributeInfo(string path, ref Win32Native.WIN32_FILE_ATTRIBUTE_DATA data, bool tryagain, bool returnErrorOnNotFound)
        {
            int num = 0;

            if (tryagain)
            {
                Win32Native.WIN32_FIND_DATA win_find_data = new Win32Native.WIN32_FIND_DATA();
                string fileName = path.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
                int    num2     = Win32Native.SetErrorMode(1);
                try
                {
                    bool           flag   = false;
                    SafeFindHandle handle = Win32Native.FindFirstFile(fileName, win_find_data);
                    try
                    {
                        if (handle.IsInvalid)
                        {
                            flag = true;
                            num  = Marshal.GetLastWin32Error();
                            if ((((num == 2) || (num == 3)) || (num == 0x15)) && !returnErrorOnNotFound)
                            {
                                num = 0;
                                data.fileAttributes = -1;
                            }
                            return(num);
                        }
                    }
                    finally
                    {
                        try
                        {
                            handle.Close();
                        }
                        catch
                        {
                            if (!flag)
                            {
                                __Error.WinIOError();
                            }
                        }
                    }
                }
                finally
                {
                    Win32Native.SetErrorMode(num2);
                }
                data.PopulateFrom(win_find_data);
                return(num);
            }
            bool flag2   = false;
            int  newMode = Win32Native.SetErrorMode(1);

            try
            {
                flag2 = Win32Native.GetFileAttributesEx(path, 0, ref data);
            }
            finally
            {
                Win32Native.SetErrorMode(newMode);
            }
            if (!flag2)
            {
                num = Marshal.GetLastWin32Error();
                if (((num != 2) && (num != 3)) && (num != 0x15))
                {
                    return(FillAttributeInfo(path, ref data, true, returnErrorOnNotFound));
                }
                if (!returnErrorOnNotFound)
                {
                    num = 0;
                    data.fileAttributes = -1;
                }
            }
            return(num);
        }