Trace Logger - some code clean up, some tiny speedups, and implement a few small tweaks like Always on Top, and Select All

This commit is contained in:
adelikat 2013-11-29 00:35:05 +00:00
parent 9ccc214667
commit 0ed9d832c7
4 changed files with 551 additions and 539 deletions

View File

@ -290,6 +290,7 @@ namespace BizHawk.Client.Common
//Trace Logger Settings //Trace Logger Settings
public bool TraceLoggerAutoLoad = false; public bool TraceLoggerAutoLoad = false;
public bool TraceLoggerSaveWindowPosition = true; public bool TraceLoggerSaveWindowPosition = true;
public bool TraceLoggerOnTop = false;
public int TraceLoggerMaxLines = 100000; public int TraceLoggerMaxLines = 100000;
public int TraceLoggerWndx = -1; public int TraceLoggerWndx = -1;
public int TraceLoggerWndy = -1; public int TraceLoggerWndy = -1;

View File

@ -28,291 +28,310 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TraceLogger)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TraceLogger));
this.TracerBox = new System.Windows.Forms.GroupBox(); this.TracerBox = new System.Windows.Forms.GroupBox();
this.TraceView = new BizHawk.Client.EmuHawk.VirtualListView(); this.TraceView = new BizHawk.Client.EmuHawk.VirtualListView();
this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.menuStrip1 = new MenuStripEx(); this.menuStrip1 = new MenuStripEx();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.FileSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.saveLogToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SaveLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.EditSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.copyAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CopyMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SelectAllMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setMaxWindowLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OptionsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.MaxLinesMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.BrowseBox = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox();
this.FileBox = new System.Windows.Forms.TextBox(); this.BrowseBox = new System.Windows.Forms.Button();
this.ToFileRadio = new System.Windows.Forms.RadioButton(); this.FileBox = new System.Windows.Forms.TextBox();
this.ToWindowRadio = new System.Windows.Forms.RadioButton(); this.ToFileRadio = new System.Windows.Forms.RadioButton();
this.ClearButton = new System.Windows.Forms.Button(); this.ToWindowRadio = new System.Windows.Forms.RadioButton();
this.LoggingEnabled = new System.Windows.Forms.CheckBox(); this.ClearButton = new System.Windows.Forms.Button();
this.TracerBox.SuspendLayout(); this.LoggingEnabled = new System.Windows.Forms.CheckBox();
this.menuStrip1.SuspendLayout(); this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox2.SuspendLayout(); this.TracerBox.SuspendLayout();
this.SuspendLayout(); this.menuStrip1.SuspendLayout();
// this.groupBox2.SuspendLayout();
// TracerBox this.SuspendLayout();
// //
this.TracerBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) // TracerBox
//
this.TracerBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.TracerBox.Controls.Add(this.TraceView); this.TracerBox.Controls.Add(this.TraceView);
this.TracerBox.Location = new System.Drawing.Point(12, 27); this.TracerBox.Location = new System.Drawing.Point(12, 27);
this.TracerBox.Name = "TracerBox"; this.TracerBox.Name = "TracerBox";
this.TracerBox.Size = new System.Drawing.Size(620, 444); this.TracerBox.Size = new System.Drawing.Size(620, 444);
this.TracerBox.TabIndex = 1; this.TracerBox.TabIndex = 1;
this.TracerBox.TabStop = false; this.TracerBox.TabStop = false;
this.TracerBox.Text = "Trace log"; this.TracerBox.Text = "Trace log";
// //
// TraceView // TraceView
// //
this.TraceView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.TraceView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.TraceView.CheckBoxes = true; this.TraceView.CheckBoxes = true;
this.TraceView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.TraceView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.Script}); this.Script});
this.TraceView.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.TraceView.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.TraceView.FullRowSelect = true; this.TraceView.FullRowSelect = true;
this.TraceView.GridLines = true; this.TraceView.GridLines = true;
this.TraceView.HideSelection = false; this.TraceView.HideSelection = false;
this.TraceView.ItemCount = 0; this.TraceView.ItemCount = 0;
this.TraceView.Location = new System.Drawing.Point(8, 18); this.TraceView.Location = new System.Drawing.Point(8, 18);
this.TraceView.Name = "TraceView"; this.TraceView.Name = "TraceView";
this.TraceView.selectedItem = -1; this.TraceView.selectedItem = -1;
this.TraceView.Size = new System.Drawing.Size(603, 414); this.TraceView.Size = new System.Drawing.Size(603, 414);
this.TraceView.TabIndex = 4; this.TraceView.TabIndex = 4;
this.TraceView.TabStop = false; this.TraceView.TabStop = false;
this.TraceView.UseCompatibleStateImageBehavior = false; this.TraceView.UseCompatibleStateImageBehavior = false;
this.TraceView.View = System.Windows.Forms.View.Details; this.TraceView.View = System.Windows.Forms.View.Details;
this.TraceView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TraceView_KeyDown); //
// // Script
// Script //
// this.Script.Text = "Instructions";
this.Script.Text = "Instructions"; this.Script.Width = 599;
this.Script.Width = 599; //
// // menuStrip1
// menuStrip1 //
// this.menuStrip1.ClickThrough = true;
this.menuStrip1.ClickThrough = true; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1, this.toolStripMenuItem1,
this.fileToolStripMenuItem, this.FileSubMenu,
this.editToolStripMenuItem, this.EditSubMenu,
this.optionsToolStripMenuItem}); this.OptionsSubMenu});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(644, 24); this.menuStrip1.Size = new System.Drawing.Size(644, 24);
this.menuStrip1.TabIndex = 2; this.menuStrip1.TabIndex = 2;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.Text = "menuStrip1";
// //
// toolStripMenuItem1 // toolStripMenuItem1
// //
this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(12, 20); this.toolStripMenuItem1.Size = new System.Drawing.Size(12, 20);
// //
// fileToolStripMenuItem // FileSubMenu
// //
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.FileSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.saveLogToolStripMenuItem, this.SaveLogMenuItem,
this.toolStripSeparator1, this.toolStripSeparator1,
this.exitToolStripMenuItem}); this.ExitMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.FileSubMenu.Name = "FileSubMenu";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); this.FileSubMenu.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "&File"; this.FileSubMenu.Text = "&File";
// //
// saveLogToolStripMenuItem // SaveLogMenuItem
// //
this.saveLogToolStripMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.SaveAs; this.SaveLogMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.SaveAs;
this.saveLogToolStripMenuItem.Name = "saveLogToolStripMenuItem"; this.SaveLogMenuItem.Name = "SaveLogMenuItem";
this.saveLogToolStripMenuItem.Size = new System.Drawing.Size(134, 22); this.SaveLogMenuItem.Size = new System.Drawing.Size(134, 22);
this.saveLogToolStripMenuItem.Text = "&Save Log"; this.SaveLogMenuItem.Text = "&Save Log";
this.saveLogToolStripMenuItem.Click += new System.EventHandler(this.saveLogToolStripMenuItem_Click); this.SaveLogMenuItem.Click += new System.EventHandler(this.SaveLogMenuItem_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(131, 6);
// //
// exitToolStripMenuItem // ExitMenuItem
// //
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; this.ExitMenuItem.Name = "ExitMenuItem";
this.exitToolStripMenuItem.ShortcutKeyDisplayString = "Alt+F4"; this.ExitMenuItem.ShortcutKeyDisplayString = "Alt+F4";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(134, 22); this.ExitMenuItem.Size = new System.Drawing.Size(134, 22);
this.exitToolStripMenuItem.Text = "E&xit"; this.ExitMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click);
// //
// editToolStripMenuItem // EditSubMenu
// //
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.EditSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.copyAllToolStripMenuItem}); this.CopyMenuItem,
this.editToolStripMenuItem.Name = "editToolStripMenuItem"; this.SelectAllMenuItem});
this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20); this.EditSubMenu.Name = "EditSubMenu";
this.editToolStripMenuItem.Text = "Edit"; this.EditSubMenu.Size = new System.Drawing.Size(39, 20);
// this.EditSubMenu.Text = "Edit";
// copyAllToolStripMenuItem //
// // CopyMenuItem
this.copyAllToolStripMenuItem.Name = "copyAllToolStripMenuItem"; //
this.copyAllToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+C"; this.CopyMenuItem.Name = "CopyMenuItem";
this.copyAllToolStripMenuItem.Size = new System.Drawing.Size(161, 22); this.CopyMenuItem.ShortcutKeyDisplayString = "";
this.copyAllToolStripMenuItem.Text = "Copy All"; this.CopyMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C)));
this.copyAllToolStripMenuItem.Click += new System.EventHandler(this.copyAllToolStripMenuItem_Click); this.CopyMenuItem.Size = new System.Drawing.Size(164, 22);
// this.CopyMenuItem.Text = "&Copy";
// optionsToolStripMenuItem this.CopyMenuItem.Click += new System.EventHandler(this.CopyMenuItem_Click);
// //
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { // SelectAllMenuItem
this.setMaxWindowLinesToolStripMenuItem, //
this.SelectAllMenuItem.Name = "SelectAllMenuItem";
this.SelectAllMenuItem.ShortcutKeyDisplayString = "";
this.SelectAllMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A)));
this.SelectAllMenuItem.Size = new System.Drawing.Size(164, 22);
this.SelectAllMenuItem.Text = "Select &All";
this.SelectAllMenuItem.Click += new System.EventHandler(this.SelectAllMenuItem_Click);
//
// OptionsSubMenu
//
this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.MaxLinesMenuItem,
this.toolStripSeparator2, this.toolStripSeparator2,
this.autoloadToolStripMenuItem, this.AutoloadMenuItem,
this.saveWindowPositionToolStripMenuItem}); this.SaveWindowPositionMenuItem,
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.AlwaysOnTopMenuItem});
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.OptionsSubMenu.Name = "OptionsSubMenu";
this.optionsToolStripMenuItem.Text = "&Options"; this.OptionsSubMenu.Size = new System.Drawing.Size(61, 20);
this.optionsToolStripMenuItem.DropDownOpened += new System.EventHandler(this.optionsToolStripMenuItem_DropDownOpened); this.OptionsSubMenu.Text = "&Options";
// this.OptionsSubMenu.DropDownOpened += new System.EventHandler(this.OptionsSubMenu_DropDownOpened);
// setMaxWindowLinesToolStripMenuItem //
// // MaxLinesMenuItem
this.setMaxWindowLinesToolStripMenuItem.Name = "setMaxWindowLinesToolStripMenuItem"; //
this.setMaxWindowLinesToolStripMenuItem.Size = new System.Drawing.Size(201, 22); this.MaxLinesMenuItem.Name = "MaxLinesMenuItem";
this.setMaxWindowLinesToolStripMenuItem.Text = "&Set Max Window Lines..."; this.MaxLinesMenuItem.Size = new System.Drawing.Size(191, 22);
this.setMaxWindowLinesToolStripMenuItem.Click += new System.EventHandler(this.setMaxWindowLinesToolStripMenuItem_Click); this.MaxLinesMenuItem.Text = "&Set Max Lines...";
// this.MaxLinesMenuItem.Click += new System.EventHandler(this.MaxLinesMenuItem_Click);
// toolStripSeparator2 //
// // toolStripSeparator2
this.toolStripSeparator2.Name = "toolStripSeparator2"; //
this.toolStripSeparator2.Size = new System.Drawing.Size(198, 6); this.toolStripSeparator2.Name = "toolStripSeparator2";
// this.toolStripSeparator2.Size = new System.Drawing.Size(188, 6);
// autoloadToolStripMenuItem //
// // AutoloadMenuItem
this.autoloadToolStripMenuItem.Name = "autoloadToolStripMenuItem"; //
this.autoloadToolStripMenuItem.Size = new System.Drawing.Size(201, 22); this.AutoloadMenuItem.Name = "AutoloadMenuItem";
this.autoloadToolStripMenuItem.Text = "&Autoload"; this.AutoloadMenuItem.Size = new System.Drawing.Size(191, 22);
this.autoloadToolStripMenuItem.Click += new System.EventHandler(this.autoloadToolStripMenuItem_Click); this.AutoloadMenuItem.Text = "&Autoload";
// this.AutoloadMenuItem.Click += new System.EventHandler(this.AutoloadMenuItem_Click);
// saveWindowPositionToolStripMenuItem //
// // SaveWindowPositionMenuItem
this.saveWindowPositionToolStripMenuItem.Name = "saveWindowPositionToolStripMenuItem"; //
this.saveWindowPositionToolStripMenuItem.Size = new System.Drawing.Size(201, 22); this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem";
this.saveWindowPositionToolStripMenuItem.Text = "&Save Window Position"; this.SaveWindowPositionMenuItem.Size = new System.Drawing.Size(191, 22);
this.saveWindowPositionToolStripMenuItem.Click += new System.EventHandler(this.saveWindowPositionToolStripMenuItem_Click); this.SaveWindowPositionMenuItem.Text = "&Save Window Position";
// this.SaveWindowPositionMenuItem.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click);
// groupBox2 //
// // groupBox2
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) //
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.BrowseBox); this.groupBox2.Controls.Add(this.BrowseBox);
this.groupBox2.Controls.Add(this.FileBox); 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(620, 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 // BrowseBox
// //
this.BrowseBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(477, 19);
this.BrowseBox.Name = "BrowseBox"; this.BrowseBox.Name = "BrowseBox";
this.BrowseBox.Size = new System.Drawing.Size(54, 23); this.BrowseBox.Size = new System.Drawing.Size(54, 23);
this.BrowseBox.TabIndex = 20; this.BrowseBox.TabIndex = 20;
this.BrowseBox.Text = "&Browse"; this.BrowseBox.Text = "&Browse";
this.BrowseBox.UseVisualStyleBackColor = true; this.BrowseBox.UseVisualStyleBackColor = true;
this.BrowseBox.Visible = false; this.BrowseBox.Visible = false;
this.BrowseBox.Click += new System.EventHandler(this.BrowseBox_Click); this.BrowseBox.Click += new System.EventHandler(this.BrowseBox_Click);
// //
// FileBox // FileBox
// //
this.FileBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.FileBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.FileBox.Location = new System.Drawing.Point(229, 20); this.FileBox.Location = new System.Drawing.Point(229, 20);
this.FileBox.Name = "FileBox"; this.FileBox.Name = "FileBox";
this.FileBox.ReadOnly = true; this.FileBox.ReadOnly = true;
this.FileBox.Size = new System.Drawing.Size(242, 20); this.FileBox.Size = new System.Drawing.Size(242, 20);
this.FileBox.TabIndex = 15; this.FileBox.TabIndex = 15;
this.FileBox.TabStop = false; this.FileBox.TabStop = false;
this.FileBox.Visible = false; this.FileBox.Visible = false;
// //
// ToFileRadio // ToFileRadio
// //
this.ToFileRadio.AutoSize = true; this.ToFileRadio.AutoSize = true;
this.ToFileRadio.Location = new System.Drawing.Point(173, 22); this.ToFileRadio.Location = new System.Drawing.Point(173, 22);
this.ToFileRadio.Name = "ToFileRadio"; this.ToFileRadio.Name = "ToFileRadio";
this.ToFileRadio.Size = new System.Drawing.Size(50, 17); this.ToFileRadio.Size = new System.Drawing.Size(50, 17);
this.ToFileRadio.TabIndex = 10; this.ToFileRadio.TabIndex = 10;
this.ToFileRadio.Text = "to file"; this.ToFileRadio.Text = "to file";
this.ToFileRadio.UseVisualStyleBackColor = true; this.ToFileRadio.UseVisualStyleBackColor = true;
this.ToFileRadio.CheckedChanged += new System.EventHandler(this.ToFileRadio_CheckedChanged); this.ToFileRadio.CheckedChanged += new System.EventHandler(this.ToFileRadio_CheckedChanged);
// //
// ToWindowRadio // ToWindowRadio
// //
this.ToWindowRadio.AutoSize = true; this.ToWindowRadio.AutoSize = true;
this.ToWindowRadio.Checked = true; this.ToWindowRadio.Checked = true;
this.ToWindowRadio.Location = new System.Drawing.Point(94, 22); this.ToWindowRadio.Location = new System.Drawing.Point(94, 22);
this.ToWindowRadio.Name = "ToWindowRadio"; this.ToWindowRadio.Name = "ToWindowRadio";
this.ToWindowRadio.Size = new System.Drawing.Size(73, 17); this.ToWindowRadio.Size = new System.Drawing.Size(73, 17);
this.ToWindowRadio.TabIndex = 5; this.ToWindowRadio.TabIndex = 5;
this.ToWindowRadio.TabStop = true; this.ToWindowRadio.TabStop = true;
this.ToWindowRadio.Text = "to window"; this.ToWindowRadio.Text = "to window";
this.ToWindowRadio.UseVisualStyleBackColor = true; this.ToWindowRadio.UseVisualStyleBackColor = true;
// //
// ClearButton // ClearButton
// //
this.ClearButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(564, 19);
this.ClearButton.Name = "ClearButton"; this.ClearButton.Name = "ClearButton";
this.ClearButton.Size = new System.Drawing.Size(47, 23); this.ClearButton.Size = new System.Drawing.Size(47, 23);
this.ClearButton.TabIndex = 25; this.ClearButton.TabIndex = 25;
this.ClearButton.Text = "&Clear"; this.ClearButton.Text = "&Clear";
this.ClearButton.UseVisualStyleBackColor = true; this.ClearButton.UseVisualStyleBackColor = true;
this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click); this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click);
// //
// LoggingEnabled // LoggingEnabled
// //
this.LoggingEnabled.Appearance = System.Windows.Forms.Appearance.Button; this.LoggingEnabled.Appearance = System.Windows.Forms.Appearance.Button;
this.LoggingEnabled.AutoSize = true; this.LoggingEnabled.AutoSize = true;
this.LoggingEnabled.Location = new System.Drawing.Point(9, 19); this.LoggingEnabled.Location = new System.Drawing.Point(9, 19);
this.LoggingEnabled.Name = "LoggingEnabled"; this.LoggingEnabled.Name = "LoggingEnabled";
this.LoggingEnabled.Size = new System.Drawing.Size(55, 23); this.LoggingEnabled.Size = new System.Drawing.Size(55, 23);
this.LoggingEnabled.TabIndex = 1; this.LoggingEnabled.TabIndex = 1;
this.LoggingEnabled.Text = "&Logging"; this.LoggingEnabled.Text = "&Logging";
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);
// //
// TraceLogger // AlwaysOnTopMenuItem
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem";
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(191, 22);
this.ClientSize = new System.Drawing.Size(644, 539); this.AlwaysOnTopMenuItem.Text = "&Always on Top";
this.Controls.Add(this.groupBox2); this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click);
this.Controls.Add(this.TracerBox); //
this.Controls.Add(this.menuStrip1); // TraceLogger
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); //
this.KeyPreview = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.MainMenuStrip = this.menuStrip1; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.MinimumSize = new System.Drawing.Size(400, 230); this.ClientSize = new System.Drawing.Size(644, 539);
this.Name = "TraceLogger"; this.Controls.Add(this.groupBox2);
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Controls.Add(this.TracerBox);
this.Text = "TraceLogger"; this.Controls.Add(this.menuStrip1);
this.Load += new System.EventHandler(this.TraceLogger_Load); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TraceLogger_KeyDown); this.KeyPreview = true;
this.TracerBox.ResumeLayout(false); this.MainMenuStrip = this.menuStrip1;
this.menuStrip1.ResumeLayout(false); this.MinimumSize = new System.Drawing.Size(400, 230);
this.menuStrip1.PerformLayout(); this.Name = "TraceLogger";
this.groupBox2.ResumeLayout(false); this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.groupBox2.PerformLayout(); this.Text = "TraceLogger";
this.ResumeLayout(false); this.Load += new System.EventHandler(this.TraceLogger_Load);
this.PerformLayout(); this.TracerBox.ResumeLayout(false);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
} }
@ -321,25 +340,27 @@
private System.Windows.Forms.GroupBox TracerBox; private System.Windows.Forms.GroupBox TracerBox;
private MenuStripEx menuStrip1; private MenuStripEx menuStrip1;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem FileSubMenu;
private System.Windows.Forms.ToolStripMenuItem saveLogToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem SaveLogMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ExitMenuItem;
private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.CheckBox LoggingEnabled; private System.Windows.Forms.CheckBox LoggingEnabled;
private System.Windows.Forms.Button ClearButton; private System.Windows.Forms.Button ClearButton;
private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem OptionsSubMenu;
private System.Windows.Forms.ToolStripMenuItem autoloadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem AutoloadMenuItem;
private VirtualListView TraceView; private VirtualListView TraceView;
public System.Windows.Forms.ColumnHeader Script; public System.Windows.Forms.ColumnHeader Script;
private System.Windows.Forms.ToolStripMenuItem setMaxWindowLinesToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem MaxLinesMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem saveWindowPositionToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem SaveWindowPositionMenuItem;
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.TextBox FileBox;
private System.Windows.Forms.Button BrowseBox; private System.Windows.Forms.Button BrowseBox;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem EditSubMenu;
private System.Windows.Forms.ToolStripMenuItem copyAllToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem CopyMenuItem;
private System.Windows.Forms.ToolStripMenuItem SelectAllMenuItem;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
} }
} }

