2024-07-06 17:06:21 -04:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
2023-11-12 09:52:02 -05:00
|
|
|
|
using Avalonia;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
|
|
using Avalonia.Markup.Xaml;
|
2023-09-05 20:09:11 -04:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using Serilog;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
using SPTInstaller.ViewModels;
|
|
|
|
|
using SPTInstaller.Views;
|
2023-09-05 20:09:11 -04:00
|
|
|
|
using System.Reactive;
|
2024-07-06 17:06:21 -04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using DynamicData;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller;
|
|
|
|
|
|
|
|
|
|
public partial class App : Application
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2024-06-09 16:14:57 -04:00
|
|
|
|
public static string LogPath = Path.Join(Environment.CurrentDirectory, "spt-installer.log");
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-07-06 17:06:21 -04:00
|
|
|
|
public static void ReLaunch(bool debug, string installPath = "")
|
|
|
|
|
{
|
|
|
|
|
var installerPath = Path.Join(Environment.CurrentDirectory, "SPTInstaller.exe");
|
|
|
|
|
|
|
|
|
|
var args = new StringBuilder()
|
|
|
|
|
.Append(debug ? "debug " : "")
|
|
|
|
|
.Append(!string.IsNullOrEmpty(installPath) ? $"installPath=\"{installPath}\"" : "")
|
|
|
|
|
.ToString();
|
|
|
|
|
|
|
|
|
|
Process.Start(new ProcessStartInfo()
|
|
|
|
|
{
|
|
|
|
|
FileName = installerPath,
|
|
|
|
|
Arguments = args
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public override void Initialize()
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
2024-02-06 18:59:39 -05:00
|
|
|
|
|
2023-09-05 20:23:28 -04:00
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
2024-02-06 18:59:39 -05:00
|
|
|
|
.MinimumLevel.Information()
|
2023-09-05 20:23:28 -04:00
|
|
|
|
.WriteTo
|
2024-06-09 16:14:57 -04:00
|
|
|
|
.File(path: LogPath,
|
|
|
|
|
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information)
|
2023-09-05 20:23:28 -04:00
|
|
|
|
.CreateLogger();
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-09-05 20:09:11 -04:00
|
|
|
|
RxApp.DefaultExceptionHandler = Observer.Create<Exception>((exception) =>
|
|
|
|
|
{
|
|
|
|
|
Log.Error(exception, "An application exception occurred");
|
|
|
|
|
});
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
|
|
|
{
|
|
|
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2024-07-06 17:06:21 -04:00
|
|
|
|
var debug = false;
|
|
|
|
|
var providedPath = "";
|
|
|
|
|
|
|
|
|
|
if (desktop.Args != null)
|
|
|
|
|
{
|
|
|
|
|
debug = desktop.Args.Any(x => x.ToLower() == "debug");
|
|
|
|
|
var installPath = desktop.Args.FirstOrDefault(x => x.StartsWith("installPath=", StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
|
|
|
|
|
|
providedPath = installPath != null && installPath.Contains('=') ? installPath?.Split('=')[1] ?? "" : "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-02-06 18:59:39 -05:00
|
|
|
|
if (debug)
|
2023-11-12 09:52:02 -05:00
|
|
|
|
{
|
2024-02-06 18:59:39 -05:00
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
|
|
.MinimumLevel.Debug()
|
|
|
|
|
.WriteTo
|
2024-06-09 16:14:57 -04:00
|
|
|
|
.File(path: LogPath,
|
|
|
|
|
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug)
|
2024-02-06 18:59:39 -05:00
|
|
|
|
.CreateLogger();
|
|
|
|
|
|
2023-11-12 09:52:02 -05:00
|
|
|
|
System.Diagnostics.Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener());
|
2024-02-06 18:59:39 -05:00
|
|
|
|
|
2023-11-12 09:52:02 -05:00
|
|
|
|
Log.Debug("TraceListener is registered");
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
desktop.MainWindow = new MainWindow
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2024-07-06 17:06:21 -04:00
|
|
|
|
DataContext = new MainWindowViewModel(providedPath, debug),
|
2023-07-12 09:19:33 +02:00
|
|
|
|
};
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|