public FAR1Archive(string Path)
        {
            m_Path = Path;
            m_Reader = new BinaryReader(File.Open(Path, FileMode.Open));

            string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            uint Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                throw(new Exception("Archive wasn't a valid FAR V.1 archive!"));
            }

            m_ManifestOffset = m_Reader.ReadUInt32();
            m_Reader.BaseStream.Seek(m_ManifestOffset, SeekOrigin.Begin);

            m_NumFiles = m_Reader.ReadUInt32();
            
            for (int i = 0; i < m_NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength = m_Reader.ReadInt32();
                Entry.DataLength2 = m_Reader.ReadInt32();
                Entry.DataOffset = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_Entries.Add(Entry);
            }

            m_Reader.Close();
        }
        /// <summary>
        /// Creates a new FAR1Archive instance from a path.
        /// </summary>
        /// <param name="Path">The path to the archive.</param>
        public FAR1Archive(string Path)
        {
            m_Path = Path;
            m_Reader = new BinaryReader(File.Open(Path, FileMode.Open));

            //Magic number - An 8-byte string (not null-terminated), consisting of the ASCII characters "FAR!byAZ"
            string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            //Version - A 4-byte unsigned integer specifying the version; 1a and 1b each specify 1.
            uint Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                throw(new Exception("Archive wasn't a valid FAR V.1 archive!"));
            }

            //File table offset - A 4-byte unsigned integer specifying the offset to the file table
            //from the beginning of the archive.
            m_ManifestOffset = m_Reader.ReadUInt32();
            m_Reader.BaseStream.Seek(m_ManifestOffset, SeekOrigin.Begin);

            m_NumFiles = m_Reader.ReadUInt32();

            for (int i = 0; i < m_NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength = m_Reader.ReadInt32();
                Entry.DataLength2 = m_Reader.ReadInt32();
                Entry.DataOffset = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_Entries.Add(Entry);
            }
        }
        /// <summary>
        /// Opens an existing FAR archive.
        /// </summary>
        /// <param name="Path">The path to the archive.</param>
        public FARArchive(string Path)
        {
            m_Reader = new BinaryReader(File.Open(Path, FileMode.Open, FileAccess.Read));
            m_FarEntries = new List<FarEntry>();

            string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            uint Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                MessageBox.Show("Archive wasn't a valid FAR V.1 archive!");
                return;
            }

            uint ManifestOffset = m_Reader.ReadUInt32();
            m_ManifestOffset = ManifestOffset;

            m_Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin);

            uint NumFiles = m_Reader.ReadUInt32();

            for (int i = 0; i < NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength = m_Reader.ReadInt32();
                Entry.DataLength2 = m_Reader.ReadInt32();
                Entry.DataOffset = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_FarEntries.Add(Entry);
            }

            //Reader.Close();
        }
        /// <summary>
        /// Creates a new FAR1Archive instance from a path.
        /// </summary>
        /// <param name="Path">The path to the archive.</param>
        public FAR1Archive(string Path)
        {
            m_Path   = Path;
            m_Reader = new BinaryReader(File.Open(Path, FileMode.Open));

            //Magic number - An 8-byte string (not null-terminated), consisting of the ASCII characters "FAR!byAZ"
            string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            //Version - A 4-byte unsigned integer specifying the version; 1a and 1b each specify 1.
            uint Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                throw(new Exception("Archive wasn't a valid FAR V.1 archive!"));
            }

            //File table offset - A 4-byte unsigned integer specifying the offset to the file table
            //from the beginning of the archive.
            m_ManifestOffset = m_Reader.ReadUInt32();
            m_Reader.BaseStream.Seek(m_ManifestOffset, SeekOrigin.Begin);

            m_NumFiles = m_Reader.ReadUInt32();

            for (int i = 0; i < m_NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength     = m_Reader.ReadInt32();
                Entry.DataLength2    = m_Reader.ReadInt32();
                Entry.DataOffset     = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename       = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_Entries.Add(Entry);
            }
        }
