committed changes for new file format
This commit is contained in:
parent
ef5437fec3
commit
dc9350fcc5
|
@ -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,14 +258,18 @@ 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
|
||||||
{
|
{
|
||||||
br.Close();
|
br.Close();
|
||||||
|
|
Binary file not shown.
|
@ -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");
|
||||||
|
|
|
@ -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,72 +38,38 @@ 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))
|
//read plugins
|
||||||
return null;
|
uint plugins = br.ReadUInt32();
|
||||||
|
PluginDb db = new PluginDb(plugins);
|
||||||
System.IO.FileStream stream = File.Open(filename, System.IO.FileMode.Open);
|
for (uint i=0; i<plugins; i++)
|
||||||
if (stream == null)
|
|
||||||
return null;
|
|
||||||
BinaryReader br = new BinaryReader(stream);
|
|
||||||
if (br == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
PluginDb db;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
//check header
|
byte status = br.ReadByte();
|
||||||
uint magic = br.ReadUInt32();
|
byte length = br.ReadByte();
|
||||||
if (magic != BINDB_MAGIC)
|
byte [] name = br.ReadBytes(length + 1);
|
||||||
throw new Exception("Invalid magic DB number");
|
uint natives = br.ReadUInt32();
|
||||||
//check version
|
uint publics = br.ReadUInt32();
|
||||||
ushort vers = br.ReadUInt16();
|
int id = db.CreatePlugin(
|
||||||
if (vers > BINDB_VERSION)
|
Encoding.ASCII.GetString(name, 0, length),
|
||||||
throw new Exception("Unknown DB version");
|
(int)natives,
|
||||||
//read plugins
|
(int)publics,
|
||||||
uint plugins = br.ReadUInt32();
|
status,
|
||||||
db = new PluginDb(plugins);
|
(int)i);
|
||||||
for (uint i=0; i<plugins; i++)
|
Plugin pl = db.GetPluginById(id);
|
||||||
|
for (uint j=0; j<natives; j++)
|
||||||
{
|
{
|
||||||
byte status = br.ReadByte();
|
length = br.ReadByte();
|
||||||
byte length = br.ReadByte();
|
name = br.ReadBytes(length + 1);
|
||||||
byte [] name = br.ReadBytes(length + 1);
|
pl.AddNative(Encoding.ASCII.GetString(name, 0, length));
|
||||||
uint natives = br.ReadUInt32();
|
}
|
||||||
uint publics = br.ReadUInt32();
|
for (uint j=0; j<publics; j++)
|
||||||
int id = db.CreatePlugin(
|
{
|
||||||
Encoding.ASCII.GetString(name, 0, length),
|
length = br.ReadByte();
|
||||||
(int)natives,
|
name = br.ReadBytes(length + 1);
|
||||||
(int)publics,
|
pl.AddPublic(Encoding.ASCII.GetString(name, 0, length));
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
db = null;
|
|
||||||
throw new Exception("DB file is corrupt");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
br.Close();
|
|
||||||
stream.Close();
|
|
||||||
GC.Collect();
|
|
||||||
}
|
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user