Trace Logger - log to file option, currently writes to Watch Filepath + GameName .txt with no option to change it

This commit is contained in:
adelikat 2012-09-30 14:52:36 +00:00
parent 89cf8e75fe
commit 75c8739fb8
2 changed files with 125 additions and 35 deletions

View File

@ -39,14 +39,16 @@
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setMaxWindowLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.ToFileRadio = new System.Windows.Forms.RadioButton();
this.ToWindowRadio = new System.Windows.Forms.RadioButton();
this.ClearButton = new System.Windows.Forms.Button();
this.LoggingEnabled = new System.Windows.Forms.CheckBox();
this.CloseButton = new System.Windows.Forms.Button();
this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setMaxWindowLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.TracerBox.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.groupBox2.SuspendLayout();
@ -150,6 +152,18 @@
this.optionsToolStripMenuItem.Text = "&Options";
this.optionsToolStripMenuItem.DropDownOpened += new System.EventHandler(this.optionsToolStripMenuItem_DropDownOpened);
//
// setMaxWindowLinesToolStripMenuItem
//
this.setMaxWindowLinesToolStripMenuItem.Name = "setMaxWindowLinesToolStripMenuItem";
this.setMaxWindowLinesToolStripMenuItem.Size = new System.Drawing.Size(201, 22);
this.setMaxWindowLinesToolStripMenuItem.Text = "&Set Max Window Lines...";
this.setMaxWindowLinesToolStripMenuItem.Click += new System.EventHandler(this.setMaxWindowLinesToolStripMenuItem_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(198, 6);
//
// autoloadToolStripMenuItem
//
this.autoloadToolStripMenuItem.Name = "autoloadToolStripMenuItem";
@ -157,22 +171,54 @@
this.autoloadToolStripMenuItem.Text = "&Autoload";
this.autoloadToolStripMenuItem.Click += new System.EventHandler(this.autoloadToolStripMenuItem_Click);
//
// saveWindowPositionToolStripMenuItem
//
this.saveWindowPositionToolStripMenuItem.Name = "saveWindowPositionToolStripMenuItem";
this.saveWindowPositionToolStripMenuItem.Size = new System.Drawing.Size(201, 22);
this.saveWindowPositionToolStripMenuItem.Text = "&Save Window Position";
this.saveWindowPositionToolStripMenuItem.Click += new System.EventHandler(this.saveWindowPositionToolStripMenuItem_Click);
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBox2.Controls.Add(this.ToFileRadio);
this.groupBox2.Controls.Add(this.ToWindowRadio);
this.groupBox2.Controls.Add(this.ClearButton);
this.groupBox2.Controls.Add(this.LoggingEnabled);
this.groupBox2.Location = new System.Drawing.Point(12, 477);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(218, 50);
this.groupBox2.Size = new System.Drawing.Size(530, 50);
this.groupBox2.TabIndex = 3;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Control";
//
// ToFileRadio
//
this.ToFileRadio.AutoSize = true;
this.ToFileRadio.Location = new System.Drawing.Point(173, 22);
this.ToFileRadio.Name = "ToFileRadio";
this.ToFileRadio.Size = new System.Drawing.Size(50, 17);
this.ToFileRadio.TabIndex = 3;
this.ToFileRadio.Text = "to file";
this.ToFileRadio.UseVisualStyleBackColor = true;
this.ToFileRadio.CheckedChanged += new System.EventHandler(this.ToFileRadio_CheckedChanged);
//
// ToWindowRadio
//
this.ToWindowRadio.AutoSize = true;
this.ToWindowRadio.Checked = true;
this.ToWindowRadio.Location = new System.Drawing.Point(94, 22);
this.ToWindowRadio.Name = "ToWindowRadio";
this.ToWindowRadio.Size = new System.Drawing.Size(73, 17);
this.ToWindowRadio.TabIndex = 2;
this.ToWindowRadio.TabStop = true;
this.ToWindowRadio.Text = "to window";
this.ToWindowRadio.UseVisualStyleBackColor = true;
//
// ClearButton
//
this.ClearButton.Location = new System.Drawing.Point(121, 19);
this.ClearButton.Location = new System.Drawing.Point(449, 19);
this.ClearButton.Name = "ClearButton";
this.ClearButton.Size = new System.Drawing.Size(75, 23);
this.ClearButton.TabIndex = 1;
@ -186,9 +232,9 @@
this.LoggingEnabled.AutoSize = true;
this.LoggingEnabled.Location = new System.Drawing.Point(9, 19);
this.LoggingEnabled.Name = "LoggingEnabled";
this.LoggingEnabled.Size = new System.Drawing.Size(97, 23);
this.LoggingEnabled.Size = new System.Drawing.Size(55, 23);
this.LoggingEnabled.TabIndex = 0;
this.LoggingEnabled.Text = "&Logging Enabled";
this.LoggingEnabled.Text = "&Logging";
this.LoggingEnabled.UseVisualStyleBackColor = true;
this.LoggingEnabled.CheckedChanged += new System.EventHandler(this.LoggingEnabled_CheckedChanged);
//
@ -204,25 +250,6 @@
this.CloseButton.UseVisualStyleBackColor = true;
this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click);
//
// saveWindowPositionToolStripMenuItem
//
this.saveWindowPositionToolStripMenuItem.Name = "saveWindowPositionToolStripMenuItem";
this.saveWindowPositionToolStripMenuItem.Size = new System.Drawing.Size(201, 22);
this.saveWindowPositionToolStripMenuItem.Text = "&Save Window Position";
this.saveWindowPositionToolStripMenuItem.Click += new System.EventHandler(this.saveWindowPositionToolStripMenuItem_Click);
//
// setMaxWindowLinesToolStripMenuItem
//
this.setMaxWindowLinesToolStripMenuItem.Name = "setMaxWindowLinesToolStripMenuItem";
this.setMaxWindowLinesToolStripMenuItem.Size = new System.Drawing.Size(201, 22);
this.setMaxWindowLinesToolStripMenuItem.Text = "&Set Max Window Lines...";
this.setMaxWindowLinesToolStripMenuItem.Click += new System.EventHandler(this.setMaxWindowLinesToolStripMenuItem_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(198, 6);
//
// TraceLogger
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -268,5 +295,7 @@
private System.Windows.Forms.ToolStripMenuItem setMaxWindowLinesToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem saveWindowPositionToolStripMenuItem;
private System.Windows.Forms.RadioButton ToFileRadio;
private System.Windows.Forms.RadioButton ToWindowRadio;
}
}

