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.

71 lignes
4.4 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.IO;
  22. using System.Security;
  23. using System.Security.AccessControl;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. public static partial class File
  27. {
  28. /// <summary>[AlphaFS] Opens the specified file for reading purposes bypassing security attributes.</summary>
  29. /// <param name="path">The file path to open.</param>
  30. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  31. /// <returns>A <see cref="FileStream"/> on the specified path, having the read-only mode and sharing options.</returns>
  32. [SecurityCritical]
  33. public static FileStream OpenBackupRead(string path, PathFormat pathFormat)
  34. {
  35. return OpenCore(null, path, FileMode.Open, FileSystemRights.ReadData, FileShare.None, ExtendedFileAttributes.BackupSemantics | ExtendedFileAttributes.SequentialScan | ExtendedFileAttributes.ReadOnly, null, null, pathFormat);
  36. }
  37. /// <summary>[AlphaFS] Opens the specified file for reading purposes bypassing security attributes. This method is simpler to use then BackupFileStream to read only file's data stream.</summary>
  38. /// <param name="path">The file path to open.</param>
  39. /// <returns>A <see cref="FileStream"/> on the specified path, having the read-only mode and sharing options.</returns>
  40. [SecurityCritical]
  41. public static FileStream OpenBackupRead(string path)
  42. {
  43. return OpenCore(null, path, FileMode.Open, FileSystemRights.ReadData, FileShare.None, ExtendedFileAttributes.BackupSemantics | ExtendedFileAttributes.SequentialScan | ExtendedFileAttributes.ReadOnly, null, null, PathFormat.RelativePath);
  44. }
  45. /// <summary>[AlphaFS] Opens the specified file for reading purposes bypassing security attributes.</summary>
  46. /// <param name="transaction">The transaction.</param>
  47. /// <param name="path">The file path to open.</param>
  48. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  49. /// <returns>A <see cref="FileStream"/> on the specified path, having the read-only mode and sharing options.</returns>
  50. [SecurityCritical]
  51. public static FileStream OpenBackupReadTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  52. {
  53. return OpenCore(transaction, path, FileMode.Open, FileSystemRights.ReadData, FileShare.None, ExtendedFileAttributes.BackupSemantics | ExtendedFileAttributes.SequentialScan | ExtendedFileAttributes.ReadOnly, null, null, pathFormat);
  54. }
  55. /// <summary>[AlphaFS] Opens the specified file for reading purposes bypassing security attributes.</summary>
  56. /// <param name="transaction">The transaction.</param>
  57. /// <param name="path">The file path to open.</param>
  58. /// <returns>A <see cref="FileStream"/> on the specified path, having the read-only mode and sharing options.</returns>
  59. [SecurityCritical]
  60. public static FileStream OpenBackupReadTransacted(KernelTransaction transaction, string path)
  61. {
  62. return OpenCore(transaction, path, FileMode.Open, FileSystemRights.ReadData, FileShare.None, ExtendedFileAttributes.BackupSemantics | ExtendedFileAttributes.SequentialScan | ExtendedFileAttributes.ReadOnly, null, null, PathFormat.RelativePath);
  63. }
  64. }
  65. }