From 595f466ded500f6ff7bebc574fd03506ac4ea4e0 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 17 Oct 2015 01:18:37 -0500 Subject: [PATCH] add a custom exception display box --- .../BizHawk.Client.Common.csproj | 11 ++ .../ExceptionBox.Designer.cs | 148 ++++++++++++++++++ BizHawk.Client.Common/ExceptionBox.cs | 85 ++++++++++ BizHawk.Client.Common/ExceptionBox.resx | 123 +++++++++++++++ BizHawk.Client.EmuHawk/Program.cs | 9 +- 5 files changed, 368 insertions(+), 8 deletions(-) create mode 100644 BizHawk.Client.Common/ExceptionBox.Designer.cs create mode 100644 BizHawk.Client.Common/ExceptionBox.cs create mode 100644 BizHawk.Client.Common/ExceptionBox.resx diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index 3be66de629..118a38e7b3 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -111,6 +111,12 @@ + + Form + + + ExceptionBox.cs + @@ -270,6 +276,11 @@ BizHawk.Bizware.BizwareGL + + + ExceptionBox.cs + + diff --git a/BizHawk.Client.Common/ExceptionBox.Designer.cs b/BizHawk.Client.Common/ExceptionBox.Designer.cs new file mode 100644 index 0000000000..36bda19aca --- /dev/null +++ b/BizHawk.Client.Common/ExceptionBox.Designer.cs @@ -0,0 +1,148 @@ +namespace BizHawk.Client.Common +{ + partial class ExceptionBox + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.btnOK = new System.Windows.Forms.Button(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.txtException = new System.Windows.Forms.TextBox(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.btnCopy = new System.Windows.Forms.Button(); + this.lblDone = new BizHawk.Client.Common.ExceptionBox.MyLabel(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.tableLayoutPanel1.SuspendLayout(); + this.flowLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // btnOK + // + this.btnOK.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnOK.Location = new System.Drawing.Point(625, 304); + this.btnOK.Name = "btnOK"; + this.btnOK.Size = new System.Drawing.Size(75, 23); + this.btnOK.TabIndex = 0; + this.btnOK.Text = "OK"; + this.btnOK.UseVisualStyleBackColor = true; + this.btnOK.Click += new System.EventHandler(this.btnOK_Click); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.Controls.Add(this.btnOK, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.txtException, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 1); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(703, 330); + this.tableLayoutPanel1.TabIndex = 1; + // + // txtException + // + this.tableLayoutPanel1.SetColumnSpan(this.txtException, 2); + this.txtException.Dock = System.Windows.Forms.DockStyle.Fill; + this.txtException.Location = new System.Drawing.Point(3, 3); + this.txtException.Multiline = true; + this.txtException.Name = "txtException"; + this.txtException.ReadOnly = true; + this.txtException.Size = new System.Drawing.Size(697, 295); + this.txtException.TabIndex = 1; + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.AutoSize = true; + this.flowLayoutPanel1.Controls.Add(this.btnCopy); + this.flowLayoutPanel1.Controls.Add(this.lblDone); + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 301); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(0); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(87, 29); + this.flowLayoutPanel1.TabIndex = 2; + // + // btnCopy + // + this.btnCopy.Location = new System.Drawing.Point(3, 3); + this.btnCopy.Name = "btnCopy"; + this.btnCopy.Size = new System.Drawing.Size(75, 23); + this.btnCopy.TabIndex = 3; + this.btnCopy.Text = "Copy"; + this.btnCopy.UseVisualStyleBackColor = true; + this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click); + // + // lblDone + // + this.lblDone.AutoSize = true; + this.lblDone.Location = new System.Drawing.Point(84, 10); + this.lblDone.Margin = new System.Windows.Forms.Padding(3, 10, 3, 0); + this.lblDone.Name = "lblDone"; + this.lblDone.Size = new System.Drawing.Size(0, 13); + this.lblDone.TabIndex = 4; + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // ExceptionBox + // + this.AcceptButton = this.btnOK; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btnOK; + this.ClientSize = new System.Drawing.Size(703, 330); + this.Controls.Add(this.tableLayoutPanel1); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ExceptionBox"; + this.Text = "Exception"; + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.flowLayoutPanel1.ResumeLayout(false); + this.flowLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button btnOK; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.TextBox txtException; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.Button btnCopy; + private ExceptionBox.MyLabel lblDone; + } +} \ No newline at end of file diff --git a/BizHawk.Client.Common/ExceptionBox.cs b/BizHawk.Client.Common/ExceptionBox.cs new file mode 100644 index 0000000000..b92dc91103 --- /dev/null +++ b/BizHawk.Client.Common/ExceptionBox.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace BizHawk.Client.Common +{ + public partial class ExceptionBox : Form + { + public ExceptionBox(Exception ex) + { + InitializeComponent(); + txtException.Text = ex.ToString(); + timer1.Start(); + } + + private void btnCopy_Click(object sender, EventArgs e) + { + DoCopy(); + } + + void DoCopy() + { + string txt = txtException.Text; + System.Windows.Forms.Clipboard.SetText(txt); + try + { + if (System.Windows.Forms.Clipboard.GetText() == txt) + { + lblDone.Text = "Done!"; + lblDone.ForeColor = SystemColors.ControlText; + return; + } + } + catch + { + } + + lblDone.Text = "ERROR!"; + lblDone.ForeColor = SystemColors.ControlText; + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if (keyData == (Keys.C | Keys.Control)) + { + DoCopy(); + return true; + } + + return false; + } + + private void btnOK_Click(object sender, EventArgs e) + { + Close(); + } + + private void timer1_Tick(object sender, EventArgs e) + { + int a = lblDone.ForeColor.A - 16; + if (a < 0) a = 0; + lblDone.ForeColor = Color.FromArgb(a, lblDone.ForeColor); + } + + //http://stackoverflow.com/questions/2636065/alpha-in-forecolor + class MyLabel : Label + { + protected override void OnPaint(PaintEventArgs e) + { + Rectangle rc = this.ClientRectangle; + StringFormat fmt = new StringFormat(StringFormat.GenericTypographic); + using (var br = new SolidBrush(this.ForeColor)) + { + e.Graphics.DrawString(this.Text, this.Font, br, rc, fmt); + } + } + } + + } +} diff --git a/BizHawk.Client.Common/ExceptionBox.resx b/BizHawk.Client.Common/ExceptionBox.resx new file mode 100644 index 0000000000..aac33d5a29 --- /dev/null +++ b/BizHawk.Client.Common/ExceptionBox.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/Program.cs b/BizHawk.Client.EmuHawk/Program.cs index cd4b51be9b..8267396640 100644 --- a/BizHawk.Client.EmuHawk/Program.cs +++ b/BizHawk.Client.EmuHawk/Program.cs @@ -198,14 +198,7 @@ namespace BizHawk.Client.EmuHawk } catch (Exception e) { - string message = e.ToString(); - if (e.InnerException != null) - { - message += "\n\nInner Exception:\n\n" + e.InnerException; - } - - message += "\n\nStackTrace:\n" + e.StackTrace; - MessageBox.Show(message); + new ExceptionBox(e).ShowDialog(); } #if WINDOWS finally