82 lines
3.2 KiB
C#
Raw Normal View History

2023-05-11 23:11:39 -04:00
using Avalonia;
using Avalonia.ReactiveUI;
using ReactiveUI;
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-11-12 09:52:02 -05:00
using Serilog;
using SPTInstaller.CustomControls;
2023-05-11 23:11:39 -04:00
namespace SPTInstaller;
internal class Program
2023-05-11 23:11:39 -04: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]
2023-11-12 09:52:02 -05:00
public static void Main(string[] args)
{
try
{
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
catch (Exception ex)
{
Log.Fatal(ex, "Installer closed unexpectedly");
}
}
2024-05-01 10:31:55 -04:00
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
{
Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetExecutingAssembly());
2024-05-01 10:31:55 -04:00
// Register all the things
// Regestering as base classes so ReactiveUI works correctly. Doesn't seem to like the interfaces :(
ServiceHelper.Register<InternalData>();
2024-05-01 10:31:55 -04:00
2023-08-25 19:09:36 -04:00
#if !TEST
ServiceHelper.Register<PreCheckBase, NetFramework472PreCheck>();
2024-03-07 15:28:09 -05:00
ServiceHelper.Register<PreCheckBase, Net8PreCheck>();
2023-08-22 10:21:52 -04:00
ServiceHelper.Register<PreCheckBase, FreeSpacePreCheck>();
2023-11-09 10:32:52 -05:00
ServiceHelper.Register<PreCheckBase, EftLauncherPreCheck>();
2024-05-01 10:31:55 -04: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-08-25 19:09:36 -04:00
for (int i = 0; i < 5; i++)
{
Locator.CurrentMutable.RegisterConstant<InstallerTaskBase>(TestTask.FromRandomName());
}
Locator.CurrentMutable.RegisterConstant<PreCheckBase>(TestPreCheck.FromRandomName(StatusSpinner.SpinnerState.OK));
Locator.CurrentMutable.RegisterConstant<PreCheckBase>(TestPreCheck.FromRandomName(StatusSpinner.SpinnerState.Warning));
Locator.CurrentMutable.RegisterConstant<PreCheckBase>(TestPreCheck.FromRandomName(StatusSpinner.SpinnerState.Error));
2023-05-11 23:11:39 -04:00
#endif
2024-05-01 10:31:55 -04: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[];
2024-05-01 10:31:55 -04:00
var installer = new InstallController(tasks, preChecks);
2024-05-01 10:31:55 -04:00
// manually register install controller
Locator.CurrentMutable.RegisterConstant(installer);
2024-05-01 10:31:55 -04:00
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
2023-05-11 23:11:39 -04:00
}
}