Ejemplo n.º 1
0
        public static unsafe void SetLastAccessTimeUtc(string path, DateTime lastWriteTimeUtc)
        {
            var normalizedPath = Path.NormalizeLongPath(Path.GetFullPath(path));

            using (var handle = GetDirectoryHandle(normalizedPath))
            {
                var fileTime = new NativeMethods.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc());
                var r        = NativeMethods.SetFileTime(handle, null, &fileTime, null);
                if (r)
                {
                    return;
                }
                var errorCode = Marshal.GetLastWin32Error();
                Common.ThrowIOError(errorCode, path);
            }
        }
Ejemplo n.º 2
0
        public static unsafe void SetLastAccessTimeUtc(String path, DateTime lastAccessTimeUtc)
        {
            string normalizedPath = Path.NormalizeLongPath(path);

            using (SafeFileHandle handle = GetFileHandle(normalizedPath,
                                                         FileMode.Open, FileAccess.Write, FileShare.ReadWrite, FileOptions.None))
            {
                var  fileTime = new NativeMethods.FILE_TIME(lastAccessTimeUtc.ToFileTimeUtc());
                bool r        = NativeMethods.SetFileTime(handle, null, &fileTime, null);
                if (!r)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Common.ThrowIOError(errorCode, path);
                }
            }
        }
Ejemplo n.º 3
0
        public static unsafe void SetCreationTimeUtc(String path, DateTime creationTimeUtc)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.SetCreationTimeUtc(path, creationTimeUtc);
                return;
            }

            string normalizedPath = Path.NormalizeLongPath(path);

            using (SafeFileHandle handle = GetFileHandle(normalizedPath,
                                                         FileMode.Open, FileAccess.Write, FileShare.ReadWrite, FileOptions.None))
            {
                var  fileTime = new NativeMethods.FILE_TIME(creationTimeUtc.ToFileTimeUtc());
                bool r        = NativeMethods.SetFileTime(handle, &fileTime, null, null);
                if (!r)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Common.ThrowIOError(errorCode, path);
                }
            }
        }
Ejemplo n.º 4
0
        public static unsafe void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
        {
            var normalizedPath = Path.NormalizeLongPath(Path.GetFullPath(path));

            using (SafeFileHandle handle = GetDirectoryHandle(normalizedPath))
            {
                var fileTime = new NativeMethods.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc());
                bool r = NativeMethods.SetFileTime(handle, null, null, &fileTime);
                if (!r)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Common.ThrowIOError(errorCode, path);
                }
            }
        }
Ejemplo n.º 5
0
 public static unsafe void SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc)
 {
     string normalizedPath = Path.NormalizeLongPath(path);
     using (SafeFileHandle handle = GetFileHandle(normalizedPath,
         FileMode.Open, FileAccess.Write, FileShare.ReadWrite, FileOptions.None))
     {
         var fileTime = new NativeMethods.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc());
         bool r = NativeMethods.SetFileTime(handle, null, null, &fileTime);
         if (!r)
         {
             int errorCode = Marshal.GetLastWin32Error();
             Common.ThrowIOError(errorCode, path);
         }
     }
 }
Ejemplo n.º 6
0
        public static unsafe void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
        {
            var normalizedPath = Path.NormalizeLongPath(Path.GetFullPath(path));

            using (var handle = GetDirectoryHandle(normalizedPath))
            {
                var fileTime = new NativeMethods.FILE_TIME(creationTimeUtc.ToFileTimeUtc());
                var r = NativeMethods.SetFileTime(handle, &fileTime, null, null);
                if (r) return;
                var errorCode = Marshal.GetLastWin32Error();
                Common.ThrowIOError(errorCode, path);
            }
        }