25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

101 satır
5.6 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. public static partial class File
  26. {
  27. #region TransferTimestamps
  28. /// <summary>[AlphaFS] Transfers the date and time stamps for the specified files.</summary>
  29. /// <remarks>This method does not change last access time for the source file.</remarks>
  30. /// <param name="sourcePath">The source file to get the date and time stamps from.</param>
  31. /// <param name="destinationPath">The destination file to set the date and time stamps.</param>
  32. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  33. [SecurityCritical]
  34. public static void TransferTimestamps(string sourcePath, string destinationPath, PathFormat pathFormat)
  35. {
  36. TransferTimestampsCore(false, null, sourcePath, destinationPath, pathFormat);
  37. }
  38. /// <summary>[AlphaFS] Transfers the date and time stamps for the specified files.</summary>
  39. /// <remarks>This method does not change last access time for the source file.</remarks>
  40. /// <param name="sourcePath">The source file to get the date and time stamps from.</param>
  41. /// <param name="destinationPath">The destination file to set the date and time stamps.</param>
  42. [SecurityCritical]
  43. public static void TransferTimestamps(string sourcePath, string destinationPath)
  44. {
  45. TransferTimestampsCore(false, null, sourcePath, destinationPath, PathFormat.RelativePath);
  46. }
  47. /// <summary>[AlphaFS] Transfers the date and time stamps for the specified files.</summary>
  48. /// <remarks>This method does not change last access time for the source file.</remarks>
  49. /// <param name="transaction">The transaction.</param>
  50. /// <param name="sourcePath">The source file to get the date and time stamps from.</param>
  51. /// <param name="destinationPath">The destination file to set the date and time stamps.</param>
  52. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  53. [SecurityCritical]
  54. public static void TransferTimestampsTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, PathFormat pathFormat)
  55. {
  56. TransferTimestampsCore(false, transaction, sourcePath, destinationPath, pathFormat);
  57. }
  58. /// <summary>[AlphaFS] Transfers the date and time stamps for the specified files.</summary>
  59. /// <remarks>This method does not change last access time for the source file.</remarks>
  60. /// <param name="transaction">The transaction.</param>
  61. /// <param name="sourcePath">The source file to get the date and time stamps from.</param>
  62. /// <param name="destinationPath">The destination file to set the date and time stamps.</param>
  63. [SecurityCritical]
  64. public static void TransferTimestampsTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
  65. {
  66. TransferTimestampsCore(false, transaction, sourcePath, destinationPath, PathFormat.RelativePath);
  67. }
  68. #endregion // TransferTimestamps
  69. #region Internal Methods
  70. /// <summary>Transfer the date and time stamps for the specified files and directories.</summary>
  71. /// <remarks>
  72. /// <para>This method does not change last access time for the source file.</para>
  73. /// <para>This method uses BackupSemantics flag to get Timestamp changed for directories.</para>
  74. /// </remarks>
  75. /// <param name="isFolder">Specifies that <paramref name="sourcePath"/> and <paramref name="destinationPath"/> are a file or directory.</param>
  76. /// <param name="transaction">The transaction.</param>
  77. /// <param name="sourcePath">The source path.</param>
  78. /// <param name="destinationPath">The destination path.</param>
  79. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  80. [SecurityCritical]
  81. internal static void TransferTimestampsCore(bool isFolder, KernelTransaction transaction, string sourcePath, string destinationPath, PathFormat pathFormat)
  82. {
  83. NativeMethods.WIN32_FILE_ATTRIBUTE_DATA attrs = GetAttributesExCore<NativeMethods.WIN32_FILE_ATTRIBUTE_DATA>(transaction, sourcePath, pathFormat, true);
  84. SetFsoDateTimeCore(isFolder, transaction, destinationPath, DateTime.FromFileTimeUtc(attrs.ftCreationTime), DateTime.FromFileTimeUtc(attrs.ftLastAccessTime), DateTime.FromFileTimeUtc(attrs.ftLastWriteTime), false, pathFormat);
  85. }
  86. #endregion // Internal Methods
  87. }
  88. }