2023-05-11 23:11:39 -04:00
|
|
|
|
using Avalonia;
|
|
|
|
|
using ReactiveUI;
|
2023-05-14 22:35:06 -04:00
|
|
|
|
using Serilog;
|
2023-08-02 23:32:44 -04:00
|
|
|
|
using System.Globalization;
|
2023-05-22 19:14:41 -04:00
|
|
|
|
using System.Reflection;
|
2024-07-10 13:33:19 -04:00
|
|
|
|
using SPTInstaller.Helpers;
|
|
|
|
|
using SPTInstaller.Models;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller.ViewModels;
|
|
|
|
|
|
|
|
|
|
public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScreen
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public RoutingState Router { get; } = new();
|
|
|
|
|
public ViewModelActivator Activator { get; } = new();
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
private string _title;
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public string Title
|
|
|
|
|
{
|
|
|
|
|
get => _title;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _title, value);
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-07-10 13:33:19 -04:00
|
|
|
|
public MainWindowViewModel(string installPath)
|
2023-07-12 09:19:33 +02:00
|
|
|
|
{
|
2024-07-10 13:33:19 -04:00
|
|
|
|
var data = ServiceHelper.Get<InternalData>() ?? throw new Exception("failed to get interanl data");
|
|
|
|
|
|
2024-05-01 10:31:55 -04:00
|
|
|
|
Title =
|
2024-07-10 13:33:19 -04:00
|
|
|
|
$"{(data.DebugMode ? "-debug-" : "")} SPT Installer {"v" + Assembly.GetExecutingAssembly().GetName()?.Version?.ToString() ?? "--unknown version--"}";
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
Log.Information($"========= {Title} Started =========");
|
|
|
|
|
Log.Information(Environment.OSVersion.VersionString);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
|
|
|
|
var uiCulture = CultureInfo.InstalledUICulture;
|
|
|
|
|
|
2023-08-02 23:32:44 -04:00
|
|
|
|
Log.Information("System Language: {iso} - {name}", uiCulture.TwoLetterISOLanguageName, uiCulture.DisplayName);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-07-10 13:33:19 -04:00
|
|
|
|
Router.Navigate.Execute(new InstallerUpdateViewModel(this, installPath));
|
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 void CloseCommand()
|
|
|
|
|
{
|
2024-05-01 10:31:55 -04:00
|
|
|
|
if (Application.Current.ApplicationLifetime is
|
|
|
|
|
Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
desktopApp.MainWindow.Close();
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
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 void MinimizeCommand()
|
|
|
|
|
{
|
2024-05-01 10:31:55 -04:00
|
|
|
|
if (Application.Current.ApplicationLifetime is
|
|
|
|
|
Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
desktopApp.MainWindow.WindowState = Avalonia.Controls.WindowState.Minimized;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|