protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pExtractAdxStruct, DoWorkEventArgs e) { ExtractHcaStruct extractAdxStruct = (ExtractHcaStruct)pExtractAdxStruct; long offset = 0; byte revisionMajor; byte revisionMinor; ushort dataOffset; long fmtChunkOffset; uint blockCount; ushort blockSize; long fileSize; int fileCount = 0; string outputPath = Path.Combine(Path.GetDirectoryName(pPath), "_cri_hca_ext"); string outputFileName; string outputFilePath; FileInfo fi = new FileInfo(pPath); using (FileStream fs = File.Open(pPath, FileMode.Open, FileAccess.Read)) { outputPath = Path.Combine(Path.GetDirectoryName(pPath), String.Format("{0}_HCAs", Path.GetFileNameWithoutExtension(pPath))); while ((offset = ParseFile.GetNextOffsetMasked(fs, offset, HCA_SIG_BYTES, MASK_BYTES)) > -1) { if (!this.CancellationPending) { // get version revisionMajor = ParseFile.ReadByte(fs, offset + 4); revisionMinor = ParseFile.ReadByte(fs, offset + 5); // get data offset dataOffset = ParseFile.ReadUshortBE(fs, offset + 6); // get 'fmt' chunk offset fmtChunkOffset = ParseFile.GetNextOffsetMasked(fs, offset, FMT_CHUNK_BYTES, MASK_BYTES); if (fmtChunkOffset > -1) { // get block count blockCount = ParseFile.ReadUintBE(fs, fmtChunkOffset + 8); // get block size blockSize = this.getBlockSize(fs, offset); // calculate file size fileSize = dataOffset + (blockCount * blockSize); // extract file outputFileName = String.Format("{0}_{1}.hca", Path.GetFileNameWithoutExtension(pPath), fileCount.ToString("X8")); outputFilePath = Path.Combine(outputPath, outputFileName); this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("{0} - offset: 0x{1} size: 0x{2}{3}", outputFileName, offset.ToString("X8"), fileSize.ToString("X8"), Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); ParseFile.ExtractChunkToFile(fs, offset, fileSize, outputFilePath, true, true); // increment counter fileCount++; // move pointer offset += fileSize; } else { throw new FormatException(String.Format("'fmt' chunk not found for HCA starting at 0x{0}", offset.ToString("X8"))); } } else { e.Cancel = true; return; } } } }