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 public class BinLog
{ {
private static uint BINLOG_MAGIC = 0x414D424C; private static uint BINLOG_MAGIC = 0x414D424C;
private static short BINLOG_VERSION = 0x0100; private static short BINLOG_VERSION = 0x0200;
private ArrayList oplist; private ArrayList oplist;
private PluginDb plugdb;
public ArrayList OpList public ArrayList OpList
{ {
@ -28,7 +29,12 @@ public ArrayList OpList
oplist = new ArrayList(init_size); 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)) if (!File.Exists(filename))
return null; return null;
@ -68,6 +74,12 @@ public static BinLog FromFile(string filename, PluginDb db)
else else
bl = new BinLog( (int)(fi.Length / 6) ); 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 do
{ {
opcode = (BinLogOp)br.ReadByte(); opcode = (BinLogOp)br.ReadByte();
@ -246,13 +258,17 @@ public static BinLog FromFile(string filename, PluginDb db)
} while (opcode != BinLogOp.BinLog_End); } while (opcode != BinLogOp.BinLog_End);
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); BinLogSimple bs = new BinLogSimple(BinLogOp.BinLog_Invalid, gametime, realtime, pl);
bl.oplist.Add(bs); bl.oplist.Add(bs);
} }
else
{
throw new Exception(e.Message);
}
} }
finally finally
{ {

View File

@ -5,7 +5,6 @@
using System.Windows.Forms; using System.Windows.Forms;
using System.Data; using System.Data;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace BinLogReader namespace BinLogReader
{ {
@ -61,7 +60,6 @@ protected override void Dispose( bool disposing )
base.Dispose( disposing ); base.Dispose( disposing );
} }
private PluginDb plugdb;
private BinLog binlog; private BinLog binlog;
#region Windows Form Designer generated code #region Windows Form Designer generated code
@ -250,7 +248,6 @@ static void Main()
private void Form1_Load(object sender, System.EventArgs e) private void Form1_Load(object sender, System.EventArgs e)
{ {
plugdb = null;
binlog = null; binlog = null;
g_UpdateViews = ViewAreas.Update_All; g_UpdateViews = ViewAreas.Update_All;
} }
@ -281,8 +278,9 @@ private void UpdateViews(ViewAreas v, BinLogFlags b)
if (v == ViewAreas.Update_All || if (v == ViewAreas.Update_All ||
((v & ViewAreas.Update_Plugins) == ViewAreas.Update_Plugins) ((v & ViewAreas.Update_Plugins) == ViewAreas.Update_Plugins)
&& (plugdb != null)) && (binlog.GetPluginDB() != null))
{ {
PluginDb plugdb = binlog.GetPluginDB();
PluginList.View = View.Details; PluginList.View = View.Details;
PluginList.Columns.Add("Number", 60, HorizontalAlignment.Left); PluginList.Columns.Add("Number", 60, HorizontalAlignment.Left);
PluginList.Columns.Add("File", 100, HorizontalAlignment.Left); PluginList.Columns.Add("File", 100, HorizontalAlignment.Left);
@ -333,25 +331,7 @@ private void MenuFileOpen_Click(object sender, System.EventArgs e)
try try
{ {
/* try to open the accompanying database file */ binlog = BinLog.FromFile(ofd.FileName);
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);
if (binlog == null) if (binlog == null)
{ {
throw new Exception("Stream failure in log file"); throw new Exception("Stream failure in log file");

View File

@ -10,8 +10,6 @@ namespace BinLogReader
/// </summary> /// </summary>
public class PluginDb public class PluginDb
{ {
private static uint BINDB_MAGIC = 0x414D4244;
private static short BINDB_VERSION = 0x0100;
private ArrayList PluginList; private ArrayList PluginList;
public int Count public int Count
@ -40,33 +38,11 @@ public Plugin GetPluginById(int id)
return (Plugin)PluginList[id]; 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
{
//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 //read plugins
uint plugins = br.ReadUInt32(); uint plugins = br.ReadUInt32();
db = new PluginDb(plugins); PluginDb db = new PluginDb(plugins);
for (uint i=0; i<plugins; i++) for (uint i=0; i<plugins; i++)
{ {
byte status = br.ReadByte(); byte status = br.ReadByte();
@ -94,18 +70,6 @@ public static PluginDb FromFile(string filename)
pl.AddPublic(Encoding.ASCII.GetString(name, 0, length)); 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; return db;
} }