public void CompressEntry(FilepathInsideArchive filepathInsideArchive, Stream content, bool leaveOpen)
        {
            if (this.currentItems.ContainsKey(filepathInsideArchive.PathInsideArchive))
            {
                throw new ArgumentException($"Item '{filepathInsideArchive.PathInsideArchive}' is not already existed in the archive.");
            }

            BPKG_FTE FileTableEntry = new BPKG_FTE();

            FileTableEntry.FilePathLength = filepathInsideArchive.PathInsideArchive.Length;

            FileTableEntry.FilePath     = filepathInsideArchive.PathInsideArchive;
            FileTableEntry.Unknown_001  = 2;
            FileTableEntry.IsCompressed = (this.CompressionLevel != CompressionLevel.None);
            FileTableEntry.IsEncrypted  = true;
            FileTableEntry.Unknown_002  = 0;

            Stream       contentStream = this.CreateTempStream(this.TemporaryFolder);
            MemoryStream memoryStream;

            using (RecyclableMemoryStream tmp = new RecyclableMemoryStream())
                if (filepathInsideArchive.PathInsideArchive.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) || filepathInsideArchive.PathInsideArchive.EndsWith(".x16", StringComparison.OrdinalIgnoreCase))
                {
                    // encode bxml
                    BXML bxml = new BXML(BXML.XOR_KEY_Data);
                    BXML.Convert(content, bxml.DetectType(content), tmp, BXML_TYPE.BXML_BINARY);

                    // FileTableEntry.FileDataOffset = (int)mosFiles.BaseStream.Position;
                    FileTableEntry.FileDataSizeUnpacked = (int)tmp.Length;

                    memoryStream = this.Pack(tmp.GetBuffer(), tmp.Length, FileTableEntry.FileDataSizeUnpacked, out FileTableEntry.FileDataSizeSheared, out FileTableEntry.FileDataSizeStored, FileTableEntry.IsEncrypted, FileTableEntry.IsCompressed, this.CompressionLevel);
                }
                else
                {
                    // compress raw
                    // FileTableEntry.FileDataOffset = (int)mosFiles.BaseStream.Position;
                    CommonMethods.StreamCopyChunk(content, tmp, 1024);

                    FileTableEntry.FileDataSizeUnpacked = (int)content.Length;

                    memoryStream = this.Pack(tmp.GetBuffer(), tmp.Length, FileTableEntry.FileDataSizeUnpacked, out FileTableEntry.FileDataSizeSheared, out FileTableEntry.FileDataSizeStored, FileTableEntry.IsEncrypted, FileTableEntry.IsCompressed, this.CompressionLevel);
                }
            contentStream.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
            contentStream.Flush();
            memoryStream.Dispose();
            memoryStream = null;

            if (!leaveOpen)
            {
                content.Dispose();
            }

            // FileTableEntry.Padding = new byte[60];
            Entry entry = Entry.FromStruct(FileTableEntry);

            this.currentItems.Add(FileTableEntry.FilePath, entry);
            this.currentContents.Add(entry, contentStream);
        }
Exemple #2
0
 internal static Entry FromStruct(BPKG_FTE source)
 {
     return(new Entry(source));
 }
Exemple #3
0
 internal Entry(BPKG_FTE source)
 {
     this.Raw = source;
 }