public ReadArchive ( bool ThrowException ) : bool | ||
ThrowException | bool | Wether or not to throw an exception if the archive was not a FAR3. If false, function will return. |
return | bool |
public bool ReadArchive(bool ThrowException)
{
m_FinishedReading.Reset();
if (m_Reader == null)
m_Reader = new FileReader(m_Path, false);
lock (m_Reader)
{
ASCIIEncoding Enc = new ASCIIEncoding();
string MagicNumber = Enc.GetString(m_Reader.ReadBytes(8));
if (!MagicNumber.Equals("FAR!byAZ", StringComparison.InvariantCultureIgnoreCase))
{
if (ThrowException)
throw new FAR3Exception("MagicNumber was wrong - FAR3Archive.cs!");
else
{
m_Reader.Close();
return false;
}
}
m_Reader.ReadUInt32(); //Version.
m_Reader.Seek((long)m_Reader.ReadUInt32());
uint NumFiles = m_Reader.ReadUInt32();
for (int i = 0; i < NumFiles; i++)
{
FAR3Entry Entry = new FAR3Entry();
Entry.DecompressedDataSize = m_Reader.ReadUInt32();
byte[] Dummy = m_Reader.ReadBytes(3);
Entry.CompressedDataSize = (uint)((Dummy[0] << 0) | (Dummy[1] << 8) | (Dummy[2]) << 16);
m_Reader.ReadByte(); //Unknown.
Entry.DataOffset = m_Reader.ReadUInt32();
Entry.Flags = m_Reader.ReadUShort();
Entry.FileNameLength = m_Reader.ReadUShort();
Entry.TypeID = m_Reader.ReadUInt32();
Entry.FileID = m_Reader.ReadUInt32();
Entry.Filename = Enc.GetString(m_Reader.ReadBytes(Entry.FileNameLength));
UniqueFileID ID = new UniqueFileID(Entry.TypeID, Entry.FileID);
if (!m_Entries.ContainsKey(ID.UniqueID))
m_Entries.AddOrUpdate(ID.UniqueID, Entry, (Key, ExistingValue) => ExistingValue = Entry);
}
}
m_FinishedReading.Set();
return true;
}
/// <summary> /// Loads all archives into memory. /// </summary> private static void LoadAllArchives() { m_StillLoading.Reset(); foreach (string Path in m_FAR3Paths) { //This should be ignored. if (!Path.Contains("packingslips.dat")) { FAR3Archive Archive = new FAR3Archive(Path); if(Archive.ReadArchive(false)) m_FAR3Archives.Add(Archive); } } if(OnThirtyThreePercentCompleted != null) OnThirtyThreePercentCompleted(); foreach (string Path in m_FAR1Paths) { FAR1Archive Archive = new FAR1Archive(Path); Archive.ReadArchive(false); m_FAR1Archives.Add(Archive); } if(OnSixtysixPercentCompleted != null) OnSixtysixPercentCompleted(); foreach (string Path in m_DBPFPaths) { DBPFArchive Archive = new DBPFArchive(Path); if(Archive.ReadArchive(false)) m_DBPFArchives.Add(Archive); } m_StillLoading.Set(); if (OnHundredPercentCompleted != null) OnHundredPercentCompleted(); }