Beispiel #1
0
        /// <summary>
        /// Get file attributes
        /// </summary>
        /// <param name="path">Path to file or folder</param>
        /// <param name="data">The file attribute structure to fill</param>
        /// <param name="tryagain">If false try get file attributes with GetFileAttributesEx function. If true try with the FindFirstFile function.</param>
        internal static void FillAttributeInfo(string path, ref WIN32_FILE_ATTRIBUTE_DATA data, bool tryagain = false)
        {
            int num;

            if (tryagain)
            {
                WIN32_FIND_DATA win_find_data = new WIN32_FIND_DATA();
                string          fileName      = path.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
                int             num2          = SafeNativeMethods.SetErrorMode(1);
                try
                {
                    SafeFindHandle handle = SafeNativeMethods.FindFirstFile(fileName, win_find_data);
                    try
                    {
                        if (handle.IsInvalid)
                        {
                            num = Marshal.GetLastWin32Error();
                            if (num != 0)
                            {
                                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                            }
                        }
                    }
                    finally
                    {
                        handle.Close();
                    }
                }
                finally
                {
                    _ = SafeNativeMethods.SetErrorMode(num2);
                }
                data.PopulateFrom(win_find_data);
                return;
            }
            bool flag2   = false;
            int  newMode = SafeNativeMethods.SetErrorMode(1);

            try
            {
                flag2 = SafeNativeMethods.GetFileAttributesEx(path, 0, ref data);
            }
            finally
            {
                _ = SafeNativeMethods.SetErrorMode(newMode);
            }
            if (!flag2)
            {
                num = Marshal.GetLastWin32Error();
                if (((num != 2) && (num != 3)) && (num != 0x15))
                {
                    FillAttributeInfo(path, ref data, true);
                    //return;
                }
                //else if (num == 2)
                //return;
                //else if (num != 0) //throw new Win32Exception(num);
                //return;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the last write time of the fullpath to a directory. If the pointed path is not a directory, or
        /// if the directory does not exist, then false is returned and fileModifiedTimeUtc is set DateTime.MinValue.
        /// </summary>
        /// <param name="fullPath">Full path to the file in the filesystem</param>
        /// <param name="fileModifiedTimeUtc">The UTC last write time for the directory</param>
        internal static bool GetLastWriteDirectoryUtcTime(string fullPath, out DateTime fileModifiedTimeUtc)
        {
            // This code was copied from the reference mananger, if there is a bug fix in that code, see if the same fix should also be made
            // there

            fileModifiedTimeUtc = DateTime.MinValue;
            WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
            bool success = false;

            success = GetFileAttributesEx(fullPath, 0, ref data);
            if (success)
            {
                if ((data.fileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
                {
                    long dt = ((long)(data.ftLastWriteTimeHigh) << 32) | ((long)data.ftLastWriteTimeLow);
                    fileModifiedTimeUtc = DateTime.FromFileTimeUtc(dt);
                }
                else
                {
                    // Path does not point to a directory
                    success = false;
                }
            }

            return(success);
        }
Beispiel #3
0
        internal static bool GetFileAttributesEx(String name, int fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
        {
            if (name == null)
            {
                return(false);
            }

            unsafe
            {
                var data = new stat_data();
                fixed(byte *filename_ascii = ToAsciiString(name))
                {
                    var returnCode = stat(filename_ascii, &data.st_dev);

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

                    var fileAttributes = FILE_ATTRIBUTE_NORMAL;

                    // if this is folder, return false
                    if ((data.st_mode & S_IFMT) == S_IFDIR)
                    {
                        fileAttributes = FILE_ATTRIBUTE_DIRECTORY;
                    }

                    lpFileInformation.fileAttributes = (int)fileAttributes;
                    lpFileInformation.fileSizeLow    = data.st_size;
                    lpFileInformation.fileSizeHigh   = 0;

                    return(true);
                }
            }
        }
Beispiel #4
0
 private static void ReadFileAttribues(FullPath path, out WIN32_FILE_ATTRIBUTE_DATA data, out int win32Error)
 {
     win32Error = 0;
     data       = default(WIN32_FILE_ATTRIBUTE_DATA);
     if (!NativeMethods.GetFileAttributesEx(path.Value, 0, ref data))
     {
         win32Error = Marshal.GetLastWin32Error();
     }
 }
Beispiel #5
0
        public unsafe void FileAttributeDataSize()
        {
            sizeof(WIN32_FILE_ATTRIBUTE_DATA).Should().Be(36);

            // An extra sanity check to make sure we're aligning correctly as
            // we're forcing uint size packing.
            WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();

            ((ulong)&data.nFileSize - (ulong)&data).Should().Be(28);
        }
Beispiel #6
0
        internal static DateTime GetLastWriteFileUtcTime(string fullPath)
        {
            DateTime minValue = DateTime.MinValue;
            WIN32_FILE_ATTRIBUTE_DATA lpFileInformation = new WIN32_FILE_ATTRIBUTE_DATA();

            if (GetFileAttributesEx(fullPath, 0, ref lpFileInformation))
            {
                minValue = DateTime.FromFileTimeUtc((long)((lpFileInformation.ftLastWriteTimeHigh << 0x20) | lpFileInformation.ftLastWriteTimeLow));
            }
            return(minValue);
        }
        private bool FileExistsNative(string entry)
        {
            WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
            var success = GetFileAttributesEx(entry, 0, ref data);

            if (success)
            {
                return((data.fileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0);
            }

            return(false);
        }
Beispiel #8
0
        /// <summary>
        /// Get the last write time of the fullpath to the file.
        /// If the file does not exist, then DateTime.MinValue is returned
        /// </summary>
        /// <param name="fullPath">Full path to the file in the filesystem</param>
        /// <returns></returns>
        internal static DateTime GetLastWriteFileUtcTime(string fullPath)
        {
            DateTime fileModifiedTime      = DateTime.MinValue;
            WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
            bool success = false;

            success = NativeMethodsShared.GetFileAttributesEx(fullPath, 0, ref data);
            if (success)
            {
                long dt = ((long)(data.ftLastWriteTimeHigh) << 32) | ((long)data.ftLastWriteTimeLow);
                fileModifiedTime = DateTime.FromFileTimeUtc(dt);
            }

            return(fileModifiedTime);
        }
Beispiel #9
0
        public static IEnumerable <LittleFileInfo> GetFiles(string folderPath)
        {
            WIN32_FIND_DATA win_find_data      = new WIN32_FIND_DATA();
            string          prefixedfolderPath = folderPath.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });

            if (!prefixedfolderPath.StartsWith("\\\\", StringComparison.Ordinal))
            {
                prefixedfolderPath = string.Concat("\\\\?\\", prefixedfolderPath);
            }
            int num2 = SafeNativeMethods.SetErrorMode(1);

            try
            {
                SafeFindHandle handle = SafeNativeMethods.FindFirstFile(prefixedfolderPath + @"\*", win_find_data);
                try
                {
                    if (handle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }
                    else
                    {
                        bool found = true;
                        while (found)
                        {
                            if (win_find_data.cFileName != "." && win_find_data.cFileName != "..")
                            {
                                WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
                                data.PopulateFrom(win_find_data);
                                yield return(new LittleFileInfo(folderPath, win_find_data.cFileName, data));
                            }
                            found = SafeNativeMethods.FindNextFile(handle, win_find_data);
                        }
                    }
                }
                finally
                {
                    handle.Close();
                }
            }
            finally
            {
                _ = SafeNativeMethods.SetErrorMode(num2);
            }
        }
Beispiel #10
0
        internal static bool GetLastWriteDirectoryUtcTime(string fullPath, out DateTime fileModifiedTimeUtc)
        {
            fileModifiedTimeUtc = DateTime.MinValue;

            WIN32_FILE_ATTRIBUTE_DATA lpFileInformation = new WIN32_FILE_ATTRIBUTE_DATA();
            bool flag = false;

            flag = GetFileAttributesEx(fullPath, 0, ref lpFileInformation);
            if (!flag)
            {
                return(flag);
            }
            if ((lpFileInformation.fileAttributes & 0x10) != 0)
            {
                long fileTime = (lpFileInformation.ftLastWriteTimeHigh << 0x20) | lpFileInformation.ftLastWriteTimeLow;
                fileModifiedTimeUtc = DateTime.FromFileTimeUtc(fileTime);
                return(flag);
            }
            return(false);
        }
Beispiel #11
0
        /// <summary>
        /// Get the last write time of the fullpath to the file.
        /// If the file does not exist, then DateTime.MinValue is returned
        /// </summary>
        /// <param name="fullPath">Full path to the file in the filesystem</param>
        /// <returns></returns>
        internal static DateTime GetLastWriteFileUtcTime(string fullPath)
        {
            DateTime fileModifiedTime = DateTime.MinValue;

            if (UseSymlinkTimeInsteadOfTargetTime)
            {
                WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
                bool success = false;

                success = NativeMethodsShared.GetFileAttributesEx(fullPath, 0, ref data);
                if (success)
                {
                    long dt = ((long)(data.ftLastWriteTimeHigh) << 32) | ((long)data.ftLastWriteTimeLow);
                    fileModifiedTime = DateTime.FromFileTimeUtc(dt);
                }
            }
            else
            {
                using (SafeFileHandle handle =
                           CreateFile(fullPath, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING,
                                      FILE_ATTRIBUTE_NORMAL, IntPtr.Zero))
                {
                    if (!handle.IsInvalid)
                    {
                        FILETIME ftCreationTime, ftLastAccessTime, ftLastWriteTime;
                        if (!GetFileTime(handle, out ftCreationTime, out ftLastAccessTime, out ftLastWriteTime) != true)
                        {
                            long fileTime = ((long)(uint)ftLastWriteTime.dwHighDateTime) << 32 |
                                            (long)(uint)ftLastWriteTime.dwLowDateTime;
                            fileModifiedTime =
                                DateTime.FromFileTimeUtc(fileTime);
                        }
                    }
                }
            }

            return(fileModifiedTime);
        }
Beispiel #12
0
 public extern static int GetFileAttributesTransactedW(
     [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string lpFileName,
     GET_FILEEX_INFO_LEVELS fInfoLevelId,
     out WIN32_FILE_ATTRIBUTE_DATA lpFileInformation,
     System.IntPtr hTransaction);
Beispiel #13
0
 private static partial bool GetFileAttributesExPrivate(
     string?name,
     GET_FILEEX_INFO_LEVELS fileInfoLevel,
     ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
Beispiel #14
0
 internal static extern bool GetFileAttributesTransacted(
     [In] string lpFileName
     , [In] GET_FILEEX_INFO_LEVELS fInfoLevelId
     , [Out] out WIN32_FILE_ATTRIBUTE_DATA attributes
     , [In] KtmTransactionHandle hTransaction);
 private static extern bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
Beispiel #16
0
		internal static extern bool GetFileAttributesEx(string name, int fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
        /// <summary>
        /// Get the last write time of the fullpath to the file. 
        /// If the file does not exist, then DateTime.MinValue is returned
        /// </summary>
        /// <param name="fullPath">Full path to the file in the filesystem</param>
        /// <returns></returns>
        internal static DateTime GetLastWriteFileUtcTime(string fullPath)
        {
            DateTime fileModifiedTime = DateTime.MinValue;
            WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
            bool success = false;

            success = NativeMethodsShared.GetFileAttributesEx(fullPath, 0, ref data);
            if (success)
            {
                long dt = ((long)(data.ftLastWriteTimeHigh) << 32) | ((long)data.ftLastWriteTimeLow);
                fileModifiedTime = DateTime.FromFileTimeUtc(dt);
            }

            return fileModifiedTime;
        }
Beispiel #18
0
 internal static extern bool GetFileAttributesEx(String name, Interop.GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
 internal static DateTime GetLastWriteFileUtcTime(string fullPath)
 {
     DateTime minValue = DateTime.MinValue;
     WIN32_FILE_ATTRIBUTE_DATA lpFileInformation = new WIN32_FILE_ATTRIBUTE_DATA();
     if (GetFileAttributesEx(fullPath, 0, ref lpFileInformation))
     {
         long fileTime = (lpFileInformation.ftLastWriteTimeHigh << 0x20) | lpFileInformation.ftLastWriteTimeLow;
         minValue = DateTime.FromFileTimeUtc(fileTime);
     }
     return minValue;
 }
Beispiel #20
0
 static extern bool GetFileAttributesEx(string lpFileName, int fInfoLevelId, out WIN32_FILE_ATTRIBUTE_DATA fileData);
Beispiel #21
0
 internal static extern bool GetFileAttributesEx(
     [MarshalAs(UnmanagedType.LPTStr)] string lpFileName,
     int fInfoLevelId,
     ref WIN32_FILE_ATTRIBUTE_DATA fileData);
        private bool FileOrDirectoryExistsNative(string path)
        {
            WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();

            return(GetFileAttributesEx(path, 0, ref data));
        }
Beispiel #23
0
        public static List <string> ListShadowCopies()
        {
            usDevice.Buffer        = Marshal.StringToHGlobalUni("Device");
            usDevice.Length        = 12;
            usDevice.MaximumLength = 12;

            usRootDevice.Buffer        = Marshal.StringToHGlobalUni("\\Device");
            usRootDevice.Length        = 14;
            usRootDevice.MaximumLength = 14;

            IntPtr pusRootDevice = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UNICODE_STRING)));

            Marshal.StructureToPtr(usRootDevice, pusRootDevice, false);
            oaDevice.ObjectName = pusRootDevice;
            oaDevice.Attributes = 0;
            oaDevice.Length     = (ulong)Marshal.SizeOf(typeof(OBJECT_ATTRIBUTES));

            IntPtr poaDevice = Marshal.AllocHGlobal(Marshal.SizeOf(oaDevice));

            Marshal.StructureToPtr(oaDevice, poaDevice, false);

            NTSTATUS status;
            IntPtr   hDeviceDirectory = IntPtr.Zero;

            byte[]   buffer       = new byte[40400];
            GCHandle pinnedArray  = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr   pbuffer      = pinnedArray.AddrOfPinnedObject();
            uint     Start        = 0;
            uint     Context      = 0;
            uint     ReturnLength = 0;
            bool     RestartScan;
            IntPtr   pDirectoryInformation = IntPtr.Zero;
            string   szName, szShadowName, szFullPath;
            WIN32_FILE_ATTRIBUTE_DATA Attribute = new WIN32_FILE_ATTRIBUTE_DATA();
            List <string>             res       = new List <string>();

            status = (NTSTATUS)NtOpenDirectoryObject(ref hDeviceDirectory, (ACCESS_MASK)(DIRECTORY_QUERY | DIRECTORY_TRAVERSE), poaDevice);
            if (status == NTSTATUS.Success)
            {
                for (Start = 0, Context = 0, RestartScan = true, status = NTSTATUS.MoreEntries; status == NTSTATUS.MoreEntries;)
                {
                    status = (NTSTATUS)NtQueryDirectoryObject(hDeviceDirectory, buffer, (uint)buffer.Length, false, RestartScan, ref Context, ref ReturnLength);
                    if (status == NTSTATUS.Success)
                    {
                        for (int i = 0; i < (Context - Start); i++)
                        {
                            OBJECT_DIRECTORY_INFORMATION directoryInformation = Utility.ReadStruct <OBJECT_DIRECTORY_INFORMATION>(Utility.GetBytes(buffer, i * Marshal.SizeOf(typeof(OBJECT_DIRECTORY_INFORMATION)), Marshal.SizeOf(typeof(OBJECT_DIRECTORY_INFORMATION))));
                            if (RtlEqualUnicodeString(usDevice, directoryInformation.TypeName, true))
                            {
                                byte[] bytestring = new byte[directoryInformation.Name.Length];
                                Marshal.Copy(directoryInformation.Name.Buffer, bytestring, 0, directoryInformation.Name.Length);
                                szName = Encoding.Unicode.GetString(bytestring);
                                if (!string.IsNullOrEmpty(szName))
                                {
                                    if (szName.StartsWith("HarddiskVolumeShadowCopy"))
                                    {
                                        szShadowName = string.Format("\\\\?\\GLOBALROOT\\Device\\{0}\\", szName);
                                        if (!string.IsNullOrEmpty(szShadowName))
                                        {
                                            Console.WriteLine("[*] ShadowCopy Volume : {0}", szName);
                                            Console.WriteLine("[*] | Path            : {0}", szShadowName);

                                            if (GetFileAttributesExW(szShadowName, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, ref Attribute))
                                            {
                                                res.Add(szShadowName);
                                                Console.Write("[*] | Volume LastWrite: ");
                                                Console.WriteLine("{0:yyyy/MM/dd HH:mm:ss}", Utility.ToDateTime(Attribute.ftLastWriteTime));
                                            }
                                            else
                                            {
                                                Console.WriteLine("GetFileAttributesEx");
                                            }

                                            Console.WriteLine("[*]");
                                            for (int j = 0; j < INT_FILES.Length; j++)
                                            {
                                                szFullPath = string.Format("{0}Windows\\System32\\config\\{1}", szShadowName, INT_FILES[j]);
                                                if (!string.IsNullOrEmpty(szFullPath))
                                                {
                                                    Console.WriteLine("[*] * {0}", szFullPath);

                                                    if (GetFileAttributesExW(szFullPath, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, ref Attribute))
                                                    {
                                                        Console.Write("[*]   | LastWrite   : ");
                                                        Console.WriteLine("{0:yyyy/MM/dd HH:mm:ss}", Utility.ToDateTime(Attribute.ftLastWriteTime));
                                                    }
                                                    else
                                                    {
                                                        Console.WriteLine("GetFileAttributesEx");
                                                    }
                                                }
                                            }
                                            Console.WriteLine("[*]");
                                        }
                                    }
                                }
                            }
                        }
                        Start       = Context;
                        RestartScan = false;
                    }
                    else
                    {
                        Console.WriteLine("NtQueryDirectoryObject: {0}", status);
                    }
                }
                CloseHandle(hDeviceDirectory);
            }
            else
            {
                Console.WriteLine("NtOpenDirectoryObject: {0}", status);
            }

            return(res);
        }
Beispiel #24
0
 public static extern bool GetFileAttributesEx(string path, GET_FILEEX_INFO_LEVELS level, out WIN32_FILE_ATTRIBUTE_DATA data);
Beispiel #25
0
 internal static extern bool GetFileAttributesEx(
     [MarshalAs(UnmanagedType.LPTStr)] string lpFileName,
     int fInfoLevelId,
     ref WIN32_FILE_ATTRIBUTE_DATA fileData);
 internal static bool GetLastWriteDirectoryUtcTime(string fullPath, out DateTime fileModifiedTimeUtc)
 {
     fileModifiedTimeUtc = DateTime.MinValue;
     WIN32_FILE_ATTRIBUTE_DATA lpFileInformation = new WIN32_FILE_ATTRIBUTE_DATA();
     bool flag = false;
     flag = GetFileAttributesEx(fullPath, 0, ref lpFileInformation);
     if (!flag)
     {
         return flag;
     }
     if ((lpFileInformation.fileAttributes & 0x10) != 0)
     {
         long fileTime = (lpFileInformation.ftLastWriteTimeHigh << 0x20) | lpFileInformation.ftLastWriteTimeLow;
         fileModifiedTimeUtc = DateTime.FromFileTimeUtc(fileTime);
         return flag;
     }
     return false;
 }
Beispiel #27
0
 static internal extern bool GetFileAttributesExW(string lpFileName, [In, MarshalAs(UnmanagedType.U4)] GET_FILEEX_INFO_LEVELS fInfoLevelId, out WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
Beispiel #28
0
 internal static extern Boolean GetFileAttributesExW(
     string lpFileName,
     GET_FILEEX_INFO_LEVELS fInfoLevelId,
     out WIN32_FILE_ATTRIBUTE_DATA fileData
     );
        /// <summary>
        /// Get the last write time of the fullpath to a directory. If the pointed path is not a directory, or
        /// if the directory does not exist, then false is returned and fileModifiedTimeUtc is set DateTime.MinValue.
        /// </summary>
        /// <param name="fullPath">Full path to the file in the filesystem</param>
        /// <param name="fileModifiedTimeUtc">The UTC last write time for the directory</param>
        internal static bool GetLastWriteDirectoryUtcTime(string fullPath, out DateTime fileModifiedTimeUtc)
        {
            // This code was copied from the reference mananger, if there is a bug fix in that code, see if the same fix should also be made
            // there

            fileModifiedTimeUtc = DateTime.MinValue;
            WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
            bool success = false;

            success = GetFileAttributesEx(fullPath, 0, ref data);
            if (success)
            {
                if ((data.fileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
                {
                    long dt = ((long)(data.ftLastWriteTimeHigh) << 32) | ((long)data.ftLastWriteTimeLow);
                    fileModifiedTimeUtc = DateTime.FromFileTimeUtc(dt);
                }
                else
                {
                    // Path does not point to a directory
                    success = false;
                }
            }

            return success;
        }
Beispiel #30
0
 internal static extern bool GetFileAttributesEx(String name, Interop.GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
 internal static extern bool GetFileAttributesEx(string name, int fileInfoLevel, out WIN32_FILE_ATTRIBUTE_DATA data);
Beispiel #32
0
 public static extern bool GetFileAttributesExW(string filename, UInt32 fInfoLevelId, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
Beispiel #33
0
 internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
 {
     name = PathInternal.EnsureExtendedPrefixIfNeeded(name) !; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
     return(GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation));
 }
Beispiel #34
0
        /// <summary>
        /// Get the last write time of the fullpath to the file. 
        /// If the file does not exist, then DateTime.MinValue is returned
        /// </summary>
        /// <param name="fullPath">Full path to the file in the filesystem</param>
        /// <returns></returns>
        internal static DateTime GetLastWriteFileUtcTime(string fullPath)
        {
            DateTime fileModifiedTime = DateTime.MinValue;

            if (UseSymlinkTimeInsteadOfTargetTime)
            {
                WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA();
                bool success = false;

                success = NativeMethodsShared.GetFileAttributesEx(fullPath, 0, ref data);
                if (success)
                {
                    long dt = ((long) (data.ftLastWriteTimeHigh) << 32) | ((long) data.ftLastWriteTimeLow);
                    fileModifiedTime = DateTime.FromFileTimeUtc(dt);
                }
            }
            else
            {
                using (SafeFileHandle handle =
                    CreateFile(fullPath, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL, IntPtr.Zero))
                {
                    if (!handle.IsInvalid)
                    {
                        FILETIME ftCreationTime, ftLastAccessTime, ftLastWriteTime;
                        if (!GetFileTime(handle, out ftCreationTime, out ftLastAccessTime, out ftLastWriteTime) != true)
                        {
                            long fileTime = ((long) (uint) ftLastWriteTime.dwHighDateTime) << 32 |
                                            (long) (uint) ftLastWriteTime.dwLowDateTime;
                            fileModifiedTime =
                                DateTime.FromFileTimeUtc(fileTime);
                        }
                    }
                }
            }

            return fileModifiedTime;
        }
 internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
 {
     name = PathInternal.EnsureExtendedPrefixOverMaxPath(name);
     return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
 }
Beispiel #36
0
 internal static extern bool GetFileAttributesEx(string name, int fileInfoLevel, out WIN32_FILE_ATTRIBUTE_DATA data);
 public static extern bool GetFileAttributesExFromApp(
     string lpFileName,
     GET_FILEEX_INFO_LEVELS fInfoLevelId,
     out WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
Beispiel #38
0
 public static extern bool GetFileAttributesExW( string filename, UInt32 fInfoLevelId, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation );
Beispiel #39
0
        internal static bool GetFileAttributesEx(string?name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
        {
            name = PathInternal.EnsureExtendedPrefixIfNeeded(name);

            return(GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation));
        }
Beispiel #40
0
        internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
        {
            string?nameWithExtendedPrefix = PathInternal.EnsureExtendedPrefixIfNeeded(name);

            Debug.Assert(nameWithExtendedPrefix != null, "null not expected when non-null is passed"); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
            return(GetFileAttributesExPrivate(nameWithExtendedPrefix, fileInfoLevel, ref lpFileInformation));
        }
Beispiel #41
0
 public static extern bool GetFileAttributesEx(string lpFileName,
                                               GET_FILEEX_INFO_LEVELS fInfoLevelId, out WIN32_FILE_ATTRIBUTE_DATA fileData);
Beispiel #42
0
 public static extern bool GetFileAttributesEx(
     string lpFileName,
     GET_FILEEX_INFO_LEVELS fInfoLevelId,
     out WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
Beispiel #43
0
 internal static extern bool GetFileAttributesEx(String name, int fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
Beispiel #44
0
 private static extern bool GetFileAttributesEx(string lpFileName,
     GET_FILEEX_INFO_LEVELS fInfoLevelId,
     out WIN32_FILE_ATTRIBUTE_DATA fileData);