12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.IO;
- using System.Runtime.InteropServices;
- using Microsoft.Win32.SafeHandles;
- namespace SMBServer
- {
- public class Win32Native
- {
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool SetFileTime(SafeFileHandle hFile, ref long lpCreationTime, IntPtr lpLastAccessTime, IntPtr lpLastWriteTime);
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool SetFileTime(SafeFileHandle hFile, IntPtr lpCreationTime, ref long lpLastAccessTime, IntPtr lpLastWriteTime);
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool SetFileTime(SafeFileHandle hFile, IntPtr lpCreationTime, IntPtr lpLastAccessTime, ref long lpLastWriteTime);
- internal static void SetCreationTime(SafeFileHandle hFile, DateTime creationTime)
- {
- long fileTime = creationTime.ToFileTime();
- bool success = SetFileTime(hFile, ref fileTime, IntPtr.Zero, IntPtr.Zero);
- if (!success)
- {
- uint error = (uint)Marshal.GetLastWin32Error();
- throw new IOException("Win32 error: " + error);
- }
- }
- internal static void SetLastAccessTime(SafeFileHandle hFile, DateTime lastAccessTime)
- {
- long fileTime = lastAccessTime.ToFileTime();
- bool success = SetFileTime(hFile, IntPtr.Zero, ref fileTime, IntPtr.Zero);
- if (!success)
- {
- uint error = (uint)Marshal.GetLastWin32Error();
- throw new IOException("Win32 error: " + error);
- }
- }
- internal static void SetLastWriteTime(SafeFileHandle hFile, DateTime lastWriteTime)
- {
- long fileTime = lastWriteTime.ToFileTime();
- bool success = SetFileTime(hFile, IntPtr.Zero, IntPtr.Zero, ref fileTime);
- if (!success)
- {
- uint error = (uint)Marshal.GetLastWin32Error();
- throw new IOException("Win32 error: " + error);
- }
- }
- }
- }
|