Exemple #5
0
        public FAR1Archive(string Path)
        {
            m_Path   = Path;
            m_Reader = new BinaryReader(File.Open(Path, FileMode.Open));

            string Header  = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            uint   Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                throw(new Exception("Archive wasn't a valid FAR V.1 archive!"));
            }

            m_ManifestOffset = m_Reader.ReadUInt32();
            m_Reader.BaseStream.Seek(m_ManifestOffset, SeekOrigin.Begin);

            m_NumFiles = m_Reader.ReadUInt32();

            for (int i = 0; i < m_NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength     = m_Reader.ReadInt32();
                Entry.DataLength2    = m_Reader.ReadInt32();
                Entry.DataOffset     = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename       = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_Entries.Add(Entry);
            }

            m_Reader.Close();
        }
        /// <summary>
        /// Gets an entry's data from a FarEntry instance.
        /// </summary>
        /// <param name="Entry">A FarEntry instance.</param>
        /// <returns>The entry's data.</returns>
        public byte[] GetEntry(FarEntry Entry)
        {
            foreach (FarEntry Ent in m_Entries)
            {
                if (Ent.Filename == Entry.Filename)
                {
                    m_Reader.BaseStream.Seek(Ent.DataOffset, SeekOrigin.Begin);
                    return(m_Reader.ReadBytes(Ent.DataLength));
                }
            }

            return(null);
        }
Exemple #7
0
        /// <summary>
        /// Opens an existing FAR archive.
        /// </summary>
        /// <param name="Path">The path to the archive.</param>
        public FARArchive(string Path)
        {
            m_Reader     = new BinaryReader(File.Open(Path, FileMode.Open));
            m_FarEntries = new List <FarEntry>();

            string Header  = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
            uint   Version = m_Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 1))
            {
                MessageBox.Show("Archive wasn't a valid FAR V.1 archive!");
                return;
            }

            uint ManifestOffset = m_Reader.ReadUInt32();

            m_ManifestOffset = ManifestOffset;

            m_Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin);


            uint NumFiles = m_Reader.ReadUInt32();

            for (int i = 0; i < NumFiles; i++)
            {
                FarEntry Entry = new FarEntry();
                Entry.DataLength     = m_Reader.ReadInt32();
                Entry.DataLength2    = m_Reader.ReadInt32();
                Entry.DataOffset     = m_Reader.ReadInt32();
                Entry.FilenameLength = m_Reader.ReadInt16();
                Entry.Filename       = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));

                m_FarEntries.Add(Entry);
            }

            //Reader.Close();
        }
 /// <summary>
 /// Gets an entry's data from an archive.
 /// </summary>
 /// <param name="Entry">The entry to get the data for.</param>
 /// <returns>The data for the entry.</returns>
 public byte[] GetEntry(FarEntry Entry)
 {
     m_Reader.BaseStream.Seek((long)Entry.DataOffset, SeekOrigin.Begin);
     return m_Reader.ReadBytes(Entry.DataLength);
 }
Exemple #9
0
 /// <summary>
 /// Gets an entry's data from an archive.
 /// </summary>
 /// <param name="Entry">The entry to get the data for.</param>
 /// <returns>The data for the entry.</returns>
 public byte[] GetEntry(FarEntry Entry)
 {
     m_Reader.BaseStream.Seek((long)Entry.DataOffset, SeekOrigin.Begin);
     return(m_Reader.ReadBytes(Entry.DataLength));
 }
        /// <summary>
        /// Gets an entry's data from a FarEntry instance.
        /// </summary>
        /// <param name="Entry">A FarEntry instance.</param>
        /// <returns>The entry's data.</returns>
        public byte[] GetEntry(FarEntry Entry)
        {
            foreach (FarEntry Ent in m_Entries)
            {
                if (Ent.Filename == Entry.Filename)
                {
                    m_Reader.BaseStream.Seek(Ent.DataOffset, SeekOrigin.Begin);
                    return m_Reader.ReadBytes(Ent.DataLength);
                }
            }

            return null;
        }