SystemTrayMenu/Business/Program.cs

68 lines
2.2 KiB
C#
Raw Normal View History

2020-03-17 09:05:52 +13:00
using System;
2019-07-05 05:04:14 +12:00
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using SystemTrayMenu.Utilities;
2019-07-05 05:04:14 +12:00
namespace SystemTrayMenu
{
internal static class Program
2019-07-05 05:04:14 +12:00
{
[STAThread]
private static void Main()
2019-07-05 05:04:14 +12:00
{
2020-03-17 02:45:19 +13:00
try
2019-07-05 05:04:14 +12:00
{
2020-03-17 02:45:19 +13:00
Log.Initialize();
SingleAppInstance.Initialize();
Language.Initialize();
2019-07-05 05:04:14 +12:00
2020-03-17 03:57:51 +13:00
Config.UpgradeIfNotUpgraded();
2020-03-17 02:45:19 +13:00
if (Config.LoadOrSetByUser())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += ThreadException;
void ThreadException(object s, ThreadExceptionEventArgs t)
{
AskUserSendError(t.Exception);
}
2019-07-05 05:04:14 +12:00
2020-03-17 02:45:19 +13:00
Scaling.Initialize();
2020-03-17 03:57:51 +13:00
FolderOptions.Initialize();
2019-07-05 05:04:14 +12:00
2020-03-17 02:45:19 +13:00
using (new SystemTrayMenu())
2019-07-05 05:04:14 +12:00
{
2020-03-17 09:05:52 +13:00
Log.WriteApplicationRuns();
2019-07-05 05:04:14 +12:00
Application.Run();
}
}
}
catch (Exception ex)
{
2020-03-17 02:45:19 +13:00
AskUserSendError(ex);
2019-07-05 05:04:14 +12:00
}
finally
{
2020-03-17 09:05:52 +13:00
Log.Close();
2019-07-05 05:04:14 +12:00
}
2020-03-17 02:45:19 +13:00
void AskUserSendError(Exception ex)
{
2020-03-17 02:45:19 +13:00
Log.Error("Application Crashed", ex);
2020-03-17 02:45:19 +13:00
#warning [Feature] When Error ask user to send us #47, todo own dialog, lines here too long
if (MessageBox.Show("A problem has been encountered and the application needs to restart. " +
"Reporting this error will help us make our product better. Press yes to open your standard email app.",
"SystemTrayMenu BugSplat", MessageBoxButtons.YesNo) == DialogResult.Yes)
2019-07-05 05:04:14 +12:00
{
2020-03-17 02:45:19 +13:00
Process.Start("mailto:" + "markus@hofknecht.eu" +
"?subject=SystemTrayMenu Bug reported" +
"&body=" + ex.ToString());
2019-07-05 05:04:14 +12:00
}
2020-03-17 09:05:52 +13:00
AppRestart.ByThreadException();
2019-07-05 05:04:14 +12:00
}
}
}
}