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 void Convert(Stream iStream, BXML_TYPE iType, Stream oStream, BXML_TYPE oType)
 {
     if ((iType == BXML_TYPE.BXML_PLAIN && oType == BXML_TYPE.BXML_BINARY) || (iType == BXML_TYPE.BXML_BINARY && oType == BXML_TYPE.BXML_PLAIN))
     {
         BXML bns_xml = new BXML(XOR_KEY_Data);
         bns_xml.Load(iStream, iType);
         bns_xml.Save(oStream, oType);
     }
     else
     {
         iStream.CopyTo(oStream);
     }
 }