1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 11:34:05 +02:00

Create a Reporter class with improved HandleException code

This commit is contained in:
chylex 2016-09-20 16:34:56 +02:00
parent 27971e09cd
commit 3176b6cb8f
3 changed files with 46 additions and 9 deletions

View File

@ -179,15 +179,8 @@ private static string GetDataStoragePath(){
}
}
public static void HandleException(string message, Exception e){
if (Log(e.ToString())){
if (MessageBox.Show(message+"\r\nDo you want to open the log file to report the issue?", BrandName+" Has Failed :(", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) == DialogResult.Yes){
Process.Start(LogFilePath);
}
}
else{
MessageBox.Show(message+"\r\nFailed writing the error into the log file.\r\nOriginal exception: "+e, BrandName+" Has Failed :(", MessageBoxButtons.OK);
}
public static void HandleException(string message, Exception e){ // TODO replace all uses
Reporter.HandleException(BrandName+" Has Failed :(", message, false, new Exception());
}
public static bool Log(string data){

43
Reporter.cs Normal file
View File

@ -0,0 +1,43 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using TweetDck.Core.Other;
namespace TweetDck{
static class Reporter{
public static void HandleException(string caption, string message, bool canIgnore, Exception e){
Program.Log(e.ToString());
FormMessage form = new FormMessage(caption, message+"\r\nError: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
form.AddButton("Exit");
Button btnIgnore = form.AddButton("Ignore");
Button btnOpenLog = new Button{
Anchor = AnchorStyles.Bottom | AnchorStyles.Left,
Location = new Point(12, 12),
Margin = new Padding(0, 0, 48, 0),
Size = new Size(88, 26),
Text = "Open Log File",
UseVisualStyleBackColor = true
};
btnOpenLog.Click += (sender, args) => Process.Start(Program.LogFilePath);
form.AddActionControl(btnOpenLog);
if (!canIgnore){
btnIgnore.Enabled = false;
}
if (form.ShowDialog() == DialogResult.OK){
if (form.ClickedButton == btnIgnore){
return;
}
}
Environment.Exit(1);
}
}
}

View File

@ -213,6 +213,7 @@
<Compile Include="Plugins\Events\PluginLoadEventArgs.cs" />
<Compile Include="Plugins\PluginManager.cs" />
<Compile Include="Plugins\PluginScriptGenerator.cs" />
<Compile Include="Reporter.cs" />
<Compile Include="Updates\FormUpdateDownload.cs">
<SubType>Form</SubType>
</Compile>