Trace Logger - log to file has a textbox and browse button. Implement the Save menu item (saves what is currently logged to the window)
This commit is contained in:
parent
2b117c3955
commit
9d1289d8d5
|
@ -44,11 +44,12 @@
|
||||||
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.BrowseBox = new System.Windows.Forms.Button();
|
||||||
|
this.FileBox = new System.Windows.Forms.TextBox();
|
||||||
this.ToFileRadio = new System.Windows.Forms.RadioButton();
|
this.ToFileRadio = new System.Windows.Forms.RadioButton();
|
||||||
this.ToWindowRadio = new System.Windows.Forms.RadioButton();
|
this.ToWindowRadio = new System.Windows.Forms.RadioButton();
|
||||||
this.ClearButton = new System.Windows.Forms.Button();
|
this.ClearButton = new System.Windows.Forms.Button();
|
||||||
this.LoggingEnabled = new System.Windows.Forms.CheckBox();
|
this.LoggingEnabled = new System.Windows.Forms.CheckBox();
|
||||||
this.CloseButton = new System.Windows.Forms.Button();
|
|
||||||
this.TracerBox.SuspendLayout();
|
this.TracerBox.SuspendLayout();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
this.groupBox2.SuspendLayout();
|
this.groupBox2.SuspendLayout();
|
||||||
|
@ -123,21 +124,22 @@
|
||||||
//
|
//
|
||||||
// saveLogToolStripMenuItem
|
// saveLogToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.saveLogToolStripMenuItem.Enabled = false;
|
this.saveLogToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.SaveAs;
|
||||||
this.saveLogToolStripMenuItem.Name = "saveLogToolStripMenuItem";
|
this.saveLogToolStripMenuItem.Name = "saveLogToolStripMenuItem";
|
||||||
this.saveLogToolStripMenuItem.Size = new System.Drawing.Size(134, 22);
|
this.saveLogToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||||
this.saveLogToolStripMenuItem.Text = "&Save Log";
|
this.saveLogToolStripMenuItem.Text = "&Save Log";
|
||||||
|
this.saveLogToolStripMenuItem.Click += new System.EventHandler(this.saveLogToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// toolStripSeparator1
|
// toolStripSeparator1
|
||||||
//
|
//
|
||||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||||
this.toolStripSeparator1.Size = new System.Drawing.Size(131, 6);
|
this.toolStripSeparator1.Size = new System.Drawing.Size(149, 6);
|
||||||
//
|
//
|
||||||
// exitToolStripMenuItem
|
// exitToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||||
this.exitToolStripMenuItem.ShortcutKeyDisplayString = "Alt+F4";
|
this.exitToolStripMenuItem.ShortcutKeyDisplayString = "Alt+F4";
|
||||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(134, 22);
|
this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||||
this.exitToolStripMenuItem.Text = "E&xit";
|
this.exitToolStripMenuItem.Text = "E&xit";
|
||||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
|
@ -181,19 +183,44 @@
|
||||||
//
|
//
|
||||||
// groupBox2
|
// groupBox2
|
||||||
//
|
//
|
||||||
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||||
| System.Windows.Forms.AnchorStyles.Left)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.groupBox2.Controls.Add(this.BrowseBox);
|
||||||
|
this.groupBox2.Controls.Add(this.FileBox);
|
||||||
this.groupBox2.Controls.Add(this.ToFileRadio);
|
this.groupBox2.Controls.Add(this.ToFileRadio);
|
||||||
this.groupBox2.Controls.Add(this.ToWindowRadio);
|
this.groupBox2.Controls.Add(this.ToWindowRadio);
|
||||||
this.groupBox2.Controls.Add(this.ClearButton);
|
this.groupBox2.Controls.Add(this.ClearButton);
|
||||||
this.groupBox2.Controls.Add(this.LoggingEnabled);
|
this.groupBox2.Controls.Add(this.LoggingEnabled);
|
||||||
this.groupBox2.Location = new System.Drawing.Point(12, 477);
|
this.groupBox2.Location = new System.Drawing.Point(12, 477);
|
||||||
this.groupBox2.Name = "groupBox2";
|
this.groupBox2.Name = "groupBox2";
|
||||||
this.groupBox2.Size = new System.Drawing.Size(530, 50);
|
this.groupBox2.Size = new System.Drawing.Size(620, 50);
|
||||||
this.groupBox2.TabIndex = 3;
|
this.groupBox2.TabIndex = 3;
|
||||||
this.groupBox2.TabStop = false;
|
this.groupBox2.TabStop = false;
|
||||||
this.groupBox2.Text = "Control";
|
this.groupBox2.Text = "Control";
|
||||||
//
|
//
|
||||||
|
// BrowseBox
|
||||||
|
//
|
||||||
|
this.BrowseBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.BrowseBox.Location = new System.Drawing.Point(477, 19);
|
||||||
|
this.BrowseBox.Name = "BrowseBox";
|
||||||
|
this.BrowseBox.Size = new System.Drawing.Size(54, 23);
|
||||||
|
this.BrowseBox.TabIndex = 5;
|
||||||
|
this.BrowseBox.Text = "&Browse";
|
||||||
|
this.BrowseBox.UseVisualStyleBackColor = true;
|
||||||
|
this.BrowseBox.Visible = false;
|
||||||
|
this.BrowseBox.Click += new System.EventHandler(this.BrowseBox_Click);
|
||||||
|
//
|
||||||
|
// FileBox
|
||||||
|
//
|
||||||
|
this.FileBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.FileBox.Location = new System.Drawing.Point(229, 20);
|
||||||
|
this.FileBox.Name = "FileBox";
|
||||||
|
this.FileBox.ReadOnly = true;
|
||||||
|
this.FileBox.Size = new System.Drawing.Size(242, 20);
|
||||||
|
this.FileBox.TabIndex = 4;
|
||||||
|
this.FileBox.Visible = false;
|
||||||
|
//
|
||||||
// ToFileRadio
|
// ToFileRadio
|
||||||
//
|
//
|
||||||
this.ToFileRadio.AutoSize = true;
|
this.ToFileRadio.AutoSize = true;
|
||||||
|
@ -219,9 +246,10 @@
|
||||||
//
|
//
|
||||||
// ClearButton
|
// ClearButton
|
||||||
//
|
//
|
||||||
this.ClearButton.Location = new System.Drawing.Point(449, 19);
|
this.ClearButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.ClearButton.Location = new System.Drawing.Point(564, 19);
|
||||||
this.ClearButton.Name = "ClearButton";
|
this.ClearButton.Name = "ClearButton";
|
||||||
this.ClearButton.Size = new System.Drawing.Size(75, 23);
|
this.ClearButton.Size = new System.Drawing.Size(47, 23);
|
||||||
this.ClearButton.TabIndex = 1;
|
this.ClearButton.TabIndex = 1;
|
||||||
this.ClearButton.Text = "&Clear";
|
this.ClearButton.Text = "&Clear";
|
||||||
this.ClearButton.UseVisualStyleBackColor = true;
|
this.ClearButton.UseVisualStyleBackColor = true;
|
||||||
|
@ -239,30 +267,17 @@
|
||||||
this.LoggingEnabled.UseVisualStyleBackColor = true;
|
this.LoggingEnabled.UseVisualStyleBackColor = true;
|
||||||
this.LoggingEnabled.CheckedChanged += new System.EventHandler(this.LoggingEnabled_CheckedChanged);
|
this.LoggingEnabled.CheckedChanged += new System.EventHandler(this.LoggingEnabled_CheckedChanged);
|
||||||
//
|
//
|
||||||
// CloseButton
|
|
||||||
//
|
|
||||||
this.CloseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
||||||
this.CloseButton.Location = new System.Drawing.Point(548, 496);
|
|
||||||
this.CloseButton.Name = "CloseButton";
|
|
||||||
this.CloseButton.Size = new System.Drawing.Size(75, 23);
|
|
||||||
this.CloseButton.TabIndex = 4;
|
|
||||||
this.CloseButton.Text = "&Close";
|
|
||||||
this.CloseButton.UseVisualStyleBackColor = true;
|
|
||||||
this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click);
|
|
||||||
//
|
|
||||||
// TraceLogger
|
// TraceLogger
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.CancelButton = this.CloseButton;
|
|
||||||
this.ClientSize = new System.Drawing.Size(644, 539);
|
this.ClientSize = new System.Drawing.Size(644, 539);
|
||||||
this.Controls.Add(this.CloseButton);
|
|
||||||
this.Controls.Add(this.groupBox2);
|
this.Controls.Add(this.groupBox2);
|
||||||
this.Controls.Add(this.TracerBox);
|
this.Controls.Add(this.TracerBox);
|
||||||
this.Controls.Add(this.menuStrip1);
|
this.Controls.Add(this.menuStrip1);
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
this.MainMenuStrip = this.menuStrip1;
|
this.MainMenuStrip = this.menuStrip1;
|
||||||
|
this.MinimumSize = new System.Drawing.Size(400, 230);
|
||||||
this.Name = "TraceLogger";
|
this.Name = "TraceLogger";
|
||||||
this.Text = "TraceLogger";
|
this.Text = "TraceLogger";
|
||||||
this.Load += new System.EventHandler(this.TraceLogger_Load);
|
this.Load += new System.EventHandler(this.TraceLogger_Load);
|
||||||
|
@ -292,11 +307,12 @@
|
||||||
private System.Windows.Forms.ToolStripMenuItem autoloadToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem autoloadToolStripMenuItem;
|
||||||
private VirtualListView TraceView;
|
private VirtualListView TraceView;
|
||||||
public System.Windows.Forms.ColumnHeader Script;
|
public System.Windows.Forms.ColumnHeader Script;
|
||||||
private System.Windows.Forms.Button CloseButton;
|
|
||||||
private System.Windows.Forms.ToolStripMenuItem setMaxWindowLinesToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem setMaxWindowLinesToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
||||||
private System.Windows.Forms.ToolStripMenuItem saveWindowPositionToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem saveWindowPositionToolStripMenuItem;
|
||||||
private System.Windows.Forms.RadioButton ToFileRadio;
|
private System.Windows.Forms.RadioButton ToFileRadio;
|
||||||
private System.Windows.Forms.RadioButton ToWindowRadio;
|
private System.Windows.Forms.RadioButton ToWindowRadio;
|
||||||
|
private System.Windows.Forms.TextBox FileBox;
|
||||||
|
private System.Windows.Forms.Button BrowseBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,10 +12,10 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
public partial class TraceLogger : Form
|
public partial class TraceLogger : Form
|
||||||
{
|
{
|
||||||
//Save to file - saves what's on screen to disk (defaults to the current log file)
|
|
||||||
//Show file that is being logged to
|
|
||||||
//Browse button to set file
|
|
||||||
//Refresh rate slider
|
//Refresh rate slider
|
||||||
|
//Make faster, such as not saving to disk until the logging is stopped, dont' add to Instructions list every frame, etc
|
||||||
|
//Remember window size
|
||||||
|
//Show a message that file was saved, when using the save menu item
|
||||||
|
|
||||||
List<string> Instructions = new List<string>();
|
List<string> Instructions = new List<string>();
|
||||||
FileInfo LogFile;
|
FileInfo LogFile;
|
||||||
|
@ -229,6 +229,8 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
if (ToFileRadio.Checked)
|
if (ToFileRadio.Checked)
|
||||||
{
|
{
|
||||||
|
FileBox.Visible = true;
|
||||||
|
BrowseBox.Visible = true;
|
||||||
string name = PathManager.FilesystemSafeName(Global.Game);
|
string name = PathManager.FilesystemSafeName(Global.Game);
|
||||||
string filename = Path.Combine(PathManager.MakeAbsolutePath(Global.Config.LogPath, ""), name) + ".txt";
|
string filename = Path.Combine(PathManager.MakeAbsolutePath(Global.Config.LogPath, ""), name) + ".txt";
|
||||||
LogFile = new FileInfo(filename);
|
LogFile = new FileInfo(filename);
|
||||||
|
@ -245,10 +247,15 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
LogFile.Create();
|
LogFile.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileBox.Text = LogFile.FullName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CloseFile();
|
CloseFile();
|
||||||
|
FileBox.Visible = false;
|
||||||
|
BrowseBox.Visible = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTracerBoxTitle();
|
SetTracerBoxTitle();
|
||||||
|
@ -256,6 +263,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
private void CloseFile()
|
private void CloseFile()
|
||||||
{
|
{
|
||||||
|
//TODO: save the remaining instructions in CoreComm
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TraceView_KeyDown(object sender, KeyEventArgs e)
|
private void TraceView_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
@ -277,5 +285,72 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BrowseBox_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var file = GetFileFromUser();
|
||||||
|
if (file != null)
|
||||||
|
{
|
||||||
|
LogFile = file;
|
||||||
|
FileBox.Text = LogFile.FullName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileInfo GetFileFromUser()
|
||||||
|
{
|
||||||
|
var sfd = new SaveFileDialog();
|
||||||
|
if (LogFile == null)
|
||||||
|
{
|
||||||
|
string name = PathManager.FilesystemSafeName(Global.Game);
|
||||||
|
sfd.FileName = name + ".txt";
|
||||||
|
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.LogPath, "");
|
||||||
|
}
|
||||||
|
else if (!String.IsNullOrWhiteSpace(LogFile.FullName))
|
||||||
|
{
|
||||||
|
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
|
||||||
|
sfd.InitialDirectory = Path.GetDirectoryName(LogFile.FullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sfd.FileName = Path.GetFileNameWithoutExtension(LogFile.FullName);
|
||||||
|
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.LogPath, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
sfd.Filter = "Text Files (*.txt)|*.txt|Log Files (*.log)|*.log|All Files|*.*";
|
||||||
|
sfd.RestoreDirectory = true;
|
||||||
|
Global.Sound.StopSound();
|
||||||
|
|
||||||
|
var result = sfd.ShowDialog();
|
||||||
|
Global.Sound.StartSound();
|
||||||
|
if (result != DialogResult.OK)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new FileInfo(sfd.FileName);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveLogToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var file = GetFileFromUser();
|
||||||
|
if (file != null)
|
||||||
|
{
|
||||||
|
DumpListToDisk(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DumpListToDisk(FileInfo file)
|
||||||
|
{
|
||||||
|
using (StreamWriter sw = new StreamWriter(file.FullName))
|
||||||
|
{
|
||||||
|
foreach (string s in Instructions)
|
||||||
|
{
|
||||||
|
sw.WriteLine(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue