SystemTrayMenu/Business/Program.cs

83 lines
2.6 KiB
C#
Raw Normal View History

// <copyright file="Program.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
2019-07-05 05:04:14 +12:00
namespace SystemTrayMenu
{
using System;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using SystemTrayMenu.Utilities;
internal static class Program
2019-07-05 05:04:14 +12:00
{
private static bool isStartup = true;
2019-07-05 05:04:14 +12:00
[STAThread]
private static void Main(string[] args)
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();
2020-05-05 05:43:47 +12:00
Translator.Initialize();
Config.Initialize();
Config.SetFolderByWindowsContextMenu(args);
2020-03-17 02:45:19 +13:00
if (Config.LoadOrSetByUser())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += ThreadException;
static void ThreadException(object s, ThreadExceptionEventArgs t)
2020-03-17 02:45:19 +13:00
{
AskUserSendError(t.Exception);
}
2019-07-05 05:04:14 +12:00
2020-05-06 23:59:31 +12:00
Scaling.Initialize();
FolderOptions.Initialize();
2020-05-06 12:39:38 +12:00
using (new App())
2019-07-05 05:04:14 +12:00
{
isStartup = false;
2020-03-17 09:05:52 +13:00
Log.WriteApplicationRuns();
2019-07-05 05:04:14 +12:00
Application.Run();
}
}
Config.Dispose();
2019-07-05 05:04:14 +12:00
}
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
}
static void AskUserSendError(Exception ex)
{
2020-03-17 02:45:19 +13:00
Log.Error("Application Crashed", ex);
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
{
Log.ProcessStart("mailto:" + "markus@hofknecht.eu" +
2020-05-03 05:30:50 +12:00
"?subject=SystemTrayMenu Bug reported " +
Assembly.GetEntryAssembly().GetName().Version +
2020-03-17 02:45:19 +13:00
"&body=" + ex.ToString());
2019-07-05 05:04:14 +12:00
}
if (!isStartup)
{
AppRestart.ByThreadException();
}
2019-07-05 05:04:14 +12:00
}
}
}
}