public void WriteV15(FileStream mainStream) { var header = new LSPKHeader15 { Version = (uint)Version }; using (var writer = new BinaryWriter(mainStream, new UTF8Encoding(), true)) { writer.Write(Package.Signature); BinUtils.WriteStruct(writer, ref header); } var writtenFiles = PackFiles(); using (var writer = new BinaryWriter(mainStream, new UTF8Encoding(), true)) { header.FileListOffset = (UInt64)mainStream.Position; WriteFileListV15(writer, writtenFiles); header.FileListSize = (UInt32)(mainStream.Position - (long)header.FileListOffset); header.Priority = _package.Metadata.Priority; header.Flags = (byte)_package.Metadata.Flags; header.Md5 = ComputeArchiveHash(); mainStream.Seek(4, SeekOrigin.Begin); BinUtils.WriteStruct(writer, ref header); } }
public void WriteV15(FileStream mainStream) { var header = new LSPKHeader15 { Version = (uint)Version }; using (var writer = new BinaryWriter(mainStream, new UTF8Encoding(), true)) { writer.Write(Package.Signature); BinUtils.WriteStruct(writer, ref header); } 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 += (long)file.Size(); } using (var writer = new BinaryWriter(mainStream, new UTF8Encoding(), true)) { byte[] fileListBuf; using (var fileList = new MemoryStream()) using (var fileListWriter = new BinaryWriter(fileList)) { foreach (PackagedFileInfo file in writtenFiles) { FileEntry15 entry = file.MakeEntryV15(); BinUtils.WriteStruct(fileListWriter, ref entry); } fileListBuf = fileList.ToArray(); } byte[] compressedFileList = LZ4Codec.EncodeHC(fileListBuf, 0, fileListBuf.Length); header.FileListOffset = (UInt64)mainStream.Position; writer.Write((UInt32)writtenFiles.Count); writer.Write((UInt32)compressedFileList.Length); writer.Write(compressedFileList); header.FileListSize = (UInt32)(mainStream.Position - (long)header.FileListOffset); header.Priority = _package.Metadata.Priority; header.Flags = (byte)_package.Metadata.Flags; header.Md5 = ComputeArchiveHash(); mainStream.Seek(4, SeekOrigin.Begin); BinUtils.WriteStruct(writer, ref header); } }