/// <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> /// 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; }