mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-09 14:34:05 +02:00
Add exception handling and logging
This commit is contained in:
parent
ebd17e1544
commit
147c268ef8
@ -3,6 +3,7 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Windows.Forms;
|
||||
using TweetDick.Core.Handling;
|
||||
|
||||
namespace TweetDick.Configuration{
|
||||
@ -71,8 +72,8 @@ public bool Save(){
|
||||
}
|
||||
|
||||
return true;
|
||||
}catch(Exception){
|
||||
// TODO
|
||||
}catch(Exception e){
|
||||
Program.HandleException("Could not save the configuration file.",e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -87,11 +88,11 @@ public static UserConfig Load(string file){
|
||||
config.file = file;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}catch(FileNotFoundException){
|
||||
}catch(Exception){
|
||||
// TODO
|
||||
}catch(Exception e){
|
||||
Program.HandleException("Could not open the configuration file.",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,13 @@ public static void Run(){
|
||||
|
||||
formWait.ShowWorkDialog(() => {
|
||||
if (!BeginMigration(decision,ex => formWait.Invoke(new Action(() => {
|
||||
if (ex != null){
|
||||
MessageBox.Show(ex.ToString()); // TODO
|
||||
}
|
||||
|
||||
formWait.Close();
|
||||
|
||||
if (ex != null){
|
||||
Program.HandleException("An unexpected exception has occurred during the migration process.",ex);
|
||||
return;
|
||||
}
|
||||
|
||||
Program.UserConfig.IgnoreMigration = true;
|
||||
Program.UserConfig.Save();
|
||||
})))){
|
||||
|
35
Program.cs
35
Program.cs
@ -1,8 +1,10 @@
|
||||
using CefSharp;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using TweetDick.Configuration;
|
||||
using TweetDick.Core;
|
||||
@ -79,6 +81,14 @@ private static void Main(){
|
||||
#endif
|
||||
});
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
|
||||
Exception ex = args.ExceptionObject as Exception;
|
||||
|
||||
if (ex != null){
|
||||
HandleException("An unhandled exception has occurred.",ex);
|
||||
}
|
||||
};
|
||||
|
||||
Application.ApplicationExit += (sender, args) => {
|
||||
UserConfig.Save();
|
||||
LockManager.Unlock();
|
||||
@ -87,5 +97,30 @@ private static void Main(){
|
||||
|
||||
Application.Run(new FormBrowser());
|
||||
}
|
||||
|
||||
public static void HandleException(string message, Exception e){
|
||||
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(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"td-log.txt"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string data){
|
||||
StringBuilder build = new StringBuilder();
|
||||
|
||||
if (!File.Exists("td-log.txt")){
|
||||
build.Append("Please, report all issues to: https://github.com/chylex/TweetDick/issues\r\n\r\n");
|
||||
}
|
||||
|
||||
build.Append("[").Append(DateTime.Now.ToString("G")).Append("]\r\n");
|
||||
build.Append(data).Append("\r\n\r\n");
|
||||
|
||||
try{
|
||||
File.AppendAllText("td-log.txt",build.ToString(),Encoding.UTF8);
|
||||
}catch{
|
||||
// oops
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user