2023-05-11 23:11:39 -04:00
|
|
|
|
using Avalonia;
|
|
|
|
|
using ReactiveUI;
|
2023-05-14 22:35:06 -04:00
|
|
|
|
using Serilog;
|
2023-08-25 23:46:11 -04:00
|
|
|
|
using SPTInstaller.CustomControls;
|
|
|
|
|
using SPTInstaller.Helpers;
|
2023-05-18 20:04:00 -04:00
|
|
|
|
using SPTInstaller.Interfaces;
|
2023-08-25 23:46:11 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller.ViewModels;
|
|
|
|
|
|
|
|
|
|
public class MessageViewModel : ViewModelBase
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
private bool _HasErrors;
|
|
|
|
|
public bool HasErrors
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
get => _HasErrors;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _HasErrors, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _Message;
|
|
|
|
|
public string Message
|
|
|
|
|
{
|
|
|
|
|
get => _Message;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _Message, value);
|
|
|
|
|
}
|
2023-05-18 20:04:00 -04:00
|
|
|
|
|
2023-07-30 16:15:52 -04:00
|
|
|
|
private bool _showCloseButton;
|
|
|
|
|
public bool ShowCloseButton
|
|
|
|
|
{
|
|
|
|
|
get => _showCloseButton;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _showCloseButton, value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-25 23:46:11 -04:00
|
|
|
|
private string _cacheInfoText;
|
|
|
|
|
public string CacheInfoText
|
|
|
|
|
{
|
|
|
|
|
get => _cacheInfoText;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _cacheInfoText, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private StatusSpinner.SpinnerState _cacheCheckState;
|
|
|
|
|
public StatusSpinner.SpinnerState CacheCheckState
|
|
|
|
|
{
|
|
|
|
|
get => _cacheCheckState;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _cacheCheckState, value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public ICommand CloseCommand { get; set; } = ReactiveCommand.Create(() =>
|
|
|
|
|
{
|
|
|
|
|
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-30 16:15:52 -04:00
|
|
|
|
public MessageViewModel(IScreen Host, IResult result, bool showCloseButton = true) : base(Host)
|
2023-07-12 09:19:33 +02:00
|
|
|
|
{
|
2023-07-30 16:15:52 -04:00
|
|
|
|
ShowCloseButton = showCloseButton;
|
2023-07-12 09:19:33 +02:00
|
|
|
|
Message = result.Message;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-08-25 23:46:11 -04:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
CacheInfoText = "Getting cache size ...";
|
|
|
|
|
CacheCheckState = StatusSpinner.SpinnerState.Running;
|
|
|
|
|
|
|
|
|
|
CacheInfoText = $"Cache Size: {DownloadCacheHelper.GetCacheSizeText()}";
|
|
|
|
|
CacheCheckState = StatusSpinner.SpinnerState.OK;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (result.Succeeded)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
Log.Information(Message);
|
|
|
|
|
return;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
|
|
|
|
|
HasErrors = true;
|
|
|
|
|
Log.Error(Message);
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|