Merge pull request #1689 from wabbajack-tools/gallery-bug-fixes

Gallery bug fixes
This commit is contained in:
Timothy Baldridge 2021-10-27 16:25:25 -06:00 committed by GitHub
commit 87c794dd57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 215 additions and 342 deletions

View File

@ -1,40 +0,0 @@
using System;
using System.Threading.Tasks;
using Avalonia.Threading;
using Wabbajack.App.Models;
namespace Wabbajack.App.Test;
public static class Extensions
{
public static async Task WaitUntil<T>(this T src, Predicate<T> check, Action? doFunc = null)
{
Dispatcher.UIThread.RunJobs();
while (!check(src))
{
doFunc?.Invoke();
await Task.Delay(100);
}
}
public static async Task WaitForLock(this LoadingLock l)
{
Dispatcher.UIThread.RunJobs();
while (!l.IsLoading)
{
Dispatcher.UIThread.RunJobs();
await Task.Delay(100);
}
}
public static async Task WaitForUnlock(this LoadingLock l)
{
Dispatcher.UIThread.RunJobs();
while (l.IsLoading)
{
Dispatcher.UIThread.RunJobs();
await Task.Delay(100);
}
}
}

View File

@ -1,74 +0,0 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Wabbajack.App.Controls;
using Wabbajack.App.Messages;
using Wabbajack.App.Screens;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Xunit;
namespace Wabbajack.App.Test;
public class GalleryItemTests
{
private readonly Configuration _config;
private readonly BrowseViewModel _gallery;
public GalleryItemTests(BrowseViewModel bvm, Configuration config)
{
_config = config;
_gallery = bvm;
}
[Fact]
public async Task CanDownloadGalleryItem()
{
_config.ModListsDownloadLocation.CreateDirectory();
foreach (var file in _config.ModListsDownloadLocation.EnumerateFiles().Where(f => f.Extension == Ext.Wabbajack))
file.Delete();
using var _ = _gallery.Activator.Activate();
await _gallery.LoadingLock.WaitForLock();
await _gallery.LoadingLock.WaitForUnlock();
Assert.True(_gallery.ModLists.Count > 0);
foreach (var item in _gallery.ModLists)
{
Assert.NotEqual(ModListState.Downloading, item.State);
if (item.State == ModListState.Downloaded)
Assert.True(item.ModListLocation.FileExists());
else
Assert.False(item.ModListLocation.FileExists());
Assert.Equal(Percent.Zero, item.Progress);
}
var modList = _gallery.ModLists.First();
modList.ExecuteCommand.Execute().Subscribe().Dispose();
var progress = Percent.Zero;
await modList.WaitUntil(x => x.State == ModListState.Downloading);
await modList.WaitUntil(x => x.State != ModListState.Downloading, () =>
{
Assert.True(modList.Progress >= progress);
progress = modList.Progress;
});
Assert.Equal(Percent.Zero, modList.Progress);
Assert.Equal(ModListState.Downloaded, modList.State);
modList.ExecuteCommand.Execute().Subscribe().Dispose();
var msgs = ((SimpleMessageBus) MessageBus.Instance).Messages.TakeLast(2).ToArray();
var configure = msgs.OfType<StartInstallConfiguration>().First();
Assert.Equal(modList.ModListLocation, configure.ModList);
var navigate = msgs.OfType<NavigateTo>().First();
Assert.Equal(typeof(InstallConfigurationViewModel), navigate.ViewModel);
}
}

View File

@ -1,31 +0,0 @@
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit.DependencyInjection;
using Xunit.DependencyInjection.Logging;
namespace Wabbajack.App.Test;
public class Startup
{
public void ConfigureServices(IServiceCollection service)
{
service.AddAppServices();
}
public void Configure(ILoggerFactory loggerFactory, ITestOutputHelperAccessor accessor)
{
loggerFactory.AddProvider(new XunitTestOutputLoggerProvider(accessor, delegate { return true; }));
MessageBus.Instance = new SimpleMessageBus();
}
}
public class SimpleMessageBus : IMessageBus
{
public List<object> Messages { get; } = new();
public void Send<T>(T message)
{
Messages.Add(message);
}
}

View File

@ -1,32 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework Condition=" '$(OS)' == 'Windows_NT'">net6.0-windows</TargetFramework>
<TargetFramework Condition=" '$(OS)' != 'Windows_NT'">net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.DependencyInjection" Version="8.1.0" />
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="8.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.App\Wabbajack.App.csproj" />
</ItemGroup>
<Target Name="AferBuild" AfterTargets="Build" Condition="!Exists('$(ProjectDir)$(OutDir)libcef.dll')">
<Message Text="Downloading Cef" />
<Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)" />
</Target>
</Project>

