Fix several more VMs

This commit is contained in:
Timothy Baldridge 2021-12-27 16:15:30 -07:00
parent 7048854f12
commit c3d1815e3c
13 changed files with 88 additions and 100 deletions

View File

@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Wabbajack.DTOs;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Lib;
namespace Wabbajack
{
[JsonName("DetailedStatus")]
public class DetailedStatus
{
public string Name { get; set; } = "";
public DateTime Checked { get; set; } = DateTime.UtcNow;
public List<DetailedStatusItem> Archives { get; set; } = new();
public DownloadMetadata DownloadMetaData { get; set; } = new();
public bool HasFailures { get; set; }
public string MachineName { get; set; } = "";
}
[JsonName("DetailedStatusItem")]
public class DetailedStatusItem
{
public bool IsFailing { get; set; }
public Archive Archive { get; set; }
public string Name => string.IsNullOrWhiteSpace(Archive!.Name) ? Archive.State.PrimaryKeyString : Archive.Name;
public string Url => Archive?.State.GetManifestURL(Archive!);
[JsonIgnore]
public bool HasUrl => Url != null;
public ArchiveStatus ArchiveStatus { get; set; }
}
public enum ArchiveStatus
{
Valid,
InValid,
Updating,
Updated,
Mirrored
}
public class ClientAPIEx
{
public static async Task<DetailedStatus> GetDetailedStatus(string machineURL)
{
var client = await ClientAPI.GetClient();
var results =
await client.GetJsonAsync<DetailedStatus>(
$"{Consts.WabbajackBuildServerUri}lists/status/{machineURL}.json");
return results;
}
}
}

View File

