您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Directory.EncryptedDirectoryRaw.cs 13 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.IO;
  22. namespace Alphaleonis.Win32.Filesystem
  23. {
  24. partial class Directory
  25. {
  26. #region Export
  27. /// <summary>[AlphaFS] Backs up (export) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
  28. /// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
  29. /// </summary>
  30. /// <remarks>
  31. /// <para>The directory being backed up is not decrypted; it is backed up in its encrypted state.</para>
  32. /// <para>If the caller does not have access to the key for the file, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to export encrypted files. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
  33. /// <para>To backup an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/> overloads and specify the directory to backup along with the destination stream of the backup data.</para>
  34. /// <para>This function is intended for the backup of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted directories.</para>
  35. /// <para>Note that this method does not back up the files inside the directory, only the directory entry itself.</para>
  36. /// </remarks>
  37. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
  38. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
  39. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/>
  40. /// <param name="fileName">The name of the file to be backed up.</param>
  41. /// <param name="outputStream">The destination stream to which the backup data will be written.</param>
  42. public static void ExportEncryptedDirectoryRaw(string fileName, Stream outputStream)
  43. {
  44. File.ImportExportEncryptedFileDirectoryRawCore(true, false, outputStream, fileName, PathFormat.RelativePath, false);
  45. }
  46. /// <summary>[AlphaFS] Backs up (export) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
  47. /// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
  48. /// </summary>
  49. /// <remarks>
  50. /// <para>The directory being backed up is not decrypted; it is backed up in its encrypted state.</para>
  51. /// <para>If the caller does not have access to the key for the file, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to export encrypted files. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
  52. /// <para>To backup an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/> overloads and specify the directory to backup along with the destination stream of the backup data.</para>
  53. /// <para>This function is intended for the backup of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted directories.</para>
  54. /// <para>Note that this method does not back up the files inside the directory, only the directory entry itself.</para>
  55. /// </remarks>
  56. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
  57. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
  58. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/>
  59. /// <param name="fileName">The name of the file to be backed up.</param>
  60. /// <param name="outputStream">The destination stream to which the backup data will be written.</param>
  61. /// <param name="pathFormat">The path format of the <paramref name="fileName"/> parameter.</param>
  62. public static void ExportEncryptedDirectoryRaw(string fileName, Stream outputStream, PathFormat pathFormat)
  63. {
  64. File.ImportExportEncryptedFileDirectoryRawCore(true, false, outputStream, fileName, pathFormat, false);
  65. }
  66. #endregion // Export
  67. #region Import
  68. /// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
  69. /// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
  70. /// </summary>
  71. /// <remarks>
  72. /// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
  73. /// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
  74. /// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
  75. /// </remarks>
  76. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
  77. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
  78. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
  79. /// <param name="inputStream">The stream to read previously backed up data from.</param>
  80. /// <param name="destinationPath">The path of the destination directory to restore to.</param>
  81. public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath)
  82. {
  83. File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, PathFormat.RelativePath, false);
  84. }
  85. /// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
  86. /// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
  87. /// </summary>
  88. /// <remarks>
  89. /// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
  90. /// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
  91. /// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
  92. /// </remarks>
  93. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
  94. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
  95. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
  96. /// <param name="inputStream">The stream to read previously backed up data from.</param>
  97. /// <param name="destinationPath">The path of the destination directory to restore to.</param>
  98. /// <param name="pathFormat">The path format of the <paramref name="destinationPath"/> parameter.</param>
  99. public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath, PathFormat pathFormat)
  100. {
  101. File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, pathFormat, false);
  102. }
  103. /// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
  104. /// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
  105. /// </summary>
  106. /// <remarks>
  107. /// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
  108. /// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
  109. /// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
  110. /// </remarks>
  111. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
  112. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
  113. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
  114. /// <param name="inputStream">The stream to read previously backed up data from.</param>
  115. /// <param name="destinationPath">The path of the destination directory to restore to.</param>
  116. /// <param name="overwriteHidden">If set to <see langword="true"/> a hidden directory will be overwritten on import.</param>
  117. public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath, bool overwriteHidden)
  118. {
  119. File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, PathFormat.RelativePath, overwriteHidden);
  120. }
  121. /// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
  122. /// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
  123. /// </summary>
  124. /// <remarks>
  125. /// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
  126. /// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
  127. /// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
  128. /// </remarks>
  129. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
  130. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
  131. /// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
  132. /// <param name="inputStream">The stream to read previously backed up data from.</param>
  133. /// <param name="destinationPath">The path of the destination directory to restore to.</param>
  134. /// <param name="overwriteHidden">If set to <see langword="true"/> a hidden directory will be overwritten on import.</param>
  135. /// <param name="pathFormat">The path format of the <paramref name="destinationPath"/> parameter.</param>
  136. public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath, bool overwriteHidden, PathFormat pathFormat)
  137. {
  138. File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, pathFormat, overwriteHidden);
  139. }
  140. #endregion // Import
  141. }
  142. }