View File

@ -34,6 +34,10 @@
<Style Selector="controls|TagView TextBlock">
<Setter Property="Foreground" Value="#121212" />
</Style>
<Style Selector="Border.Settings">
<Setter Property="BorderThickness" Value="2"></Setter>
</Style>
</Styles>

View File

@ -6,8 +6,8 @@ public class Configuration
{
public AbsolutePath ModListsDownloadLocation { get; set; }
public AbsolutePath SavedSettingsLocation { get; set; }
public AbsolutePath EncryptedDataLocation { get; set; }
public AbsolutePath LogLocation { get; set; }
public AbsolutePath ImageCacheLocation { get; set; }
}

View File

@ -42,6 +42,7 @@ public partial class BrowseItemView : ReactiveUserControl<BrowseItemViewModel>
{
return modListState switch
{
ModListState.Disabled => MaterialIconKind.Error,
ModListState.Downloaded => MaterialIconKind.PlayArrow,
ModListState.Downloading => MaterialIconKind.LocalAreaNetworkPending,
ModListState.NotDownloaded => MaterialIconKind.Download,

View File

@ -11,6 +11,7 @@ using Microsoft.Extensions.Logging;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Messages;
using Wabbajack.App.Models;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.Downloaders;
@ -28,7 +29,8 @@ public enum ModListState
{
Downloaded,
NotDownloaded,
Downloading
Downloading,
Disabled
}
public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
@ -43,11 +45,12 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
private readonly ILogger _logger;
private readonly ModlistMetadata _metadata;
private readonly ModListSummary _summary;
private readonly ImageCache _imageCache;
public BrowseItemViewModel(ModlistMetadata metadata, ModListSummary summary, HttpClient client,
IResource<HttpClient> limiter,
FileHashCache hashCache, Configuration configuration, DownloadDispatcher dispatcher,
IResource<DownloadDispatcher> downloadLimiter, GameLocator gameLocator,
IResource<DownloadDispatcher> downloadLimiter, GameLocator gameLocator, ImageCache imageCache,
DTOSerializer dtos, ILogger logger)
{
Activator = new ViewModelActivator();
@ -59,6 +62,7 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
_configuration = configuration;
_dispatcher = dispatcher;
_downloadLimiter = downloadLimiter;
_imageCache = imageCache;
_logger = logger;
_dtos = dtos;
@ -78,8 +82,8 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
{
if (State == ModListState.Downloaded)
{
MessageBus.Instance.Send(new StartInstallConfiguration(ModListLocation));
MessageBus.Instance.Send(new NavigateTo(typeof(InstallConfigurationViewModel)));
MessageBus.Current.SendMessage(new StartInstallConfiguration(ModListLocation));
MessageBus.Current.SendMessage(new NavigateTo(typeof(InstallConfigurationViewModel)));
}
else
{
@ -87,7 +91,7 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
}
},
this.ObservableForProperty(t => t.State)
.Select(c => c.Value != ModListState.Downloading)
.Select(c => c.Value != ModListState.Downloading && c.Value != ModListState.Disabled)
.StartWith(true));
LoadListImage().FireAndForget();
@ -96,7 +100,7 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
public string Title => _metadata.ImageContainsTitle ? "" : _metadata.Title;
public string MachineURL => _metadata.Links.MachineURL;
public string Description => _metadata.Description;
public string Description => State == ModListState.Disabled ? "Disabled: Under Construction \n " + _metadata.Description : _metadata.Description;
public Uri ImageUri => new(_metadata.Links.ImageUri);
@ -163,13 +167,14 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
public async Task LoadListImage()
{
using var job = await _limiter.Begin("Loading modlist image", 0, CancellationToken.None);
var response = await _client.GetByteArrayAsync(ImageUri);
Image = new Bitmap(new MemoryStream(response));
Image = await _imageCache.From(ImageUri);
}
public async Task<ModListState> GetState()
{
if (_metadata.ForceDown || _summary.HasFailures)
return ModListState.Disabled;
var file = ModListLocation;
if (!file.FileExists())
return ModListState.NotDownloaded;

View File

@ -19,8 +19,8 @@ public class InstalledListViewModel : ViewModelBase
Play = ReactiveCommand.Create(() =>
{
MessageBus.Instance.Send(new ConfigureLauncher(InstallPath));
MessageBus.Instance.Send(new NavigateTo(typeof(LauncherViewModel)));
MessageBus.Current.SendMessage(new ConfigureLauncher(InstallPath));
MessageBus.Current.SendMessage(new NavigateTo(typeof(LauncherViewModel)));
});
}

View File

@ -5,7 +5,7 @@
xmlns:i="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.LargeIconButton">
<Button x:Name="Button">
<Button x:Name="Button" x:FieldModifier="public">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<i:MaterialIcon x:Name="IconControl" Width="140" Height="140" />
<TextBlock x:Name="TextBlock" HorizontalAlignment="Center" FontSize="28" FontWeight="Bold" />

View File

@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using Avalonia.Threading;
using Microsoft.Extensions.Logging;
using Wabbajack.App.Messages;
namespace Wabbajack.App;
public interface IMessageBus
{
public void Send<T>(T message);
}
public class MessageBus : IMessageBus
{
private readonly ILogger<MessageBus> _logger;
private readonly IReceiverMarker[] _receivers;
public MessageBus(ILogger<MessageBus> logger, IEnumerable<IReceiverMarker> receivers)
{
Instance = this;
_receivers = receivers.ToArray();
_logger = logger;
}
public static IMessageBus Instance { get; set; }
public void Send<T>(T message)
{
AvaloniaScheduler.Instance.Schedule(message, TimeSpan.FromMilliseconds(200), (_, msg) =>
{
foreach (var receiver in _receivers.OfType<IReceiver<T>>())
{
_logger.LogInformation("Sending {msg} to {receiver}", msg, receiver);
try
{
receiver.Receive(msg);
}
catch (Exception ex)
{
_logger.LogCritical(ex, "Failed sending {msg} to {receiver}", msg, receiver);
}
}
return Disposable.Empty;
});
}
}

View File

@ -1,10 +0,0 @@
namespace Wabbajack.App.Messages;
public interface IReceiverMarker
{
}
public interface IReceiver<in T> : IReceiverMarker
{
public void Receive(T val);
}

View File

@ -0,0 +1,47 @@
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using SkiaSharp;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
namespace Wabbajack.App.Models;
public class ImageCache
{
private readonly Configuration _configuration;
private readonly HttpClient _client;
private readonly IResource<HttpClient> _limiter;
public ImageCache(Configuration configuration, HttpClient client, IResource<HttpClient> limiter)
{
_configuration = configuration;
_configuration.ImageCacheLocation.CreateDirectory();
_client = client;
_limiter = limiter;
}
public async Task<IBitmap> From(Uri uri)
{
var hash = (await Encoding.UTF8.GetBytes(uri.ToString()).Hash()).ToHex();
var file = _configuration.ImageCacheLocation.Combine(hash);
if (!file.FileExists())
{
using var job = await _limiter.Begin("Loading Image", 0, CancellationToken.None);
var wdata = await _client.GetByteArrayAsync(uri);
await file.WriteAllBytesAsync(wdata);
return new Bitmap(new MemoryStream(wdata));
}
var data = await file.ReadAllBytesAsync();
return new Bitmap(new MemoryStream(data));
}
}

View File

@ -39,7 +39,7 @@
<TextBox
x:Name="SearchBox"
Width="95"
VerticalContentAlignment="Center" />
VerticalContentAlignment="Center" x:FieldModifier="public" />
<CheckBox
x:Name="ShowNSFW"
Margin="10,0,10,0"
@ -63,18 +63,16 @@
</WrapPanel>
<ScrollViewer Grid.Row="1">
<ItemsControl x:Name="GalleryList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<ItemsRepeater x:Name="GalleryList" x:FieldModifier="public">
<ItemsRepeater.Layout>
<UniformGridLayout></UniformGridLayout>
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<controls:BrowseItemView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</ScrollViewer>

View File

@ -48,10 +48,12 @@ public class BrowseViewModel : ViewModelBase, IActivatableViewModel
private readonly SourceCache<GameSelectorItemViewModel, string> _gamesList = new(x => x.Name);
private readonly SourceCache<BrowseItemViewModel, string> _modLists = new(x => x.MachineURL);
private readonly ImageCache _imageCache;
public BrowseViewModel(ILogger<BrowseViewModel> logger, Client wjClient, HttpClient httpClient,
IResource<HttpClient> limiter, FileHashCache hashCache,
IResource<DownloadDispatcher> dispatcherLimiter, DownloadDispatcher dispatcher, GameLocator gameLocator,
ImageCache imageCache,
DTOSerializer dtos, Configuration configuration)
{
LoadingLock = new LoadingLock();
@ -65,6 +67,7 @@ public class BrowseViewModel : ViewModelBase, IActivatableViewModel
_dispatcher = dispatcher;
_dispatcherLimiter = dispatcherLimiter;
_gameLocator = gameLocator;
_imageCache = imageCache;
_dtos = dtos;
@ -131,6 +134,7 @@ public class BrowseViewModel : ViewModelBase, IActivatableViewModel
.Filter(onlyInstalledGamesFilter)
.Filter(onlyUtilityListsFilter)
.Filter(showNSFWFilter)
.SortBy(x => x.State == ModListState.Disabled ? 1 : 0)
.Bind(out _filteredModLists)
.Subscribe();
@ -191,7 +195,7 @@ public class BrowseViewModel : ViewModelBase, IActivatableViewModel
if (!summaries.TryGetValue(m.Links.MachineURL, out var summary)) summary = new ModListSummary();
return new BrowseItemViewModel(m, summary, _httpClient, _limiter, _hashCache, _configuration, _dispatcher,
_dispatcherLimiter, _gameLocator, _dtos, _logger);
_dispatcherLimiter, _gameLocator, _imageCache, _dtos, _logger);
});
_modLists.Edit(lsts =>

View File

@ -1,4 +1,5 @@
using System;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Threading;
@ -14,7 +15,7 @@ using Wabbajack.RateLimiter;
namespace Wabbajack.App.Screens;
public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<StartCompilation>
public class CompilationViewModel : ViewModelBase
{
private readonly ILogger<CompilationViewModel> _logger;
private readonly IServiceProvider _provider;
@ -26,13 +27,17 @@ public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<St
_logger = logger;
_provider = provider;
Activator = new ViewModelActivator();
MessageBus.Current.Listen<StartCompilation>()
.Subscribe(Receive)
.DisposeWith(VMDisposables);
}
[Reactive] public string StatusText { get; set; } = "";
[Reactive] public Percent StepsProgress { get; set; } = Percent.Zero;
[Reactive] public Percent StepProgress { get; set; } = Percent.Zero;
public void Receive(StartCompilation val)
private void Receive(StartCompilation val)
{
if (val.Settings is MO2CompilerSettings mo2)
{

View File

@ -22,7 +22,7 @@ using Consts = Wabbajack.Compiler.Consts;
namespace Wabbajack.App.Screens;
public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
public class CompilerConfigurationViewModel : ViewModelBase
{
private readonly DTOSerializer _dtos;
private readonly SettingsManager _settingsManager;
@ -94,8 +94,8 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
await SaveSettingsFile();
await _settingsManager.Save("last_compilation", SettingsOutputLocation);
MessageBus.Instance.Send(new StartCompilation(settings));
MessageBus.Instance.Send(new NavigateTo(typeof(CompilationViewModel)));
MessageBus.Current.SendMessage(new StartCompilation(settings));
MessageBus.Current.SendMessage(new NavigateTo(typeof(CompilationViewModel)));
}
private CompilerSettings GetSettings()

View File

@ -1,4 +1,5 @@
using System;
using Avalonia.Controls.Mixins;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Messages;
@ -6,11 +7,14 @@ using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Screens;
public class ErrorPageViewModel : ViewModelBase, IActivatableViewModel, IReceiver<Error>
public class ErrorPageViewModel : ViewModelBase
{
public ErrorPageViewModel()
{
Activator = new ViewModelActivator();
MessageBus.Current.Listen<Error>()
.Subscribe(Receive)
.DisposeWith(VMDisposables);
}
[Reactive] public string ShortMessage { get; set; }
@ -25,7 +29,7 @@ public class ErrorPageViewModel : ViewModelBase, IActivatableViewModel, IReceive
public static void Display(string prefix, Exception ex)
{
MessageBus.Instance.Send(new Error(prefix, ex));
MessageBus.Instance.Send(new NavigateTo(typeof(ErrorPageViewModel)));
MessageBus.Current.SendMessage(new Error(prefix, ex));
MessageBus.Current.SendMessage(new NavigateTo(typeof(ErrorPageViewModel)));
}
}

View File

@ -1,3 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reactive;
@ -20,7 +22,7 @@ using Wabbajack.Paths.IO;
namespace Wabbajack.App.Screens;
public class LauncherViewModel : ViewModelBase, IActivatableViewModel, IReceiver<ConfigureLauncher>
public class LauncherViewModel : ViewModelBase
{
private readonly ILogger<LauncherViewModel> _logger;
@ -32,6 +34,10 @@ public class LauncherViewModel : ViewModelBase, IActivatableViewModel, IReceiver
PlayButton = ReactiveCommand.Create(() => { StartGame().FireAndForget(); });
_logger = logger;
MessageBus.Current.Listen<ConfigureLauncher>()
.Subscribe(v => Receive(v))
.DisposeWith(VMDisposables);
this.WhenActivated(disposables =>
{
this.WhenAnyValue(v => v.InstallFolder)

View File

@ -6,7 +6,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Screens.SettingsView">
<WrapPanel Margin="40">
<Border x:Name="LoginBorder" Margin="5" BorderThickness="1">
<Border x:Name="LoginBorder" Margin="5" BorderThickness="1" Classes="Settings">
<Grid RowDefinitions="Auto, Auto, Auto, Auto" ColumnDefinitions="20, 100, Auto, Auto">
<TextBlock FontSize="20" Grid.ColumnSpan="4">Logins</TextBlock>
@ -34,7 +34,7 @@
</Grid>
</Border>
<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1">
<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1" Classes="Settings">
<Grid RowDefinitions="Auto, Auto">
<TextBlock FontSize="20" Grid.ColumnSpan="4">Resource Limits</TextBlock>

View File

@ -17,7 +17,7 @@ using Wabbajack.Services.OSIntegrated.TokenProviders;
namespace Wabbajack.App.Screens;
public class SettingsViewModel : ViewModelBase, IReceiverMarker
public class SettingsViewModel : ViewModelBase
{
private readonly Subject<AbsolutePath> _fileSystemEvents = new();
private readonly ILogger<SettingsViewModel> _logger;
@ -47,7 +47,7 @@ public class SettingsViewModel : ViewModelBase, IReceiverMarker
.Select(_ => nexusProvider.HaveToken());
NexusLogin =
ReactiveCommand.Create(() => { MessageBus.Instance.Send(new NavigateTo(typeof(NexusLoginViewModel))); },
ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(NexusLoginViewModel))); },
haveNexusToken.Select(x => !x));
NexusLogout = ReactiveCommand.Create(nexusProvider.DeleteToken, haveNexusToken.Select(x => x));
});

View File

@ -30,7 +30,7 @@ using Wabbajack.RateLimiter;
namespace Wabbajack.App.ViewModels;
public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInstallation>
public class StandardInstallationViewModel : ViewModelBase
{
private readonly DTOSerializer _dtos;
private readonly HttpClient _httpClient;
@ -57,6 +57,10 @@ public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInsta
_installStateManager = manager;
Activator = new ViewModelActivator();
MessageBus.Current.Listen<StartInstallation>()
.Subscribe(Receive)
.DisposeWith(VMDisposables);
this.WhenActivated(disposables =>
{
_slideTimer = new Timer(_ =>
@ -214,7 +218,7 @@ public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInsta
Image = path
});
MessageBus.Instance.Send(new ConfigureLauncher(config.Install));
MessageBus.Instance.Send(new NavigateTo(typeof(LauncherViewModel)));
MessageBus.Current.SendMessage(new ConfigureLauncher(config.Install));
MessageBus.Current.SendMessage(new NavigateTo(typeof(LauncherViewModel)));
}
}

View File

@ -35,7 +35,6 @@ public static class ServiceExtensions
public static IServiceCollection AddAppServices(this IServiceCollection services)
{
services.AddAllSingleton<ILoggerProvider, LoggerProvider>();
services.AddSingleton<MessageBus>();
services.AddSingleton<MainWindow>();
services.AddSingleton<BrowseViewModel>();
services.AddTransient<BrowseItemViewModel>();
@ -58,23 +57,24 @@ public static class ServiceExtensions
services.AddSingleton<IScreenView, BrowseView>();
services.AddSingleton<IScreenView, LauncherView>();
services.AddSingleton<IScreenView, PlaySelectView>();
services.AddSingleton<ImageCache>();
services.AddSingleton<InstallationStateManager>();
services.AddSingleton<HttpClient>();
services.AddSingleton<LogScreenViewModel>();
services.AddSingleton<PlaySelectViewModel>();
services.AddAllSingleton<IReceiverMarker, ErrorPageViewModel>();
services.AddAllSingleton<IReceiverMarker, StandardInstallationViewModel>();
services.AddAllSingleton<IReceiverMarker, InstallConfigurationViewModel>();
services.AddAllSingleton<IReceiverMarker, CompilerConfigurationViewModel>();
services.AddAllSingleton<IReceiverMarker, MainWindowViewModel>();
services.AddAllSingleton<IReceiverMarker, SettingsViewModel>();
services.AddAllSingleton<IReceiverMarker, NexusLoginViewModel>();
services.AddAllSingleton<IReceiverMarker, LoversLabOAuthLoginViewModel>();
services.AddAllSingleton<IReceiverMarker, VectorPlexusOAuthLoginViewModel>();
services.AddAllSingleton<IReceiverMarker, CompilationViewModel>();
services.AddAllSingleton<IReceiverMarker, LauncherViewModel>();
services.AddSingleton<ErrorPageViewModel>();
services.AddSingleton<StandardInstallationViewModel>();
services.AddSingleton<InstallConfigurationViewModel>();
services.AddSingleton<CompilerConfigurationViewModel>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<SettingsViewModel>();
services.AddSingleton<NexusLoginViewModel>();
services.AddSingleton<LoversLabOAuthLoginViewModel>();
services.AddSingleton<VectorPlexusOAuthLoginViewModel>();
services.AddSingleton<CompilationViewModel>();
services.AddSingleton<LauncherViewModel>();
// Services
services.AddAllSingleton<IDownloader, IDownloader<Manual>, ManualDownloader>();
@ -98,7 +98,8 @@ public static class ServiceExtensions
EncryptedDataLocation = KnownFolders.WabbajackAppLocal.Combine("encrypted"),
ModListsDownloadLocation = KnownFolders.EntryPoint.Combine("downloaded_mod_lists"),
SavedSettingsLocation = KnownFolders.WabbajackAppLocal.Combine("saved_settings"),
LogLocation = KnownFolders.EntryPoint.Combine("logs")
LogLocation = KnownFolders.EntryPoint.Combine("logs"),
ImageCacheLocation = KnownFolders.WabbajackAppLocal.Combine("image_cache")
});
services.AddSingleton<SettingsManager>();

View File

@ -9,7 +9,7 @@ using Wabbajack.App.Messages;
namespace Wabbajack.App.ViewModels;
public abstract class GuidedWebViewModel : ViewModelBase, IReceiverMarker
public abstract class GuidedWebViewModel : ViewModelBase
{
protected ILogger _logger;

View File

@ -1,7 +1,9 @@
using System;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Avalonia.Controls.Mixins;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using ReactiveUI;
@ -21,7 +23,7 @@ using Wabbajack.Paths.IO;
namespace Wabbajack.App.ViewModels;
public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewModel, IReceiver<StartInstallConfiguration>
public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewModel
{
private readonly DTOSerializer _dtos;
private readonly InstallationStateManager _stateManager;
@ -33,6 +35,11 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode
_dtos = dtos;
Activator = new ViewModelActivator();
MessageBus.Current.Listen<StartInstallConfiguration>()
.Subscribe(Receive)
.DisposeWith(VMDisposables);
this.WhenActivated(disposables =>
{
this.ValidationRule(x => x.ModListPath, p => p.FileExists(), "Wabbajack file must exist");
@ -88,7 +95,7 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode
public ViewModelActivator Activator { get; }
public void Receive(StartInstallConfiguration val)
private void Receive(StartInstallConfiguration val)
{
ModListPath = val.ModList;
}
@ -108,8 +115,8 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode
Metadata = metadata
}).FireAndForget();
MessageBus.Instance.Send(new NavigateTo(typeof(StandardInstallationViewModel)));
MessageBus.Instance.Send(new StartInstallation(ModListPath, Install, Download, metadata));
MessageBus.Current.SendMessage(new NavigateTo(typeof(StandardInstallationViewModel)));
MessageBus.Current.SendMessage(new StartInstallation(ModListPath, Install, Download, metadata));
}
private async Task<IBitmap> LoadModListImage(AbsolutePath path)

View File

@ -22,8 +22,7 @@ using Wabbajack.RateLimiter;
namespace Wabbajack.App.ViewModels;
public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewModel, IReceiver<NavigateTo>,
IReceiver<NavigateBack>
public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewModel, IDisposable
{
private readonly InstallationStateManager _manager;
private readonly IServiceProvider _provider;
@ -32,6 +31,8 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
private readonly IEnumerable<IScreenView> _screens;
private StatusReport[] _prevReport;
private CompositeDisposable VMDisposables = new();
public MainWindowViewModel(IEnumerable<IScreenView> screens, IEnumerable<IResource> resources,
IServiceProvider provider,
InstallationStateManager manager)
@ -45,6 +46,14 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
Activator = new ViewModelActivator();
MessageBus.Current.Listen<NavigateTo>()
.Subscribe(Receive)
.DisposeWith(VMDisposables);
MessageBus.Current.Listen<NavigateBack>()
.Subscribe(Receive)
.DisposeWith(VMDisposables);
_resourcePoller = StartResourcePoller(TimeSpan.FromSeconds(0.25));
this.WhenActivated(disposables =>
@ -103,7 +112,7 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
BreadCrumbs =
BreadCrumbs.Push((Control) _screens.First(s => s.ViewModelType == typeof(ModeSelectionViewModel)));
MessageBus.Instance.Send(new ConfigureLauncher(setting.Install));
MessageBus.Current.SendMessage(new ConfigureLauncher(setting.Install));
Receive(new NavigateTo(typeof(LauncherViewModel)));
}
else
@ -137,4 +146,10 @@ public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewMod
await Task.Delay(TimeSpan.FromSeconds(0.5));
}
}
public void Dispose()
{
_resourcePoller.Dispose();
VMDisposables.Dispose();
}
}

