Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

NativeMethods.PathManagement.cs 6.2 KiB

7 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.Diagnostics.CodeAnalysis;
  23. using System.Runtime.InteropServices;
  24. using System.Security;
  25. using System.Text;
  26. namespace Alphaleonis.Win32.Filesystem
  27. {
  28. internal static partial class NativeMethods
  29. {
  30. /// <summary>Retrieves the full path and file name of the specified file or directory.</summary>
  31. /// <returns>If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.</returns>
  32. /// <remarks>The GetFullPathName function is not recommended for multithreaded applications or shared library code.</remarks>
  33. /// <remarks>Minimum supported client: Windows XP [desktop apps only]</remarks>
  34. /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
  35. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  36. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetFullPathNameW"), SuppressUnmanagedCodeSecurity]
  37. [return: MarshalAs(UnmanagedType.U4)]
  38. internal static extern uint GetFullPathName([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] uint nBufferLength, StringBuilder lpBuffer, IntPtr lpFilePart);
  39. /// <summary>Retrieves the full path and file name of the specified file or directory as a transacted operation.</summary>
  40. /// <returns>If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.</returns>
  41. /// <remarks>Minimum supported client: Windows Vista [desktop apps only]</remarks>
  42. /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only]</remarks>
  43. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  44. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetFullPathNameTransactedW"), SuppressUnmanagedCodeSecurity]
  45. [return: MarshalAs(UnmanagedType.U4)]
  46. internal static extern uint GetFullPathNameTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] uint nBufferLength, StringBuilder lpBuffer, IntPtr lpFilePart, SafeHandle hTransaction);
  47. /// <summary>Converts the specified path to its long form.</summary>
  48. /// <returns>
  49. /// If the function succeeds, the return value is nonzero.
  50. /// If the function fails, the return value is zero. To get extended error information, call GetLastError.
  51. /// </returns>
  52. /// <remarks>Minimum supported client: Windows XP [desktop apps only]</remarks>
  53. /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
  54. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  55. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetLongPathNameW"), SuppressUnmanagedCodeSecurity]
  56. [return: MarshalAs(UnmanagedType.U4)]
  57. internal static extern uint GetLongPathName([MarshalAs(UnmanagedType.LPWStr)] string lpszShortPath, StringBuilder lpszLongPath, [MarshalAs(UnmanagedType.U4)] uint cchBuffer);
  58. /// <summary>Converts the specified path to its long form as a transacted operation.</summary>
  59. /// <returns>
  60. /// If the function succeeds, the return value is nonzero.
  61. /// If the function fails, the return value is zero. To get extended error information, call GetLastError.
  62. /// </returns>
  63. /// <remarks>Minimum supported client: Windows Vista [desktop apps only]</remarks>
  64. /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only]</remarks>
  65. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  66. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetLongPathNameTransactedW"), SuppressUnmanagedCodeSecurity]
  67. [return: MarshalAs(UnmanagedType.U4)]
  68. internal static extern uint GetLongPathNameTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpszShortPath, StringBuilder lpszLongPath, [MarshalAs(UnmanagedType.U4)] uint cchBuffer, SafeHandle hTransaction);
  69. /// <summary>Retrieves the short path form of the specified path.</summary>
  70. /// <returns>
  71. /// If the function succeeds, the return value is nonzero.
  72. /// If the function fails, the return value is zero. To get extended error information, call GetLastError.
  73. /// </returns>
  74. /// <remarks>Minimum supported client: Windows XP</remarks>
  75. /// <remarks>Minimum supported server: Windows Server 2003</remarks>
  76. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  77. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetShortPathNameW"), SuppressUnmanagedCodeSecurity]
  78. [return: MarshalAs(UnmanagedType.U4)]
  79. internal static extern uint GetShortPathName([MarshalAs(UnmanagedType.LPWStr)] string lpszLongPath, StringBuilder lpszShortPath, [MarshalAs(UnmanagedType.U4)] uint cchBuffer);
  80. }
  81. }