2023-05-11 23:11:39 -04:00
|
|
|
|
using Avalonia;
|
2023-07-29 23:00:13 -04:00
|
|
|
|
using Gitea.Client;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
using ReactiveUI;
|
2023-05-14 22:35:06 -04:00
|
|
|
|
using Serilog;
|
2023-07-29 23:00:13 -04:00
|
|
|
|
using SPTInstaller.Models;
|
2023-08-02 23:32:44 -04:00
|
|
|
|
using System.Globalization;
|
2023-05-22 19:14:41 -04:00
|
|
|
|
using System.Reflection;
|
2023-07-29 23:00:13 -04:00
|
|
|
|
using System.Threading.Tasks;
|
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();
|
2023-07-30 16:15:52 -04:00
|
|
|
|
public InstallerUpdateInfo UpdateInfo { get; } = new();
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
private string _title;
|
|
|
|
|
public string Title
|
|
|
|
|
{
|
|
|
|
|
get => _title;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _title, value);
|
|
|
|
|
}
|
2023-05-22 19:14:41 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public MainWindowViewModel()
|
|
|
|
|
{
|
2023-07-29 23:00:13 -04:00
|
|
|
|
Configuration.Default.BasePath = "https://dev.sp-tarkov.com/api/v1";
|
2023-05-22 19:14:41 -04:00
|
|
|
|
|
2023-07-29 23:00:13 -04:00
|
|
|
|
Version? version = Assembly.GetExecutingAssembly().GetName()?.Version;
|
|
|
|
|
|
|
|
|
|
Title = $"SPT Installer {"v" + version?.ToString() ?? "--unknown version--"}";
|
2023-05-22 19:14:41 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
Log.Information($"========= {Title} Started =========");
|
|
|
|
|
Log.Information(Environment.OSVersion.VersionString);
|
2023-05-14 22:35:06 -04:00
|
|
|
|
|
2023-08-02 23:32:44 -04:00
|
|
|
|
var uiCulture= CultureInfo.InstalledUICulture;
|
|
|
|
|
|
|
|
|
|
Log.Information("System Language: {iso} - {name}", uiCulture.TwoLetterISOLanguageName, uiCulture.DisplayName);
|
|
|
|
|
|
2023-07-29 23:00:13 -04:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
2023-07-30 16:15:52 -04:00
|
|
|
|
await UpdateInfo.CheckForUpdates(version);
|
2023-07-29 23:00:13 -04:00
|
|
|
|
});
|
|
|
|
|
|
2023-07-30 16:15:52 -04:00
|
|
|
|
Router.Navigate.Execute(new PreChecksViewModel(this, DismissUpdateCommand));
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public void CloseCommand()
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public void MinimizeCommand()
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
|
2023-07-30 16:15:52 -04:00
|
|
|
|
public void DismissUpdateCommand()
|
|
|
|
|
{
|
|
|
|
|
UpdateInfo.UpdateAvailable = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task UpdateInstallerCommand()
|
|
|
|
|
{
|
|
|
|
|
Router.Navigate.Execute(new MessageViewModel(this, Result.FromSuccess("Please wait while the update is installed"), false));
|
|
|
|
|
await UpdateInfo.UpdateInstaller();
|
|
|
|
|
}
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|