View File

@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using Fizzler.Systems.HtmlAgilityPack;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using Wabbajack.App.Extensions;
using Wabbajack.App.Messages;
using Wabbajack.DTOs.Logins;
@ -87,7 +88,7 @@ public class NexusLoginViewModel : GuidedWebViewModel
token.ThrowIfCancellationRequested();
await Task.Delay(500, token);
MessageBus.Instance.Send(new NavigateBack());
MessageBus.Current.SendMessage(new NavigateBack());
}
Instructions = "Success, saving information...";

View File

@ -1,9 +1,18 @@
using ReactiveUI;
using System;
using System.Reactive.Disposables;
using ReactiveUI;
using ReactiveUI.Validation.Helpers;
namespace Wabbajack.App.ViewModels;
public class ViewModelBase : ReactiveValidationObject, IActivatableViewModel
public class ViewModelBase : ReactiveValidationObject, IActivatableViewModel, IDisposable
{
protected readonly CompositeDisposable VMDisposables = new();
public ViewModelActivator Activator { get; protected set; }
public void Dispose()
{
VMDisposables.Dispose();
Activator.Dispose();
}
}

View File

@ -33,7 +33,7 @@
<Grid RowDefinitions="40, *">
<Grid ColumnDefinitions="40, *, 40, 40, 40, 40">
<Button Grid.Column="0" x:Name="BackButton">
<Button Grid.Column="0" x:Name="BackButton" x:FieldModifier="public">
<i:MaterialIcon Kind="ArrowBack" />
</Button>
@ -50,12 +50,12 @@
<i:MaterialIcon Kind="WindowMinimize" />
</Button>
<Button Grid.Column="5" x:Name="CloseButton">
<Button Grid.Column="5" x:Name="CloseButton" x:FieldModifier="public">
<i:MaterialIcon Kind="Close" />
</Button>
</Grid>
<ContentControl Grid.Row="1" x:Name="Contents" />
<ContentControl Grid.Row="1" x:Name="Contents" x:FieldModifier="public" />
</Grid>

