コード例 #1
0
        public void WriteV7(FileStream mainStream)
        {
            if (Compression == CompressionMethod.LZ4)
            {
                throw new ArgumentException("LZ4 compression is only supported by V10 and later package versions");
            }

            using (var writer = new BinaryWriter(mainStream, new UTF8Encoding(), true))
            {
                var header = new LSPKHeader7
                {
                    Version      = (uint)Version,
                    NumFiles     = (UInt32)_package.Files.Count,
                    FileListSize = (UInt32)(Marshal.SizeOf(typeof(FileEntry7)) * _package.Files.Count)
                };
                header.DataOffset = (UInt32)Marshal.SizeOf(typeof(LSPKHeader7)) + header.FileListSize;
                int paddingLength = PaddingLength();
                if (header.DataOffset % paddingLength > 0)
                {
                    header.DataOffset += (UInt32)(paddingLength - header.DataOffset % paddingLength);
                }

                // Write a placeholder instead of the actual headers; we'll write them after we
                // compressed and flushed all files to disk
                var placeholder = new byte[header.DataOffset];
                writer.Write(placeholder);

                long totalSize    = _package.Files.Sum(p => (long)p.Size());
                long currentSize  = 0;
                var  writtenFiles = new List <PackagedFileInfo>();
                foreach (AbstractFileInfo file in _package.Files)
                {
                    WriteProgress(file, currentSize, totalSize);
                    writtenFiles.Add(WriteFile(file));
                    currentSize += file.Size();
                }

                mainStream.Seek(0, SeekOrigin.Begin);
                header.LittleEndian = 0;
                header.NumParts     = (UInt16)_streams.Count;
                BinUtils.WriteStruct(writer, ref header);

                foreach (PackagedFileInfo file in writtenFiles)
                {
                    FileEntry7 entry = file.MakeEntryV7();
                    if (entry.ArchivePart == 0)
                    {
                        entry.OffsetInFile -= header.DataOffset;
                    }

                    BinUtils.WriteStruct(writer, ref entry);
                }
            }
        }
コード例 #2
0
ファイル: PackageWriter.cs プロジェクト: Norbyte/lslib
        public void WriteV7(FileStream mainStream)
        {
            if (Compression == CompressionMethod.LZ4)
            {
                throw new ArgumentException("LZ4 compression is only supported by V10 and later package versions");
            }

            using (var writer = new BinaryWriter(mainStream, new UTF8Encoding(), true))
            {
                var header = new LSPKHeader7();
                header.Version = Version;
                header.NumFiles = (UInt32)package.Files.Count;
                header.FileListSize = (UInt32)(Marshal.SizeOf(typeof(FileEntry7)) * package.Files.Count);
                header.DataOffset = (UInt32)Marshal.SizeOf(typeof(LSPKHeader7)) + header.FileListSize;
                var paddingLength = PaddingLength();
                if (header.DataOffset % paddingLength > 0)
                {
                    header.DataOffset += (UInt32)(paddingLength - (header.DataOffset % paddingLength));
                }

                // Write a placeholder instead of the actual headers; we'll write them after we 
                // compressed and flushed all files to disk
                var placeholder = new byte[header.DataOffset];
                writer.Write(placeholder);

                long totalSize = package.Files.Sum(p => (long)p.Size());
                long currentSize = 0;
                List<PackagedFileInfo> writtenFiles = new List<PackagedFileInfo>();
                foreach (var file in this.package.Files)
                {
                    writeProgress(file, currentSize, totalSize);
                    writtenFiles.Add(WriteFile(file));
                    currentSize += file.Size();
                }

                mainStream.Seek(0, SeekOrigin.Begin);
                header.LittleEndian = 0;
                header.NumParts = (UInt16)streams.Count;
                BinUtils.WriteStruct<LSPKHeader7>(writer, ref header);

                foreach (var file in writtenFiles)
                {
                    var entry = file.MakeEntryV7();
                    if (entry.ArchivePart == 0)
                    {
                        entry.OffsetInFile -= header.DataOffset;
                    }

                    BinUtils.WriteStruct<FileEntry7>(writer, ref entry);
                }
            }
        }