Exemple #1
0
        internal static PackagedFileInfo CreateFromEntry(FileEntry7 entry, Stream dataStream)
        {
            var info = new PackagedFileInfo();

            info.PackageStream = dataStream;

            var nameLen = 0;

            for (nameLen = 0; nameLen < entry.Name.Length && entry.Name[nameLen] != 0; nameLen++)
            {
            }
            info.Name = Encoding.UTF8.GetString(entry.Name, 0, nameLen);

            info.OffsetInFile     = entry.OffsetInFile;
            info.SizeOnDisk       = entry.SizeOnDisk;
            info.UncompressedSize = entry.UncompressedSize;
            info.ArchivePart      = entry.ArchivePart;
            info.Crc = 0;

            if (entry.UncompressedSize > 0)
            {
                info.Flags = BinUtils.MakeCompressionFlags(CompressionMethod.Zlib, CompressionLevel.DefaultCompression);
            }
            else
            {
                info.Flags = 0;
            }

            return(info);
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
        internal FileEntry7 MakeEntryV7()
        {
            var entry = new FileEntry7();

            entry.Name = new byte[256];
            var encodedName = Encoding.UTF8.GetBytes(Name.Replace('\\', '/'));

            Array.Copy(encodedName, entry.Name, encodedName.Length);

            entry.OffsetInFile     = OffsetInFile;
            entry.SizeOnDisk       = SizeOnDisk;
            entry.UncompressedSize = ((Flags & 0x0F) == 0) ? 0 : UncompressedSize;
            entry.ArchivePart      = ArchivePart;
            return(entry);
        }
Exemple #4
0
        internal FileEntry7 MakeEntryV7()
        {
            var entry = new FileEntry7();
            entry.Name = new byte[256];
            var encodedName = Encoding.UTF8.GetBytes(Name.Replace('\\', '/'));
            Array.Copy(encodedName, entry.Name, encodedName.Length);

            entry.OffsetInFile = OffsetInFile;
            entry.SizeOnDisk = SizeOnDisk;
            entry.UncompressedSize = ((Flags & 0x0F) == 0) ? 0 : UncompressedSize;
            entry.ArchivePart = ArchivePart;
            return entry;
        }
Exemple #5
0
        internal static PackagedFileInfo CreateFromEntry(FileEntry7 entry, Stream dataStream)
        {
            var info = new PackagedFileInfo();
            info.PackageStream = dataStream;

            var nameLen = 0;
            for (nameLen = 0; nameLen < entry.Name.Length && entry.Name[nameLen] != 0; nameLen++) { }
            info.Name = Encoding.UTF8.GetString(entry.Name, 0, nameLen);

            info.OffsetInFile = entry.OffsetInFile;
            info.SizeOnDisk = entry.SizeOnDisk;
            info.UncompressedSize = entry.UncompressedSize;
            info.ArchivePart = entry.ArchivePart;
            info.Crc = 0;

            if (entry.UncompressedSize > 0)
            {
                info.Flags = BinUtils.MakeCompressionFlags(CompressionMethod.Zlib, CompressionLevel.DefaultCompression);
            }
            else
            {
                info.Flags = 0;
            }

            return info;
        }