public virtual void Refresh() { try { switch (this.source) { case Source.Attributes: System.IO.FileAttributes attributes = NativeMethods.FileManagement.GetFileAttributes(this.Path); this.PopulateData(this.Path, attributes); break; case Source.FindResult: var findResult = NativeMethods.FileManagement.FindFirstFile(this.Path); this.PopulateData(findResult); findResult.FindHandle.Close(); break; case Source.FileInfo: using (SafeFileHandle fileHandle = GetFileHandle(this.Path)) { NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info = NativeMethods.FileManagement.GetFileInformationByHandle(fileHandle); this.PopulateData(this.Path, fileHandle, info); } break; } } catch (System.IO.FileNotFoundException) { this.Exists = false; } }
internal static IFileSystemInformation Create(string path, IFileService fileService) { using (SafeFileHandle fileHandle = GetFileHandle(path)) { string canonicalPath = NativeMethods.FileManagement.GetFinalPathName(fileHandle, 0); // GetFinalPathNameByHandle will use the legacy drive for the volume (e.g. \\?\C:\). We may have started with C:\ or some other // volume name format (\\?\Volume({GUID}), etc.) and we want to put the original volume specifier back. canonicalPath = Paths.ReplaceRoot(path, canonicalPath); NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info = NativeMethods.FileManagement.GetFileInformationByHandle(fileHandle); return(Create(canonicalPath, fileHandle, info, fileService)); } }
protected override void PopulateData(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info) { base.PopulateData(originalPath, fileHandle, info); this.Length = NativeMethods.HighLowToLong(info.nFileSizeHigh, info.nFileSizeLow); this.directory = Paths.GetDirectory(this.Path); }
new internal static IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info, IFileService fileService) { if ((info.dwFileAttributes & System.IO.FileAttributes.Directory) != 0) { throw new ArgumentOutOfRangeException(nameof(info)); } var fileInfo = new FileInformation(fileService); fileInfo.PopulateData(originalPath, fileHandle, info); return(fileInfo); }
protected virtual void PopulateData(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info) { this.source = Source.FileInfo; string originalRoot = Paths.GetRoot(originalPath); string finalPath = NativeMethods.FileManagement.GetFinalPathName(fileHandle, NativeMethods.FileManagement.FinalPathFlags.FILE_NAME_NORMALIZED); finalPath = Paths.ReplaceRoot(originalPath, finalPath); this.source = Source.FindResult; this.Path = finalPath; this.Attributes = info.dwFileAttributes; this.CreationTime = NativeMethods.GetDateTime(info.ftCreationTime); this.LastAccessTime = NativeMethods.GetDateTime(info.ftLastAccessTime); this.LastWriteTime = NativeMethods.GetDateTime(info.ftLastWriteTime); this.Name = Paths.GetFileOrDirectoryName(finalPath) ?? finalPath; this.FileIndex = NativeMethods.HighLowToLong(info.nFileIndexHigh, info.nFileSizeLow); this.NumberOfLinks = info.nNumberOfLinks; this.VolumeSerialNumber = info.dwVolumeSerialNumber; this.Exists = true; }
internal static IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info, IFileService fileService) { if ((info.dwFileAttributes & System.IO.FileAttributes.Directory) != 0) { return(DirectoryInformation.Create(originalPath, fileHandle, info, fileService)); } else { return(FileInformation.Create(originalPath, fileHandle, info, fileService)); } }