internal static DateTime GetLastWriteTimeInternal(KernelTransaction transaction, string path, bool getUtc, PathFormat pathFormat)
        {
            NativeMethods.FileTime lastWriteTime = GetAttributesExInternal <NativeMethods.Win32FileAttributeData>(transaction, path, pathFormat).LastWriteTime;

            return(getUtc
            ? DateTime.FromFileTimeUtc(lastWriteTime)
            : DateTime.FromFileTime(lastWriteTime));
        }
Beispiel #2
0
        internal static DateTime GetCreationTimeInternal(KernelTransaction transaction, string path, bool returnUtc, PathFormat pathFormat)
        {
            NativeMethods.FileTime creationTime = GetAttributesExInternal <NativeMethods.Win32FileAttributeData>(transaction, path, pathFormat).CreationTime;

            return(returnUtc
            ? DateTime.FromFileTimeUtc(creationTime)
            : DateTime.FromFileTime(creationTime));
        }
Beispiel #3
0
        internal static DateTime GetChangeTimeInternal(bool isFolder, KernelTransaction transaction, SafeFileHandle safeHandle, string path, bool getUtc, PathFormat pathFormat)
        {
            if (!NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(Resources.RequiresWindowsVistaOrHigher);
            }

            bool callerHandle = safeHandle != null;

            if (!callerHandle)
            {
                if (pathFormat != PathFormat.LongFullPath && Utils.IsNullOrWhiteSpace(path))
                {
                    throw new ArgumentNullException("path");
                }

                string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars);

                safeHandle = CreateFileInternal(transaction, pathLp, isFolder ? ExtendedFileAttributes.BackupSemantics : ExtendedFileAttributes.Normal, null, FileMode.Open, FileSystemRights.ReadData, FileShare.ReadWrite, true, PathFormat.LongFullPath);
            }


            try
            {
                NativeMethods.IsValidHandle(safeHandle);

                using (var safeBuffer = new SafeGlobalMemoryBufferHandle(IntPtr.Size + Marshal.SizeOf(typeof(NativeMethods.FileBasicInfo))))
                {
                    NativeMethods.FileBasicInfo fbi;

                    if (!NativeMethods.GetFileInformationByHandleEx_FileBasicInfo(safeHandle, NativeMethods.FileInfoByHandleClass.FileBasicInfo, out fbi, (uint)safeBuffer.Capacity))
                    {
                        NativeError.ThrowException(Marshal.GetLastWin32Error());
                    }

                    safeBuffer.StructureToPtr(fbi, true);
                    NativeMethods.FileTime changeTime = safeBuffer.PtrToStructure <NativeMethods.FileBasicInfo>().ChangeTime;

                    return(getUtc
                  ? DateTime.FromFileTimeUtc(changeTime)
                  : DateTime.FromFileTime(changeTime));
                }
            }
            finally
            {
                // Handle is ours, dispose.
                if (!callerHandle && safeHandle != null)
                {
                    safeHandle.Close();
                }
            }
        }