Exemplo n.º 1
0
        public static string GetLongPath(string path)
        {
            path = ZlpIOHelper.CheckAddLongPathPrefix(path);

            // --
            // Determine length.

            var sb = new StringBuilder();

            var realLength = PInvokeHelper.GetLongPathName(path, sb, 0);

            // --

            sb.Length  = (int)realLength;
            realLength = PInvokeHelper.GetLongPathName(path, sb, (uint)sb.Length);

            if (realLength <= 0)
            {
                var lastWin32Error = Marshal.GetLastWin32Error();
                throw new Win32Exception(
                          lastWin32Error,
                          $"Error {lastWin32Error} getting long path for '{path}': {ZlpIOHelper.CheckAddDotEnd(new Win32Exception(lastWin32Error).Message)}");
            }
            else
            {
                return(sb.ToString());
            }
        }
Exemplo n.º 2
0
        public static string GetFullPath(string path)
        {
            path = ZlpIOHelper.CheckAddLongPathPrefix(path);

            // --
            // Determine length.

            var sb = new StringBuilder();

            var realLength = PInvokeHelper.GetFullPathName(path, 0, sb, IntPtr.Zero);

            // --

            sb.Length  = realLength;
            realLength = PInvokeHelper.GetFullPathName(path, sb.Length, sb, IntPtr.Zero);

            if (realLength <= 0)
            {
                var lastWin32Error = Marshal.GetLastWin32Error();
                throw new Win32Exception(
                          lastWin32Error,
                          string.Format(
                              "Error {0} getting full path for '{1}': {2}",
                              lastWin32Error,
                              path,
                              ZlpIOHelper.CheckAddDotEnd(new Win32Exception(lastWin32Error).Message)));
            }
            else
            {
                return(sb.ToString());
            }
        }