Beispiel #1
0
        /// <summary>
        /// Gets a canonical version of the given handle's path.
        /// </summary>
        public static string GetFinalPathNameByHandle(
            SafeFileHandle fileHandle,
            GetFinalPathNameByHandleFlags flags = GetFinalPathNameByHandleFlags.FILE_NAME_NORMALIZED | GetFinalPathNameByHandleFlags.VOLUME_NAME_DOS)
        {
            var wrapper = new FinalPathNameByHandleWrapper {
                FileHandle = fileHandle, Flags = flags
            };

            return(BufferHelper.ApiInvoke(ref wrapper));
        }
Beispiel #2
0
        /// <summary>
        /// Gets a canonical version of the given handle's path.
        /// </summary>
        public static string GetFinalPathNameByHandle(
            SafeFileHandle fileHandle,
            GetFinalPathNameByHandleFlags flags = GetFinalPathNameByHandleFlags.FileNameNormalized | GetFinalPathNameByHandleFlags.VolumeNameDos)
        {
            var wrapper = new FinalPathNameByHandleWrapper {
                FileHandle = fileHandle, Flags = flags
            };

            return(BufferHelper.ApiInvoke(ref wrapper));
        }
Beispiel #3
0
        /// <summary>
        /// Gets a canonical version of the given file's path.
        /// </summary>
        /// <param name="resolveLinks">True to get the destination of links rather than the link itself.</param>
        public static string GetFinalPathName(string path, GetFinalPathNameByHandleFlags finalPathFlags, bool resolveLinks)
        {
            if (path == null)
            {
                return(null);
            }

            // BackupSemantics is needed to get directory handles
            FileFlags flags = FileFlags.BackupSemantics;

            if (!resolveLinks)
            {
                flags |= FileFlags.OpenReparsePoint;
            }

            using (SafeFileHandle fileHandle = CreateFile(path, CreationDisposition.OpenExisting, 0, ShareModes.ReadWrite,
                                                          FileAttributes.None, flags))
            {
                return(GetFinalPathNameByHandle(fileHandle, finalPathFlags));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets a canonical version of the given file's path.
        /// </summary>
        /// <param name="resolveLinks">True to get the destination of links rather than the link itself.</param>
        public static string GetFinalPathName(string path, GetFinalPathNameByHandleFlags finalPathFlags, bool resolveLinks)
        {
            if (path == null)
            {
                return(null);
            }

            // BackupSemantics is needed to get directory handles
            FileFlags flags = FileFlags.FILE_FLAG_BACKUP_SEMANTICS;

            if (!resolveLinks)
            {
                flags |= FileFlags.FILE_FLAG_OPEN_REPARSE_POINT;
            }

            using (SafeFileHandle fileHandle = FileMethods.CreateFile(path, 0, ShareMode.FILE_SHARE_READWRITE,
                                                                      CreationDisposition.OPEN_EXISTING, FileAttributes.NONE, flags))
            {
                return(GetFinalPathNameByHandle(fileHandle, finalPathFlags));
            }
        }
Beispiel #5
0
 public static extern uint GetFinalPathNameByHandleW(
     SafeFileHandle hFile,
     SafeHandle lpszFilePath,
     uint cchFilePath,
     GetFinalPathNameByHandleFlags dwFlags);
Beispiel #6
0
 /// <summary>
 /// Gets a canonical version of the given handle's path.
 /// </summary>
 public static string GetFinalPathNameByHandle(SafeFileHandle fileHandle, GetFinalPathNameByHandleFlags flags = GetFinalPathNameByHandleFlags.FILE_NAME_NORMALIZED | GetFinalPathNameByHandleFlags.VOLUME_NAME_DOS)
 {
     return(BufferHelper.CachedApiInvoke((buffer) => Direct.GetFinalPathNameByHandleW(fileHandle, buffer, buffer.CharCapacity, flags)));
 }