2020-07-07 07:15:45 +12:00
|
|
|
|
// <copyright file="Program.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
2019-07-05 05:04:14 +12:00
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
|
|
2020-03-24 00:32:47 +13:00
|
|
|
|
internal static class Program
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
2020-11-08 22:07:55 +13:00
|
|
|
|
private static bool isStartup = true;
|
|
|
|
|
|
2019-07-05 05:04:14 +12:00
|
|
|
|
[STAThread]
|
2021-09-23 22:00:50 +12:00
|
|
|
|
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();
|
2020-05-05 05:43:47 +12:00
|
|
|
|
Translator.Initialize();
|
2021-09-23 22:00:50 +12:00
|
|
|
|
Config.SetFolderByWindowsContextMenu(args);
|
2021-10-05 04:47:39 +13:00
|
|
|
|
Config.LoadOrSetByUser();
|
2022-01-02 07:10:20 +13:00
|
|
|
|
Config.Initialize();
|
2020-05-06 23:59:31 +12:00
|
|
|
|
|
2022-02-08 04:41:30 +13:00
|
|
|
|
if (SingleAppInstance.Initialize())
|
2021-10-05 04:47:39 +13:00
|
|
|
|
{
|
2022-01-02 07:10:20 +13:00
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
|
Application.ThreadException += (sender, e) => AskUserSendError(e.Exception);
|
|
|
|
|
Scaling.Initialize();
|
|
|
|
|
FolderOptions.Initialize();
|
|
|
|
|
|
|
|
|
|
using (new App())
|
|
|
|
|
{
|
|
|
|
|
isStartup = false;
|
|
|
|
|
Log.WriteApplicationRuns();
|
|
|
|
|
Application.Run();
|
|
|
|
|
}
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
2021-06-26 23:24:56 +12:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2020-03-24 00:24:16 +13:00
|
|
|
|
|
2020-07-07 02:46:47 +12:00
|
|
|
|
static void AskUserSendError(Exception ex)
|
2020-03-15 22:27:05 +13:00
|
|
|
|
{
|
2020-03-17 02:45:19 +13:00
|
|
|
|
Log.Error("Application Crashed", ex);
|
2020-03-15 22:27:05 +13:00
|
|
|
|
|
2022-02-20 01:59:51 +13:00
|
|
|
|
DialogResult dialogResult = MessageBox.Show(
|
2020-07-07 07:15:45 +12:00
|
|
|
|
"A problem has been encountered and the application needs to restart. " +
|
|
|
|
|
"Reporting this error will help us make our product better. " +
|
2022-02-20 01:59:51 +13:00
|
|
|
|
"Press 'Yes' to open your standard email app (emailto: Markus@Hofknecht.eu). " + Environment.NewLine +
|
2022-02-23 04:52:02 +13:00
|
|
|
|
@"You can also create an issue manually here https://github.com/Hofknecht/SystemTrayMenu/issues" + Environment.NewLine +
|
2022-02-20 01:59:51 +13:00
|
|
|
|
"Press 'Cancel' to quit SystemTrayMenu.",
|
|
|
|
|
"SystemTrayMenu Crashed",
|
|
|
|
|
MessageBoxButtons.YesNoCancel);
|
|
|
|
|
|
|
|
|
|
if (dialogResult == DialogResult.Yes)
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
2020-03-30 06:26:45 +13: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
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 01:59:51 +13:00
|
|
|
|
if (!isStartup && dialogResult != DialogResult.Cancel)
|
2020-11-08 22:07:55 +13:00
|
|
|
|
{
|
|
|
|
|
AppRestart.ByThreadException();
|
|
|
|
|
}
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|