You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Directory.SetCreationTime.cs 12 KiB

7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 the directory was created.</summary>
  29. /// <param name="path">The directory for which to set the creation date and time information.</param>
  30. /// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  31. [SecurityCritical]
  32. public static void SetCreationTime(string path, DateTime creationTime)
  33. {
  34. File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), null, null, false, PathFormat.RelativePath);
  35. }
  36. /// <summary>Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
  37. /// <param name="path">The directory for which to set the creation date and time information.</param>
  38. /// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  39. [SecurityCritical]
  40. public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
  41. {
  42. File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, null, null, false, PathFormat.RelativePath);
  43. }
  44. #endregion // .NET
  45. /// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
  46. /// <param name="path">The directory for which to set the creation date and time information.</param>
  47. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  48. /// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  49. [SecurityCritical]
  50. public static void SetCreationTime(string path, DateTime creationTime, PathFormat pathFormat)
  51. {
  52. File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), null, null, false, pathFormat);
  53. }
  54. /// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
  55. /// <param name="path">The directory for which to set the creation date and time information.</param>
  56. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  57. /// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  58. /// <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>
  59. [SecurityCritical]
  60. public static void SetCreationTime(string path, DateTime creationTime, bool modifyReparsePoint, PathFormat pathFormat)
  61. {
  62. File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), null, null, modifyReparsePoint, pathFormat);
  63. }
  64. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
  65. /// <param name="path">The directory for which to set the creation date and time information.</param>
  66. /// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation 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 SetCreationTimeUtc(string path, DateTime creationTimeUtc, PathFormat pathFormat)
  70. {
  71. File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, null, null, false, pathFormat);
  72. }
  73. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
  74. /// <param name="path">The directory for which to set the creation date and time information.</param>
  75. /// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation 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 SetCreationTimeUtc(string path, DateTime creationTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  80. {
  81. File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, null, null, modifyReparsePoint, pathFormat);
  82. }
  83. #region Transactional
  84. /// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
  85. /// <param name="transaction">The transaction.</param>
  86. /// <param name="path">The directory for which to set the creation date and time information.</param>
  87. /// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
  88. [SecurityCritical]
  89. public static void SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime)
  90. {
  91. File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), null, null, false, PathFormat.RelativePath);
  92. }
  93. /// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
  94. /// <param name="transaction">The transaction.</param>
  95. /// <param name="path">The directory for which to set the creation date and time information.</param>
  96. /// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation 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 SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime, PathFormat pathFormat)
  100. {
  101. File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), null, null, false, pathFormat);
  102. }
  103. /// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
  104. /// <param name="transaction">The transaction.</param>
  105. /// <param name="path">The directory for which to set the creation date and time information.</param>
  106. /// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation 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 SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime, bool modifyReparsePoint, PathFormat pathFormat)
  111. {
  112. File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), null, null, modifyReparsePoint, pathFormat);
  113. }
  114. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
  115. /// <param name="transaction">The transaction.</param>
  116. /// <param name="path">The directory for which to set the creation date and time information.</param>
  117. /// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  118. [SecurityCritical]
  119. public static void SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc)
  120. {
  121. File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, null, null, false, PathFormat.RelativePath);
  122. }
  123. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
  124. /// <param name="transaction">The transaction.</param>
  125. /// <param name="path">The directory for which to set the creation date and time information.</param>
  126. /// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation 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 SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, PathFormat pathFormat)
  130. {
  131. File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, null, null, false, pathFormat);
  132. }
  133. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
  134. /// <param name="transaction">The transaction.</param>
  135. /// <param name="path">The directory for which to set the creation date and time information.</param>
  136. /// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation 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 SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  141. {
  142. File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, null, null, modifyReparsePoint, pathFormat);
  143. }
  144. #endregion // Transactional
  145. }
  146. }