2022-10-23 11:02:31 +13:00
// <copyright file="Program.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu
{
using System ;
using System.Reflection ;
using System.Windows ;
using SystemTrayMenu.Utilities ;
internal static class Program
{
private static bool isStartup = true ;
[STAThread]
private static void Main ( string [ ] args )
{
try
{
Log . Initialize ( ) ;
Translator . Initialize ( ) ;
Config . SetFolderByWindowsContextMenu ( args ) ;
Config . LoadOrSetByUser ( ) ;
Config . Initialize ( ) ;
2023-05-16 09:26:03 +12:00
// Without a valid path we cannot do anything, just close application
if ( string . IsNullOrEmpty ( Config . Path ) )
{
MessageBox . Show (
Translator . GetText ( "Your root directory for the app does not exist or is empty! Change the root directory or put some files, directories or shortcuts into the root directory." ) ,
"SystemTrayMenu" ,
MessageBoxButton . OK ) ;
return ;
}
2022-10-23 11:02:31 +13:00
if ( SingleAppInstance . Initialize ( ) )
{
AppDomain currentDomain = AppDomain . CurrentDomain ;
currentDomain . UnhandledException + = ( sender , args )
= > AskUserSendError ( ( Exception ) args . ExceptionObject ) ;
Scaling . Initialize ( ) ;
FolderOptions . Initialize ( ) ;
2023-05-08 10:14:23 +12:00
using App app = new ( ) ;
app . InitializeComponent ( ) ;
isStartup = false ;
Log . WriteApplicationRuns ( ) ;
app . Run ( ) ;
2022-10-23 11:02:31 +13:00
}
}
catch ( Exception ex )
{
AskUserSendError ( ex ) ;
}
finally
{
Log . Close ( ) ;
}
static void AskUserSendError ( Exception ex )
{
Log . Error ( "Application Crashed" , ex ) ;
MessageBoxResult dialogResult = MessageBox . Show (
2023-04-30 04:52:52 +12:00
"A problem has been encountered and SystemTrayMenu needs to restart. " +
"Reporting this error will help us making our product better." +
Environment . NewLine + Environment . NewLine +
"We kindly ask you to press 'Yes' and send us the crash report before restarting the application. " +
"This will open your standard email app and prepare a mail that you can directly send off. " +
"Alternatively, you can also create an issue manually here: https://github.com/Hofknecht/SystemTrayMenu/issues" +
Environment . NewLine + Environment . NewLine +
"Pressing 'No' will only restart the application." +
Environment . NewLine +
"Pressing 'Cancel' will quit the application." ,
2022-10-23 11:02:31 +13:00
"SystemTrayMenu Crashed" ,
MessageBoxButton . YesNoCancel ) ;
if ( dialogResult = = MessageBoxResult . Yes )
{
2022-12-04 10:41:03 +13:00
Version ? version = Assembly . GetEntryAssembly ( ) ? . GetName ( ) . Version ;
2022-10-23 11:02:31 +13:00
Log . ProcessStart ( "mailto:" + "markus@hofknecht.eu" +
"?subject=SystemTrayMenu Bug reported " +
2022-12-04 10:41:03 +13:00
( version ! = null ? version . ToString ( ) : string . Empty ) +
2022-10-23 11:02:31 +13:00
"&body=" + ex . ToString ( ) ) ;
}
if ( ! isStartup & & dialogResult ! = MessageBoxResult . Cancel )
{
AppRestart . ByThreadException ( ) ;
}
}
}
}
2023-04-30 04:52:52 +12:00
}