Exemplo n.º 1
0
 /// <summary>
 /// Removes an entry from the archive.
 /// </summary>
 /// <param name="entry">The entry to be removed.</param>
 public void Remove(XflArchiveEntry entry)
 {
     // Make sure this entry is still stored in this archive
     if (entry.Archive == this)
     {
         // Remove
         _Entries.Remove(entry.Path);
         entry.Archive = null;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new archive entry. Overwrites existing entries.
        /// </summary>
        /// <param name="path">Internal path to store the file at.</param>
        /// <param name="content">Contents of the new file.</param>
        /// <returns>The entry that was added.</returns>
        public XflArchiveEntry CreateEntry(string path, byte[] content = null)
        {
            var entry = new XflArchiveEntry(this);

            entry.Path    = path;
            entry.Content = content ?? new byte[0];

            _Entries[path] = entry;

            return(entry);
        }
Exemplo n.º 3
0
        private void ReadStream(Stream input)
        {
            using (var reader = new BinaryReader(input))
            {
                // READ HEADER
                var magic = new string(reader.ReadChars(MAGIC.Length));
                if (magic != MAGIC)
                {
                    throw new FileFormatException("Not an XFL archive.");
                }

                var tableSize = reader.ReadInt32();
                var fileCount = reader.ReadInt32();
                var fileStart = input.Position + tableSize;
                var entries   = new List <XflArchiveEntry>();

                // READ TABLE
                for (int i = 0; i < fileCount; i++)
                {
                    var entry = new XflArchiveEntry(this);

                    var bytes = reader.ReadBytes(0x20).TakeWhile(v => v != 0).ToArray();
                    entry.Path   = _ShiftJIS.GetString(bytes);
                    entry.Offset = fileStart + reader.ReadInt32();
                    entry.Size   = reader.ReadInt32();

                    entries.Add(entry);
                }

                // READ FILES
                foreach (var entry in entries)
                {
                    input.Seek(entry.Offset, SeekOrigin.Begin);
                    entry.Content = reader.ReadBytes(entry.Size);

                    _Entries[entry.Path] = entry;
                }
            }
        }