using System;
using System.Collections;
using System.IO;
using System.Text;
namespace BinLogReader
{
///
/// Aggregates plugin information
///
public class PluginDb
{
private static uint BINDB_MAGIC = 0x414D4244;
private static short BINDB_VERSION = 0x0100;
private ArrayList PluginList;
public int Count
{
get
{
return PluginList.Count;
}
}
public PluginDb(uint plugins)
{
PluginList = new ArrayList((int)plugins);
}
public Plugin GetPluginById(ushort id)
{
return GetPluginById((int)id);
}
public Plugin GetPluginById(int id)
{
if (id < 0 || id >= PluginList.Count)
return null;
return (Plugin)PluginList[id];
}
public static PluginDb FromFile(string filename)
{
if (!File.Exists(filename))
return null;
System.IO.FileStream stream = File.Open(filename, System.IO.FileMode.Open);
if (stream == null)
return null;
BinaryReader br = new BinaryReader(stream);
if (br == null)
return null;
PluginDb db;
try
{
//check header
uint magic = br.ReadUInt32();
if (magic != BINDB_MAGIC)
throw new Exception("Invalid magic DB number");
//check version
ushort vers = br.ReadUInt16();
if (vers > BINDB_VERSION)
throw new Exception("Unknown DB version");
//read plugins
uint plugins = br.ReadUInt32();
db = new PluginDb(plugins);
for (uint i=0; i