25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

77 lines
3.7 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.Runtime.InteropServices;
  23. using System.Security;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. public static partial class File
  27. {
  28. /// <summary>[AlphaFS] Retrieves the encryption status of the specified file.</summary>
  29. /// <param name="path">The name of the file.</param>
  30. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  31. /// <returns>The <see cref="FileEncryptionStatus"/> of the specified <paramref name="path"/>.</returns>
  32. [SecurityCritical]
  33. public static FileEncryptionStatus GetEncryptionStatus(string path, PathFormat pathFormat)
  34. {
  35. return GetEncryptionStatusCore(path, pathFormat);
  36. }
  37. /// <summary>[AlphaFS] Retrieves the encryption status of the specified file.</summary>
  38. /// <param name="path">The name of the file.</param>
  39. /// <returns>The <see cref="FileEncryptionStatus"/> of the specified <paramref name="path"/>.</returns>
  40. [SecurityCritical]
  41. public static FileEncryptionStatus GetEncryptionStatus(string path)
  42. {
  43. return GetEncryptionStatusCore(path, PathFormat.RelativePath);
  44. }
  45. /// <summary>Retrieves the encryption status of the specified file.</summary>
  46. /// <param name="path">The name of the file.</param>
  47. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  48. /// <returns>The <see cref="FileEncryptionStatus"/> of the specified <paramref name="path"/>.</returns>
  49. [SecurityCritical]
  50. internal static FileEncryptionStatus GetEncryptionStatusCore(string path, PathFormat pathFormat)
  51. {
  52. if (pathFormat != PathFormat.LongFullPath && Utils.IsNullOrWhiteSpace(path))
  53. throw new ArgumentNullException("path");
  54. string pathLp = Path.GetExtendedLengthPathCore(null, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
  55. FileEncryptionStatus status;
  56. // FileEncryptionStatus()
  57. // In the ANSI version of this function, the name is limited to 248 characters.
  58. // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
  59. // 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
  60. if (!NativeMethods.FileEncryptionStatus(pathLp, out status))
  61. NativeError.ThrowException(Marshal.GetLastWin32Error(), pathLp);
  62. return status;
  63. }
  64. }
  65. }