View File

@ -1,9 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO;
using BizHawk.Client.Common; using BizHawk.Client.Common;
@ -11,49 +12,43 @@ namespace BizHawk.Client.EmuHawk
{ {
public partial class TraceLogger : Form, IToolForm public partial class TraceLogger : Form, IToolForm
{ {
//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 // Make faster, such as not saving to disk until the logging is stopped, dont' add to Instructions list every frame, etc
//Remember window size // Remember window size
private readonly List<string> _instructions = new List<string>();
private readonly List<string> Instructions = new List<string>(); private FileInfo _logFile;
private FileInfo LogFile;
public bool AskSave() { return true; }
public bool UpdateBefore { get { return false; } }
public TraceLogger() public TraceLogger()
{ {
InitializeComponent(); InitializeComponent();
TraceView.QueryItemText += TraceView_QueryItemText; TraceView.QueryItemText += TraceView_QueryItemText;
TraceView.QueryItemBkColor += TraceView_QueryItemBkColor;
TraceView.VirtualMode = true; TraceView.VirtualMode = true;
TopMost = Global.Config.TraceLoggerOnTop;
Closing += (o, e) => SaveConfigSettings(); Closing += (o, e) => SaveConfigSettings();
} }
public void SaveConfigSettings() public bool UpdateBefore
{
get { return false; }
}
public bool AskSave()
{
return true;
}
private void SaveConfigSettings()
{ {
Global.CoreComm.Tracer.Enabled = false; Global.CoreComm.Tracer.Enabled = false;
Global.Config.TraceLoggerWndx = Location.X; Global.Config.TraceLoggerWndx = Location.X;
Global.Config.TraceLoggerWndy = Location.Y; Global.Config.TraceLoggerWndy = Location.Y;
} }
private void TraceView_QueryItemBkColor(int index, int column, ref Color color)
{
//TODO
}
private void TraceView_QueryItemText(int index, int column, out string text) private void TraceView_QueryItemText(int index, int column, out string text)
{ {
if (index < Instructions.Count) text = index < _instructions.Count ? _instructions[index] : String.Empty;
{
text = Instructions[index];
}
else
{
text = "";
}
} }
private void TraceLogger_Load(object sender, EventArgs e) private void TraceLogger_Load(object sender, EventArgs e)
@ -72,7 +67,15 @@ namespace BizHawk.Client.EmuHawk
public void UpdateValues() public void UpdateValues()
{ {
DoInstructions(); TraceView.BlazingFast = !GlobalWin.MainForm.EmulatorPaused;
if (ToWindowRadio.Checked)
{
LogToWindow();
}
else
{
LogToFile();
}
} }
public void Restart() public void Restart()
@ -97,16 +100,210 @@ namespace BizHawk.Client.EmuHawk
private void ClearList() private void ClearList()
{ {
Instructions.Clear(); _instructions.Clear();
TraceView.ItemCount = 0; TraceView.ItemCount = 0;
SetTracerBoxTitle(); SetTracerBoxTitle();
} }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void LogToFile()
{
using (var sw = new StreamWriter(_logFile.FullName, true))
{
sw.Write(Global.CoreComm.Tracer.TakeContents());
}
}
private void LogToWindow()
{
var instructions = Global.CoreComm.Tracer.TakeContents().Split('\n');
if (!String.IsNullOrWhiteSpace(instructions[0]))
{
_instructions.AddRange(instructions);
}
if (_instructions.Count >= Global.Config.TraceLoggerMaxLines)
{
var x = _instructions.Count - Global.Config.TraceLoggerMaxLines;
_instructions.RemoveRange(0, x);
}
TraceView.ItemCount = _instructions.Count;
}
private Point GetPromptPoint()
{
return PointToScreen(
new Point(TraceView.Location.X + 30, TraceView.Location.Y + 30)
);
}
private void SetTracerBoxTitle()
{
if (Global.CoreComm.Tracer.Enabled)
{
if (ToFileRadio.Checked)
{
TracerBox.Text = "Trace log - logging to file...";
}
else if (_instructions.Any())
{
TracerBox.Text = "Trace log - logging - " + _instructions.Count + " instructions";
}
else
{
TracerBox.Text = "Trace log - logging...";
}
}
else
{
if (_instructions.Any())
{
TracerBox.Text = "Trace log - " + _instructions.Count + " instructions";
}
else
{
TracerBox.Text = "Trace log";
}
}
}
private void CloseFile()
{
// TODO: save the remaining instructions in CoreComm
}
private FileInfo GetFileFromUser()
{
var sfd = new SaveFileDialog();
if (_logFile == null)
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + ".txt";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPath, null);
}
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.PathEntries.LogPath, null);
}
sfd.Filter = "Text Files (*.txt)|*.txt|Log Files (*.log)|*.log|All Files|*.*";
sfd.RestoreDirectory = true;
var result = sfd.ShowHawkDialog();
if (result == DialogResult.OK)
{
return new FileInfo(sfd.FileName);
}
else
{
return null;
}
}
private void DumpListToDisk(FileSystemInfo file)
{
using (var sw = new StreamWriter(file.FullName))
{
foreach (var instruction in _instructions)
{
sw.WriteLine(instruction);
}
}
}
#region Events
#region Menu Items
private void SaveLogMenuItem_Click(object sender, EventArgs e)
{
var file = GetFileFromUser();
if (file != null)
{
DumpListToDisk(file);
GlobalWin.OSD.AddMessage("Log dumped to " + file.FullName);
}
}
private void ExitMenuItem_Click(object sender, EventArgs e)
{ {
Close(); Close();
} }
private void CopyMenuItem_Click(object sender, EventArgs e)
{
var indices = TraceView.SelectedIndices;
if (indices.Count > 0)
{
var blob = new StringBuilder();
foreach (int index in indices)
{
blob.AppendLine(_instructions[index]);
}
blob.Remove(blob.Length - 2, 2); // Lazy way to not have a line break at the end
Clipboard.SetDataObject(blob.ToString());
}
}
private void SelectAllMenuItem_Click(object sender, EventArgs e)
{
for (var i = 0; i < _instructions.Count; i++)
{
TraceView.SelectItem(i, true);
}
}
private void MaxLinesMenuItem_Click(object sender, EventArgs e)
{
var prompt = new InputPrompt();
prompt.SetMessage("Max lines to display in the window");
prompt.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString());
prompt.TextInputType = InputPrompt.InputType.UNSIGNED;
prompt._Location = GetPromptPoint();
prompt.ShowDialog();
if (prompt.UserOK)
{
var max = int.Parse(prompt.UserText);
if (max > 0)
{
Global.Config.TraceLoggerMaxLines = max;
}
}
}
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
{
AutoloadMenuItem.Checked = Global.Config.TraceLoggerAutoLoad;
SaveWindowPositionMenuItem.Checked = Global.Config.TraceLoggerSaveWindowPosition;
AlwaysOnTopMenuItem.Checked = Global.Config.TraceLoggerOnTop;
}
private void AutoloadMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TraceLoggerAutoLoad ^= true;
}
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TraceLoggerSaveWindowPosition ^= true;
}
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TraceLoggerOnTop ^= true;
TopMost = Global.Config.TraceLoggerOnTop;
}
#endregion
#region Dialog and ListView Events
private void LoggingEnabled_CheckedChanged(object sender, EventArgs e) private void LoggingEnabled_CheckedChanged(object sender, EventArgs e)
{ {
Global.CoreComm.Tracer.Enabled = LoggingEnabled.Checked; Global.CoreComm.Tracer.Enabled = LoggingEnabled.Checked;
@ -118,115 +315,13 @@ namespace BizHawk.Client.EmuHawk
ClearList(); ClearList();
} }
private void DoInstructions() private void BrowseBox_Click(object sender, EventArgs e)
{ {
if (ToWindowRadio.Checked) var file = GetFileFromUser();
if (file != null)
{ {
LogToWindow(); _logFile = file;
SetTracerBoxTitle(); FileBox.Text = _logFile.FullName;
}
else
{
LogToFile();
}
}
private void LogToFile()
{
using (StreamWriter sw = new StreamWriter(LogFile.FullName, true))
{
sw.Write(Global.CoreComm.Tracer.TakeContents());
}
}
private void LogToWindow()
{
string[] instructions = Global.CoreComm.Tracer.TakeContents().Split('\n');
if (!String.IsNullOrWhiteSpace(instructions[0]))
{
foreach (string s in instructions)
{
Instructions.Add(s);
}
}
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)
{
Global.Config.TraceLoggerAutoLoad ^= true;
}
private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
autoloadToolStripMenuItem.Checked = Global.Config.TraceLoggerAutoLoad;
saveWindowPositionToolStripMenuItem.Checked = Global.Config.TraceLoggerSaveWindowPosition;
}
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TraceLoggerSaveWindowPosition ^= true;
}
private Point GetPromptPoint()
{
Point p = new Point(TraceView.Location.X + 30, TraceView.Location.Y + 30);
return PointToScreen(p);
}
private void setMaxWindowLinesToolStripMenuItem_Click(object sender, EventArgs e)
{
InputPrompt p = new InputPrompt();
p.SetMessage("Max lines to display in the window");
p.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString());
p.TextInputType = InputPrompt.InputType.UNSIGNED;
p._Location = GetPromptPoint();
p.ShowDialog();
if (p.UserOK)
{
int x = int.Parse(p.UserText);
if (x > 0)
{
Global.Config.TraceLoggerMaxLines = x;
}
}
}
private void SetTracerBoxTitle()
{
if (Global.CoreComm.Tracer.Enabled)
{
if (ToFileRadio.Checked)
{
TracerBox.Text = "Trace log - logging to file...";
}
else if (Instructions.Count > 0)
{
TracerBox.Text = "Trace log - logging - " + Instructions.Count.ToString() + " instructions";
}
else
{
TracerBox.Text = "Trace log - logging...";
}
}
else
{
if (Instructions.Count > 0)
{
TracerBox.Text = "Trace log - " + Instructions.Count.ToString() + " instructions";
}
else
{
TracerBox.Text = "Trace log";
}
} }
} }
@ -236,142 +331,38 @@ namespace BizHawk.Client.EmuHawk
{ {
FileBox.Visible = true; FileBox.Visible = true;
BrowseBox.Visible = true; BrowseBox.Visible = true;
string name = PathManager.FilesystemSafeName(Global.Game); var name = PathManager.FilesystemSafeName(Global.Game);
string filename = Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPath, null), name) + ".txt"; var filename = Path.Combine(PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPath, null), name) + ".txt";
LogFile = new FileInfo(filename); _logFile = new FileInfo(filename);
if (LogFile.Directory != null && !LogFile.Directory.Exists) if (_logFile.Directory != null && !_logFile.Directory.Exists)
{ {
LogFile.Directory.Create(); _logFile.Directory.Create();
} }
if (LogFile.Exists)
if (_logFile.Exists)
{ {
LogFile.Delete(); _logFile.Delete();
LogFile.Create(); _logFile.Create();
} }
else else
{ {
LogFile.Create(); _logFile.Create();
} }
FileBox.Text = LogFile.FullName; FileBox.Text = _logFile.FullName;
} }
else else
{ {
CloseFile(); CloseFile();
FileBox.Visible = false; FileBox.Visible = false;
BrowseBox.Visible = false; BrowseBox.Visible = false;
} }
SetTracerBoxTitle(); SetTracerBoxTitle();
} }
private void CloseFile() #endregion
{
//TODO: save the remaining instructions in CoreComm
}
private void TraceView_KeyDown(object sender, KeyEventArgs e) #endregion
{
if (e.Control && e.KeyCode == Keys.C)
{
ListView.SelectedIndexCollection indexes = TraceView.SelectedIndices;
if (indexes.Count > 0)
{
StringBuilder blob = new StringBuilder();
foreach (int x in indexes)
{
blob.Append(Instructions[x]);
blob.Append("\r\n");
}
blob.Remove(blob.Length - 2, 2); //Lazy way to not have a line break at the end
Clipboard.SetDataObject(blob.ToString());
}
}
}
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.PathEntries.LogPath, null);
}
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.PathEntries.LogPath, null);
}
sfd.Filter = "Text Files (*.txt)|*.txt|Log Files (*.log)|*.log|All Files|*.*";
sfd.RestoreDirectory = true;
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
}
return new FileInfo(sfd.FileName);
}
private void saveLogToolStripMenuItem_Click(object sender, EventArgs e)
{
var file = GetFileFromUser();
if (file != null)
{
DumpListToDisk(file);
GlobalWin.OSD.AddMessage("Log dumped to " + file.FullName);
}
}
private void DumpListToDisk(FileInfo file)
{
using (StreamWriter sw = new StreamWriter(file.FullName))
{
foreach (string s in Instructions)
{
sw.WriteLine(s);
}
}
}
void CopyAllToClipboard()
{
StringBuilder sb = new StringBuilder();
foreach (string s in Instructions)
sb.AppendLine(s);
string ss = sb.ToString();
if (!string.IsNullOrEmpty(ss))
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
}
private void TraceLogger_KeyDown(object sender, KeyEventArgs e)
{
if (ModifierKeys.HasFlag(Keys.Control) && e.KeyCode == Keys.C)
CopyAllToClipboard();
}
private void copyAllToolStripMenuItem_Click(object sender, EventArgs e)
{
CopyAllToClipboard();
}
} }
} }

View File

@ -93,8 +93,7 @@ namespace BizHawk.Emulation.Common
{ {
if (logging) if (logging)
{ {
buffer.Append(content); buffer.AppendLine(content);
buffer.Append('\n');
} }
} }