public IFile ParseStream(Stream stream, string name, IProgressReporter reporter) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var fatPartType = GetFatType(stream); if (fatPartType == null) { LoggerService.WriteCallerLine($"{nameof(FATPartType)} can't be null."); return(null); } var part = FileFactory.CreatePartition(Constants.PartitionKey_FAT); var stoken = part.GetStoken(Constants.PartitionKey_FAT); stoken.BaseStream = stream; stoken.Name = name; stoken.Size = stream.Length; stoken.TypeGuid = Constants.PartitionType_FAT32; if (fatPartType == FATPartType.FAT32) { stoken.PartType = ServiceProvider.GetAllInstances <IPartitionType>().FirstOrDefault(p => p.GUID == Constants.PartitionType_FAT32); } else { stoken.PartType = ServiceProvider.GetAllInstances <IPartitionType>().FirstOrDefault(p => p.GUID == Constants.PartitionType_FAT16); } var unmanagedManager = new UnmanagedFATManager(stream); var partInfo = new FATPartInfo { UnmanagedFATManager = unmanagedManager }; //设定FAT分区详细信息; stoken.SetInstance(partInfo, Constants.PartitionStokenTag_FATPartInfo); if (unmanagedManager.FATManagerPtr == IntPtr.Zero) { unmanagedManager.Dispose(); throw new InvalidOperationException($"{nameof(unmanagedManager.FATManagerPtr)} can't be nullptr."); } LoadPartInfo(partInfo); LoadPartContent(part, reporter); part.Disposing += OnPartDisposing; return(part); }
/// <summary> /// 加载文件系统基本信息; /// </summary> /// <param name="info"></param> private static void LoadPartInfo(FATPartInfo info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } try { var infoPtr = Fat_Get_FsInfo(info.UnmanagedFATManager.FATManagerPtr); var infoPtrBack = Fat_Get_BackupFsInfo(info.UnmanagedFATManager.FATManagerPtr); var dbrPtr = Fat_Get_FsDBR(info.UnmanagedFATManager.FATManagerPtr); var dbrPtrBack = Fat_Get_BackupFsDBR(info.UnmanagedFATManager.FATManagerPtr); //为避免多次编写重复的判断是否为空,赋值语句,减少错误率,使用泛型方法将逻辑统一,编辑DBR或者Info; void SetFatDbrOrInfo <TFsEntity, TEntity>( IntPtr fsPtr, Func <TFsEntity, IntPtr> getEntityPtr, Func <TFsEntity, long> getOffset, Action <TEntity, long> setInfoOrDBR) where TFsEntity : struct where TEntity : struct