Пример #1
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var dataAlignment = PkgSupport.DetermineAlignment((files[0] as PkgArchiveFileInfo).Type);
            var entryOffset   = HeaderSize;
            var dataOffset    = (entryOffset + files.Count * EntrySize + dataAlignment - 1) & ~(dataAlignment - 1);

            // Write files
            var entries = new List <PkgEntry>();

            var dataPosition = dataOffset;

            foreach (var file in files.Cast <PkgArchiveFileInfo>())
            {
                // Write file data
                var alignment           = PkgSupport.DetermineAlignment(file.Type);
                var alignedDataPosition = (dataPosition + alignment - 1) & ~(alignment - 1);

                output.Position = alignedDataPosition;
                var writtenSize = file.SaveFileData(output);

                // Create entry
                entries.Add(new PkgEntry
                {
                    startOffset = alignedDataPosition,
                    endOffset   = (int)(alignedDataPosition + writtenSize),
                    hash        = file.Hash
                });

                dataPosition = (int)(alignedDataPosition + writtenSize);
            }
            bw.WriteAlignment(4);

            // Write entries
            output.Position = entryOffset;
            bw.WriteMultiple(entries);

            // Write header
            output.Position = 0;
            bw.WriteType(new PkgHeader {
                fileCount = files.Count, tableSize = dataOffset - 4, dataSize = (int)(output.Length - dataOffset)
            });
        }
Пример #2
0
        public override void SetFileData(Stream fileData)
        {
            base.SetFileData(fileData);

            Type = PkgSupport.DetermineMagic(fileData);
        }
Пример #3
0
 public PkgArchiveFileInfo(Stream fileData, string filePath, uint hash) : base(fileData, filePath)
 {
     Hash = hash;
     Type = PkgSupport.DetermineMagic(fileData);
 }