Ejemplo n.º 1
0
        private ArchiveFileInfo CreateAfi(Stream file, string name, EncFileEntry entry)
        {
            if (entry.IsCompressed)
            {
                return(new ArchiveFileInfo(file, name, Kompression.Implementations.Compressions.LzEnc, entry.decompSize));
            }

            return(new ArchiveFileInfo(file, name));
        }
Ejemplo n.º 2
0
        public void Save(Stream output, IList <IArchiveFileInfo> files)
        {
            using var bw = new BinaryWriterX(output);

            // Calculate offsets
            var fileOffset = (4 + files.Count * FileEntrySize + 0x3F) & ~0x3F;

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

            bw.BaseStream.Position = fileOffset;
            foreach (var file in files.Cast <ArchiveFileInfo>())
            {
                fileOffset = (int)bw.BaseStream.Position;
                var writtenSize = file.SaveFileData(output);

                if (file != files.Last())
                {
                    bw.WriteAlignment(0x40);
                }

                var entry = new EncFileEntry
                {
                    offset     = fileOffset,
                    size       = (uint)writtenSize,
                    decompSize = (int)file.FileSize
                };
                if (file.UsesCompression)
                {
                    entry.size |= 0x80000000;
                }

                entries.Add(entry);
            }

            // Write entries
            bw.BaseStream.Position = 0;

            bw.Write(files.Count);
            bw.WriteMultiple(entries);
        }