View File

@ -6,12 +6,14 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace BizHawk.MultiClient
{
public partial class TraceLogger : Form
{
List<string> Instructions = new List<string>();
FileInfo LogFile;
public TraceLogger()
{
@ -64,7 +66,6 @@ namespace BizHawk.MultiClient
public void UpdateValues()
{
DoInstructions();
SetTracerBoxTitle();
}
public void Restart()
@ -80,6 +81,7 @@ namespace BizHawk.MultiClient
ClearList();
}
else
{
this.Close();
}
@ -109,6 +111,27 @@ namespace BizHawk.MultiClient
}
private void DoInstructions()
{
if (ToWindowRadio.Checked)
{
LogToWindow();
SetTracerBoxTitle();
}
else
{
LogToFile();
}
}
private void LogToFile()
{
using (StreamWriter sw = new StreamWriter(LogFile.FullName, true))
{
sw.Write(Global.CoreInputComm.Tracer.TakeContents());
}
}
private void LogToWindow()
{
string[] instructions = Global.CoreInputComm.Tracer.TakeContents().Split('\n');
if (!String.IsNullOrWhiteSpace(instructions[0]))
@ -118,14 +141,15 @@ namespace BizHawk.MultiClient
Instructions.Add(s);
}
if (Instructions.Count >= Global.Config.TraceLoggerMaxLines)
{
int x = Instructions.Count - Global.Config.TraceLoggerMaxLines;
Instructions.RemoveRange(0, x);
}
TraceView.ItemCount = Instructions.Count;
}
if (Instructions.Count >= Global.Config.TraceLoggerMaxLines)
{
int x = Instructions.Count - Global.Config.TraceLoggerMaxLines;
Instructions.RemoveRange(0, x);
}
TraceView.ItemCount = Instructions.Count;
}
private void autoloadToolStripMenuItem_Click(object sender, EventArgs e)
@ -170,7 +194,11 @@ namespace BizHawk.MultiClient
{
if (Global.CoreInputComm.Tracer.Enabled)
{
if (Instructions.Count > 0)
if (ToFileRadio.Checked)
{
TracerBox.Text = "Trace log - logging to file...";
}
else if (Instructions.Count > 0)
{
TracerBox.Text = "Trace log - logging - " + Instructions.Count.ToString() + " instructions";
}
@ -191,5 +219,38 @@ namespace BizHawk.MultiClient
}
}
}
private void ToFileRadio_CheckedChanged(object sender, EventArgs e)
{
if (ToFileRadio.Checked)
{
string name = PathManager.FilesystemSafeName(Global.Game);
string filename = Path.Combine(PathManager.MakeAbsolutePath(Global.Config.WatchPath, ""), name) + ".txt";
LogFile = new FileInfo(filename);
if (!LogFile.Directory.Exists)
{
LogFile.Directory.Create();
}
if (LogFile.Exists)
{
LogFile.Delete();
LogFile.Create();
}
else
{
LogFile.Create();
}
}
else
{
CloseFile();
}
SetTracerBoxTitle();
}
private void CloseFile()
{
}
}
}