Fleshed out log and database readers, began basics of GUI

This commit is contained in:
David Anderson
2006-03-16 06:40:18 +00:00
parent e067a980be
commit 82fe1e10d9
7 changed files with 1148 additions and 25 deletions

View File

@ -4,6 +4,7 @@ using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text.RegularExpressions;
namespace BinLogReader
{
@ -14,11 +15,19 @@ namespace BinLogReader
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.OpenFileDialog ofd;
private System.Windows.Forms.MenuItem MenuFileOpen;
private System.Windows.Forms.TabPage PluginsTab;
private System.Windows.Forms.TabPage LogTextTab;
private System.Windows.Forms.TabPage ViewTab;
private System.Windows.Forms.TabPage LogListTab;
private System.Windows.Forms.ListView PluginList;
private System.Windows.Forms.RichTextBox TextLog;
private System.Windows.Forms.TabControl MainTab;
/// <summary>
/// Required designer variable.
/// </summary>
@ -51,6 +60,9 @@ namespace BinLogReader
base.Dispose( disposing );
}
private PluginDb plugdb;
private BinLog binlog;
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
@ -60,11 +72,23 @@ namespace BinLogReader
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.MenuFileOpen = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.ofd = new System.Windows.Forms.OpenFileDialog();
this.MainTab = new System.Windows.Forms.TabControl();
this.PluginsTab = new System.Windows.Forms.TabPage();
this.PluginList = new System.Windows.Forms.ListView();
this.LogTextTab = new System.Windows.Forms.TabPage();
this.TextLog = new System.Windows.Forms.RichTextBox();
this.LogListTab = new System.Windows.Forms.TabPage();
this.ViewTab = new System.Windows.Forms.TabPage();
this.MainTab.SuspendLayout();
this.PluginsTab.SuspendLayout();
this.LogTextTab.SuspendLayout();
this.SuspendLayout();
//
// mainMenu1
//
@ -76,15 +100,16 @@ namespace BinLogReader
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.MenuFileOpen,
this.menuItem3,
this.menuItem4});
this.menuItem1.Text = "&File";
//
// menuItem2
// MenuFileOpen
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "&Open";
this.MenuFileOpen.Index = 0;
this.MenuFileOpen.Text = "&Open";
this.MenuFileOpen.Click += new System.EventHandler(this.MenuFileOpen_Click);
//
// menuItem3
//
@ -109,18 +134,110 @@ namespace BinLogReader
this.menuItem6.Index = 0;
this.menuItem6.Text = "&About";
//
// ofd
//
this.ofd.Filter = "Binary Log Files|*.blg";
//
// MainTab
//
this.MainTab.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.MainTab.Controls.Add(this.PluginsTab);
this.MainTab.Controls.Add(this.LogTextTab);
this.MainTab.Controls.Add(this.LogListTab);
this.MainTab.Controls.Add(this.ViewTab);
this.MainTab.Location = new System.Drawing.Point(8, 12);
this.MainTab.Name = "MainTab";
this.MainTab.SelectedIndex = 0;
this.MainTab.Size = new System.Drawing.Size(656, 372);
this.MainTab.TabIndex = 0;
this.MainTab.SelectedIndexChanged += new System.EventHandler(this.MainTab_SelectedIndexChanged);
//
// PluginsTab
//
this.PluginsTab.Controls.Add(this.PluginList);
this.PluginsTab.Location = new System.Drawing.Point(4, 22);
this.PluginsTab.Name = "PluginsTab";
this.PluginsTab.Size = new System.Drawing.Size(648, 346);
this.PluginsTab.TabIndex = 0;
this.PluginsTab.Text = "Plugins";
//
// PluginList
//
this.PluginList.AllowColumnReorder = true;
this.PluginList.AutoArrange = false;
this.PluginList.Dock = System.Windows.Forms.DockStyle.Fill;
this.PluginList.FullRowSelect = true;
this.PluginList.Location = new System.Drawing.Point(0, 0);
this.PluginList.MultiSelect = false;
this.PluginList.Name = "PluginList";
this.PluginList.Size = new System.Drawing.Size(648, 346);
this.PluginList.TabIndex = 0;
this.PluginList.View = System.Windows.Forms.View.Details;
//
// LogTextTab
//
this.LogTextTab.Controls.Add(this.TextLog);
this.LogTextTab.Location = new System.Drawing.Point(4, 22);
this.LogTextTab.Name = "LogTextTab";
this.LogTextTab.Size = new System.Drawing.Size(648, 346);
this.LogTextTab.TabIndex = 1;
this.LogTextTab.Text = "Event Log (Text)";
//
// TextLog
//
this.TextLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.TextLog.Font = new System.Drawing.Font("Lucida Sans Typewriter", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.TextLog.Location = new System.Drawing.Point(0, 0);
this.TextLog.Name = "TextLog";
this.TextLog.Size = new System.Drawing.Size(648, 346);
this.TextLog.TabIndex = 0;
this.TextLog.Text = "";
//
// LogListTab
//
this.LogListTab.Location = new System.Drawing.Point(4, 22);
this.LogListTab.Name = "LogListTab";
this.LogListTab.Size = new System.Drawing.Size(648, 346);
this.LogListTab.TabIndex = 3;
this.LogListTab.Text = "Event Log (List)";
//
// ViewTab
//
this.ViewTab.Location = new System.Drawing.Point(4, 22);
this.ViewTab.Name = "ViewTab";
this.ViewTab.Size = new System.Drawing.Size(648, 346);
this.ViewTab.TabIndex = 2;
this.ViewTab.Text = "View Configuration";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(772, 437);
this.ClientSize = new System.Drawing.Size(676, 393);
this.Controls.Add(this.MainTab);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "AMX Mod X BinLogReader";
this.Load += new System.EventHandler(this.Form1_Load);
this.MainTab.ResumeLayout(false);
this.PluginsTab.ResumeLayout(false);
this.LogTextTab.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
public enum ViewAreas
{
Update_All=0,
Update_Plugins=1,
Update_Text=2,
}
private ViewAreas g_UpdateViews;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -132,12 +249,138 @@ namespace BinLogReader
private void Form1_Load(object sender, System.EventArgs e)
{
PluginDb db = PluginDb.FromFile("c:\\hlserver\\cstrike\\addons\\amxmodx\\data\\binlogs\\bindb0001.bdb");
plugdb = null;
binlog = null;
g_UpdateViews = ViewAreas.Update_All;
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void ClearViews(ViewAreas v)
{
if (v == ViewAreas.Update_All ||
((v & ViewAreas.Update_Plugins) == ViewAreas.Update_Plugins))
{
PluginList.Clear();
PluginList.Columns.Clear();
}
if (v == ViewAreas.Update_Text ||
((v & ViewAreas.Update_Text) == ViewAreas.Update_Text))
{
TextLog.Clear();
}
}
private void UpdateViews(ViewAreas v, BinLogFlags b)
{
ClearViews(v);
if (v == ViewAreas.Update_All ||
((v & ViewAreas.Update_Plugins) == ViewAreas.Update_Plugins)
&& (plugdb != null))
{
PluginList.View = View.Details;
PluginList.Columns.Add("Number", 60, HorizontalAlignment.Left);
PluginList.Columns.Add("File", 100, HorizontalAlignment.Left);
PluginList.Columns.Add("Title", 120, HorizontalAlignment.Left);
PluginList.Columns.Add("Version", 60, HorizontalAlignment.Left);
PluginList.Columns.Add("Status", 60, HorizontalAlignment.Left);
int num = plugdb.Count;
ListViewItem[] items = new ListViewItem[num];
for (int i=0; i<num; i++)
{
Plugin pl = plugdb.GetPluginById(i);
ListViewItem item = new ListViewItem(i.ToString());
item.SubItems.Add(pl.File);
item.SubItems.Add(pl.Title);
item.SubItems.Add(pl.Version);
item.SubItems.Add(pl.Status);
items[i] = item;
}
PluginList.Items.AddRange(items);
}
if (v == ViewAreas.Update_Text ||
((v & ViewAreas.Update_Text) == ViewAreas.Update_Text)
&& (binlog != null))
{
ArrayList al = binlog.OpList;
BinLogEntry ble;
string fulltext = "";
for (int i=0; i<al.Count; i++)
{
ble = (BinLogEntry)al[i];
fulltext += BinLogEntry.BinLogString(ble,
(BinLogFlags.Show_GameTime | BinLogFlags.Show_PlugFile | BinLogFlags.Show_PlugId));
fulltext += "\n";
}
TextLog.Text = fulltext;
}
}
private void MenuFileOpen_Click(object sender, System.EventArgs e)
{
DialogResult res = ofd.ShowDialog(this);
if (res != DialogResult.OK)
{
return;
}
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);
if (binlog == null)
{
throw new Exception("Stream failure in log file");
}
MainTab.SelectedTab = MainTab.TabPages[0];
ClearViews(ViewAreas.Update_All);
UpdateViews(ViewAreas.Update_Plugins, BinLogFlags.Show_PlugFile | BinLogFlags.Show_GameTime);
g_UpdateViews = ViewAreas.Update_Text;
}
catch (Exception ex)
{
string msg = "Failed to open binary log";
if (ex.Message != null)
msg += ": " + ex.Message;
MessageBox.Show(this,
msg,
"AMX Mod X Binary Log Reader",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void MainTab_SelectedIndexChanged(object sender, System.EventArgs e)
{
if ((g_UpdateViews & ViewAreas.Update_Text) == ViewAreas.Update_Text)
{
UpdateViews(ViewAreas.Update_Text, BinLogFlags.Show_PlugFile|BinLogFlags.Show_GameTime);
g_UpdateViews &= ~(ViewAreas.Update_Text);
}
}
}
}