2023-05-11 23:11:39 -04:00
using Avalonia ;
using Avalonia.ReactiveUI ;
using ReactiveUI ;
2023-05-14 22:35:06 -04:00
using Serilog ;
2023-05-11 23:11:39 -04:00
using Splat ;
using SPTInstaller.Controllers ;
using SPTInstaller.Helpers ;
using SPTInstaller.Installer_Tasks ;
using SPTInstaller.Installer_Tasks.PreChecks ;
using SPTInstaller.Interfaces ;
using SPTInstaller.Models ;
using System.Linq ;
using System.Reflection ;
2023-07-12 09:19:33 +02:00
namespace SPTInstaller ;
internal class Program
2023-05-11 23:11:39 -04:00
{
2023-07-12 09:19:33 +02:00
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main ( string [ ] args ) = > BuildAvaloniaApp ( )
. StartWithClassicDesktopLifetime ( args ) ;
2023-05-11 23:11:39 -04:00
2023-07-12 09:19:33 +02:00
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp ( )
{
Locator . CurrentMutable . RegisterViewsForViewModels ( Assembly . GetExecutingAssembly ( ) ) ;
2023-05-11 23:11:39 -04:00
2023-07-12 09:19:33 +02:00
// Register all the things
// Regestering as base classes so ReactiveUI works correctly. Doesn't seem to like the interfaces :(
ServiceHelper . Register < InternalData > ( ) ;
ServiceHelper . Register < PreCheckBase , NetFramework472PreCheck > ( ) ;
ServiceHelper . Register < PreCheckBase , NetCore6PreCheck > ( ) ;
ServiceHelper . Register < PreCheckBase , FreeSpacePreCheck > ( ) ;
2023-05-11 23:11:39 -04:00
#if ! TEST
2023-07-12 09:19:33 +02:00
var logPath = Path . Join ( Environment . CurrentDirectory , "spt-aki-installer_.log" ) ;
2023-05-14 22:35:06 -04:00
2023-07-12 09:19:33 +02:00
Log . Logger = new LoggerConfiguration ( )
. MinimumLevel . Debug ( )
. WriteTo
. File ( path : logPath ,
restrictedToMinimumLevel : Serilog . Events . LogEventLevel . Debug ,
rollingInterval : RollingInterval . Day )
. CreateLogger ( ) ;
2023-05-14 22:35:06 -04:00
2023-07-12 09:19:33 +02:00
ServiceHelper . Register < InstallerTaskBase , InitializationTask > ( ) ;
ServiceHelper . Register < InstallerTaskBase , ReleaseCheckTask > ( ) ;
ServiceHelper . Register < InstallerTaskBase , DownloadTask > ( ) ;
ServiceHelper . Register < InstallerTaskBase , CopyClientTask > ( ) ;
ServiceHelper . Register < InstallerTaskBase , SetupClientTask > ( ) ;
2023-05-11 23:11:39 -04:00
#else
2023-05-14 22:35:06 -04:00
for ( int i = 0 ; i < 5 ; i + + )
2023-05-11 23:11:39 -04:00
{
Locator . CurrentMutable . RegisterConstant < InstallerTaskBase > ( TestTask . FromRandomName ( ) ) ;
}
#endif
2023-07-12 09:19:33 +02:00
// need the interfaces for the controller and splat won't resolve them since we need to base classes in avalonia (what a mess), so doing it manually here
var tasks = Locator . Current . GetServices < InstallerTaskBase > ( ) . ToArray ( ) as IProgressableTask [ ] ;
var preChecks = Locator . Current . GetServices < PreCheckBase > ( ) . ToArray ( ) as IPreCheck [ ] ;
2023-05-11 23:11:39 -04:00
2023-07-12 09:19:33 +02:00
var installer = new InstallController ( tasks , preChecks ) ;
2023-05-11 23:11:39 -04:00
2023-07-12 09:19:33 +02:00
// manually register install controller
Locator . CurrentMutable . RegisterConstant ( installer ) ;
2023-05-11 23:11:39 -04:00
2023-07-12 09:19:33 +02:00
return AppBuilder . Configure < App > ( )
. UsePlatformDetect ( )
. LogToTrace ( )
. UseReactiveUI ( ) ;
2023-05-11 23:11:39 -04:00
}
}