2019-04-22 18:41:43 +12:00
using System ;
using System.Collections.Generic ;
using System.Configuration ;
using System.Data ;
using System.Linq ;
2019-05-04 23:07:52 +12:00
using System.Reflection ;
2019-04-22 18:41:43 +12:00
using System.Threading.Tasks ;
using System.Windows ;
using ModAssistant ;
namespace ModAssistant
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static string BeatSaberInstallDirectory ;
public static string BeatSaberInstallType ;
public static bool SaveModSelection ;
public static bool CheckInstalledMods ;
2019-05-04 23:07:52 +12:00
public static bool SelectInstalledMods ;
public static string Version = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) ;
2019-04-22 18:41:43 +12:00
public static List < string > SavedMods = ModAssistant . Properties . Settings . Default . SavedMods . Split ( ',' ) . ToList ( ) ;
private void Application_Startup ( object sender , StartupEventArgs e )
{
2019-05-26 16:17:27 +12:00
if ( ModAssistant . Properties . Settings . Default . UpgradeRequired )
{
ModAssistant . Properties . Settings . Default . Upgrade ( ) ;
ModAssistant . Properties . Settings . Default . UpgradeRequired = false ;
ModAssistant . Properties . Settings . Default . Save ( ) ;
}
2019-05-05 03:05:48 +12:00
Version = Version . Substring ( 0 , Version . Length - 2 ) ;
2019-04-22 18:41:43 +12:00
BeatSaberInstallDirectory = Utils . GetInstallDir ( ) ;
2019-05-30 16:03:28 +12:00
while ( String . IsNullOrEmpty ( App . BeatSaberInstallDirectory ) )
{
if ( System . Windows . Forms . MessageBox . Show ( $"Press OK to try again, or Cancel to close application." , $"Couldn't find your Beat Saber install folder!" , System . Windows . Forms . MessageBoxButtons . OKCancel ) = = System . Windows . Forms . DialogResult . OK )
{
App . BeatSaberInstallDirectory = Utils . GetManualDir ( ) ;
}
else
{
Environment . Exit ( 0 ) ;
}
}
2019-04-22 18:41:43 +12:00
BeatSaberInstallType = ModAssistant . Properties . Settings . Default . StoreType ;
SaveModSelection = ModAssistant . Properties . Settings . Default . SaveSelected ;
2019-04-22 18:49:03 +12:00
CheckInstalledMods = ModAssistant . Properties . Settings . Default . CheckInstalled ;
2019-05-04 23:07:52 +12:00
SelectInstalledMods = ModAssistant . Properties . Settings . Default . SelectInstalled ;
2019-04-22 18:41:43 +12:00
if ( e . Args . Length = = 0 )
{
2019-05-05 03:05:48 +12:00
Updater . Run ( ) ;
2019-04-22 18:41:43 +12:00
MainWindow window = new MainWindow ( ) ;
window . Show ( ) ;
}
else
{
ArgumentHandler ( e . Args ) ;
}
}
private void ArgumentHandler ( string [ ] Args )
{
2019-04-30 04:34:41 +12:00
switch ( Args [ 0 ] )
{
case "--install" :
if ( ! String . IsNullOrEmpty ( Args [ 1 ] ) )
OneClickInstaller . InstallAsset ( Args [ 1 ] ) ;
else
Utils . SendNotify ( "Invalid argument! '--install' requires an option." ) ;
break ;
2019-05-05 13:17:53 +12:00
case "--no-update" :
2019-05-05 03:05:48 +12:00
MainWindow window = new MainWindow ( ) ;
window . Show ( ) ;
2019-04-30 04:34:41 +12:00
break ;
2019-05-05 04:08:54 +12:00
case "--register" :
2019-05-08 04:56:54 +12:00
if ( ! String . IsNullOrEmpty ( Args [ 1 ] ) )
OneClickInstaller . Register ( Args [ 1 ] , true ) ;
else
Utils . SendNotify ( "Invalid argument! '--register' requires an option." ) ;
break ;
case "--unregister" :
if ( ! String . IsNullOrEmpty ( Args [ 1 ] ) )
OneClickInstaller . Unregister ( Args [ 1 ] , true ) ;
else
Utils . SendNotify ( "Invalid argument! '--unregister' requires an option." ) ;
2019-05-05 04:08:54 +12:00
break ;
2019-04-30 04:34:41 +12:00
default :
Utils . SendNotify ( "Unrecognized argument. Closing Mod Assistant." ) ;
break ;
}
Current . Shutdown ( ) ;
2019-04-22 18:41:43 +12:00
}
private void Application_DispatcherUnhandledException ( object sender , System . Windows . Threading . DispatcherUnhandledExceptionEventArgs e )
{
2019-05-08 04:56:54 +12:00
MessageBox . Show ( "An unhandled exception just occurred: " + e . Exception , "Exception" , MessageBoxButton . OK , MessageBoxImage . Warning ) ;
2019-04-22 18:41:43 +12:00
e . Handled = true ;
2019-05-08 04:56:54 +12:00
Application . Current . Shutdown ( ) ;
2019-04-22 18:41:43 +12:00
}
}
}