選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

178 行
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.IO;
  23. using System.Security;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. #region ByHandleFileInfo
  27. /// <summary>Contains information that the GetFileInformationByHandle function retrieves.</summary>
  28. [SerializableAttribute]
  29. [SecurityCritical]
  30. public sealed class ByHandleFileInfo
  31. {
  32. #region Constructor
  33. internal ByHandleFileInfo(NativeMethods.BY_HANDLE_FILE_INFORMATION fibh)
  34. {
  35. CreationTimeUtc = DateTime.FromFileTimeUtc(fibh.ftCreationTime);
  36. LastAccessTimeUtc = DateTime.FromFileTimeUtc(fibh.ftLastAccessTime);
  37. LastWriteTimeUtc = DateTime.FromFileTimeUtc(fibh.ftLastWriteTime);
  38. Attributes = fibh.dwFileAttributes;
  39. FileIndex = NativeMethods.ToLong(fibh.nFileIndexHigh, fibh.nFileIndexLow);
  40. FileSize = NativeMethods.ToLong(fibh.nFileSizeHigh, fibh.nFileSizeLow);
  41. NumberOfLinks = fibh.nNumberOfLinks;
  42. VolumeSerialNumber = fibh.dwVolumeSerialNumber;
  43. }
  44. #endregion // Constructor
  45. #region Properties
  46. #region Attributes
  47. /// <summary>Gets the file attributes.</summary>
  48. /// <value>The file attributes.</value>
  49. public FileAttributes Attributes { get; private set; }
  50. #endregion // Attributes
  51. #region CreationTime
  52. /// <summary>Gets the time this entry was created.</summary>
  53. /// <value>The time this entry was created.</value>
  54. public DateTime CreationTime
  55. {
  56. get { return CreationTimeUtc.ToLocalTime(); }
  57. }
  58. #endregion // CreationTime
  59. #region CreationTimeUtc
  60. /// <summary>Gets the time, in coordinated universal time (UTC), this entry was created.</summary>
  61. /// <value>The time, in coordinated universal time (UTC), this entry was created.</value>
  62. public DateTime CreationTimeUtc { get; private set; }
  63. #endregion // CreationTimeUtc
  64. #region LastAccessTime
  65. /// <summary>Gets the time this entry was last accessed.
  66. /// For a file, the structure specifies the last time that a file is read from or written to.
  67. /// For a directory, the structure specifies when the directory is created.
  68. /// For both files and directories, the specified date is correct, but the time of day is always set to midnight.
  69. /// If the underlying file system does not support the last access time, this member is zero (0).
  70. /// </summary>
  71. /// <value>The time this entry was last accessed.</value>
  72. public DateTime LastAccessTime
  73. {
  74. get { return LastAccessTimeUtc.ToLocalTime(); }
  75. }
  76. #endregion // LastAccessTime
  77. #region LastAccessTimeUtc
  78. /// <summary>Gets the time, in coordinated universal time (UTC), this entry was last accessed.
  79. /// For a file, the structure specifies the last time that a file is read from or written to.
  80. /// For a directory, the structure specifies when the directory is created.
  81. /// For both files and directories, the specified date is correct, but the time of day is always set to midnight.
  82. /// If the underlying file system does not support the last access time, this member is zero (0).
  83. /// </summary>
  84. /// <value>The time, in coordinated universal time (UTC), this entry was last accessed.</value>
  85. public DateTime LastAccessTimeUtc { get; private set; }
  86. #endregion // LastAccessTimeUtc
  87. #region LastWriteTime
  88. /// <summary>Gets the time this entry was last modified.
  89. /// For a file, the structure specifies the last time that a file is written to.
  90. /// For a directory, the structure specifies when the directory is created.
  91. /// If the underlying file system does not support the last access time, this member is zero (0).
  92. /// </summary>
  93. /// <value>The time this entry was last modified.</value>
  94. public DateTime LastWriteTime
  95. {
  96. get { return LastWriteTimeUtc.ToLocalTime(); }
  97. }
  98. #endregion // LastWriteTime
  99. #region LastWriteTimeUtc
  100. /// <summary>Gets the time, in coordinated universal time (UTC), this entry was last modified.
  101. /// For a file, the structure specifies the last time that a file is written to.
  102. /// For a directory, the structure specifies when the directory is created.
  103. /// If the underlying file system does not support the last access time, this member is zero (0).
  104. /// </summary>
  105. /// <value>The time, in coordinated universal time (UTC), this entry was last modified.</value>
  106. public DateTime LastWriteTimeUtc { get; private set; }
  107. #endregion // LastWriteTimeUtc
  108. #region VolumeSerialNumber
  109. /// <summary>Gets the serial number of the volume that contains a file.</summary>
  110. /// <value>The serial number of the volume that contains a file.</value>
  111. public int VolumeSerialNumber { get; private set; }
  112. #endregion // VolumeSerialNumber
  113. #region FileSize
  114. /// <summary>Gets the size of the file.</summary>
  115. /// <value>The size of the file.</value>
  116. public long FileSize { get; private set; }
  117. #endregion // FileSize
  118. #region NumberOfLinks
  119. /// <summary>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.</summary>
  120. /// <value>The number of links to this file. </value>
  121. public int NumberOfLinks { get; private set; }
  122. #endregion // NumberOfLinks
  123. #region FileIndex
  124. /// <summary>
  125. /// Gets the unique identifier associated with the file. The identifier and the volume serial number uniquely identify a
  126. /// file on a single computer. To determine whether two open handles represent the same file, combine the identifier
  127. /// and the volume serial number for each file and compare them.
  128. /// </summary>
  129. /// <value>The unique identifier of the file.</value>
  130. public long FileIndex { get; private set; }
  131. #endregion // FileIndex
  132. #endregion // Properties
  133. }
  134. #endregion // ByHandleFileInfo
  135. }