Exemplo n.º 1
0
        /* ---------------------------------------------------------------------------------------------------------------------------------- */
        public byte[] RetrieveTzarFile(PackTzarFile tzarFile)
        {
            byte[] fileBuffer = new byte [tzarFile.Size];

            m_packStream.Seek(tzarFile.Offset, SeekOrigin.Begin);
            m_packStream.Read(fileBuffer, 0, tzarFile.Size);

            return(fileBuffer);
        }
Exemplo n.º 2
0
        /* ---------------------------------------------------------------------------------------------------------------------------------- */
        public static byte[] DecompressTzarFile(PackTzarFile fileInfo, WdtFile wdtFile)
        {
            byte[] fileBuffer = new byte[fileInfo.Size];

            int fileStartChapter = fileInfo.Offset / wdtFile.PageSize;
            int fileStartOffset  = fileInfo.Offset % wdtFile.PageSize;
            int fileChapterSpan  = (fileInfo.Size + fileStartOffset) / wdtFile.PageSize + 1;

            byte[] chaptersBuffer = new byte[fileChapterSpan * wdtFile.PageSize];
            var    chaptersStream = new MemoryStream(chaptersBuffer);

            for (int i = 0; i < fileChapterSpan; i++)
            {
                DecompressChapter(wdtFile, wdtFile.ChapterList[fileStartChapter + i], chaptersStream);
            }

            chaptersStream.Seek(fileStartOffset, SeekOrigin.Begin);
            chaptersStream.Read(fileBuffer, 0, fileInfo.Size);

            return(fileBuffer);
        }
Exemplo n.º 3
0
        /* ---------------------------------------------------------------------------------------------------------------------------------- */
        void ParseFromPackFileStream(Stream packFileStream)
        {
            packFileStream.Seek(CONTENTS_OFFSET, SeekOrigin.Begin);
            var decompressedContents = new BinaryReader(packFileStream);

            int numberOfFiles = decompressedContents.ReadInt32();
            int archiveSize   = decompressedContents.ReadInt32();

            m_packTzarFiles = new List <PackTzarFile> (numberOfFiles);

            StringBuilder filePathBuilder = new StringBuilder(256);

            // Read first tzar file
            byte nameLength      = decompressedContents.ReadByte();
            byte nameReuseLength = decompressedContents.ReadByte();

            filePathBuilder.Append(decompressedContents.ReadChars(nameLength));

            int fileOffset = decompressedContents.ReadInt32();
            int fileLength = decompressedContents.ReadInt32();

            PackTzarFile lastTzarFile = new PackTzarFile(filePathBuilder.ToString(), nameLength, fileLength, fileOffset);

            // Read subsequent tzar files
            for (int i = 0; i < numberOfFiles - 1; i++)
            {
                nameLength      = decompressedContents.ReadByte();
                nameReuseLength = decompressedContents.ReadByte();

                filePathBuilder.Remove(nameReuseLength, filePathBuilder.Length - nameReuseLength);
                filePathBuilder.Append(decompressedContents.ReadChars(nameLength - nameReuseLength));

                fileOffset = decompressedContents.ReadInt32();
                fileLength = decompressedContents.ReadInt32();

                lastTzarFile = new PackTzarFile(filePathBuilder.ToString(), nameLength, fileLength, fileOffset);

                m_packTzarFiles.Add(lastTzarFile);
            }
        }