public ArchiveListing Read() { ArchiveListingHeaderV2 header; using (Stream input = Decrypt(out header)) { _progressTotalChanged.NullSafeInvoke(header.EntriesCount); short blockNumber = -1; bool? flag = null; ArchiveListingEntryInfoV2[] entries = new ArchiveListingEntryInfoV2[header.EntriesCount]; for (int i = 0; i < entries.Length; i++) { entries[i] = input.ReadContent <ArchiveListingEntryInfoV2>(); if (entries[i].Flag != flag) { flag = entries[i].Flag; blockNumber++; } entries[i].BlockNumber = blockNumber; } ArchiveListingCompressedData data = new ArchiveListingCompressedData(header); data.ReadFromStream(input); ArchiveListing result = new ArchiveListing(_accessor, header); ParseEntries(entries, data, result); return(result); } }
public static ArchiveListing Read(ArchiveAccessor accessor, Action <long> progressIncrement, Action <long> progressTotalChanged) { using (ArchiveListingReaderV2 reader = new ArchiveListingReaderV2(accessor, progressIncrement, progressTotalChanged)) { ArchiveListing result = reader.Read(); return(result); } }
public void Write(ArchiveListing listing, out ArchiveListingBlockInfo[] blocksInfo, out ArchiveListingEntryInfoV2[] entriesInfoV2) { using (MemoryStream ms = new MemoryStream(32768)) { int blockNumber = 0, unpackedBlockOffset = 0; entriesInfoV2 = new ArchiveListingEntryInfoV2[listing.Count]; List <ArchiveListingBlockInfo> blocks = new List <ArchiveListingBlockInfo>(128); using (FormattingStreamWriter sw = new FormattingStreamWriter(ms, Encoding.ASCII, 4096, true, CultureInfo.InvariantCulture)) { sw.AutoFlush = true; for (int i = 0; i < listing.Count; i++) { ArchiveEntry entry = listing[i]; ArchiveListingEntryInfoV2 info = new ArchiveListingEntryInfoV2 { BlockNumber = (short)(ms.Position / 8192) }; info.Flag = (info.BlockNumber % 2 != 0); entriesInfoV2[i] = info; if (blockNumber != info.BlockNumber) { int blockSize = (int)(ms.Position - unpackedBlockOffset); ms.Position = unpackedBlockOffset; ArchiveListingBlockInfo block = new ArchiveListingBlockInfo { Offset = (int)_output.Position, UncompressedSize = blockSize }; block.CompressedSize = ZLibHelper.Compress(ms, _output, block.UncompressedSize); blocks.Add(block); blockNumber++; unpackedBlockOffset = (int)ms.Position; sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name); } else if (i == listing.Count - 1) { info.Offset = (short)(ms.Position - unpackedBlockOffset); sw.Write("{0:x}:{1:x}:{2:x}:{3}\0end\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name); int blockSize = (int)(ms.Position - unpackedBlockOffset); ms.Position = unpackedBlockOffset; ArchiveListingBlockInfo block = new ArchiveListingBlockInfo { Offset = (int)_output.Position, UncompressedSize = blockSize }; block.CompressedSize = ZLibHelper.Compress(ms, _output, block.UncompressedSize); blocks.Add(block); } else { info.Offset = (short)(ms.Position - unpackedBlockOffset); sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name); } } } blocksInfo = blocks.ToArray(); } }
public ArchiveListing Read() { ArchiveListingHeaderV1 header = _input.ReadStruct <ArchiveListingHeaderV1>(); _progressTotalChanged.NullSafeInvoke(header.EntriesCount); ArchiveListingEntryInfoV1[] entries = _input.ReadStructs <ArchiveListingEntryInfoV1>(header.EntriesCount); ArchiveListingCompressedData data = new ArchiveListingCompressedData(header); data.ReadFromStream(_input); ArchiveListing result = new ArchiveListing(_accessor, header); ParseEntries(entries, data, result); return(result); }
private ArchiveListingWriterV2(ArchiveListing listing) { _listing = listing; _accessor = _listing.Accessor; }
public static void Write(ArchiveListing listing) { ArchiveListingWriterV2 writer = new ArchiveListingWriterV2(listing); writer.Write(); }
private void ParseEntries(ArchiveListingEntryInfoV2[] entries, ArchiveListingCompressedData data, ArchiveListing result) { byte[] buff = new byte[0]; for (int currentBlock = -1, i = 0; i < entries.Length; i++) { ArchiveListingEntryInfoV2 entryInfoV2 = entries[i]; if (entryInfoV2.BlockNumber != currentBlock) { currentBlock = entryInfoV2.BlockNumber; buff = data.AcquireData(currentBlock); } string name; long sector, uncompressedSize, compressedSize; ParseInfo(entryInfoV2, buff, out sector, out uncompressedSize, out compressedSize, out name); ArchiveEntry entry = new ArchiveEntry(name, sector, compressedSize, uncompressedSize) { UnknownNumber = entryInfoV2.UnknownNumber, UnknownValue = entryInfoV2.UnknownValue, UnknownData = entryInfoV2.UnknownData }; result.Add(entry); _progressIncrement.NullSafeInvoke(1); } }
public ImgbArchiveAccessor(ArchiveListing parent, ArchiveEntry headersEntry, ArchiveEntry contentEntry) : base(parent, headersEntry) { ContentEntry = contentEntry; }
public DbArchiveAccessor(ArchiveListing parent, ArchiveEntry headersEntry) { Parent = parent; HeadersEntry = headersEntry; }