@ -1,12 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reactive.Subjects; using System.Reactive.Subjects;
using System.Text; using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using System.Windows.Input;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Wabbajack.Common; using Wabbajack.Common;
@ -35,11 +31,11 @@ namespace Wabbajack
public Subject<bool> IsBackEnabledSubject { get; } = new Subject<bool>(); public Subject<bool> IsBackEnabledSubject { get; } = new Subject<bool>();
public IObservable<bool> IsBackEnabled { get; } public IObservable<bool> IsBackEnabled { get; }
public BackNavigatingVM(MainWindowVM mainWindowVM) public BackNavigatingVM(ILogger logger, MainWindowVM mainWindowVM)
{ {
IsBackEnabled = IsBackEnabledSubject.StartWith(true); IsBackEnabled = IsBackEnabledSubject.StartWith(true);
BackCommand = ReactiveCommand.Create( BackCommand = ReactiveCommand.Create(
execute: () => Utils.CatchAndLog(() => execute: () => logger.CatchAndLog(() =>
{ {
mainWindowVM.NavigateTo(NavigateBackTarget); mainWindowVM.NavigateTo(NavigateBackTarget);
Unload(); Unload();

View File

@ -29,6 +29,7 @@ namespace Wabbajack
public void AbsorbStatus(IJob cpu) public void AbsorbStatus(IJob cpu)
{ {
/* TODO
bool starting = cpu.IsWorking && !IsWorking; bool starting = cpu.IsWorking && !IsWorking;
if (starting) if (starting)
{ {
@ -39,6 +40,7 @@ namespace Wabbajack
Msg = cpu.Msg; Msg = cpu.Msg;
ProgressPercent = cpu.ProgressPercent; ProgressPercent = cpu.ProgressPercent;
IsWorking = cpu.IsWorking; IsWorking = cpu.IsWorking;
*/
} }
} }
} }

View File

@ -1,23 +1,18 @@
using DynamicData; using DynamicData.Binding;
using DynamicData.Binding;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Windows.Input;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using Wabbajack.Common; using DynamicData;
using Wabbajack.Lib; using Wabbajack.Compiler;
using Wabbajack.Lib.AuthorApi; using Wabbajack.Lib.Extensions;
using Wabbajack.Lib.FileUploader;
using Wabbajack.Lib.Interventions; using Wabbajack.Lib.Interventions;
using Wabbajack.RateLimiter;
namespace Wabbajack namespace Wabbajack
{ {

View File

@ -7,6 +7,7 @@ using System.Reactive.Linq;
using System.Windows.Input; using System.Windows.Input;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
@ -16,6 +17,7 @@ using Wabbajack.DTOs;
using Wabbajack.Hashing.xxHash64; using Wabbajack.Hashing.xxHash64;
using Wabbajack.Lib.Extensions; using Wabbajack.Lib.Extensions;
using Wabbajack.Networking.WabbajackClientApi; using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Services.OSIntegrated.Services;
namespace Wabbajack namespace Wabbajack
{ {
@ -59,8 +61,8 @@ namespace Wabbajack
public ICommand ClearFiltersCommand { get; } public ICommand ClearFiltersCommand { get; }
public ModListGalleryVM(ILogger<ModListGalleryVM> logger, MainWindowVM mainWindowVM, Client wjClient, public ModListGalleryVM(ILogger<ModListGalleryVM> logger, MainWindowVM mainWindowVM, Client wjClient,
GameLocator locator) GameLocator locator, ServiceProvider provider)
: base(mainWindowVM) : base(logger, mainWindowVM)
{ {
MWVM = mainWindowVM; MWVM = mainWindowVM;
_wjClient = wjClient; _wjClient = wjClient;
@ -136,7 +138,8 @@ namespace Wabbajack
// Convert to VM and bind to resulting list // Convert to VM and bind to resulting list
sourceList sourceList
.ObserveOnGuiThread() .ObserveOnGuiThread()
.Transform(m => new ModListMetadataVM(this, m)) .Transform(m => new ModListMetadataVM(provider.GetService<ILogger<ModListMetadataVM>>(),this, m,
provider.GetService<ModListDownloadMaintainer>(), provider.GetService<Client>()))
.DisposeMany() .DisposeMany()
// Filter only installed // Filter only installed
.Filter(this.WhenAny(x => x.OnlyInstalled) .Filter(this.WhenAny(x => x.OnlyInstalled)

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reactive.Subjects; using System.Reactive.Subjects;
@ -12,6 +13,7 @@ using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.DTOs; using Wabbajack.DTOs;
using Wabbajack.DTOs.ServerResponses;
using Wabbajack.Lib; using Wabbajack.Lib;
using Wabbajack.Lib.Extensions; using Wabbajack.Lib.Extensions;
using Wabbajack.Networking.WabbajackClientApi; using Wabbajack.Networking.WabbajackClientApi;
@ -79,11 +81,11 @@ namespace Wabbajack
public bool LoadingImage => _LoadingImage.Value; public bool LoadingImage => _LoadingImage.Value;
private Subject<bool> IsLoadingIdle; private Subject<bool> IsLoadingIdle;
private readonly ILogger<ModListMetadataVM> _logger; private readonly ILogger _logger;
private readonly ModListDownloadMaintainer _maintainer; private readonly ModListDownloadMaintainer _maintainer;
private readonly Client _wjClient; private readonly Client _wjClient;
public ModListMetadataVM(ILogger<ModListMetadataVM> logger, ModListGalleryVM parent, ModlistMetadata metadata, public ModListMetadataVM(ILogger logger, ModListGalleryVM parent, ModlistMetadata metadata,
ModListDownloadMaintainer maintainer, Client wjClient) ModListDownloadMaintainer maintainer, Client wjClient)
{ {
_logger = logger; _logger = logger;
@ -115,10 +117,15 @@ namespace Wabbajack
IsLoadingIdle.OnNext(false); IsLoadingIdle.OnNext(false);
try try
{ {
var status = await ClientAPIEx.GetDetailedStatus(metadata.Links.MachineURL); var status = await wjClient.GetDetailedStatus(metadata.Links.MachineURL);
var coll = _parent.MWVM.ModListContentsVM.Value.Status; var coll = _parent.MWVM.ModListContentsVM.Value.Status;
coll.Clear(); coll.Clear();
coll.AddRange(status.Archives); coll.AddRange(status.Archives.Select(a => new DetailedStatusItem
{
Archive = a.Original,
ArchiveStatus = a.Status,
IsFailing = a.Status != ArchiveStatus.InValid
}));
_parent.MWVM.NavigateTo(_parent.MWVM.ModListContentsVM.Value); _parent.MWVM.NavigateTo(_parent.MWVM.ModListContentsVM.Value);
} }
finally finally

View File

@ -8,9 +8,11 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Extensions.Logging;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.Lib; using Wabbajack.Lib;
using Wabbajack.Lib.Interventions; using Wabbajack.Lib.Interventions;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Paths; using Wabbajack.Paths;
using Wabbajack.View_Models; using Wabbajack.View_Models;
@ -38,6 +40,8 @@ namespace Wabbajack
public readonly ModeSelectionVM ModeSelectionVM; public readonly ModeSelectionVM ModeSelectionVM;
public readonly Lazy<ModListContentsVM> ModListContentsVM; public readonly Lazy<ModListContentsVM> ModListContentsVM;
public readonly UserInterventionHandlers UserInterventionHandlers; public readonly UserInterventionHandlers UserInterventionHandlers;
private readonly Client _wjClient;
private readonly ILogger<MainWindowVM> _logger;
public ICommand CopyVersionCommand { get; } public ICommand CopyVersionCommand { get; }
public ICommand ShowLoginManagerVM { get; } public ICommand ShowLoginManagerVM { get; }
@ -48,8 +52,10 @@ namespace Wabbajack
[Reactive] [Reactive]
public bool UpdateAvailable { get; private set; } public bool UpdateAvailable { get; private set; }
public MainWindowVM(MainWindow mainWindow, MainSettings settings) public MainWindowVM(ILogger<MainWindowVM> logger, MainWindow mainWindow, MainSettings settings, Client wjClient)
{ {
_logger = logger;
_wjClient = wjClient;
ConverterRegistration.Register(); ConverterRegistration.Register();
MainWindow = mainWindow; MainWindow = mainWindow;
Settings = settings; Settings = settings;
@ -85,7 +91,7 @@ namespace Wabbajack
catch (Exception ex) catch (Exception ex)
when (ex.GetType() != typeof(TaskCanceledException)) when (ex.GetType() != typeof(TaskCanceledException))
{ {
Utils.Error(ex, $"Error while handling user intervention of type {msg?.GetType()}"); _logger.LogError(ex, "Error while handling user intervention of type {Type}",msg?.GetType());
try try
{ {
if (msg is IUserIntervention {Handled: false} intervention) if (msg is IUserIntervention {Handled: false} intervention)
@ -95,7 +101,7 @@ namespace Wabbajack
} }
catch (Exception cancelEx) catch (Exception cancelEx)
{ {
Utils.Error(cancelEx, $"Error while cancelling user intervention of type {msg?.GetType()}"); _logger.LogError(cancelEx, "Error while cancelling user intervention of type {Type}",msg?.GetType());
} }
} }
}) })
@ -119,14 +125,14 @@ namespace Wabbajack
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
Consts.CurrentMinimumWabbajackVersion = Version.Parse(fvi.FileVersion); Consts.CurrentMinimumWabbajackVersion = Version.Parse(fvi.FileVersion);
VersionDisplay = $"v{fvi.FileVersion}"; VersionDisplay = $"v{fvi.FileVersion}";
Utils.Log($"Wabbajack Version: {fvi.FileVersion}"); _logger.LogInformation("Wabbajack Version: {FileVersion}", fvi.FileVersion);
Task.Run(() => Metrics.Send("started_wabbajack", fvi.FileVersion)).FireAndForget(); Task.Run(() => _wjClient.SendMetric("started_wabbajack", fvi.FileVersion)).FireAndForget();
Task.Run(() => Metrics.Send("started_sha", ThisAssembly.Git.Sha)); Task.Run(() => _wjClient.SendMetric("started_sha", ThisAssembly.Git.Sha));
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.Error(ex); _logger.LogError(ex, "During App configuration");
VersionDisplay = "ERROR"; VersionDisplay = "ERROR";
} }
CopyVersionCommand = ReactiveCommand.Create(() => CopyVersionCommand = ReactiveCommand.Create(() =>

View File

@ -5,9 +5,11 @@ using System.Reactive.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using Microsoft.Extensions.Logging;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.DTOs; using Wabbajack.DTOs;
using Wabbajack.DTOs.ServerResponses;
namespace Wabbajack.View_Models namespace Wabbajack.View_Models
{ {
@ -26,9 +28,12 @@ namespace Wabbajack.View_Models
private readonly ReadOnlyObservableCollection<ModListArchive> _archives; private readonly ReadOnlyObservableCollection<ModListArchive> _archives;
public ReadOnlyObservableCollection<ModListArchive> Archives => _archives; public ReadOnlyObservableCollection<ModListArchive> Archives => _archives;
private static readonly Regex NameMatcher = new(@"(?<=\.)[^\.]+(?=\+State)", RegexOptions.Compiled); private static readonly Regex NameMatcher = new(@"(?<=\.)[^\.]+(?=\+State)", RegexOptions.Compiled);
public ModListContentsVM(MainWindowVM mwvm) : base(mwvm) private readonly ILogger<ModListContentsVM> _logger;
public ModListContentsVM(ILogger<ModListContentsVM> logger, MainWindowVM mwvm) : base(logger, mwvm)
{ {
_logger = logger;
_mwvm = mwvm; _mwvm = mwvm;
Status = new ObservableCollectionExtended<DetailedStatusItem>(); Status = new ObservableCollectionExtended<DetailedStatusItem>();
@ -47,7 +52,6 @@ namespace Wabbajack.View_Models
{ {
Name = a.Name, Name = a.Name,
Size = a.Archive?.Size ?? 0, Size = a.Archive?.Size ?? 0,
Url = a.Url ?? "",
Downloader = TransformClassName(a.Archive) ?? "Unknown", Downloader = TransformClassName(a.Archive) ?? "Unknown",
Hash = a.Archive!.Hash.ToBase64() Hash = a.Archive!.Hash.ToBase64()
}) })

View File

@ -4,6 +4,7 @@ using System.Reactive.Subjects;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Extensions.Logging;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Wabbajack.Lib; using Wabbajack.Lib;
@ -33,7 +34,7 @@ namespace Wabbajack.View_Models.Settings
private readonly Client _wjClient; private readonly Client _wjClient;
private IObservable<bool> IsUploading { get; } private IObservable<bool> IsUploading { get; }
public AuthorFilesVM(WabbajackApiTokenProvider token, Client wjClient, SettingsVM vm) : base(vm.MWVM) public AuthorFilesVM(ILogger<AuthorFilesVM> logger, WabbajackApiTokenProvider token, Client wjClient, SettingsVM vm) : base(logger, vm.MWVM)
{ {
_token = token; _token = token;
_wjClient = wjClient; _wjClient = wjClient;

View File

@ -7,8 +7,12 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ReactiveUI; using ReactiveUI;
using Wabbajack.Lib; using Wabbajack.Lib;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Services.OSIntegrated.TokenProviders;
using Wabbajack.View_Models.Settings; using Wabbajack.View_Models.Settings;
namespace Wabbajack namespace Wabbajack
@ -23,15 +27,16 @@ namespace Wabbajack
public ICommand OpenTerminalCommand { get; } public ICommand OpenTerminalCommand { get; }
public SettingsVM(MainWindowVM mainWindowVM) public SettingsVM(ILogger<SettingsVM> logger, MainWindowVM mainWindowVM, ServiceProvider provider)
: base(mainWindowVM) : base(logger, mainWindowVM)
{ {
MWVM = mainWindowVM; MWVM = mainWindowVM;
Login = new LoginManagerVM(this); Login = new LoginManagerVM(this);
Performance = mainWindowVM.Settings.Performance; Performance = mainWindowVM.Settings.Performance;
AuthorFile = new AuthorFilesVM(this); AuthorFile = new AuthorFilesVM(provider.GetService<ILogger<AuthorFilesVM>>()!,
provider.GetService<WabbajackApiTokenProvider>()!, provider.GetService<Client>()!, this);
Filters = mainWindowVM.Settings.Filters; Filters = mainWindowVM.Settings.Filters;
OpenTerminalCommand = ReactiveCommand.CreateFromTask(() => OpenTerminal()); OpenTerminalCommand = ReactiveCommand.CreateFromTask(OpenTerminal);
} }
private async Task OpenTerminal() private async Task OpenTerminal()
@ -39,7 +44,7 @@ namespace Wabbajack
var process = new ProcessStartInfo var process = new ProcessStartInfo
{ {
FileName = "cmd.exe", FileName = "cmd.exe",
WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!
}; };
Process.Start(process); Process.Start(process);
await MWVM.ShutdownApplication(); await MWVM.ShutdownApplication();

View File

@ -0,0 +1,20 @@
using System;
using Microsoft.Extensions.Logging;
namespace Wabbajack.Common;
public static class LoggerExtensions
{
public static void CatchAndLog(this ILogger logger, Action fn)
{
try
{
fn();
}
catch (Exception ex)
{
logger.LogError(ex, "In Catch and log");
}
}
}

View File

@ -30,6 +30,11 @@ public record StatusUpdate(string StatusText, Percent StepsProgress, Percent Ste
{ {
} }
public interface IInstaller
{
Task<bool> Begin(CancellationToken token);
}
public abstract class AInstaller<T> public abstract class AInstaller<T>
where T : AInstaller<T> where T : AInstaller<T>
{ {

View File

@ -76,10 +76,10 @@ public class StandardInstaller : AInstaller<StandardInstaller>
} }
_logger.LogInformation("Install Folder: {installFolder}", _configuration.Install); _logger.LogInformation("Install Folder: {InstallFolder}", _configuration.Install);
_logger.LogInformation("Downloads Folder: {downloadFolder}", _configuration.Downloads); _logger.LogInformation("Downloads Folder: {DownloadFolder}", _configuration.Downloads);
_logger.LogInformation("Game Folder: {gameFolder}", _configuration.GameFolder); _logger.LogInformation("Game Folder: {GameFolder}", _configuration.GameFolder);
_logger.LogInformation("Wabbajack Folder: {wabbajackFolder}", KnownFolders.EntryPoint); _logger.LogInformation("Wabbajack Folder: {WabbajackFolder}", KnownFolders.EntryPoint);
_configuration.Install.CreateDirectory(); _configuration.Install.CreateDirectory();
_configuration.Downloads.CreateDirectory(); _configuration.Downloads.CreateDirectory();