amxmodx/plugins/BinLogReader/PluginDb.cs

101 lines
2.1 KiB
C#
Raw Permalink Normal View History

2006-03-15 13:42:25 +00:00
using System;
using System.Collections;
using System.IO;
using System.Text;
namespace BinLogReader
{
/// <summary>
/// Aggregates plugin information
/// </summary>
public class PluginDb
{
private ArrayList PluginList;
public int Count
{
get
{
return PluginList.Count;
}
}
2006-03-15 13:42:25 +00:00
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];
}
2006-03-19 21:40:24 +00:00
public static PluginDb FromFile(BinaryReader br)
2006-03-15 13:42:25 +00:00
{
2006-03-19 21:40:24 +00:00
//read plugins
uint plugins = br.ReadUInt32();
PluginDb db = new PluginDb(plugins);
for (uint i=0; i<plugins; i++)
2006-03-15 13:42:25 +00:00
{
2006-03-19 21:40:24 +00:00
byte status = br.ReadByte();
byte length = br.ReadByte();
uint files = 0;
2006-03-19 21:40:24 +00:00
byte [] name = br.ReadBytes(length + 1);
if (status == 2)
{
files = br.ReadUInt32();
}
2006-03-19 21:40:24 +00:00
uint natives = br.ReadUInt32();
uint publics = br.ReadUInt32();
int id = db.CreatePlugin(
Encoding.ASCII.GetString(name, 0, length),
(int)natives,
(int)publics,
(int)files,
2006-03-19 21:40:24 +00:00
status,
(int)i);
Plugin pl = db.GetPluginById(id);
for (uint j=0; j<files; j++)
{
length = br.ReadByte();
name = br.ReadBytes(length + 1);
pl.AddFile(Encoding.ASCII.GetString(name, 0, length));
}
if (files == 0)
{
pl.AddFile(pl.File);
}
2006-03-19 21:40:24 +00:00
for (uint j=0; j<natives; j++)
2006-03-15 13:42:25 +00:00
{
2006-03-19 21:40:24 +00:00
length = br.ReadByte();
name = br.ReadBytes(length + 1);
pl.AddNative(Encoding.ASCII.GetString(name, 0, length));
}
for (uint j=0; j<publics; j++)
{
length = br.ReadByte();
name = br.ReadBytes(length + 1);
pl.AddPublic(Encoding.ASCII.GetString(name, 0, length));
2006-03-15 13:42:25 +00:00
}
}
return db;
}
private int CreatePlugin(string file, int natives, int publics, int files, byte status, int index)
2006-03-15 13:42:25 +00:00
{
Plugin pl = new Plugin(file, natives, publics, files, status, index);
2006-03-15 13:42:25 +00:00
PluginList.Add(pl);
return PluginList.Count - 1;
}
}
}