Exemple #1
0
        private static byte[] CreateZipFileFromEntries(FileEntryList entries)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var zipOutputStream = new ZipOutputStream(memoryStream))
                {
                    zipOutputStream.SetLevel(3); //0-9, 9 being the highest level of compression

                    foreach (var entry in entries)
                    {
                        zipOutputStream.PutNextEntry(new ZipEntry(entry.Name)
                        {
                            Size = entry.Bytes.Length
                        });
                        zipOutputStream.Write(entry.Bytes, 0, entry.Bytes.Length);
                    }

                    zipOutputStream.CloseEntry();
                    zipOutputStream.IsStreamOwner = false;
                }

                memoryStream.Position = 0;
                return(memoryStream.ToArray());
            }
        }
 private static void SaveCachedEntries(string filePath, FileEntryList entries)
 {
     using (var resultZipFile = new ZipFile())
     {
         entries.CopyToZipFile(resultZipFile);
         resultZipFile.Save(filePath);
     }
 }
 private static byte[] CreateZipFileFromEntries(FileEntryList entries)
 {
     using (var resultZipFile = new ZipFile())
     {
         entries.CopyToZipFile(resultZipFile);
         return(resultZipFile.GetBytes());
     }
 }
Exemple #4
0
 private static void SaveCachedEntries(string filePath, FileEntryList entries)
 {
     using (var stream = new FileStream(filePath, FileMode.Create))
     {
         using (var resultZipFile = new ZipArchive(stream, ZipArchiveMode.Create))
         {
             entries.CopyToZipFile(resultZipFile);
         }
     }
 }
        /// <summary>
        /// Loads an Abide Update package file from the specified stream.
        /// </summary>
        /// <param name="inStream">The stream containing the Abide Update package.</param>
        /// <exception cref="AbideUpdatePackageException"></exception>
        public void Load(Stream inStream)
        {
            //Check file...
            if (inStream.Length < 32)
            {
                throw new AbideUpdatePackageException("Invalid AddOn package file.");
            }

            //Prepare
            FileEntry[] fileEntries = null;

            try
            {
                //Create Reader
                using (BinaryReader reader = new BinaryReader(inStream))
                {
                    //Read Header
                    header = reader.ReadStructure <HEADER>();
                    if (header.AupTag == AupFourCc)  //Quick sanity check...
                    {
                        fileEntries = new FileEntry[header.EntryCount];
                        for (uint i = 0; i < header.EntryCount; i++)
                        {
                            fileEntries[i] = new FileEntry(reader.ReadStructure <ENTRY>());
                        }
                        string[] filenames = reader.ReadUTF8StringTable(header.FileNamesOffset, header.FileIndexOffset, (int)header.EntryCount);

                        //Loop
                        for (int i = 0; i < header.EntryCount; i++)
                        {
                            //Create
                            fileEntries[i].Filename = filenames[i];

                            //Goto
                            inStream.Seek(fileEntries[i].Offset + header.DataOffset, SeekOrigin.Begin);

                            //Read
                            fileEntries[i].Data = reader.ReadBytes(fileEntries[i].Length);

                            //Set Length
                            fileEntries[i].Length = fileEntries[i].Data.Length;
                        }

                        //Setup
                        this.fileEntries = new FileEntryList(fileEntries);
                    }
                    else
                    {
                        throw new AbideUpdatePackageException("Invalid file header.");
                    }
                }
            }
            catch (Exception ex) { throw new AbideUpdatePackageException(ex); }
        }
 private static byte[] CreateZipFileFromEntries(FileEntryList entries)
 {
     using (var stream = new MemoryStream())
     {
         using (var resultZipFile = new ZipArchive(stream, ZipArchiveMode.Create))
         {
             entries.CopyToZipFile(resultZipFile);
         }
         return(stream.ToArray());
     }
 }
 /// <summary>
 /// Initializes a new <see cref="UpdatePackageFile"/> instance.
 /// </summary>
 public UpdatePackageFile()
 {
     //Prepare
     fileEntries = new FileEntryList();
 }
Exemple #8
0
        /// <summary>
        /// Loads an Abide AddOn package file from the specified stream.
        /// </summary>
        /// <param name="inStream">The stream containing the Abide AddOn package.</param>
        /// <exception cref="AbideAddOnPackageException"></exception>
        public void Load(Stream inStream)
        {
            //Check file...
            if (inStream.Length < 32)
            {
                throw new AbideAddOnPackageException("Invalid AddOn package file.");
            }

            //Prepare
            FileEntry[] fileEntries = null;

            try
            {
                //Create Reader
                using (BinaryReader reader = new BinaryReader(inStream))
                {
                    //Read Header
                    header = reader.Read <Header>();
                    if (header.AaoTag == AaoFourCc)  //Quick sanity check...
                    {
                        fileEntries = new FileEntry[header.EntryCount];
                        for (uint i = 0; i < header.EntryCount; i++)
                        {
                            fileEntries[i] = new FileEntry(reader.Read <Entry>());
                        }
                        string[] filenames = reader.ReadUTF8StringTable(header.FileNamesOffset, header.FileIndexOffset, (int)header.EntryCount);

                        //Loop
                        for (int i = 0; i < header.EntryCount; i++)
                        {
                            //Create
                            fileEntries[i].Filename = filenames[i];

                            //Goto
                            inStream.Seek(fileEntries[i].Offset + header.DataOffset, SeekOrigin.Begin);

                            //Read
                            byte[] data = reader.ReadBytes(fileEntries[i].Length);

                            //Decompress?
                            if (fileEntries[i].Compression != FourCc.Zero)
                            {
                                fileEntries[i].Data = decompressData?.Invoke(data, fileEntries[i].Compression);
                            }
                            else
                            {
                                fileEntries[i].Data = data;
                            }

                            //Set Length
                            fileEntries[i].Length = fileEntries[i].Data.Length;
                        }

                        //Setup
                        this.fileEntries = new FileEntryList(fileEntries);
                    }
                    else
                    {
                        throw new AbideAddOnPackageException("Invalid file header.");
                    }
                }
            }
            catch (Exception ex) { throw new AbideAddOnPackageException(ex); }
        }
Exemple #9
0
 /// <summary>
 /// Initializes a new <see cref="AddOnPackageFile"/> instance.
 /// </summary>
 public AddOnPackageFile()
 {
     //Prepare
     fileEntries = new FileEntryList();
 }