Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

87 linhas
4.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.IO;
  22. using System.Security;
  23. using FileStream = System.IO.FileStream;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. public static partial class File
  27. {
  28. /// <summary>Opens an existing file for reading.</summary>
  29. /// <param name="path">The file to be opened for reading.</param>
  30. /// <returns>A read-only <see cref="FileStream"/> on the specified path.</returns>
  31. /// <remarks>
  32. /// This method is equivalent to the <see cref="FileStream"/>(string, FileMode, FileAccess, FileShare) constructor overload with a
  33. /// <see cref="FileMode"/> value of Open, a <see cref="FileAccess"/> value of Read and a <see cref="FileShare"/> value of Read.
  34. /// </remarks>
  35. [SecurityCritical]
  36. public static FileStream OpenRead(string path)
  37. {
  38. return Open(path, FileMode.Open, FileAccess.Read);
  39. }
  40. /// <summary>[AlphaFS] Opens an existing file for reading.</summary>
  41. /// <param name="path">The file to be opened for reading.</param>
  42. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  43. /// <returns>A read-only <see cref="FileStream"/> on the specified path.</returns>
  44. /// <remarks>
  45. /// This method is equivalent to the <see cref="FileStream"/>(string, FileMode, FileAccess, FileShare) constructor overload with a
  46. /// <see cref="FileMode"/> value of Open, a <see cref="FileAccess"/> value of Read and a <see cref="FileShare"/> value of Read.
  47. /// </remarks>
  48. [SecurityCritical]
  49. public static FileStream OpenRead(string path, PathFormat pathFormat)
  50. {
  51. return Open(path, FileMode.Open, FileAccess.Read, pathFormat);
  52. }
  53. /// <summary>[AlphaFS] Opens an existing file for reading.</summary>
  54. /// <param name="transaction">The transaction.</param>
  55. /// <param name="path">The file to be opened for reading.</param>
  56. /// <returns>A read-only <see cref="FileStream"/> on the specified path.</returns>
  57. /// <remarks>
  58. /// This method is equivalent to the <see cref="FileStream"/>(string, FileMode, FileAccess, FileShare) constructor overload with a
  59. /// <see cref="FileMode"/> value of Open, a <see cref="FileAccess"/> value of Read and a <see cref="FileShare"/> value of Read.
  60. /// </remarks>
  61. [SecurityCritical]
  62. public static FileStream OpenReadTransacted(KernelTransaction transaction, string path)
  63. {
  64. return OpenTransacted(transaction, path, FileMode.Open, FileAccess.Read);
  65. }
  66. /// <summary>[AlphaFS] Opens an existing file for reading.</summary>
  67. /// <param name="transaction">The transaction.</param>
  68. /// <param name="path">The file to be opened for reading.</param>
  69. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  70. /// <returns>A read-only <see cref="FileStream"/> on the specified path.</returns>
  71. /// <remarks>
  72. /// This method is equivalent to the <see cref="FileStream"/>(string, FileMode, FileAccess, FileShare) constructor overload with a
  73. /// <see cref="FileMode"/> value of Open, a <see cref="FileAccess"/> value of Read and a <see cref="FileShare"/> value of Read.
  74. /// </remarks>
  75. [SecurityCritical]
  76. public static FileStream OpenReadTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  77. {
  78. return OpenTransacted(transaction, path, FileMode.Open, FileAccess.Read, pathFormat);
  79. }
  80. }
  81. }