diff --git a/plugins/BinLogReader/BinLog.cs b/plugins/BinLogReader/BinLog.cs index e97bd83f..cf6cac36 100644 --- a/plugins/BinLogReader/BinLog.cs +++ b/plugins/BinLogReader/BinLog.cs @@ -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 @@ public ArrayList OpList 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 @@ public static BinLog FromFile(string filename, PluginDb db) 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 @@ public static BinLog FromFile(string filename, PluginDb db) } 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(); diff --git a/plugins/BinLogReader/BinLogReader.exe b/plugins/BinLogReader/BinLogReader.exe index 52a9ce4e..72069d60 100644 Binary files a/plugins/BinLogReader/BinLogReader.exe and b/plugins/BinLogReader/BinLogReader.exe differ diff --git a/plugins/BinLogReader/Form1.cs b/plugins/BinLogReader/Form1.cs index 91f0dfd3..e4a24e6b 100644 --- a/plugins/BinLogReader/Form1.cs +++ b/plugins/BinLogReader/Form1.cs @@ -5,7 +5,6 @@ using System.Windows.Forms; using System.Data; using System.Text; -using System.Text.RegularExpressions; namespace BinLogReader { @@ -61,7 +60,6 @@ protected override void Dispose( bool disposing ) base.Dispose( disposing ); } - private PluginDb plugdb; private BinLog binlog; #region Windows Form Designer generated code @@ -250,7 +248,6 @@ static void Main() private void Form1_Load(object sender, System.EventArgs e) { - plugdb = null; binlog = null; g_UpdateViews = ViewAreas.Update_All; } @@ -281,8 +278,9 @@ private void UpdateViews(ViewAreas v, BinLogFlags b) 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 @@ private void MenuFileOpen_Click(object sender, System.EventArgs e) 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"); diff --git a/plugins/BinLogReader/PluginDb.cs b/plugins/BinLogReader/PluginDb.cs index 9c464a26..9621b7fc 100644 --- a/plugins/BinLogReader/PluginDb.cs +++ b/plugins/BinLogReader/PluginDb.cs @@ -10,8 +10,6 @@ namespace BinLogReader /// 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 @@ public Plugin GetPluginById(int 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 + //read plugins + uint plugins = br.ReadUInt32(); + PluginDb db = new PluginDb(plugins); + for (uint i=0; i BINDB_VERSION) - throw new Exception("Unknown DB version"); - //read plugins - uint plugins = br.ReadUInt32(); - db = new PluginDb(plugins); - for (uint i=0; i