View File

@ -14,7 +14,7 @@
<Image Margin="40,20,40,0" Source="../Assets/Wabba_Mouth.png" />
</Viewbox>
<Grid Grid.Row="1" ColumnDefinitions="*, *, *, *" HorizontalAlignment="Center">
<controls:LargeIconButton Grid.Column="0" Text="Browse" Icon="CloudDownload" x:Name="BrowseButton" />
<controls:LargeIconButton Grid.Column="0" Text="Browse" Icon="CloudDownload" x:Name="BrowseButton" x:FieldModifier="public"/>
<controls:LargeIconButton Grid.Column="1" Text="Install" Icon="HarddiskPlus" x:Name="InstallButton" />
<controls:LargeIconButton Grid.Column="2" Text="Compile" Icon="DatabaseImport" x:Name="CompileButton" />
<controls:LargeIconButton Grid.Column="3" Text="Play" Icon="TelevisionPlay" x:Name="LaunchButton" />

View File

@ -16,22 +16,22 @@ public partial class ModeSelectionView : ScreenBase<ModeSelectionViewModel>
{
InstallButton.Button.Command = ReactiveCommand.Create(() =>
{
MessageBus.Instance.Send(new NavigateTo(typeof(InstallConfigurationViewModel)));
MessageBus.Current.SendMessage(new NavigateTo(typeof(InstallConfigurationViewModel)));
}).DisposeWith(disposables);
BrowseButton.Button.Command = ReactiveCommand.Create(() =>
{
MessageBus.Instance.Send(new NavigateTo(typeof(BrowseViewModel)));
MessageBus.Current.SendMessage(new NavigateTo(typeof(BrowseViewModel)));
}).DisposeWith(disposables);
CompileButton.Button.Command = ReactiveCommand.Create(() =>
{
MessageBus.Instance.Send(new NavigateTo(typeof(CompilerConfigurationViewModel)));
MessageBus.Current.SendMessage(new NavigateTo(typeof(CompilerConfigurationViewModel)));
}).DisposeWith(disposables);
LaunchButton.Button.Command = ReactiveCommand.Create(() =>
{
MessageBus.Instance.Send(new NavigateTo(typeof(PlaySelectViewModel)));
MessageBus.Current.SendMessage(new NavigateTo(typeof(PlaySelectViewModel)));
});
});
}

