Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 internal WriteArchiveEventArgs(Stream _archive, string _filename, FilepathInsideArchive _filepathinside) : base()
 {
     this.ArchiveStream     = _archive;
     this.Filename          = _filename;
     this.PathInsideArchive = _filepathinside;
 }
Ejemplo n.º 3
0
 public void UpdateEntryPath(Entry entry, FilepathInsideArchive path)
 {
     entry.Raw.FilePath       = path;
     entry.Raw.FilePathLength = path.PathInsideArchive.Length;
 }
Ejemplo n.º 4
0
 public Entry this[FilepathInsideArchive path] => this.currentItems[path.PathInsideArchive];
Ejemplo n.º 5
0
 public void CompressEntry(FilepathInsideArchive filepathInsideArchive, byte[] content)
 {
     using (MemoryStream memStream = new MemoryStream(content, false))
         this.CompressEntry(filepathInsideArchive, memStream, false);
 }
Ejemplo n.º 6
0
 public void CompressEntry(FilepathInsideArchive filepathInsideArchive, Stream content)
 {
     this.CompressEntry(filepathInsideArchive, content, false);
 }
Ejemplo n.º 7
0
 public void CompressFile(FilepathInsideArchive filepathInsideArchive, string filepath)
 {
     using (FileStream fs = File.OpenRead(filepath))
         this.CompressEntry(filepathInsideArchive, fs, true);
 }
Ejemplo n.º 8
0
 public void CompressString(FilepathInsideArchive filepathInsideArchive, string content, Encoding encoding)
 {
     this.CompressEntry(filepathInsideArchive, encoding.GetBytes(content));
 }
Ejemplo n.º 9
0
 public void CompressString(FilepathInsideArchive filepathInsideArchive, string content)
 {
     this.CompressString(filepathInsideArchive, content, Encoding.Unicode);
 }
Ejemplo n.º 10
0
 public void RemoveEntry(FilepathInsideArchive path)
 {
     this.RemoveEntry(this[path]);
 }