/// <summary> /// 获取设备分区 /// </summary> public override void LoadDevicePartitions() { try { Asyn?.Advance(1, LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_JiaZaiXiTongFenQuLieBiao)); var rootTable = new DSK_PART_TABLE(); var result = FileServiceCoreDll.GetMirrorFilePartitions(ref rootTable, Device.Source.ToString()); if (result != 0) { LoggerManagerSingle.Instance.Error("1/123获取镜像文件的分区信息失败并返回"); return; } if (rootTable.next == IntPtr.Zero) //无法读取分区,需要进行深度分区扫描 { var handle = FileServiceCoreDll.MountDisk(Device.Handle, -1, (ulong)Device.TotalSectors, 0x12); if (handle == IntPtr.Zero) { LoggerManagerSingle.Instance.Error(string.Format("2/123获取镜像文件的分区信息成功;无法读取分区,需要进行深度分区扫描;加载磁盘句柄失败(句柄:{0}, disNum:{1},扇区数:{2},设备类型:0x12)", Device.Handle, -1, Device.TotalSectors)); } FindVolumeCallBack fv = (ref FIND_VOLUME_PROGRESS pdi) => { return(0); }; try { result = FileServiceCoreDll.GetPhysicalPartitionsByScall(handle, fv, 0, 1, ref rootTable); } catch (Exception ex) { LoggerManagerSingle.Instance.Error("深度查找分区异常", ex); } if (result != 0) { LoggerManagerSingle.Instance.Error("3/123获取镜像文件的分区信息成功; 无法读取分区,需要进行深度分区扫描; 深度查找分区失败并返回"); return; } var parts = CreatePartition(rootTable); Device.Parts.AddRange(parts); FileServiceCoreDll.UnloadDeviceHandle(ref handle); } else { var parts = CreatePartition(rootTable); Device.Parts.AddRange(parts); } } catch (Exception ex) { LoggerManagerSingle.Instance.Error("获取设备分区异常", ex); } }
/// <summary> /// 导出单个文件到指定目录 /// isCover是否覆盖已存在的文件,默认不覆盖 /// </summary> private void ExportFile(FNodeX file, string savePath, bool isMedia = false, bool isCover = false) { var path = FileHelper.ConnectPath(savePath, file.Directory.ToSafeString(), (isMedia && file.IsDelete) ? "Del_" + file.FileName : file.FileName); if (!file.IsFolder) { path = path.TrimEnd('\\'); } if (!isCover && File.Exists(path)) { return; } const int t = 500 * 1024 * 1024; if (file.Size > t) { return; } Directory.CreateDirectory(FileHelper.GetFilePath(path)); RecoveryFile(file, path); Asyn?.Advance(0, string.Format(LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_WenJianHuiFuChengGong), file.FullPath.TrimEnd(@"\"))); var creatime = BaseTypeExtension.ToSafeDateTime(file.Source.CreateTime); if (creatime != null) { File.SetCreationTime(path, (DateTime)creatime); } var accessTime = BaseTypeExtension.ToSafeDateTime(file.Source.LastAccessTime); if (accessTime != null) { File.SetLastAccessTime(path, (DateTime)accessTime); } var modifyTime = BaseTypeExtension.ToSafeDateTime(file.Source.ModifyTime); if (modifyTime != null) { File.SetLastWriteTime(path, (DateTime)modifyTime); } }
/// <summary> /// 获取文件系统 /// </summary> /// <returns></returns> public FNodeX GetFileSystem() { _isStop = false; if (Device == null) { return(null); } // 打开设备 OpenDevice(); // 加载设备分区 if (Device.Parts.Count == 0) { LoadDevicePartitions(); } var fileTree = new FNodeX { IsRoot = true }; int count = Device.Parts.Count; // 构建分区文件系统 foreach (var part in Device.Parts) { RunPartition = (FileSystemPartition)part; Asyn?.Advance(1 / count, string.Format(LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_ZuZhuangFenQuDeWenJianXiTongSh), RunPartition.Name)); MountDevice(); var tree = ScanFileSystem(Device, RunPartition); if (tree == null) { continue; } // 扫描设备 fileTree.Collection.Add(tree); if (_isStop) { break; } } LoggerManagerSingle.Instance.Info(string.Format("扫描文件系统结束, 得到文件/文件夹数:{0}", AllFileNodeX.Count)); Asyn?.Advance(1, LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_WenJianXiTongZuZhuangWanBi)); return(fileTree); }