committed changes for new file format

This commit is contained in:
David Anderson 2006-03-19 21:40:24 +00:00
parent ef5437fec3
commit dc9350fcc5
4 changed files with 51 additions and 91 deletions

View File

@ -11,9 +11,10 @@ namespace BinLogReader
public class BinLog
{
private static uint BINLOG_MAGIC = 0x414D424C;
private static short BINLOG_VERSION = 0x0100;
private static short BINLOG_VERSION = 0x0200;
private ArrayList oplist;
private PluginDb plugdb;
public ArrayList OpList
{
@ -28,7 +29,12 @@ namespace BinLogReader
oplist = new ArrayList(init_size);
}
public static BinLog FromFile(string filename, PluginDb db)
public PluginDb GetPluginDB()
{
return plugdb;
}
public static BinLog FromFile(string filename)
{
if (!File.Exists(filename))
return null;
@ -68,6 +74,12 @@ namespace BinLogReader
else
bl = new BinLog( (int)(fi.Length / 6) );
bl.plugdb = PluginDb.FromFile(br);
PluginDb db = bl.plugdb;
if (db == null)
throw new Exception("Plugin database read failure");
do
{
opcode = (BinLogOp)br.ReadByte();
@ -246,14 +258,18 @@ namespace BinLogReader
} while (opcode != BinLogOp.BinLog_End);
opcode =BinLogOp.BinLog_End;
}
catch
catch (Exception e)
{
if (bl != null)
if (bl != null && bl.plugdb != null)
{
BinLogSimple bs = new BinLogSimple(BinLogOp.BinLog_Invalid, gametime, realtime, pl);
bl.oplist.Add(bs);
}
else
{
throw new Exception(e.Message);
}
}
}
finally
{
br.Close();

View File

@ -5,7 +5,6 @@ using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
namespace BinLogReader
{
@ -61,7 +60,6 @@ namespace BinLogReader
base.Dispose( disposing );
}
private PluginDb plugdb;
private BinLog binlog;
#region Windows Form Designer generated code
@ -250,7 +248,6 @@ namespace BinLogReader
private void Form1_Load(object sender, System.EventArgs e)
{
plugdb = null;
binlog = null;
g_UpdateViews = ViewAreas.Update_All;
}
@ -281,8 +278,9 @@ namespace BinLogReader
if (v == ViewAreas.Update_All ||
((v & ViewAreas.Update_Plugins) == ViewAreas.Update_Plugins)
&& (plugdb != null))
&& (binlog.GetPluginDB() != null))
{
PluginDb plugdb = binlog.GetPluginDB();
PluginList.View = View.Details;
PluginList.Columns.Add("Number", 60, HorizontalAlignment.Left);
PluginList.Columns.Add("File", 100, HorizontalAlignment.Left);
@ -333,25 +331,7 @@ namespace BinLogReader
try
{
/* try to open the accompanying database file */
Regex r = new Regex(@"binlog(\d+)\.blg");
Match m = r.Match(ofd.FileName);
if (!m.Success)
{
throw new Exception("Failed to find binary database, filename unrecognized!");
}
Group g = m.Groups[1];
CaptureCollection cc = g.Captures;
Capture c = cc[0];
string dbfile = r.Replace(ofd.FileName, "bindb" + c.ToString() + ".bdb", 1);
plugdb = PluginDb.FromFile(dbfile);
if (plugdb == null)
{
throw new Exception("Stream failure in database file");
}
binlog = BinLog.FromFile(ofd.FileName, plugdb);
binlog = BinLog.FromFile(ofd.FileName);
if (binlog == null)
{
throw new Exception("Stream failure in log file");

View File

@ -10,8 +10,6 @@ namespace BinLogReader
/// </summary>
public class PluginDb
{
private static uint BINDB_MAGIC = 0x414D4244;
private static short BINDB_VERSION = 0x0100;
private ArrayList PluginList;
public int Count
@ -40,72 +38,38 @@ namespace BinLogReader
return (Plugin)PluginList[id];
}
public static PluginDb FromFile(string filename)
public static PluginDb FromFile(BinaryReader br)
{
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
//read plugins
uint plugins = br.ReadUInt32();
PluginDb db = new PluginDb(plugins);
for (uint i=0; i<plugins; i++)
{
//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<plugins; i++)
byte status = br.ReadByte();
byte length = br.ReadByte();
byte [] name = br.ReadBytes(length + 1);
uint natives = br.ReadUInt32();
uint publics = br.ReadUInt32();
int id = db.CreatePlugin(
Encoding.ASCII.GetString(name, 0, length),
(int)natives,
(int)publics,
status,
(int)i);
Plugin pl = db.GetPluginById(id);
for (uint j=0; j<natives; j++)
{
byte status = br.ReadByte();
byte length = br.ReadByte();
byte [] name = br.ReadBytes(length + 1);
uint natives = br.ReadUInt32();
uint publics = br.ReadUInt32();
int id = db.CreatePlugin(
Encoding.ASCII.GetString(name, 0, length),
(int)natives,
(int)publics,
status,
(int)i);
Plugin pl = db.GetPluginById(id);
for (uint j=0; j<natives; j++)
{
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));
}
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));
}
}
catch
{
db = null;
throw new Exception("DB file is corrupt");
}
finally
{
br.Close();
stream.Close();
GC.Collect();
}
return db;
}