Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

887 rader
56 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. using System.Security.AccessControl;
  25. namespace Alphaleonis.Win32.Filesystem
  26. {
  27. public static partial class File
  28. {
  29. #region SetCreationTime
  30. /// <summary>Sets the date and time the file was created.</summary>
  31. /// <param name="path">The file for which to set the creation date and time information.</param>
  32. /// <param name="creationTime">
  33. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  34. /// is expressed in local time.
  35. /// </param>
  36. [SecurityCritical]
  37. public static void SetCreationTime(string path, DateTime creationTime)
  38. {
  39. SetFsoDateTimeCore(false, null, path, creationTime.ToUniversalTime(), null, null, false, PathFormat.RelativePath);
  40. }
  41. /// <summary>[AlphaFS] Sets the date and time the file was created.</summary>
  42. /// <param name="path">The file for which to set the creation date and time information.</param>
  43. /// <param name="creationTime">
  44. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  45. /// is expressed in local time.
  46. /// </param>
  47. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  48. [SecurityCritical]
  49. public static void SetCreationTime(string path, DateTime creationTime, PathFormat pathFormat)
  50. {
  51. SetFsoDateTimeCore(false, null, path, creationTime.ToUniversalTime(), null, null, false, pathFormat);
  52. }
  53. /// <summary>[AlphaFS] Sets the date and time the file was created.</summary>
  54. /// <param name="path">The file for which to set the creation date and time information.</param>
  55. /// <param name="creationTime">
  56. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  57. /// is expressed in local time.
  58. /// </param>
  59. /// <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>
  60. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  61. [SecurityCritical]
  62. public static void SetCreationTime(string path, DateTime creationTime, bool modifyReparsePoint, PathFormat pathFormat)
  63. {
  64. SetFsoDateTimeCore(false, null, path, creationTime.ToUniversalTime(), null, null, modifyReparsePoint, pathFormat);
  65. }
  66. #region Transactional
  67. /// <summary>[AlphaFS] Sets the date and time the file was created.</summary>
  68. /// <param name="transaction">The transaction.</param>
  69. /// <param name="path">The file for which to set the creation date and time information.</param>
  70. /// <param name="creationTime">
  71. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  72. /// is expressed in local time.
  73. /// </param>
  74. [SecurityCritical]
  75. public static void SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime)
  76. {
  77. SetFsoDateTimeCore(false, transaction, path, creationTime.ToUniversalTime(), null, null, false, PathFormat.RelativePath);
  78. }
  79. /// <summary>[AlphaFS] Sets the date and time the file was created.</summary>
  80. /// <param name="transaction">The transaction.</param>
  81. /// <param name="path">The file for which to set the creation date and time information.</param>
  82. /// <param name="creationTime">
  83. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  84. /// is expressed in local time.
  85. /// </param>
  86. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  87. [SecurityCritical]
  88. public static void SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime, PathFormat pathFormat)
  89. {
  90. SetFsoDateTimeCore(false, transaction, path, creationTime.ToUniversalTime(), null, null, false, pathFormat);
  91. }
  92. /// <summary>[AlphaFS] Sets the date and time the file was created.</summary>
  93. /// <param name="transaction">The transaction.</param>
  94. /// <param name="path">The file for which to set the creation date and time information.</param>
  95. /// <param name="creationTime">
  96. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  97. /// is expressed in local time.
  98. /// </param>
  99. /// <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>
  100. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  101. [SecurityCritical]
  102. public static void SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime, bool modifyReparsePoint, PathFormat pathFormat)
  103. {
  104. SetFsoDateTimeCore(false, transaction, path, creationTime.ToUniversalTime(), null, null, modifyReparsePoint, pathFormat);
  105. }
  106. #endregion // Transacted
  107. #endregion // SetCreationTime
  108. #region SetCreationTimeUtc
  109. /// <summary>Sets the date and time, in coordinated universal time (UTC), that the file was created.</summary>
  110. /// <param name="path">The file for which to set the creation date and time information.</param>
  111. /// <param name="creationTimeUtc">
  112. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  113. /// is expressed in UTC time.
  114. /// </param>
  115. [SecurityCritical]
  116. public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
  117. {
  118. SetFsoDateTimeCore(false, null, path, creationTimeUtc, null, null, false, PathFormat.RelativePath);
  119. }
  120. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the file was created.</summary>
  121. /// <param name="path">The file for which to set the creation date and time information.</param>
  122. /// <param name="creationTimeUtc">
  123. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  124. /// is expressed in UTC time.
  125. /// </param>
  126. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  127. [SecurityCritical]
  128. public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc, PathFormat pathFormat)
  129. {
  130. SetFsoDateTimeCore(false, null, path, creationTimeUtc, null, null, false, pathFormat);
  131. }
  132. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the file was created.</summary>
  133. /// <param name="path">The file for which to set the creation date and time information.</param>
  134. /// <param name="creationTimeUtc">
  135. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  136. /// is expressed in UTC time.
  137. /// </param>
  138. /// <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>
  139. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  140. [SecurityCritical]
  141. public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  142. {
  143. SetFsoDateTimeCore(false, null, path, creationTimeUtc, null, null, modifyReparsePoint, pathFormat);
  144. }
  145. #region Transactional
  146. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the file was created.</summary>
  147. /// <param name="transaction">The transaction.</param>
  148. /// <param name="path">The file for which to set the creation date and time information.</param>
  149. /// <param name="creationTimeUtc">
  150. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  151. /// is expressed in UTC time.
  152. /// </param>
  153. [SecurityCritical]
  154. public static void SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc)
  155. {
  156. SetFsoDateTimeCore(false, transaction, path, creationTimeUtc, null, null, false, PathFormat.RelativePath);
  157. }
  158. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the file was created.</summary>
  159. /// <param name="transaction">The transaction.</param>
  160. /// <param name="path">The file for which to set the creation date and time information.</param>
  161. /// <param name="creationTimeUtc">
  162. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  163. /// is expressed in UTC time.
  164. /// </param>
  165. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  166. [SecurityCritical]
  167. public static void SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, PathFormat pathFormat)
  168. {
  169. SetFsoDateTimeCore(false, transaction, path, creationTimeUtc, null, null, false, pathFormat);
  170. }
  171. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the file was created.</summary>
  172. /// <param name="transaction">The transaction.</param>
  173. /// <param name="path">The file for which to set the creation date and time information.</param>
  174. /// <param name="creationTimeUtc">
  175. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  176. /// is expressed in UTC time.
  177. /// </param>
  178. /// <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>
  179. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  180. [SecurityCritical]
  181. public static void SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  182. {
  183. SetFsoDateTimeCore(false, transaction, path, creationTimeUtc, null, null, modifyReparsePoint, pathFormat);
  184. }
  185. #endregion // Transacted
  186. #endregion // SetCreationTimeUtc
  187. #region SetLastAccessTime
  188. /// <summary>Sets the date and time that the specified file was last accessed.</summary>
  189. /// <param name="path">The file for which to set the access date and time information.</param>
  190. /// <param name="lastAccessTime">
  191. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  192. /// value is expressed in local time.
  193. /// </param>
  194. [SecurityCritical]
  195. public static void SetLastAccessTime(string path, DateTime lastAccessTime)
  196. {
  197. SetFsoDateTimeCore(false, null, path, null, lastAccessTime.ToUniversalTime(), null, false, PathFormat.RelativePath);
  198. }
  199. /// <summary>[AlphaFS] Sets the date and time that the specified file was last accessed.</summary>
  200. /// <param name="path">The file for which to set the access date and time information.</param>
  201. /// <param name="lastAccessTime">
  202. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  203. /// value is expressed in local time.
  204. /// </param>
  205. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  206. [SecurityCritical]
  207. public static void SetLastAccessTime(string path, DateTime lastAccessTime, PathFormat pathFormat)
  208. {
  209. SetFsoDateTimeCore(false, null, path, null, lastAccessTime.ToUniversalTime(), null, false, pathFormat);
  210. }
  211. /// <summary>[AlphaFS] Sets the date and time that the specified file was last accessed.</summary>
  212. /// <param name="path">The file for which to set the access date and time information.</param>
  213. /// <param name="lastAccessTime">
  214. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  215. /// value is expressed in local time.
  216. /// </param>
  217. /// <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>
  218. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  219. [SecurityCritical]
  220. public static void SetLastAccessTime(string path, DateTime lastAccessTime, bool modifyReparsePoint, PathFormat pathFormat)
  221. {
  222. SetFsoDateTimeCore(false, null, path, null, lastAccessTime.ToUniversalTime(), null, modifyReparsePoint, pathFormat);
  223. }
  224. #region Transaction
  225. /// <summary>[AlphaFS] Sets the date and time that the specified file was last accessed.</summary>
  226. /// <param name="transaction">The transaction.</param>
  227. /// <param name="path">The file for which to set the access date and time information.</param>
  228. /// <param name="lastAccessTime">
  229. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  230. /// value is expressed in local time.
  231. /// </param>
  232. [SecurityCritical]
  233. public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime)
  234. {
  235. SetFsoDateTimeCore(false, transaction, path, null, lastAccessTime.ToUniversalTime(), null, false, PathFormat.RelativePath);
  236. }
  237. /// <summary>[AlphaFS] Sets the date and time that the specified file was last accessed.</summary>
  238. /// <param name="transaction">The transaction.</param>
  239. /// <param name="path">The file for which to set the access date and time information.</param>
  240. /// <param name="lastAccessTime">
  241. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  242. /// value is expressed in local time.
  243. /// </param>
  244. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  245. [SecurityCritical]
  246. public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime, PathFormat pathFormat)
  247. {
  248. SetFsoDateTimeCore(false, transaction, path, null, lastAccessTime.ToUniversalTime(), null, false, pathFormat);
  249. }
  250. /// <summary>[AlphaFS] Sets the date and time that the specified file was last accessed.</summary>
  251. /// <param name="transaction">The transaction.</param>
  252. /// <param name="path">The file for which to set the access date and time information.</param>
  253. /// <param name="lastAccessTime">
  254. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  255. /// value is expressed in local time.
  256. /// </param>
  257. /// <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>
  258. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  259. [SecurityCritical]
  260. public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime, bool modifyReparsePoint, PathFormat pathFormat)
  261. {
  262. SetFsoDateTimeCore(false, transaction, path, null, lastAccessTime.ToUniversalTime(), null, modifyReparsePoint, pathFormat);
  263. }
  264. #endregion // Transaction
  265. #endregion // SetLastAccessTime
  266. #region SetLastAccessTimeUtc
  267. /// <summary>Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.</summary>
  268. /// <param name="path">The file for which to set the access date and time information.</param>
  269. /// <param name="lastAccessTimeUtc">
  270. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  271. /// value is expressed in UTC time.
  272. /// </param>
  273. [SecurityCritical]
  274. public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
  275. {
  276. SetFsoDateTimeCore(false, null, path, null, lastAccessTimeUtc, null, false, PathFormat.RelativePath);
  277. }
  278. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.</summary>
  279. /// <param name="path">The file for which to set the access date and time information.</param>
  280. /// <param name="lastAccessTimeUtc">
  281. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  282. /// value is expressed in UTC time.
  283. /// </param>
  284. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  285. [SecurityCritical]
  286. public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc, PathFormat pathFormat)
  287. {
  288. SetFsoDateTimeCore(false, null, path, null, lastAccessTimeUtc, null, false, pathFormat);
  289. }
  290. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.</summary>
  291. /// <param name="path">The file for which to set the access date and time information.</param>
  292. /// <param name="lastAccessTimeUtc">
  293. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  294. /// value is expressed in UTC time.
  295. /// </param>
  296. /// <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>
  297. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  298. [SecurityCritical]
  299. public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  300. {
  301. SetFsoDateTimeCore(false, null, path, null, lastAccessTimeUtc, null, modifyReparsePoint, pathFormat);
  302. }
  303. #region Transactional
  304. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.</summary>
  305. /// <param name="transaction">The transaction.</param>
  306. /// <param name="path">The file for which to set the access date and time information.</param>
  307. /// <param name="lastAccessTimeUtc">
  308. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  309. /// value is expressed in UTC time.
  310. /// </param>
  311. [SecurityCritical]
  312. public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc)
  313. {
  314. SetFsoDateTimeCore(false, transaction, path, null, lastAccessTimeUtc, null, false, PathFormat.RelativePath);
  315. }
  316. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.</summary>
  317. /// <param name="transaction">The transaction.</param>
  318. /// <param name="path">The file for which to set the access date and time information.</param>
  319. /// <param name="lastAccessTimeUtc">
  320. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  321. /// value is expressed in UTC time.
  322. /// </param>
  323. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  324. [SecurityCritical]
  325. public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc, PathFormat pathFormat)
  326. {
  327. SetFsoDateTimeCore(false, transaction, path, null, lastAccessTimeUtc, null, false, pathFormat);
  328. }
  329. /// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.</summary>
  330. /// <param name="transaction">The transaction.</param>
  331. /// <param name="path">The file for which to set the access date and time information.</param>
  332. /// <param name="lastAccessTimeUtc">
  333. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  334. /// value is expressed in UTC time.
  335. /// </param>
  336. /// <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>
  337. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  338. [SecurityCritical]
  339. public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  340. {
  341. SetFsoDateTimeCore(false, transaction, path, null, lastAccessTimeUtc, null, modifyReparsePoint, pathFormat);
  342. }
  343. #endregion // Transacted
  344. #endregion // SetLastAccessTimeUtc
  345. #region SetLastWriteTime
  346. /// <summary>Sets the date and time that the specified file was last written to.</summary>
  347. /// <param name="path">The file for which to set the date and time information.</param>
  348. /// <param name="lastWriteTime">
  349. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  350. /// is expressed in local time.
  351. /// </param>
  352. [SecurityCritical]
  353. public static void SetLastWriteTime(string path, DateTime lastWriteTime)
  354. {
  355. SetFsoDateTimeCore(false, null, path, null, null, lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
  356. }
  357. /// <summary>[AlphaFS] Sets the date and time that the specified file was last written to.</summary>
  358. /// <param name="path">The file for which to set the date and time information.</param>
  359. /// <param name="lastWriteTime">
  360. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  361. /// is expressed in local time.
  362. /// </param>
  363. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  364. [SecurityCritical]
  365. public static void SetLastWriteTime(string path, DateTime lastWriteTime, PathFormat pathFormat)
  366. {
  367. SetFsoDateTimeCore(false, null, path, null, null, lastWriteTime.ToUniversalTime(), false, pathFormat);
  368. }
  369. /// <summary>[AlphaFS] Sets the date and time that the specified file was last written to.</summary>
  370. /// <param name="path">The file for which to set the date and time information.</param>
  371. /// <param name="lastWriteTime">
  372. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  373. /// is expressed in local time.
  374. /// </param>
  375. /// <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>
  376. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  377. [SecurityCritical]
  378. public static void SetLastWriteTime(string path, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
  379. {
  380. SetFsoDateTimeCore(false, null, path, null, null, lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
  381. }
  382. #region Transactional
  383. /// <summary>[AlphaFS] Sets the date and time that the specified file was last written to.</summary>
  384. /// <param name="transaction">The transaction.</param>
  385. /// <param name="path">The file for which to set the date and time information.</param>
  386. /// <param name="lastWriteTime">
  387. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  388. /// is expressed in local time.
  389. /// </param>
  390. [SecurityCritical]
  391. public static void SetLastWriteTimeTransacted(KernelTransaction transaction, string path, DateTime lastWriteTime)
  392. {
  393. SetFsoDateTimeCore(false, transaction, path, null, null, lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
  394. }
  395. /// <summary>[AlphaFS] Sets the date and time that the specified file was last written to.</summary>
  396. /// <param name="transaction">The transaction.</param>
  397. /// <param name="path">The file for which to set the date and time information.</param>
  398. /// <param name="lastWriteTime">
  399. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  400. /// is expressed in local time.
  401. /// </param>
  402. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  403. [SecurityCritical]
  404. public static void SetLastWriteTimeTransacted(KernelTransaction transaction, string path, DateTime lastWriteTime, PathFormat pathFormat)
  405. {
  406. SetFsoDateTimeCore(false, transaction, path, null, null, lastWriteTime.ToUniversalTime(), false, pathFormat);
  407. }
  408. /// <summary>[AlphaFS] Sets the date and time that the specified file was last written to.</summary>
  409. /// <param name="transaction">The transaction.</param>
  410. /// <param name="path">The file for which to set the date and time information.</param>
  411. /// <param name="lastWriteTime">
  412. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  413. /// is expressed in local time.
  414. /// </param>
  415. /// <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>
  416. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  417. [SecurityCritical]
  418. public static void SetLastWriteTimeTransacted(KernelTransaction transaction, string path, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
  419. {
  420. SetFsoDateTimeCore(false, transaction, path, null, null, lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
  421. }
  422. #endregion // Transacted
  423. #endregion // SetLastWriteTime
  424. #region SetLastWriteTimeUtc
  425. /// <summary>Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.</summary>
  426. /// <param name="path">The file for which to set the date and time information.</param>
  427. /// <param name="lastWriteTimeUtc">
  428. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  429. /// is expressed in UTC time.
  430. /// </param>
  431. [SecurityCritical]
  432. public static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
  433. {
  434. SetFsoDateTimeCore(false, null, path, null, null, lastWriteTimeUtc, false, PathFormat.RelativePath);
  435. }
  436. /// <summary>
  437. /// [AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
  438. /// </summary>
  439. /// <param name="path">The file for which to set the date and time information.</param>
  440. /// <param name="lastWriteTimeUtc">
  441. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  442. /// is expressed in UTC time.
  443. /// </param>
  444. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  445. [SecurityCritical]
  446. public static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc, PathFormat pathFormat)
  447. {
  448. SetFsoDateTimeCore(false, null, path, null, null, lastWriteTimeUtc, false, pathFormat);
  449. }
  450. /// <summary>
  451. /// [AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
  452. /// </summary>
  453. /// <param name="path">The file for which to set the date and time information.</param>
  454. /// <param name="lastWriteTimeUtc">
  455. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  456. /// is expressed in UTC time.
  457. /// </param>
  458. /// <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>
  459. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  460. [SecurityCritical]
  461. public static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  462. {
  463. SetFsoDateTimeCore(false, null, path, null, null, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
  464. }
  465. #region Transactional
  466. /// <summary>
  467. /// [AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
  468. /// </summary>
  469. /// <param name="transaction">The transaction.</param>
  470. /// <param name="path">The file for which to set the date and time information.</param>
  471. /// <param name="lastWriteTimeUtc">
  472. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  473. /// is expressed in UTC time.
  474. /// </param>
  475. [SecurityCritical]
  476. public static void SetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastWriteTimeUtc)
  477. {
  478. SetFsoDateTimeCore(false, transaction, path, null, null, lastWriteTimeUtc, false, PathFormat.RelativePath);
  479. }
  480. /// <summary>
  481. /// [AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
  482. /// </summary>
  483. /// <param name="transaction">The transaction.</param>
  484. /// <param name="path">The file for which to set the date and time information.</param>
  485. /// <param name="lastWriteTimeUtc">
  486. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  487. /// is expressed in UTC time.
  488. /// </param>
  489. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  490. [SecurityCritical]
  491. public static void SetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastWriteTimeUtc, PathFormat pathFormat)
  492. {
  493. SetFsoDateTimeCore(false, transaction, path, null, null, lastWriteTimeUtc, false, pathFormat);
  494. }
  495. /// <summary>
  496. /// [AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
  497. /// </summary>
  498. /// <param name="transaction">The transaction.</param>
  499. /// <param name="path">The file for which to set the date and time information.</param>
  500. /// <param name="lastWriteTimeUtc">
  501. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  502. /// is expressed in UTC time.
  503. /// </param>
  504. /// <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>
  505. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  506. [SecurityCritical]
  507. public static void SetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  508. {
  509. SetFsoDateTimeCore(false, transaction, path, null, null, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
  510. }
  511. #endregion // Transacted
  512. #endregion // SetLastWriteTimeUtc
  513. #region SetTimestamps
  514. /// <summary>[AlphaFS] Sets all the date and time stamps for the specified file, at once.</summary>
  515. /// <param name="path">The file for which to set the dates and times information.</param>
  516. /// <param name="creationTime">
  517. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  518. /// is expressed in local time.
  519. /// </param>
  520. /// <param name="lastAccessTime">
  521. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  522. /// value is expressed in local time.
  523. /// </param>
  524. /// <param name="lastWriteTime">
  525. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  526. /// is expressed in local time.
  527. /// </param>
  528. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  529. [SecurityCritical]
  530. public static void SetTimestamps(string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, PathFormat pathFormat)
  531. {
  532. SetFsoDateTimeCore(false, null, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, pathFormat);
  533. }
  534. /// <summary>[AlphaFS] Sets all the date and time stamps for the specified file, at once.</summary>
  535. /// <param name="path">The file for which to set the dates and times information.</param>
  536. /// <param name="creationTime">
  537. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  538. /// is expressed in local time.
  539. /// </param>
  540. /// <param name="lastAccessTime">
  541. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  542. /// value is expressed in local time.
  543. /// </param>
  544. /// <param name="lastWriteTime">
  545. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  546. /// is expressed in local time.
  547. /// </param>
  548. [SecurityCritical]
  549. public static void SetTimestamps(string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime)
  550. {
  551. SetFsoDateTimeCore(false, null, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
  552. }
  553. /// <summary>[AlphaFS] Sets all the date and time stamps for the specified file, at once.</summary>
  554. /// <param name="path">The file for which to set the dates and times information.</param>
  555. /// <param name="creationTime">
  556. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  557. /// is expressed in local time.
  558. /// </param>
  559. /// <param name="lastAccessTime">
  560. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  561. /// value is expressed in local time.
  562. /// </param>
  563. /// <param name="lastWriteTime">
  564. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  565. /// is expressed in local time.
  566. /// </param>
  567. /// <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>
  568. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  569. [SecurityCritical]
  570. public static void SetTimestamps(string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
  571. {
  572. SetFsoDateTimeCore(false, null, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
  573. }
  574. /// <summary>[AlphaFS] Sets all the date and time stamps for the specified file, at once.</summary>
  575. /// <param name="transaction">The transaction.</param>
  576. /// <param name="path">The file for which to set the dates and times information.</param>
  577. /// <param name="creationTime">
  578. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  579. /// is expressed in local time.
  580. /// </param>
  581. /// <param name="lastAccessTime">
  582. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  583. /// value is expressed in local time.
  584. /// </param>
  585. /// <param name="lastWriteTime">
  586. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  587. /// is expressed in local time.
  588. /// </param>
  589. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  590. [SecurityCritical]
  591. public static void SetTimestampsTransacted(KernelTransaction transaction, string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, PathFormat pathFormat)
  592. {
  593. SetFsoDateTimeCore(false, transaction, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, pathFormat);
  594. }
  595. /// <summary>[AlphaFS] Sets all the date and time stamps for the specified file, at once.</summary>
  596. /// <param name="transaction">The transaction.</param>
  597. /// <param name="path">The file for which to set the dates and times information.</param>
  598. /// <param name="creationTime">
  599. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  600. /// is expressed in local time.
  601. /// </param>
  602. /// <param name="lastAccessTime">
  603. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  604. /// value is expressed in local time.
  605. /// </param>
  606. /// <param name="lastWriteTime">
  607. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  608. /// is expressed in local time.
  609. /// </param>
  610. [SecurityCritical]
  611. public static void SetTimestampsTransacted(KernelTransaction transaction, string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime)
  612. {
  613. SetFsoDateTimeCore(false, transaction, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
  614. }
  615. /// <summary>[AlphaFS] Sets all the date and time stamps for the specified file, at once.</summary>
  616. /// <param name="transaction">The transaction.</param>
  617. /// <param name="path">The file for which to set the dates and times information.</param>
  618. /// <param name="creationTime">
  619. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  620. /// is expressed in local time.
  621. /// </param>
  622. /// <param name="lastAccessTime">
  623. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  624. /// value is expressed in local time.
  625. /// </param>
  626. /// <param name="lastWriteTime">
  627. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  628. /// is expressed in local time.
  629. /// </param>
  630. /// <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>
  631. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  632. [SecurityCritical]
  633. public static void SetTimestampsTransacted(KernelTransaction transaction, string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
  634. {
  635. SetFsoDateTimeCore(false, transaction, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
  636. }
  637. #endregion // SetTimestamps
  638. #region SetTimestampsUtc
  639. /// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified file, at once.</summary>
  640. /// <param name="path">The file for which to set the dates and times information.</param>
  641. /// <param name="creationTimeUtc">
  642. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  643. /// is expressed in UTC time.
  644. /// </param>
  645. /// <param name="lastAccessTimeUtc">
  646. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  647. /// value is expressed in UTC time.
  648. /// </param>
  649. /// <param name="lastWriteTimeUtc">
  650. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  651. /// is expressed in UTC time.
  652. /// </param>
  653. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  654. [SecurityCritical]
  655. public static void SetTimestampsUtc(string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, PathFormat pathFormat)
  656. {
  657. SetFsoDateTimeCore(false, null, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, pathFormat);
  658. }
  659. /// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified file, at once.</summary>
  660. /// <param name="path">The file for which to set the dates and times information.</param>
  661. /// <param name="creationTimeUtc">
  662. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  663. /// is expressed in UTC time.
  664. /// </param>
  665. /// <param name="lastAccessTimeUtc">
  666. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  667. /// value is expressed in UTC time.
  668. /// </param>
  669. /// <param name="lastWriteTimeUtc">
  670. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  671. /// is expressed in UTC time.
  672. /// </param>
  673. [SecurityCritical]
  674. public static void SetTimestampsUtc(string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc)
  675. {
  676. SetFsoDateTimeCore(false, null, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, PathFormat.RelativePath);
  677. }
  678. /// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified file, at once.</summary>
  679. /// <param name="path">The file for which to set the dates and times information.</param>
  680. /// <param name="creationTimeUtc">
  681. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  682. /// is expressed in UTC time.
  683. /// </param>
  684. /// <param name="lastAccessTimeUtc">
  685. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  686. /// value is expressed in UTC time.
  687. /// </param>
  688. /// <param name="lastWriteTimeUtc">
  689. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  690. /// is expressed in UTC time.
  691. /// </param>
  692. /// <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>
  693. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  694. [SecurityCritical]
  695. public static void SetTimestampsUtc(string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  696. {
  697. SetFsoDateTimeCore(false, null, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
  698. }
  699. /// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified file, at once.</summary>
  700. /// <param name="transaction">The transaction.</param>
  701. /// <param name="path">The file for which to set the dates and times information.</param>
  702. /// <param name="creationTimeUtc">
  703. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  704. /// is expressed in UTC time.
  705. /// </param>
  706. /// <param name="lastAccessTimeUtc">
  707. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  708. /// value is expressed in UTC time.
  709. /// </param>
  710. /// <param name="lastWriteTimeUtc">
  711. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  712. /// is expressed in UTC time.
  713. /// </param>
  714. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  715. [SecurityCritical]
  716. public static void SetTimestampsUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, PathFormat pathFormat)
  717. {
  718. SetFsoDateTimeCore(false, transaction, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, pathFormat);
  719. }
  720. /// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified file, at once.</summary>
  721. /// <param name="transaction">The transaction.</param>
  722. /// <param name="path">The file for which to set the dates and times information.</param>
  723. /// <param name="creationTimeUtc">
  724. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  725. /// is expressed in UTC time.
  726. /// </param>
  727. /// <param name="lastAccessTimeUtc">
  728. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  729. /// value is expressed in UTC time.
  730. /// </param>
  731. /// <param name="lastWriteTimeUtc">
  732. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  733. /// is expressed in UTC time.
  734. /// </param>
  735. [SecurityCritical]
  736. public static void SetTimestampsUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc)
  737. {
  738. SetFsoDateTimeCore(false, transaction, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, PathFormat.RelativePath);
  739. }
  740. /// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified file, at once.</summary>
  741. /// <param name="transaction">The transaction.</param>
  742. /// <param name="path">The file for which to set the dates and times information.</param>
  743. /// <param name="creationTimeUtc">
  744. /// A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value
  745. /// is expressed in UTC time.
  746. /// </param>
  747. /// <param name="lastAccessTimeUtc">
  748. /// A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This
  749. /// value is expressed in UTC time.
  750. /// </param>
  751. /// <param name="lastWriteTimeUtc">
  752. /// A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value
  753. /// is expressed in UTC time.
  754. /// </param>
  755. /// <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>
  756. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  757. [SecurityCritical]
  758. public static void SetTimestampsUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  759. {
  760. SetFsoDateTimeCore(false, transaction, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
  761. }
  762. #endregion // SetTimestampsUtc
  763. #region Internal Methods
  764. /// <summary>Set the date and time, in coordinated universal time (UTC), that the file or directory was created and/or last accessed and/or written to.</summary>
  765. /// <exception cref="ArgumentException"/>
  766. /// <exception cref="NotSupportedException"/>
  767. /// <param name="isFolder">Specifies that <paramref name="path"/> is a file or directory.</param>
  768. /// <param name="transaction">The transaction.</param>
  769. /// <param name="path">The file or directory for which to set the date and time information.</param>
  770. /// <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>
  771. /// <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>
  772. /// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
  773. /// <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>
  774. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  775. [SecurityCritical]
  776. internal static void SetFsoDateTimeCore(bool isFolder, KernelTransaction transaction, string path, DateTime? creationTimeUtc, DateTime? lastAccessTimeUtc, DateTime? lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
  777. {
  778. // Because we already check here, use false for CreateFileCore() to prevent another check.
  779. if (pathFormat == PathFormat.RelativePath)
  780. Path.CheckSupportedPathFormat(path, false, false);
  781. var attributes = isFolder ? ExtendedFileAttributes.BackupSemantics : ExtendedFileAttributes.Normal;
  782. if (modifyReparsePoint)
  783. attributes |= ExtendedFileAttributes.OpenReparsePoint;
  784. using (var creationTime = SafeGlobalMemoryBufferHandle.FromLong(creationTimeUtc.HasValue ? creationTimeUtc.Value.ToFileTimeUtc() : (long?)null))
  785. using (var lastAccessTime = SafeGlobalMemoryBufferHandle.FromLong(lastAccessTimeUtc.HasValue ? lastAccessTimeUtc.Value.ToFileTimeUtc() : (long?)null))
  786. using (var lastWriteTime = SafeGlobalMemoryBufferHandle.FromLong(lastWriteTimeUtc.HasValue ? lastWriteTimeUtc.Value.ToFileTimeUtc() : (long?)null))
  787. using (var safeHandle = CreateFileCore(transaction, path, attributes, null, FileMode.Open, FileSystemRights.WriteAttributes, FileShare.Delete | FileShare.Write, false, pathFormat))
  788. if (!NativeMethods.SetFileTime(safeHandle, creationTime, lastAccessTime, lastWriteTime))
  789. NativeError.ThrowException(path);
  790. }
  791. #endregion // Internal Methods
  792. }
  793. }