/* 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.Diagnostics.CodeAnalysis; using System.IO; using System.Security; namespace Alphaleonis.Win32.Filesystem { /// Contains information about files in the specified directory. Used for directory handles. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dir")] [Serializable] [SecurityCritical] public sealed class FileIdBothDirectoryInfo { #region Constructor #region FileIdBothDirectoryInfo internal FileIdBothDirectoryInfo(NativeMethods.FILE_ID_BOTH_DIR_INFO fibdi, string fileName) { CreationTimeUtc = DateTime.FromFileTimeUtc(fibdi.CreationTime); LastAccessTimeUtc = DateTime.FromFileTimeUtc(fibdi.LastAccessTime); LastWriteTimeUtc = DateTime.FromFileTimeUtc(fibdi.LastWriteTime); ChangeTimeUtc = DateTime.FromFileTimeUtc(fibdi.ChangeTime); AllocationSize = fibdi.AllocationSize; EndOfFile = fibdi.EndOfFile; ExtendedAttributesSize = fibdi.EaSize; FileAttributes = fibdi.FileAttributes; FileId = fibdi.FileId; FileIndex = fibdi.FileIndex; FileName = fileName; // ShortNameLength is the number of bytes in the short name; since we have a unicode string we must divide that by 2. ShortName = new string(fibdi.ShortName, 0, fibdi.ShortNameLength / 2); } #endregion // FileIdBothDirectoryInfo #endregion // Constructor #region Properties #region AllocationSize /// The number of bytes that are allocated for the file. This value is usually a multiple of the sector or cluster size of the underlying physical device. public long AllocationSize { get; set; } #endregion // AllocationSize #region ChangeTime /// Gets the time this entry was changed. /// The time this entry was changed. public DateTime ChangeTime { get { return ChangeTimeUtc.ToLocalTime(); } } #endregion // ChangeTime #region ChangeTimeUtc /// Gets the time, in coordinated universal time (UTC), this entry was changed. /// The time, in coordinated universal time (UTC), this entry was changed. public DateTime ChangeTimeUtc { get; set; } #endregion // ChangeTimeUtc #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; set; } #endregion // CreationTimeUtc #region EaSize /// The size of the extended attributes for the file. public int ExtendedAttributesSize { get; set; } #endregion // EaSize #region EndOfFile /// The absolute new end-of-file position as a byte offset from the start of the file to the end of the file. /// Because this value is zero-based, it actually refers to the first free byte in the file. In other words, EndOfFile is the offset to /// the byte that immediately follows the last valid byte in the file. /// public long EndOfFile { get; set; } #endregion // EndOfFile #region FileAttributes /// The file attributes. public FileAttributes FileAttributes { get; set; } #endregion FileAttributes #region FileId /// The file ID. public long FileId { get; set; } #endregion // FileId #region FileIndex /// The byte offset of the file within the parent directory. This member is undefined for file systems, such as NTFS, /// in which the position of a file within the parent directory is not fixed and can be changed at any time to maintain sort order. /// public long FileIndex { get; set; } #endregion // FileIndex #region FileName /// The name of the file. public string FileName { get; set; } #endregion // FileName #region LastAccessTime /// Gets the time this entry was last accessed. /// 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. /// The time, in coordinated universal time (UTC), this entry was last accessed. public DateTime LastAccessTimeUtc { get; set; } #endregion // LastAccessTimeUtc #region LastWriteTime /// Gets the time this entry was last modified. /// 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. /// The time, in coordinated universal time (UTC), this entry was last modified. public DateTime LastWriteTimeUtc { get; set; } #endregion // LastWriteTimeUtc #region ShortName /// The short 8.3 file naming convention (for example, FILENAME.TXT) name of the file. public string ShortName { get; set; } #endregion // ShortName #endregion // Properties } }