2006-03-15 13:42:25 +00:00
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
2006-03-16 19:29:46 +00:00
using System.Text ;
2006-03-15 13:42:25 +00:00
namespace BinLogReader
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System . Windows . Forms . Form
{
private System . Windows . Forms . MainMenu mainMenu1 ;
private System . Windows . Forms . MenuItem menuItem1 ;
private System . Windows . Forms . MenuItem menuItem3 ;
private System . Windows . Forms . MenuItem menuItem4 ;
private System . Windows . Forms . MenuItem menuItem5 ;
private System . Windows . Forms . MenuItem menuItem6 ;
2006-03-16 06:40:18 +00:00
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 ;
2006-03-15 13:42:25 +00:00
/// <summary>
/// Required designer variable.
/// </summary>
private System . ComponentModel . Container components = null ;
public Form1 ( )
{
//
// Required for Windows Form Designer support
//
InitializeComponent ( ) ;
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose ( bool disposing )
{
if ( disposing )
{
if ( components ! = null )
{
components . Dispose ( ) ;
}
}
base . Dispose ( disposing ) ;
}
2006-03-16 06:40:18 +00:00
private BinLog binlog ;
2006-03-15 13:42:25 +00:00
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent ( )
{
this . mainMenu1 = new System . Windows . Forms . MainMenu ( ) ;
this . menuItem1 = new System . Windows . Forms . MenuItem ( ) ;
2006-03-16 06:40:18 +00:00
this . MenuFileOpen = new System . Windows . Forms . MenuItem ( ) ;
2006-03-15 13:42:25 +00:00
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 ( ) ;
2006-03-16 06:40:18 +00:00
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 ( ) ;
2006-03-15 13:42:25 +00:00
//
// mainMenu1
//
this . mainMenu1 . MenuItems . AddRange ( new System . Windows . Forms . MenuItem [ ] {
this . menuItem1 ,
this . menuItem5 } ) ;
//
// menuItem1
//
this . menuItem1 . Index = 0 ;
this . menuItem1 . MenuItems . AddRange ( new System . Windows . Forms . MenuItem [ ] {
2006-03-16 06:40:18 +00:00
this . MenuFileOpen ,
2006-03-15 13:42:25 +00:00
this . menuItem3 ,
this . menuItem4 } ) ;
this . menuItem1 . Text = "&File" ;
//
2006-03-16 06:40:18 +00:00
// MenuFileOpen
2006-03-15 13:42:25 +00:00
//
2006-03-16 06:40:18 +00:00
this . MenuFileOpen . Index = 0 ;
this . MenuFileOpen . Text = "&Open" ;
this . MenuFileOpen . Click + = new System . EventHandler ( this . MenuFileOpen_Click ) ;
2006-03-15 13:42:25 +00:00
//
// menuItem3
//
this . menuItem3 . Index = 1 ;
this . menuItem3 . Text = "-" ;
//
// menuItem4
//
this . menuItem4 . Index = 2 ;
this . menuItem4 . Text = "E&xit" ;
this . menuItem4 . Click + = new System . EventHandler ( this . menuItem4_Click ) ;
//
// menuItem5
//
this . menuItem5 . Index = 1 ;
this . menuItem5 . MenuItems . AddRange ( new System . Windows . Forms . MenuItem [ ] {
this . menuItem6 } ) ;
this . menuItem5 . Text = "&Help" ;
//
// menuItem6
//
this . menuItem6 . Index = 0 ;
this . menuItem6 . Text = "&About" ;
//
2006-03-16 06:40:18 +00:00
// 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" ;
//
2006-03-15 13:42:25 +00:00
// Form1
//
this . AutoScaleBaseSize = new System . Drawing . Size ( 5 , 13 ) ;
2006-03-16 06:40:18 +00:00
this . ClientSize = new System . Drawing . Size ( 676 , 393 ) ;
this . Controls . Add ( this . MainTab ) ;
2006-03-15 13:42:25 +00:00
this . Menu = this . mainMenu1 ;
this . Name = "Form1" ;
this . Text = "AMX Mod X BinLogReader" ;
this . Load + = new System . EventHandler ( this . Form1_Load ) ;
2006-03-16 06:40:18 +00:00
this . MainTab . ResumeLayout ( false ) ;
this . PluginsTab . ResumeLayout ( false ) ;
this . LogTextTab . ResumeLayout ( false ) ;
this . ResumeLayout ( false ) ;
2006-03-15 13:42:25 +00:00
}
#endregion
2006-03-16 06:40:18 +00:00
public enum ViewAreas
{
Update_All = 0 ,
Update_Plugins = 1 ,
Update_Text = 2 ,
}
private ViewAreas g_UpdateViews ;
2006-03-15 13:42:25 +00:00
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main ( )
{
Application . Run ( new Form1 ( ) ) ;
}
private void Form1_Load ( object sender , System . EventArgs e )
{
2006-03-16 06:40:18 +00:00
binlog = null ;
g_UpdateViews = ViewAreas . Update_All ;
2006-03-15 13:42:25 +00:00
}
private void menuItem4_Click ( object sender , System . EventArgs e )
{
Application . Exit ( ) ;
}
2006-03-16 06:40:18 +00:00
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 )
2006-03-19 21:40:24 +00:00
& & ( binlog . GetPluginDB ( ) ! = null ) )
2006-03-16 06:40:18 +00:00
{
2006-03-19 21:40:24 +00:00
PluginDb plugdb = binlog . GetPluginDB ( ) ;
2006-03-16 06:40:18 +00:00
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 ;
2006-03-16 19:29:46 +00:00
StringBuilder sb = new StringBuilder ( al . Count * 10 ) ;
BinLogFlags flags = ( BinLogFlags . Show_GameTime | BinLogFlags . Show_PlugFile | BinLogFlags . Show_PlugId ) ;
2006-03-16 06:40:18 +00:00
for ( int i = 0 ; i < al . Count ; i + + )
{
ble = ( BinLogEntry ) al [ i ] ;
2006-03-16 19:29:46 +00:00
BinLogEntry . BinLogString ( sb , ble , flags ) ;
sb . Append ( "\n" ) ;
2006-03-16 06:40:18 +00:00
}
2006-03-16 19:29:46 +00:00
TextLog . Text = sb . ToString ( ) ;
2006-03-16 06:40:18 +00:00
}
}
private void MenuFileOpen_Click ( object sender , System . EventArgs e )
{
DialogResult res = ofd . ShowDialog ( this ) ;
if ( res ! = DialogResult . OK )
{
return ;
}
try
{
2006-03-19 21:40:24 +00:00
binlog = BinLog . FromFile ( ofd . FileName ) ;
2006-03-16 06:40:18 +00:00
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 ) ;
}
}
2006-03-15 13:42:25 +00:00
}
}