private void ParseEntries(ArchiveListingEntryInfoV1[] entries, ArchiveListingCompressedData data, ArchiveListing result)
        {
            byte[] buff = new byte[0];

            for (int currentBlock = -1, i = 0; i < entries.Length; i++)
            {
                ArchiveListingEntryInfoV1 entryInfoV1 = entries[i];
                if (entryInfoV1.BlockNumber != currentBlock)
                {
                    currentBlock = entryInfoV1.BlockNumber;
                    buff = data.AcquireData(currentBlock);
                }

                string name;
                long sector, uncompressedSize, compressedSize;
                ParseInfo(entryInfoV1, buff, out sector, out uncompressedSize, out compressedSize, out name);

                ArchiveEntry entry = new ArchiveEntry(name, sector, compressedSize, uncompressedSize)
                {
                    UnknownNumber = entryInfoV1.UnknownNumber,
                    UnknownValue = entryInfoV1.UnknownValue
                };

                result.Add(entry);
                _progressIncrement.NullSafeInvoke(1);
            }
        }
Exemple #2
0
        private void ParseInfo(ArchiveListingEntryInfoV1 entryInfo, byte[] uncompressedData, out long sector, out long uncompressedSize, out long compressedSize, out string name)
        {
            string[] info;
            unsafe
            {
                fixed(byte *ptr = &uncompressedData[entryInfo.Offset])
                {
                    string str = new string((sbyte *)ptr);

                    info = str.Split(':');
                }
            }

            if (info.Length < 4)
            {
                name             = String.Join(":", info);
                sector           = -1;
                uncompressedSize = -1;
                compressedSize   = -1;
            }
            else
            {
                sector           = long.Parse(info[0], NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                uncompressedSize = long.Parse(info[1], NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                compressedSize   = long.Parse(info[2], NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                name             = info[3];
            }
        }
Exemple #3
0
        private void ParseEntries(ArchiveListingEntryInfoV1[] entries, ArchiveListingCompressedData data, ArchiveListing result)
        {
            byte[] buff = new byte[0];

            for (int currentBlock = -1, i = 0; i < entries.Length; i++)
            {
                ArchiveListingEntryInfoV1 entryInfoV1 = entries[i];
                if (entryInfoV1.BlockNumber != currentBlock)
                {
                    currentBlock = entryInfoV1.BlockNumber;
                    buff         = data.AcquireData(currentBlock);
                }

                string name;
                long   sector, uncompressedSize, compressedSize;
                ParseInfo(entryInfoV1, buff, out sector, out uncompressedSize, out compressedSize, out name);

                ArchiveEntry entry = new ArchiveEntry(name, sector, compressedSize, uncompressedSize)
                {
                    UnknownNumber = entryInfoV1.UnknownNumber,
                    UnknownValue  = entryInfoV1.UnknownValue
                };

                result.Add(entry);
                _progressIncrement.NullSafeInvoke(1);
            }
        }
Exemple #4
0
        public void Write(ArchiveListing listing, out ArchiveListingBlockInfo[] blocksInfo, out ArchiveListingEntryInfoV1[] entriesInfoV1)
        {
            using (MemoryStream ms = new MemoryStream(32768))
            {
                int blockNumber = 0, unpackedBlockOffset = 0;
                entriesInfoV1 = new ArchiveListingEntryInfoV1[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];
                        entriesInfoV1[i] = new ArchiveListingEntryInfoV1 {
                            BlockNumber = (short)(ms.Position / 8192)
                        };

                        if (blockNumber != entriesInfoV1[i].BlockNumber)
                        {
                            //sw.Write("end\0");
                            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)
                        {
                            entriesInfoV1[i].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
                        {
                            entriesInfoV1[i].Offset = (short)(ms.Position - unpackedBlockOffset);
                            sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name);
                        }

                        //lengths[i] = (int)_output.Position - offsets[i];
                        //blockSize += lengths[i];
                    }
                }
                blocksInfo = blocks.ToArray();
            }
        }
        public void Write(ArchiveListing listing, out ArchiveListingBlockInfo[] blocksInfo, out ArchiveListingEntryInfoV1[] entriesInfoV1)
        {
            using (MemoryStream ms = new MemoryStream(32768))
            {
                int blockNumber = 0, unpackedBlockOffset = 0;
                entriesInfoV1 = new ArchiveListingEntryInfoV1[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];
                        entriesInfoV1[i] = new ArchiveListingEntryInfoV1 {BlockNumber = (short)(ms.Position / 8192)};

                        if (blockNumber != entriesInfoV1[i].BlockNumber)
                        {
                            //sw.Write("end\0");
                            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)
                        {
                            entriesInfoV1[i].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
                        {
                            entriesInfoV1[i].Offset = (short)(ms.Position - unpackedBlockOffset);
                            sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name);
                        }

                        //lengths[i] = (int)_output.Position - offsets[i];
                        //blockSize += lengths[i];
                    }
                }
                blocksInfo = blocks.ToArray();
            }
        }
        private void ParseInfo(ArchiveListingEntryInfoV1 entryInfo, byte[] uncompressedData, out long sector, out long uncompressedSize, out long compressedSize, out string name)
        {
            string[] info;
            unsafe
            {
                fixed (byte* ptr = &uncompressedData[entryInfo.Offset])
                {
                    string str = new string((sbyte*)ptr);
                    info = str.Split(':');
                }
            }

            if (info.Length < 4)
            {
                name = String.Join(":", info);
                sector = -1;
                uncompressedSize = -1;
                compressedSize = -1;
            }
            else
            {
                sector = long.Parse(info[0], NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                uncompressedSize = long.Parse(info[1], NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                compressedSize = long.Parse(info[2], NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                name = info[3];
            }
        }