View File

@ -6,35 +6,35 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\"/>
<AvaloniaResource Include="Assets\**"/>
<AvaloniaXaml Remove="Assets\Wabbajack.axaml"/>
<AvaloniaResource Include="Assets\Wabbajack.axaml"/>
<Folder Include="Models\" />
<AvaloniaResource Include="Assets\**" />
<AvaloniaXaml Remove="Assets\Wabbajack.axaml" />
<AvaloniaResource Include="Assets\Wabbajack.axaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.8"/>
<PackageReference Include="Avalonia.Desktop" Version="0.10.8"/>
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.8"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.8"/>
<PackageReference Include="CefNet.Avalonia" Version="94.0.21246.700"/>
<PackageReference Include="DynamicData" Version="7.4.1"/>
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1"/>
<PackageReference Include="HtmlAgilityPack" Version="1.11.37"/>
<PackageReference Include="Material.Icons.Avalonia" Version="1.0.2"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0-rc.2.21480.5"/>
<PackageReference Include="ReactiveUI.Fody" Version="16.2.6"/>
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1"/>
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4"/>
<PackageReference Include="Avalonia" Version="0.10.8" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.8" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.8" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.8" />
<PackageReference Include="CefNet.Avalonia" Version="94.0.21246.700" />
<PackageReference Include="DynamicData" Version="7.4.1" />
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.37" />
<PackageReference Include="Material.Icons.Avalonia" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0-rc.2.21480.5" />
<PackageReference Include="ReactiveUI.Fody" Version="16.2.6" />
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.CLI\Wabbajack.CLI.csproj"/>
<ProjectReference Include="..\Wabbajack.DTOs\Wabbajack.DTOs.csproj"/>
<ProjectReference Include="..\Wabbajack.Installer\Wabbajack.Installer.csproj"/>
<ProjectReference Include="..\Wabbajack.Paths\Wabbajack.Paths.csproj"/>
<ProjectReference Include="..\Wabbajack.Services.OSIntegrated\Wabbajack.Services.OSIntegrated.csproj"/>
<ProjectReference Include="..\Wabbajack.CLI\Wabbajack.CLI.csproj" />
<ProjectReference Include="..\Wabbajack.DTOs\Wabbajack.DTOs.csproj" />
<ProjectReference Include="..\Wabbajack.Installer\Wabbajack.Installer.csproj" />
<ProjectReference Include="..\Wabbajack.Paths\Wabbajack.Paths.csproj" />
<ProjectReference Include="..\Wabbajack.Services.OSIntegrated\Wabbajack.Services.OSIntegrated.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Mvc.Core"/>
<Reference Include="Microsoft.AspNetCore.Mvc.Core" />
</ItemGroup>
<ItemGroup>
<Compile Update="Screens\SettingsView.axaml.cs">
@ -51,7 +51,7 @@
</ItemGroup>
<Target Name="AferBuild" AfterTargets="Build" Condition="!Exists('$(ProjectDir)$(OutDir)libcef.dll')">
<Message Text="Downloading Cef"/>
<Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)"/>
<Message Text="Downloading Cef" />
<Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)" />
</Target>
</Project>

View File

@ -116,8 +116,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.GameF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Launcher", "Wabbajack.Launcher\Wabbajack.Launcher.csproj", "{23D49FCC-A6CB-4873-879B-F90DA1871AA3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.App.Test", "Wabbajack.App.Test\Wabbajack.App.Test.csproj", "{05E7E8BB-1F44-4E3D-8443-110FD237AA92}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -324,10 +322,6 @@ Global
{23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Release|Any CPU.Build.0 = Release|Any CPU
{05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05E7E8BB-1F44-4E3D-8443-110FD237AA92}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4057B668-8595-44FE-9805-007B284A838F} = {98B731EE-4FC0-4482-A069-BCBA25497871}

5
global.json Normal file
View File

@ -0,0 +1,5 @@
{
"sdk": {
"version": "6.0.*"
}
}