Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

205 lignes
7.1 KiB

  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using System;
  22. using System.Diagnostics.CodeAnalysis;
  23. using System.IO;
  24. using System.Security;
  25. namespace Alphaleonis.Win32.Filesystem
  26. {
  27. /// <summary>Contains information about files in the specified directory. Used for directory handles.</summary>
  28. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dir")]
  29. [Serializable]
  30. [SecurityCritical]
  31. public sealed class FileIdBothDirectoryInfo
  32. {
  33. #region Constructor
  34. #region FileIdBothDirectoryInfo
  35. internal FileIdBothDirectoryInfo(NativeMethods.FILE_ID_BOTH_DIR_INFO fibdi, string fileName)
  36. {
  37. CreationTimeUtc = DateTime.FromFileTimeUtc(fibdi.CreationTime);
  38. LastAccessTimeUtc = DateTime.FromFileTimeUtc(fibdi.LastAccessTime);
  39. LastWriteTimeUtc = DateTime.FromFileTimeUtc(fibdi.LastWriteTime);
  40. ChangeTimeUtc = DateTime.FromFileTimeUtc(fibdi.ChangeTime);
  41. AllocationSize = fibdi.AllocationSize;
  42. EndOfFile = fibdi.EndOfFile;
  43. ExtendedAttributesSize = fibdi.EaSize;
  44. FileAttributes = fibdi.FileAttributes;
  45. FileId = fibdi.FileId;
  46. FileIndex = fibdi.FileIndex;
  47. FileName = fileName;
  48. // ShortNameLength is the number of bytes in the short name; since we have a unicode string we must divide that by 2.
  49. ShortName = new string(fibdi.ShortName, 0, fibdi.ShortNameLength / 2);
  50. }
  51. #endregion // FileIdBothDirectoryInfo
  52. #endregion // Constructor
  53. #region Properties
  54. #region AllocationSize
  55. /// <summary>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.</summary>
  56. public long AllocationSize { get; set; }
  57. #endregion // AllocationSize
  58. #region ChangeTime
  59. /// <summary>Gets the time this entry was changed.</summary>
  60. /// <value>The time this entry was changed.</value>
  61. public DateTime ChangeTime
  62. {
  63. get { return ChangeTimeUtc.ToLocalTime(); }
  64. }
  65. #endregion // ChangeTime
  66. #region ChangeTimeUtc
  67. /// <summary>Gets the time, in coordinated universal time (UTC), this entry was changed.</summary>
  68. /// <value>The time, in coordinated universal time (UTC), this entry was changed.</value>
  69. public DateTime ChangeTimeUtc { get; set; }
  70. #endregion // ChangeTimeUtc
  71. #region CreationTime
  72. /// <summary>Gets the time this entry was created.</summary>
  73. /// <value>The time this entry was created.</value>
  74. public DateTime CreationTime
  75. {
  76. get { return CreationTimeUtc.ToLocalTime(); }
  77. }
  78. #endregion // CreationTime
  79. #region CreationTimeUtc
  80. /// <summary>Gets the time, in coordinated universal time (UTC), this entry was created.</summary>
  81. /// <value>The time, in coordinated universal time (UTC), this entry was created.</value>
  82. public DateTime CreationTimeUtc { get; set; }
  83. #endregion // CreationTimeUtc
  84. #region EaSize
  85. /// <summary>The size of the extended attributes for the file.</summary>
  86. public int ExtendedAttributesSize { get; set; }
  87. #endregion // EaSize
  88. #region EndOfFile
  89. /// <summary>The absolute new end-of-file position as a byte offset from the start of the file to the end of the file.
  90. /// Because this value is zero-based, it actually refers to the first free byte in the file. In other words, <b>EndOfFile</b> is the offset to
  91. /// the byte that immediately follows the last valid byte in the file.
  92. /// </summary>
  93. public long EndOfFile { get; set; }
  94. #endregion // EndOfFile
  95. #region FileAttributes
  96. /// <summary>The file attributes.</summary>
  97. public FileAttributes FileAttributes { get; set; }
  98. #endregion FileAttributes
  99. #region FileId
  100. /// <summary>The file ID.</summary>
  101. public long FileId { get; set; }
  102. #endregion // FileId
  103. #region FileIndex
  104. /// <summary>The byte offset of the file within the parent directory. This member is undefined for file systems, such as NTFS,
  105. /// 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.
  106. /// </summary>
  107. public long FileIndex { get; set; }
  108. #endregion // FileIndex
  109. #region FileName
  110. /// <summary>The name of the file.</summary>
  111. public string FileName { get; set; }
  112. #endregion // FileName
  113. #region LastAccessTime
  114. /// <summary>Gets the time this entry was last accessed.</summary>
  115. /// <value>The time this entry was last accessed.</value>
  116. public DateTime LastAccessTime
  117. {
  118. get { return LastAccessTimeUtc.ToLocalTime(); }
  119. }
  120. #endregion // LastAccessTime
  121. #region LastAccessTimeUtc
  122. /// <summary>Gets the time, in coordinated universal time (UTC), this entry was last accessed.</summary>
  123. /// <value>The time, in coordinated universal time (UTC), this entry was last accessed.</value>
  124. public DateTime LastAccessTimeUtc { get; set; }
  125. #endregion // LastAccessTimeUtc
  126. #region LastWriteTime
  127. /// <summary>Gets the time this entry was last modified.</summary>
  128. /// <value>The time this entry was last modified.</value>
  129. public DateTime LastWriteTime
  130. {
  131. get { return LastWriteTimeUtc.ToLocalTime(); }
  132. }
  133. #endregion // LastWriteTime
  134. #region LastWriteTimeUtc
  135. /// <summary>Gets the time, in coordinated universal time (UTC), this entry was last modified.</summary>
  136. /// <value>The time, in coordinated universal time (UTC), this entry was last modified.</value>
  137. public DateTime LastWriteTimeUtc { get; set; }
  138. #endregion // LastWriteTimeUtc
  139. #region ShortName
  140. /// <summary>The short 8.3 file naming convention (for example, FILENAME.TXT) name of the file.</summary>
  141. public string ShortName { get; set; }
  142. #endregion // ShortName
  143. #endregion // Properties
  144. }
  145. }