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.

170 lignes
12 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.Security;
  23. namespace Alphaleonis.Win32.Filesystem
  24. {
  25. partial class Directory
  26. {
  27. #region .NET
  28. /// <summary>Sets the date and time that the specified directory was last accessed.</summary>
  29. /// <param name="path">The file for which to set the access date and time information.</param>
  30. /// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  31. [SecurityCritical]
  32. public static void SetLastAccessTime(string path, DateTime lastAccessTime)
  33. {
  34. File.SetFsoDateTimeCore(true, null, path, null, lastAccessTime.ToUniversalTime(), null, false, PathFormat.RelativePath);
  35. }
  36. /// <summary>Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  37. /// <param name="path">The directory for which to set the access date and time information.</param>
  38. /// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  39. [SecurityCritical]
  40. public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
  41. {
  42. File.SetFsoDateTimeCore(true, null, path, null, lastAccessTimeUtc, null, false, PathFormat.RelativePath);
  43. }
  44. #endregion // .NET
  45. /// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
  46. /// <param name="path">The file for which to set the access date and time information.</param>
  47. /// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  48. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  49. [SecurityCritical]
  50. public static void SetLastAccessTime(string path, DateTime lastAccessTime, PathFormat pathFormat)
  51. {
  52. File.SetFsoDateTimeCore(true, null, path, null, lastAccessTime.ToUniversalTime(), null, false, pathFormat);
  53. }
  54. /// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
  55. /// <param name="path">The file for which to set the access date and time information.</param>
  56. /// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  57. /// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
  58. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  59. [SecurityCritical]
  60. public static void SetLastAccessTime(string path, DateTime lastAccessTime, bool modifyReparsePoint, PathFormat pathFormat)
  61. {
  62. File.SetFsoDateTimeCore(true, null, path, null, lastAccessTime.ToUniversalTime(), null, modifyReparsePoint, pathFormat);
  63. }
  64. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  65. /// <param name="path">The directory for which to set the access date and time information.</param>
  66. /// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  67. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  68. [SecurityCritical]
  69. public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc, PathFormat pathFormat)
  70. {
  71. File.SetFsoDateTimeCore(true, null, path, null, lastAccessTimeUtc, null, false, pathFormat);
  72. }
  73. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  74. /// <param name="path">The directory for which to set the access date and time information.</param>
  75. /// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  76. /// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
  77. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  78. [SecurityCritical]
  79. public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  80. {
  81. File.SetFsoDateTimeCore(true, null, path, null, lastAccessTimeUtc, null, modifyReparsePoint, pathFormat);
  82. }
  83. #region Transactional
  84. /// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
  85. /// <param name="transaction">The transaction.</param>
  86. /// <param name="path">The directory for which to set the access date and time information.</param>
  87. /// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  88. [SecurityCritical]
  89. public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime)
  90. {
  91. File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTime.ToUniversalTime(), null, false, PathFormat.RelativePath);
  92. }
  93. /// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
  94. /// <param name="transaction">The transaction.</param>
  95. /// <param name="path">The directory for which to set the access date and time information.</param>
  96. /// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  97. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  98. [SecurityCritical]
  99. public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime, PathFormat pathFormat)
  100. {
  101. File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTime.ToUniversalTime(), null, false, pathFormat);
  102. }
  103. /// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
  104. /// <param name="transaction">The transaction.</param>
  105. /// <param name="path">The directory for which to set the access date and time information.</param>
  106. /// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  107. /// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
  108. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  109. [SecurityCritical]
  110. public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime, bool modifyReparsePoint, PathFormat pathFormat)
  111. {
  112. File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTime.ToUniversalTime(), null, modifyReparsePoint, pathFormat);
  113. }
  114. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  115. /// <param name="transaction">The transaction.</param>
  116. /// <param name="path">The directory for which to set the access date and time information.</param>
  117. /// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  118. [SecurityCritical]
  119. public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc)
  120. {
  121. File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTimeUtc, null, false, PathFormat.RelativePath);
  122. }
  123. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  124. /// <param name="transaction">The transaction.</param>
  125. /// <param name="path">The directory for which to set the access date and time information.</param>
  126. /// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  127. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  128. [SecurityCritical]
  129. public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc, PathFormat pathFormat)
  130. {
  131. File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTimeUtc, null, false, pathFormat);
  132. }
  133. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  134. /// <param name="transaction">The transaction.</param>
  135. /// <param name="path">The directory for which to set the access date and time information.</param>
  136. /// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  137. /// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
  138. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  139. [SecurityCritical]
  140. public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  141. {
  142. File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTimeUtc, null, modifyReparsePoint, pathFormat);
  143. }
  144. #endregion // Transactional
  145. }
  146. }