/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ using System; using System.IO; using System.Security; namespace Alphaleonis.Win32.Filesystem { #region ByHandleFileInfo /// Contains information that the GetFileInformationByHandle function retrieves. [SerializableAttribute] [SecurityCritical] public sealed class ByHandleFileInfo { #region Constructor internal ByHandleFileInfo(NativeMethods.BY_HANDLE_FILE_INFORMATION fibh) { CreationTimeUtc = DateTime.FromFileTimeUtc(fibh.ftCreationTime); LastAccessTimeUtc = DateTime.FromFileTimeUtc(fibh.ftLastAccessTime); LastWriteTimeUtc = DateTime.FromFileTimeUtc(fibh.ftLastWriteTime); Attributes = fibh.dwFileAttributes; FileIndex = NativeMethods.ToLong(fibh.nFileIndexHigh, fibh.nFileIndexLow); FileSize = NativeMethods.ToLong(fibh.nFileSizeHigh, fibh.nFileSizeLow); NumberOfLinks = fibh.nNumberOfLinks; VolumeSerialNumber = fibh.dwVolumeSerialNumber; } #endregion // Constructor #region Properties #region Attributes /// Gets the file attributes. /// The file attributes. public FileAttributes Attributes { get; private set; } #endregion // Attributes #region CreationTime /// Gets the time this entry was created. /// The time this entry was created. public DateTime CreationTime { get { return CreationTimeUtc.ToLocalTime(); } } #endregion // CreationTime #region CreationTimeUtc /// Gets the time, in coordinated universal time (UTC), this entry was created. /// The time, in coordinated universal time (UTC), this entry was created. public DateTime CreationTimeUtc { get; private set; } #endregion // CreationTimeUtc #region LastAccessTime /// Gets the time this entry was last accessed. /// For a file, the structure specifies the last time that a file is read from or written to. /// For a directory, the structure specifies when the directory is created. /// For both files and directories, the specified date is correct, but the time of day is always set to midnight. /// If the underlying file system does not support the last access time, this member is zero (0). /// /// The time this entry was last accessed. public DateTime LastAccessTime { get { return LastAccessTimeUtc.ToLocalTime(); } } #endregion // LastAccessTime #region LastAccessTimeUtc /// Gets the time, in coordinated universal time (UTC), this entry was last accessed. /// For a file, the structure specifies the last time that a file is read from or written to. /// For a directory, the structure specifies when the directory is created. /// For both files and directories, the specified date is correct, but the time of day is always set to midnight. /// If the underlying file system does not support the last access time, this member is zero (0). /// /// The time, in coordinated universal time (UTC), this entry was last accessed. public DateTime LastAccessTimeUtc { get; private set; } #endregion // LastAccessTimeUtc #region LastWriteTime /// Gets the time this entry was last modified. /// For a file, the structure specifies the last time that a file is written to. /// For a directory, the structure specifies when the directory is created. /// If the underlying file system does not support the last access time, this member is zero (0). /// /// The time this entry was last modified. public DateTime LastWriteTime { get { return LastWriteTimeUtc.ToLocalTime(); } } #endregion // LastWriteTime #region LastWriteTimeUtc /// Gets the time, in coordinated universal time (UTC), this entry was last modified. /// For a file, the structure specifies the last time that a file is written to. /// For a directory, the structure specifies when the directory is created. /// If the underlying file system does not support the last access time, this member is zero (0). /// /// The time, in coordinated universal time (UTC), this entry was last modified. public DateTime LastWriteTimeUtc { get; private set; } #endregion // LastWriteTimeUtc #region VolumeSerialNumber /// Gets the serial number of the volume that contains a file. /// The serial number of the volume that contains a file. public int VolumeSerialNumber { get; private set; } #endregion // VolumeSerialNumber #region FileSize /// Gets the size of the file. /// The size of the file. public long FileSize { get; private set; } #endregion // FileSize #region NumberOfLinks /// Gets the number of links to this file. For the FAT file system this member is always 1. For the NTFS file system, it can be more than 1. /// The number of links to this file. public int NumberOfLinks { get; private set; } #endregion // NumberOfLinks #region FileIndex /// /// Gets the unique identifier associated with the file. The identifier and the volume serial number uniquely identify a /// file on a single computer. To determine whether two open handles represent the same file, combine the identifier /// and the volume serial number for each file and compare them. /// /// The unique identifier of the file. public long FileIndex { get; private set; } #endregion // FileIndex #endregion // Properties } #endregion // ByHandleFileInfo }