public FileSystem Load(Context context, IProgress <string> progress, System.Threading.CancellationToken ct) { context.Reader.ReadHeaderMagic(); long nextBlockOffset = context.Reader.ReadFirstBlockOffset(); int i = 0; while (nextBlockOffset < context.Reader.StreamLength) { if (progress != null) { progress.Report("Block " + i); } FileEntities.BlockHeader block = context.Reader.ReadBlockHeader(nextBlockOffset); this.verifier.VerifyBlockHeader(block); this.LoadFileHeaders(context, block); nextBlockOffset = block.NextBlockOffset; i++; } return(context.FileSystem); }
public void VerifyBlockHeader(FileEntities.BlockHeader block) { if (block.UncompressedFileHeadersSize != block.NumFiles * 560) { throw new FileFormatException(FileFormatException.EntityType.BlockHeader, FileFormatException.Error.InvalidValue, block.Offset, "The file headers size does not match the number of files."); } else if (!block.IsCompressed && block.CompressedFileHeadersSize != block.UncompressedFileHeadersSize) { throw new FileFormatException(FileFormatException.EntityType.BlockHeader, FileFormatException.Error.InvalidValue, block.Offset, "The compressed file headers size should match the uncompressed size when compression is disabled."); } else if (block.Offset < 792 + block.CompressedFileHeadersSize) { throw new FileFormatException(FileFormatException.EntityType.BlockHeader, FileFormatException.Error.InvalidValue, block.Offset, "The file header offset must be after the end of the RDA header."); } }