Code cleanup and fix test running

This commit is contained in:
Timothy Baldridge 2021-10-23 10:51:17 -06:00
parent 2b5662a15b
commit f99f4a7538
577 changed files with 26516 additions and 27096 deletions

View File

@ -43,7 +43,7 @@ jobs:
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --filter "Category=!FlakeyNetwork"
run: dotnet test --no-restore --filter "Category!=FlakeyNetwork"
publish:
name: Publish Projects

View File

@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using Avalonia.Threading;
using ReactiveUI;
using Wabbajack.App.Models;
namespace Wabbajack.App.Test;
@ -28,6 +27,7 @@ public static class Extensions
await Task.Delay(100);
}
}
public static async Task WaitForUnlock(this LoadingLock l)
{
Dispatcher.UIThread.RunJobs();

View File

@ -1,5 +1,4 @@
using System;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Wabbajack.App.Controls;
@ -15,8 +14,8 @@ namespace Wabbajack.App.Test;
public class GalleryItemTests
{
private readonly BrowseViewModel _gallery;
private readonly Configuration _config;
private readonly BrowseViewModel _gallery;
public GalleryItemTests(BrowseViewModel bvm, Configuration config)
{
@ -28,9 +27,7 @@ public class GalleryItemTests
public async Task CanDownloadGalleryItem()
{
foreach (var file in _config.ModListsDownloadLocation.EnumerateFiles().Where(f => f.Extension == Ext.Wabbajack))
{
file.Delete();
}
using var _ = _gallery.Activator.Activate();
await _gallery.LoadingLock.WaitForLock();

View File

@ -1,17 +1,13 @@
using System.Collections.Generic;
using Avalonia.Threading;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Wabbajack.App;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Services.OSIntegrated;
using Xunit.DependencyInjection;
using Xunit.DependencyInjection.Logging;
namespace Wabbajack.App.Test
namespace Wabbajack.App.Test;
public class Startup
{
public class Startup
{
public void ConfigureServices(IServiceCollection service)
{
service.AddAppServices();
@ -22,14 +18,14 @@ namespace Wabbajack.App.Test
loggerFactory.AddProvider(new XunitTestOutputLoggerProvider(accessor, delegate { return true; }));
MessageBus.Instance = new SimpleMessageBus();
}
}
}
public class SimpleMessageBus : IMessageBus
{
public class SimpleMessageBus : IMessageBus
{
public List<object> Messages { get; } = new();
public void Send<T>(T message)
{
Messages.Add(message);
}
}
}

View File

@ -7,21 +7,21 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<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="7.7.0" />
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="7.5.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="7.7.0"/>
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="7.5.1"/>
<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" />
<ProjectReference Include="..\Wabbajack.App\Wabbajack.App.csproj"/>
</ItemGroup>
</Project>

View File

@ -1,25 +1,24 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Wabbajack.App"
xmlns:i="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
x:Class="Wabbajack.App.App">
<Application.DataTemplates>
<local:ViewLocator/>
<local:ViewLocator />
</Application.DataTemplates>
<Application.Styles>
<StyleInclude Source="avares://Material.Icons.Avalonia/App.xaml"></StyleInclude>
<FluentTheme Mode="Dark"/>
<StyleInclude Source="avares://Wabbajack.App/Assets/Wabbajack.axaml"></StyleInclude>
<StyleInclude Source="avares://Material.Icons.Avalonia/App.xaml" />
<FluentTheme Mode="Dark" />
<StyleInclude Source="avares://Wabbajack.App/Assets/Wabbajack.axaml" />
<Style Selector="Button:not(:pointerover) /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Background" Value="Transparent" />
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="BorderBrush" Value="LightGray"></Setter>
<Setter Property="CornerRadius" Value="5"></Setter>
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="5" />
</Style>
</Application.Styles>
</Application>

View File

@ -3,32 +3,25 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using CefNet;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using Splat;
using Wabbajack.App.Controls;
using Wabbajack.App.Converters;
using Wabbajack.App.Interfaces;
using Wabbajack.App.Models;
using Wabbajack.App.Utilities;
using Wabbajack.App.ViewModels;
using Wabbajack.App.Views;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Networking.NexusApi;
using Wabbajack.Services.OSIntegrated;
namespace Wabbajack.App
namespace Wabbajack.App;
public class App : Application
{
public class App : Application
{
public static IServiceProvider Services { get; private set; } = null!;
public static Window? MainWindow { get; set; }
public static event EventHandler FrameworkInitialized;
public static event EventHandler FrameworkShutdown;
public static IServiceProvider Services { get; private set; } = null!;
public static Window? MainWindow { get; set; }
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
@ -37,14 +30,8 @@ namespace Wabbajack.App
public override void OnFrameworkInitializationCompleted()
{
var host = Host.CreateDefaultBuilder(Array.Empty<string>())
.ConfigureLogging(c =>
{
c.ClearProviders();
})
.ConfigureServices((host, services) =>
{
services.AddAppServices();
}).Build();
.ConfigureLogging(c => { c.ClearProviders(); })
.ConfigureServices((host, services) => { services.AddAppServices(); }).Build();
Services = host.Services;
SetupConverters();
@ -78,5 +65,4 @@ namespace Wabbajack.App
{
Locator.CurrentMutable.RegisterConstant<IBindingTypeConverter>(new AbsoultePathBindingConverter());
}
}
}

View File

@ -9,34 +9,31 @@
<Style Selector="controls|TagView Border">
<Setter Property="BorderThickness" Value="1"></Setter>
<Setter Property="BorderBrush" Value="#121212"></Setter>
<Setter Property="CornerRadius" Value="5"></Setter>
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="#121212" />
<Setter Property="CornerRadius" Value="5" />
</Style>
<Style Selector="controls|TagView.ModList Border">
<Setter Property="Background" Value="#868CFC"></Setter>
<Setter Property="Background" Value="#868CFC" />
</Style>
<Style Selector="controls|TagView.Game Border">
<Setter Property="Background" Value="#F686FC"></Setter>
<Setter Property="Background" Value="#F686FC" />
</Style>
<Style Selector="controls|TagView.GameNotInstalled Border">
<Setter Property="Background" Value="#FCBB86"></Setter>
<Setter Property="Background" Value="#FCBB86" />
</Style>
<Style Selector="controls|TagView.GameNotInstalled Border">
<Setter Property="Background" Value="#FCBB86"></Setter>
<Setter Property="Background" Value="#FCBB86" />
</Style>
<Style Selector="controls|TagView TextBlock">
<Setter Property="Foreground" Value="#121212"></Setter>
<Setter Property="Foreground" Value="#121212" />
</Style>
</Styles>

View File

@ -1 +1,6 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="cloud-download-alt" class="svg-inline--fa fa-cloud-download-alt fa-w-20" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zm-132.9 88.7L299.3 420.7c-6.2 6.2-16.4 6.2-22.6 0L171.3 315.3c-10.1-10.1-2.9-27.3 11.3-27.3H248V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16v112h65.4c14.2 0 21.4 17.2 11.3 27.3z"></path></svg>
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="cloud-download-alt"
class="svg-inline--fa fa-cloud-download-alt fa-w-20" role="img" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 640 512">
<path fill="currentColor"
d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zm-132.9 88.7L299.3 420.7c-6.2 6.2-16.4 6.2-22.6 0L171.3 315.3c-10.1-10.1-2.9-27.3 11.3-27.3H248V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16v112h65.4c14.2 0 21.4 17.2 11.3 27.3z"></path>
</svg>

Before

Width:  |  Height:  |  Size: 687 B

After

Width:  |  Height:  |  Size: 713 B

View File

@ -1,14 +1,13 @@
using Wabbajack.Paths;
namespace Wabbajack.App
namespace Wabbajack.App;
public class Configuration
{
public class Configuration
{
public AbsolutePath ModListsDownloadLocation { get; set; }
public AbsolutePath SavedSettingsLocation { get; set; }
public AbsolutePath EncryptedDataLocation { get; set; }
public AbsolutePath LogLocation { get; set; }
}
}

View File

@ -42,12 +42,12 @@
<ItemsControl Grid.Row="2" x:Name="TagsList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:TagView></controls:TagView>
<controls:TagView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
@ -89,7 +89,7 @@
<avalonia:MaterialIcon
Width="20"
Height="20"
x:Name="ExecuteIcon"/>
x:Name="ExecuteIcon" />
</Button>
</Grid>
</Grid>

View File

@ -1,17 +1,13 @@
using System;
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using Material.Icons;
using ReactiveUI;
using Wabbajack.App.Views;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public partial class BrowseItemView : ReactiveUserControl<BrowseItemViewModel>
{
public partial class BrowseItemView : ReactiveUserControl<BrowseItemViewModel>
{
public BrowseItemView()
{
InitializeComponent();
@ -52,5 +48,4 @@ namespace Wabbajack.App.Controls
_ => throw new ArgumentOutOfRangeException(nameof(modListState), modListState, null)
};
}
}
}

View File

@ -4,13 +4,10 @@ using System.Linq;
using System.Net.Http;
using System.Reactive;
using System.Reactive.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.CompilerServices;
using Octokit;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Messages;
@ -20,64 +17,37 @@ using Wabbajack.Downloaders;
using Wabbajack.Downloaders.GameFile;
using Wabbajack.DTOs;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Installer;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.VFS;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public enum ModListState
{
public enum ModListState
{
Downloaded,
NotDownloaded,
Downloading
}
}
public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
{
private readonly ModlistMetadata _metadata;
private readonly ModListSummary _summary;
public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
{
private readonly HttpClient _client;
private readonly IResource<HttpClient> _limiter;
private readonly FileHashCache _hashCache;
private readonly Configuration _configuration;
private readonly DownloadDispatcher _dispatcher;
private readonly ILogger _logger;
private readonly IResource<DownloadDispatcher> _downloadLimiter;
private readonly DTOSerializer _dtos;
private readonly FileHashCache _hashCache;
private readonly IResource<HttpClient> _limiter;
private readonly ILogger _logger;
private readonly ModlistMetadata _metadata;
private readonly ModListSummary _summary;
public string Title => _metadata.ImageContainsTitle ? "" : _metadata.Title;
public string MachineURL => _metadata.Links.MachineURL;
public string Description => _metadata.Description;
public Uri ImageUri => new(_metadata.Links.ImageUri);
[Reactive]
public IBitmap Image { get; set; }
[Reactive]
public ModListState State { get; set; }
[Reactive]
public ReactiveCommand<Unit,Unit> ExecuteCommand { get; set; }
[Reactive]
public Percent Progress { get; set; }
public AbsolutePath ModListLocation => _configuration.ModListsDownloadLocation.Combine(_metadata.Links.MachineURL).WithExtension(Ext.Wabbajack);
public Game Game => _metadata.Game;
public bool IsUtilityList => _metadata.UtilityList;
public bool IsNSFW => _metadata.NSFW;
[Reactive]
public TagViewModel[] Tags { get; set; }
public BrowseItemViewModel(ModlistMetadata metadata, ModListSummary summary, HttpClient client, IResource<HttpClient> limiter,
FileHashCache hashCache, Configuration configuration, DownloadDispatcher dispatcher, IResource<DownloadDispatcher> downloadLimiter, GameLocator gameLocator,
public BrowseItemViewModel(ModlistMetadata metadata, ModListSummary summary, HttpClient client,
IResource<HttpClient> limiter,
FileHashCache hashCache, Configuration configuration, DownloadDispatcher dispatcher,
IResource<DownloadDispatcher> downloadLimiter, GameLocator gameLocator,
DTOSerializer dtos, ILogger logger)
{
Activator = new ViewModelActivator();
@ -95,7 +65,8 @@ namespace Wabbajack.App.Controls
var haveGame = gameLocator.IsInstalled(_metadata.Game);
Tags = metadata.tags
.Select(t => new TagViewModel(t, "ModList"))
.Prepend(new TagViewModel(_metadata.Game.MetaData().HumanFriendlyGameName, haveGame ? "Game" : "GameNotInstalled"))
.Prepend(new TagViewModel(_metadata.Game.MetaData().HumanFriendlyGameName,
haveGame ? "Game" : "GameNotInstalled"))
.ToArray();
OpenWebsiteCommand = ReactiveCommand.Create(() =>
@ -114,7 +85,6 @@ namespace Wabbajack.App.Controls
{
DownloadModList().FireAndForget();
}
},
this.ObservableForProperty(t => t.State)
.Select(c => c.Value != ModListState.Downloading)
@ -124,6 +94,33 @@ namespace Wabbajack.App.Controls
UpdateState().FireAndForget();
}
public string Title => _metadata.ImageContainsTitle ? "" : _metadata.Title;
public string MachineURL => _metadata.Links.MachineURL;
public string Description => _metadata.Description;
public Uri ImageUri => new(_metadata.Links.ImageUri);
[Reactive] public IBitmap Image { get; set; }
[Reactive] public ModListState State { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> ExecuteCommand { get; set; }
[Reactive] public Percent Progress { get; set; }
public AbsolutePath ModListLocation => _configuration.ModListsDownloadLocation.Combine(_metadata.Links.MachineURL)
.WithExtension(Ext.Wabbajack);
public Game Game => _metadata.Game;
public bool IsUtilityList => _metadata.UtilityList;
public bool IsNSFW => _metadata.NSFW;
[Reactive] public TagViewModel[] Tags { get; set; }
public ReactiveCommand<Unit, Unit> OpenWebsiteCommand { get; set; }
private async Task DownloadModList()
{
State = ModListState.Downloading;
@ -164,9 +161,6 @@ namespace Wabbajack.App.Controls
}
public ReactiveCommand<Unit,Unit> OpenWebsiteCommand { get; set; }
public async Task LoadListImage()
{
using var job = await _limiter.Begin("Loading modlist image", 0, CancellationToken.None);
@ -180,14 +174,14 @@ namespace Wabbajack.App.Controls
if (!file.FileExists())
return ModListState.NotDownloaded;
return (await _hashCache.FileHashCachedAsync(file, CancellationToken.None)) !=
_metadata.DownloadMetadata?.Hash ? ModListState.NotDownloaded : ModListState.Downloaded;
return await _hashCache.FileHashCachedAsync(file, CancellationToken.None) !=
_metadata.DownloadMetadata?.Hash
? ModListState.NotDownloaded
: ModListState.Downloaded;
}
public async Task UpdateState()
{
State = await GetState();
}
}
}

View File

@ -8,34 +8,34 @@
<UserControl.Styles>
<Style Selector="Button:not(:pointerover) /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="BorderBrush" Value="LightGray"></Setter>
<Setter Property="CornerRadius" Value="0, 5, 5, 0"></Setter>
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="0, 5, 5, 0" />
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="BorderBrush" Value="LightGray"></Setter>
<Setter Property="CornerRadius" Value="0, 5, 5, 0"></Setter>
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="0, 5, 5, 0" />
</Style>
<Style Selector="TextBox:not(:focus) /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="BorderBrush" Value="LightGray"></Setter>
<Setter Property="CornerRadius" Value="5, 0, 0, 5"></Setter>
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="5, 0, 0, 5" />
</Style>
<Style Selector="TextBox:focus /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="BorderBrush" Value="LightGray"></Setter>
<Setter Property="CornerRadius" Value="5, 0, 0, 5"></Setter>
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="5, 0, 0, 5" />
</Style>
</UserControl.Styles>
<Grid ColumnDefinitions="*, 30" Height="30">
<TextBox Grid.Column="0" Name="Path" Height="30" x:Name="TextBox" IsEnabled="False"></TextBox>
<TextBox Grid.Column="0" Name="Path" Height="30" x:Name="TextBox" IsEnabled="False" />
<Button Grid.Column="1" Name="SelectButton" Height="30">
<i:MaterialIcon Kind="Search"></i:MaterialIcon>
<i:MaterialIcon Kind="Search" />
</Button>
</Grid>
</UserControl>

View File

@ -1,21 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using Microsoft.Extensions.DependencyInjection;
using ReactiveUI;
using Wabbajack.Paths;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public partial class FileSelectionBox : ReactiveUserControl<FileSelectionBoxViewModel>
{
public partial class FileSelectionBox : ReactiveUserControl<FileSelectionBoxViewModel>
{
public static readonly DirectProperty<FileSelectionBox, AbsolutePath> SelectedPathProperty =
AvaloniaProperty.RegisterDirect<FileSelectionBox, AbsolutePath>(nameof(SelectedPath), o => o.SelectedPath);
public static readonly StyledProperty<string> AllowedExtensionsProperty =
AvaloniaProperty.Register<FileSelectionBox, string>(nameof(AllowedExtensions));
public static readonly StyledProperty<bool> SelectFolderProperty =
AvaloniaProperty.Register<FileSelectionBox, bool>(nameof(SelectFolder));
private AbsolutePath _selectedPath;
public FileSelectionBox()
{
DataContext = App.Services.GetService<FileSelectionBoxViewModel>()!;
@ -43,31 +50,21 @@ namespace Wabbajack.App.Controls
});
}
public static readonly DirectProperty<FileSelectionBox, AbsolutePath> SelectedPathProperty =
AvaloniaProperty.RegisterDirect<FileSelectionBox, AbsolutePath>(nameof(SelectedPath), o => o.SelectedPath);
private AbsolutePath _selectedPath;
public AbsolutePath SelectedPath
{
get => _selectedPath;
set => SetAndRaise(SelectedPathProperty, ref _selectedPath, value);
}
public static readonly StyledProperty<string> AllowedExtensionsProperty =
AvaloniaProperty.Register<FileSelectionBox, string>(nameof(AllowedExtensions));
public string AllowedExtensions
{
get => GetValue(AllowedExtensionsProperty);
set => SetValue(AllowedExtensionsProperty, value);
}
public static readonly StyledProperty<bool> SelectFolderProperty =
AvaloniaProperty.Register<FileSelectionBox, bool>(nameof(SelectFolder));
public bool SelectFolder
{
get => GetValue(SelectFolderProperty);
set => SetValue(SelectFolderProperty, value);
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
@ -9,22 +10,12 @@ using ReactiveUI.Fody.Helpers;
using Wabbajack.App.ViewModels;
using Wabbajack.Paths;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public class FileSelectionBoxViewModel : ViewModelBase
{
public class FileSelectionBoxViewModel : ViewModelBase
{
[Reactive] public AbsolutePath Path { get; set; }
[Reactive] public Extension[] Extensions { get; set; } = Array.Empty<Extension>();
[Reactive] public bool SelectFolder { get; set; }
[Reactive]
public ReactiveCommand<Unit, Task> BrowseCommand { get; set; } = null!;
public FileSelectionBoxViewModel()
{
Activator = new ViewModelActivator();
this.WhenActivated(disposables =>
{
@ -32,9 +23,9 @@ namespace Wabbajack.App.Controls
{
if (SelectFolder)
{
var dialog = new OpenFolderDialog()
var dialog = new OpenFolderDialog
{
Title = "Select a folder",
Title = "Select a folder"
};
var result = await dialog.ShowAsync(App.MainWindow);
if (result != null)
@ -47,9 +38,9 @@ namespace Wabbajack.App.Controls
{
AllowMultiple = false,
Title = "Select a file",
Filters = new()
Filters = new List<FileDialogFilter>
{
new FileDialogFilter { Extensions = extensions, Name = "*" }
new FileDialogFilter {Extensions = extensions, Name = "*"}
}
};
var results = await dialog.ShowAsync(App.MainWindow);
@ -58,8 +49,13 @@ namespace Wabbajack.App.Controls
}
}).DisposeWith(disposables);
});
}
}
[Reactive] public AbsolutePath Path { get; set; }
[Reactive] public Extension[] Extensions { get; set; } = Array.Empty<Extension>();
[Reactive] public bool SelectFolder { get; set; }
[Reactive] public ReactiveCommand<Unit, Task> BrowseCommand { get; set; } = null!;
}

View File

@ -4,5 +4,5 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.GameSelectorItemView">
<TextBlock x:Name="GameName"></TextBlock>
<TextBlock x:Name="GameName" />
</UserControl>

View File

@ -1,14 +1,11 @@
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using ReactiveUI;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public partial class GameSelectorItemView : ReactiveUserControl<GameSelectorItemViewModel>
{
public partial class GameSelectorItemView : ReactiveUserControl<GameSelectorItemViewModel>
{
public GameSelectorItemView()
{
InitializeComponent();
@ -19,6 +16,4 @@ namespace Wabbajack.App.Controls
.DisposeWith(disposables);
});
}
}
}

View File

@ -3,21 +3,18 @@ using ReactiveUI.Fody.Helpers;
using Wabbajack.App.ViewModels;
using Wabbajack.DTOs;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public class GameSelectorItemViewModel : ViewModelBase, IActivatableViewModel
{
public class GameSelectorItemViewModel : ViewModelBase, IActivatableViewModel
{
[Reactive]
public Game Game { get; set; }
[Reactive]
public string Name { get; set; }
public GameSelectorItemViewModel(Game game)
{
Activator = new ViewModelActivator();
Game = game;
Name = game.MetaData().HumanFriendlyGameName;
}
}
[Reactive] public Game Game { get; set; }
[Reactive] public string Name { get; set; }
}

View File

@ -6,10 +6,10 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.InstalledListView">
<Grid RowDefinitions="Auto, Auto" ColumnDefinitions="*, Auto">
<TextBlock Grid.Row="0" Grid.Column="0" x:Name="Title"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="InstallationPath"></TextBlock>
<TextBlock Grid.Row="0" Grid.Column="0" x:Name="Title" />
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="InstallationPath" />
<Button Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" x:Name="PlayButton">
<i:MaterialIcon Kind="PlayArrow"></i:MaterialIcon>
<i:MaterialIcon Kind="PlayArrow" />
</Button>
</Grid>
</UserControl>

View File

@ -1,7 +1,6 @@
using Avalonia.Controls.Mixins;
using Avalonia.ReactiveUI;
using ReactiveUI;
using Wabbajack.App.Utilities;
namespace Wabbajack.App.Controls;
@ -24,5 +23,4 @@ public partial class InstalledListView : ReactiveUserControl<InstalledListViewMo
.DisposeWith(disposables);
});
}
}

View File

@ -1,6 +1,5 @@
using System.Reactive;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Messages;
using Wabbajack.App.Screens;
using Wabbajack.App.ViewModels;
@ -12,10 +11,6 @@ namespace Wabbajack.App.Controls;
public class InstalledListViewModel : ViewModelBase
{
private readonly InstallationConfigurationSetting _setting;
public AbsolutePath InstallPath => _setting.Install;
public string Name => _setting.Metadata?.Title ?? "";
public ReactiveCommand<Unit, Unit> Play { get; }
public InstalledListViewModel(InstallationConfigurationSetting setting)
{
@ -29,4 +24,8 @@ public class InstalledListViewModel : ViewModelBase
});
}
public AbsolutePath InstallPath => _setting.Install;
public string Name => _setting.Metadata?.Title ?? "";
public ReactiveCommand<Unit, Unit> Play { get; }
}

View File

@ -7,8 +7,8 @@
x:Class="Wabbajack.App.Controls.LargeIconButton">
<Button x:Name="Button">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<i:MaterialIcon x:Name="IconControl" Width="140" Height="140"></i:MaterialIcon>
<TextBlock x:Name="TextBlock" HorizontalAlignment="Center" FontSize="28" FontWeight="Bold"></TextBlock>
<i:MaterialIcon x:Name="IconControl" Width="140" Height="140" />
<TextBlock x:Name="TextBlock" HorizontalAlignment="Center" FontSize="28" FontWeight="Bold" />
</StackPanel>
</Button>

View File

@ -2,34 +2,20 @@ using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Material.Icons;
using Material.Icons.Avalonia;
using ReactiveUI;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public partial class LargeIconButton : UserControl, IActivatableView
{
public partial class LargeIconButton : UserControl, IActivatableView
{
public static readonly StyledProperty<string> TextProperty =
AvaloniaProperty.Register<LargeIconButton, string>(nameof(Text));
public string Text
{
get => GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public static readonly StyledProperty<MaterialIconKind> IconProperty =
AvaloniaProperty.Register<LargeIconButton, MaterialIconKind>(nameof(IconProperty));
public MaterialIconKind Icon
{
get => GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
public LargeIconButton()
{
InitializeComponent();
@ -45,9 +31,17 @@ namespace Wabbajack.App.Controls
.BindTo(TextBlock, x => x.Text)
.DisposeWith(dispose);
});
}
public string Text
{
get => GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public MaterialIconKind Icon
{
get => GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
}

View File

@ -13,22 +13,22 @@
<ItemsControl x:Name="Messages">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:LogViewItem></controls:LogViewItem>
<controls:LogViewItem />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="CopyLog">
<avalonia:MaterialIcon Kind="ContentCopy"></avalonia:MaterialIcon>
<avalonia:MaterialIcon Kind="ContentCopy" />
</Button>
<Button x:Name="OpenFolder">
<avalonia:MaterialIcon Kind="Folder"></avalonia:MaterialIcon>
<avalonia:MaterialIcon Kind="Folder" />
</Button>
</StackPanel>
</Grid>

View File

@ -3,7 +3,6 @@ using Avalonia.Controls.Mixins;
using Avalonia.ReactiveUI;
using Microsoft.Extensions.DependencyInjection;
using ReactiveUI;
using Wabbajack.App.Utilities;
namespace Wabbajack.App.Controls;

View File

@ -4,5 +4,5 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.LogViewItem">
<TextBlock x:Name="Message" FontSize="10"></TextBlock>
<TextBlock x:Name="Message" FontSize="10" />
</UserControl>

View File

@ -16,5 +16,4 @@ public partial class LogViewItem : ReactiveUserControl<LoggerProvider.ILogMessag
.DisposeWith(disposables);
});
}
}

View File

@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reactive;
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls.Mixins;
using Avalonia.Input;
using DynamicData;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Utilities;
@ -18,10 +13,6 @@ namespace Wabbajack.App.Controls;
public class LogViewModel : ViewModelBase, IActivatableViewModel
{
private readonly LoggerProvider _provider;
public ReadOnlyObservableCollection<LoggerProvider.ILogMessage> Messages => _provider.MessageLog;
[Reactive]
public ReactiveCommand<Unit, Unit> CopyLogFile { get; set; }
public LogViewModel(LoggerProvider provider)
{
@ -35,4 +26,8 @@ public class LogViewModel : ViewModelBase, IActivatableViewModel
Application.Current.Clipboard.SetDataObjectAsync(obj);
});
}
public ReadOnlyObservableCollection<LoggerProvider.ILogMessage> Messages => _provider.MessageLog;
[Reactive] public ReactiveCommand<Unit, Unit> CopyLogFile { get; set; }
}

View File

@ -7,8 +7,8 @@
x:Class="Wabbajack.App.Controls.RemovableListItem">
<StackPanel Orientation="Horizontal">
<Button x:Name="DeleteButton">
<i:MaterialIcon Kind="MinusCircle"></i:MaterialIcon>
<i:MaterialIcon Kind="MinusCircle" />
</Button>
<TextBlock x:Name="Text" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="Text" VerticalAlignment="Center" />
</StackPanel>
</UserControl>

View File

@ -1,7 +1,6 @@
using Avalonia.Controls.Mixins;
using Avalonia.ReactiveUI;
using ReactiveUI;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Controls;
@ -17,8 +16,6 @@ public partial class RemovableListItem : ReactiveUserControl<RemovableItemViewMo
this.BindCommand(ViewModel, vm => vm.DeleteCommand, view => view.DeleteButton)
.DisposeWith(disposables);
});
}
}

View File

@ -1,4 +1,3 @@
using System;
using System.Reactive;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
@ -8,15 +7,12 @@ namespace Wabbajack.App.Controls;
public class RemovableItemViewModel : ViewModelBase
{
[Reactive]
public string Text { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> DeleteCommand { get; set; }
public RemovableItemViewModel()
{
Activator = new ViewModelActivator();
}
[Reactive] public string Text { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> DeleteCommand { get; set; }
}

View File

@ -5,12 +5,12 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.ResourceView">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ResourceName" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="ResourceName" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label Width="100" HorizontalContentAlignment="Right" VerticalAlignment="Center">Tasks:</Label>
<TextBox x:Name="MaxTasks" Width="20" HorizontalAlignment="Left" VerticalAlignment="Center"></TextBox>
<TextBox x:Name="MaxTasks" Width="20" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label Width="100" HorizontalContentAlignment="Right" VerticalAlignment="Center">Throughput:</Label>
<TextBox x:Name="MaxThroughput" Width="20" HorizontalAlignment="Left" VerticalAlignment="Center"></TextBox>
<TextBox x:Name="MaxThroughput" Width="20" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label Width="100" HorizontalContentAlignment="Right" VerticalAlignment="Center">Status:</Label>
<TextBlock x:Name="CurrentThrougput" Width="50" HorizontalAlignment="Left" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="CurrentThrougput" Width="50" HorizontalAlignment="Left" VerticalAlignment="Center" />
</StackPanel>
</UserControl>

View File

@ -1,5 +1,3 @@
using System.Reactive.Disposables;
using Avalonia.ReactiveUI;
using FluentFTP.Helpers;
@ -25,8 +23,6 @@ public partial class ResourceView : ReactiveUserControl<ResourceViewModel>, IAct
this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThrougput.Text,
val => val.FileSizeToString())
.DisposeWith(disposables);
});
}
}

View File

@ -1,7 +1,8 @@
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Timers;using ReactiveUI;
using System.Timers;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.ViewModels;
using Wabbajack.RateLimiter;
@ -13,18 +14,6 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
private readonly IResource _resource;
private readonly Timer _timer;
[Reactive]
public int MaxTasks { get; set; }
[Reactive]
public long MaxThroughput { get; set; }
[Reactive]
public long CurrentThroughput { get; set; }
[Reactive]
public string Name { get; set; }
public ResourceViewModel(IResource resource)
{
Activator = new ViewModelActivator();
@ -46,31 +35,32 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
this.WhenAnyValue(vm => vm.MaxThroughput)
.Skip(1)
.Subscribe(v =>
{
_resource.MaxThroughput = MaxThroughput;
}).DisposeWith(disposables);
.Subscribe(v => { _resource.MaxThroughput = MaxThroughput; }).DisposeWith(disposables);
this.WhenAnyValue(vm => vm.MaxTasks)
.Skip(1)
.Subscribe(v =>
{
_resource.MaxTasks = MaxTasks;
}).DisposeWith(disposables);
.Subscribe(v => { _resource.MaxTasks = MaxTasks; }).DisposeWith(disposables);
});
}
[Reactive] public int MaxTasks { get; set; }
[Reactive] public long MaxThroughput { get; set; }
[Reactive] public long CurrentThroughput { get; set; }
[Reactive] public string Name { get; set; }
public void Dispose()
{
_timer.Dispose();
}
private void TimerElapsed(object? sender, ElapsedEventArgs e)
{
MaxTasks = _resource.MaxTasks;
MaxThroughput = _resource.MaxThroughput;
CurrentThroughput = _resource.StatusReport.Transferred;
}
public void Dispose()
{
_timer.Dispose();
}
}

View File

@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.TagView">
<Border x:Name = "Border"
<Border x:Name="Border"
Margin="5,5,0,5"
BorderThickness="1"
CornerRadius="7,7,7,7"
@ -13,6 +13,6 @@
<TextBlock
x:Name="Text"
Margin="5,5,5,5"
FontSize="10"/>
FontSize="10" />
</Border>
</UserControl>

View File

@ -1,15 +1,12 @@
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using DynamicData;
using ReactiveUI;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public partial class TagView : ReactiveUserControl<TagViewModel>
{
public partial class TagView : ReactiveUserControl<TagViewModel>
{
public TagView()
{
InitializeComponent();
@ -22,5 +19,4 @@ namespace Wabbajack.App.Controls
.DisposeWith(disposables);
});
}
}
}

View File

@ -2,16 +2,10 @@ using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Controls
namespace Wabbajack.App.Controls;
public class TagViewModel : ViewModelBase, IActivatableViewModel
{
public class TagViewModel : ViewModelBase, IActivatableViewModel
{
[Reactive]
public string Name { get; set; }
[Reactive]
public string Tag { get; set; }
public TagViewModel(string name, string tag)
{
Activator = new ViewModelActivator();
@ -19,5 +13,7 @@ namespace Wabbajack.App.Controls
Tag = tag;
}
}
[Reactive] public string Name { get; set; }
[Reactive] public string Tag { get; set; }
}

View File

@ -2,10 +2,10 @@ using System;
using ReactiveUI;
using Wabbajack.Paths;
namespace Wabbajack.App.Converters
namespace Wabbajack.App.Converters;
public class AbsoultePathBindingConverter : IBindingTypeConverter
{
public class AbsoultePathBindingConverter : IBindingTypeConverter
{
public int GetAffinityForObjects(Type fromType, Type toType)
{
if (fromType == typeof(string) && toType == typeof(AbsolutePath) ||
@ -14,12 +14,12 @@ namespace Wabbajack.App.Converters
return 0;
}
public bool TryConvert(object? @from, Type toType, object? conversionHint, out object? result)
public bool TryConvert(object? from, Type toType, object? conversionHint, out object? result)
{
switch (@from)
switch (from)
{
case string s:
result = (AbsolutePath)s;
result = (AbsolutePath) s;
return true;
case AbsolutePath ap:
result = ap.ToString();
@ -29,5 +29,4 @@ namespace Wabbajack.App.Converters
return false;
}
}
}
}

View File

@ -3,10 +3,10 @@ using System.Reactive.Disposables;
using System.Reactive.Subjects;
using System.Threading.Tasks;
namespace Wabbajack.App.Extensions
namespace Wabbajack.App.Extensions;
public static class IObservableExtensions
{
public static class IObservableExtensions
{
public static IObservable<TOut> SelectAsync<TIn, TOut>(this IObservable<TIn> input,
CompositeDisposable disposable,
Func<TIn, ValueTask<TOut>> func)
@ -21,6 +21,4 @@ namespace Wabbajack.App.Extensions
return returnObs;
}
}
}

View File

@ -1,12 +1,5 @@
using System;
using System.Linq.Expressions;
using System.Reactive.Linq;
using ReactiveUI;
namespace Wabbajack.App.Extensions;
namespace Wabbajack.App.Extensions
public static class ReactiveUIExtensions
{
public static class ReactiveUIExtensions
{
}
}

View File

@ -7,16 +7,13 @@ using CefNet.Avalonia;
using HtmlAgilityPack;
using Wabbajack.DTOs.Logins;
namespace Wabbajack.App.Extensions
namespace Wabbajack.App.Extensions;
public static class WebViewExtensions
{
public static class WebViewExtensions
{
public static async Task WaitForReady(this WebView view)
{
while (view.BrowserObject == null)
{
await Task.Delay(200);
}
while (view.BrowserObject == null) await Task.Delay(200);
}
/// <summary>
@ -27,10 +24,7 @@ namespace Wabbajack.App.Extensions
public static async Task NavigateTo(this WebView view, Uri uri)
{
view.Navigate(uri.ToString());
while (view.IsBusy)
{
await Task.Delay(200);
}
while (view.IsBusy) await Task.Delay(200);
}
public static async Task<Cookie[]> Cookies(this WebView view, string domainEnding, CancellationToken token)
@ -42,7 +36,7 @@ namespace Wabbajack.App.Extensions
Domain = c.Domain,
Name = c.Name,
Path = c.Path,
Value = c.Value,
Value = c.Value
}).ToArray();
}
@ -58,6 +52,4 @@ namespace Wabbajack.App.Extensions
doc.LoadHtml(source);
return doc;
}
}
}

View File

@ -5,12 +5,10 @@ using Avalonia.Controls.Primitives;
using Avalonia.Platform;
using Avalonia.Styling;
namespace Wabbajack.App
{
public class FluentWindow : Window, IStyleable
{
Type IStyleable.StyleKey => typeof(Window);
namespace Wabbajack.App;
public class FluentWindow : Window, IStyleable
{
public FluentWindow()
{
ExtendClientAreaToDecorationsHint = true;
@ -36,6 +34,8 @@ namespace Wabbajack.App
});
}
Type IStyleable.StyleKey => typeof(Window);
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
@ -43,5 +43,4 @@ namespace Wabbajack.App
ExtendClientAreaChromeHints.PreferSystemChrome |
ExtendClientAreaChromeHints.OSXThickTitleBar;
}
}
}

View File

@ -1,3 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ReactiveUI />
<ReactiveUI/>
</Weavers>

View File

@ -1,9 +1,8 @@
using System.Threading.Tasks;
namespace Wabbajack.App.Interfaces
namespace Wabbajack.App.Interfaces;
public interface INavigationParameter<T>
{
public interface INavigationParameter<T>
{
public Task NavigatedTo(T param);
}
}

View File

@ -1,10 +1,8 @@
using System;
namespace Wabbajack.App.Interfaces
{
public interface IScreenView
{
public Type ViewModelType { get; }
namespace Wabbajack.App.Interfaces;
}
public interface IScreenView
{
public Type ViewModelType { get; }
}

View File

@ -2,23 +2,21 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Avalonia.Threading;
using Microsoft.Extensions.Logging;
using Wabbajack.App.Messages;
namespace Wabbajack.App
{
public interface IMessageBus
{
public void Send<T>(T message);
}
namespace Wabbajack.App;
public class MessageBus : IMessageBus
{
public static IMessageBus Instance { get; set; }
private readonly IReceiverMarker[] _receivers;
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)
{
@ -27,6 +25,8 @@ namespace Wabbajack.App
_logger = logger;
}
public static IMessageBus Instance { get; set; }
public void Send<T>(T message)
{
AvaloniaScheduler.Instance.Schedule(message, TimeSpan.FromMilliseconds(200), (_, msg) =>
@ -47,5 +47,4 @@ namespace Wabbajack.App
return Disposable.Empty;
});
}
}
}

View File

@ -1,9 +1,7 @@
using Wabbajack.Paths;
namespace Wabbajack.App.Messages
{
public record ConfigureLauncher(AbsolutePath InstallFolder)
{
namespace Wabbajack.App.Messages;
}
public record ConfigureLauncher(AbsolutePath InstallFolder)
{
}

View File

@ -4,5 +4,4 @@ namespace Wabbajack.App.Messages;
public record Error(string Prefix, Exception Exception)
{
}

View File

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

View File

@ -1,10 +1,5 @@
namespace Wabbajack.App.Messages
{
public class NavigateBack
{
public NavigateBack()
{
namespace Wabbajack.App.Messages;
}
}
public class NavigateBack
{
}

View File

@ -1,10 +1,7 @@
using System;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Messages
namespace Wabbajack.App.Messages;
public record NavigateTo(Type ViewModel)
{
public record NavigateTo(Type ViewModel)
{
}
}

View File

@ -4,5 +4,4 @@ namespace Wabbajack.App.Messages;
public record StartCompilation(CompilerSettings Settings)
{
}

View File

@ -1,8 +1,7 @@
using Wabbajack.Paths;
namespace Wabbajack.App.Messages
namespace Wabbajack.App.Messages;
public record StartInstallConfiguration(AbsolutePath ModList)
{
public record StartInstallConfiguration(AbsolutePath ModList)
{
}
}

View File

@ -1,9 +1,9 @@
using Wabbajack.DTOs;
using Wabbajack.Paths;
namespace Wabbajack.App.Messages
namespace Wabbajack.App.Messages;
public record StartInstallation(AbsolutePath ModListPath, AbsolutePath Install, AbsolutePath Download,
ModlistMetadata? Metadata)
{
public record StartInstallation(AbsolutePath ModListPath, AbsolutePath Install, AbsolutePath Download, ModlistMetadata? Metadata)
{
}
}

View File

@ -8,11 +8,10 @@ using Wabbajack.DTOs.SavedSettings;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.App.Models
namespace Wabbajack.App.Models;
public class InstallationStateManager
{
public class InstallationStateManager
{
private static AbsolutePath Path => KnownFolders.WabbajackAppLocal.Combine("install-configuration-state.json");
private readonly DTOSerializer _dtos;
private readonly ILogger<InstallationStateManager> _logger;
@ -22,6 +21,8 @@ namespace Wabbajack.App.Models
_logger = logger;
}
private static AbsolutePath Path => KnownFolders.WabbajackAppLocal.Combine("install-configuration-state.json");
public async Task<InstallationConfigurationSetting> GetLastState()
{
var state = await GetAll();
@ -66,7 +67,6 @@ namespace Wabbajack.App.Models
_logger.LogError(ex, "While loading json");
return new InstallConfigurationState();
}
}
public async Task<InstallationConfigurationSetting?> Get(AbsolutePath modListPath)
@ -78,5 +78,4 @@ namespace Wabbajack.App.Models
{
return (await GetAll()).Settings.FirstOrDefault(f => f.Install == folder);
}
}
}

View File

@ -1,10 +1,8 @@
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia.Threading;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Models;
@ -12,12 +10,6 @@ public class LoadingLock : ReactiveObject, IDisposable
{
private readonly CompositeDisposable _disposable;
[Reactive]
public int LoadLevel { get; private set; }
[Reactive]
public bool IsLoading { get; private set; }
public LoadingLock()
{
_disposable = new CompositeDisposable();
@ -25,21 +17,24 @@ public class LoadingLock : ReactiveObject, IDisposable
this.WhenAnyValue(vm => vm.LoadLevel)
.Subscribe(v => IsLoading = v > 0)
.DisposeWith(_disposable);
}
public IDisposable WithLoading()
{
Dispatcher.UIThread.Post(() => { LoadLevel++;}, DispatcherPriority.Background);
return Disposable.Create(() =>
{
Dispatcher.UIThread.Post(() => { LoadLevel--;}, DispatcherPriority.Background);
});
}
[Reactive] public int LoadLevel { get; private set; }
[Reactive] public bool IsLoading { get; private set; }
public void Dispose()
{
GC.SuppressFinalize(this);
_disposable.Dispose();
}
public IDisposable WithLoading()
{
Dispatcher.UIThread.Post(() => { LoadLevel++; }, DispatcherPriority.Background);
return Disposable.Create(() =>
{
Dispatcher.UIThread.Post(() => { LoadLevel--; }, DispatcherPriority.Background);
});
}
}

View File

@ -3,7 +3,6 @@ using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Wabbajack.Common;
using Wabbajack.DTOs.JsonConverters;
@ -26,7 +25,10 @@ public class SettingsManager
_configuration.SavedSettingsLocation.CreateDirectory();
}
private AbsolutePath GetPath(string key) => _configuration.SavedSettingsLocation.Combine(key).WithExtension(Ext.Json);
private AbsolutePath GetPath(string key)
{
return _configuration.SavedSettingsLocation.Combine(key).WithExtension(Ext.Json);
}
public async Task Save<T>(string key, T value)
{
@ -35,6 +37,7 @@ public class SettingsManager
{
await JsonSerializer.SerializeAsync(s, value, _dtos.Options);
}
await tmp.MoveToAsync(GetPath(key), true, CancellationToken.None);
}
@ -45,13 +48,11 @@ public class SettingsManager
try
{
if (path.FileExists())
{
await using (var s = path.Open(FileMode.Open))
{
return (await JsonSerializer.DeserializeAsync<T>(s, _dtos.Options))!;
}
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Loading settings {Key}", key);

View File

@ -3,28 +3,31 @@ using Avalonia;
using Avalonia.ReactiveUI;
using CefNet;
namespace Wabbajack.App
{
namespace Wabbajack.App;
class Program
{
internal class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
public static void Main(string[] args)
{
BuildAvaloniaApp()
.StartWithCefNetApplicationLifetime(args);
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
{
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.AfterSetup(AfterSetupCallback)
.LogToTrace()
.UseReactiveUI();
}
private static void AfterSetupCallback(AppBuilder obj)
{
}
}
}

View File

@ -54,7 +54,7 @@
x:Name="OnlyInstalledCheckbox"
Margin="10,0,10,0"
VerticalAlignment="Center"
Content="Only Installed"/>
Content="Only Installed" />
<Button
x:Name="ClearFiltersButton"
Margin="0,0,10,0">

View File

@ -1,15 +1,11 @@
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using ReactiveUI;
using Wabbajack.App.ViewModels;
using Wabbajack.App.Views;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public partial class BrowseView : ScreenBase<BrowseViewModel>
{
public partial class BrowseView : ScreenBase<BrowseViewModel>
{
public BrowseView()
{
InitializeComponent();
@ -40,5 +36,4 @@ namespace Wabbajack.App.Screens
.DisposeWith(disposables);
});
}
}
}

View File

@ -8,74 +8,51 @@ using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Threading;
using DynamicData;
using DynamicData.Binding;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Controls;
using Wabbajack.App.Models;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.DTOs;
using Wabbajack.Networking.WabbajackClientApi;
using DynamicData.Binding;
using Microsoft.Extensions.DependencyInjection;
using Wabbajack.App.Models;
using Wabbajack.Downloaders;
using Wabbajack.Downloaders.GameFile;
using Wabbajack.DTOs;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Installer;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.VFS;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public class BrowseViewModel : ViewModelBase, IActivatableViewModel
{
public class BrowseViewModel : ViewModelBase, IActivatableViewModel
{
private readonly Client _wjClient;
private readonly ILogger<BrowseViewModel> _logger;
private readonly HttpClient _httpClient;
private readonly IResource<HttpClient> _limiter;
private readonly FileHashCache _hashCache;
private readonly Configuration _configuration;
private readonly DownloadDispatcher _dispatcher;
private readonly IResource<DownloadDispatcher> _dispatcherLimiter;
private SourceCache<BrowseItemViewModel, string> _modLists = new(x => x.MachineURL);
private readonly DTOSerializer _dtos;
public readonly ReadOnlyObservableCollection<GameSelectorItemViewModel> _filteredGamesList;
public readonly ReadOnlyObservableCollection<BrowseItemViewModel> _filteredModLists;
public ReadOnlyObservableCollection<BrowseItemViewModel> ModLists => _filteredModLists;
private SourceCache<GameSelectorItemViewModel, string> _gamesList = new(x => x.Name);
public readonly ReadOnlyObservableCollection<GameSelectorItemViewModel> _filteredGamesList;
private readonly GameLocator _gameLocator;
private readonly DTOSerializer _dtos;
public ReadOnlyObservableCollection<GameSelectorItemViewModel> GamesList => _filteredGamesList;
private readonly FileHashCache _hashCache;
private readonly HttpClient _httpClient;
private readonly IResource<HttpClient> _limiter;
private readonly ILogger<BrowseViewModel> _logger;
private readonly Client _wjClient;
[Reactive]
public GameSelectorItemViewModel? SelectedGame { get; set; }
private readonly SourceCache<GameSelectorItemViewModel, string> _gamesList = new(x => x.Name);
[Reactive]
public string SearchText { get; set; }
private readonly SourceCache<BrowseItemViewModel, string> _modLists = new(x => x.MachineURL);
[Reactive] public bool OnlyInstalledGames { get; set; } = false;
[Reactive] public bool OnlyUtilityLists { get; set; } = false;
[Reactive] public bool ShowNSFW { get; set; } = false;
[Reactive] public bool IsLoading { get; set; } = false;
[Reactive]
public LoadingLock LoadingLock { get; set; }
public BrowseViewModel(ILogger<BrowseViewModel> logger, Client wjClient, HttpClient httpClient, IResource<HttpClient> limiter, FileHashCache hashCache,
IResource<DownloadDispatcher> dispatcherLimiter, DownloadDispatcher dispatcher, GameLocator gameLocator, DTOSerializer dtos, Configuration configuration)
public BrowseViewModel(ILogger<BrowseViewModel> logger, Client wjClient, HttpClient httpClient,
IResource<HttpClient> limiter, FileHashCache hashCache,
IResource<DownloadDispatcher> dispatcherLimiter, DownloadDispatcher dispatcher, GameLocator gameLocator,
DTOSerializer dtos, Configuration configuration)
{
LoadingLock = new LoadingLock();
Activator = new ViewModelActivator();
@ -91,7 +68,7 @@ namespace Wabbajack.App.Screens
_dtos = dtos;
IObservable<Func<BrowseItemViewModel, bool>> searchTextPredicates = this.ObservableForProperty(vm => vm.SearchText)
var searchTextPredicates = this.ObservableForProperty(vm => vm.SearchText)
.Select(change => change.Value)
.StartWith("")
.Select<string, Func<BrowseItemViewModel, bool>>(txt =>
@ -102,14 +79,10 @@ namespace Wabbajack.App.Screens
});
_gamesList.Edit(e =>
{
e.Clear();
foreach (var game in GameRegistry.Games.Keys)
{
e.AddOrUpdate(new GameSelectorItemViewModel(game));
}
foreach (var game in GameRegistry.Games.Keys) e.AddOrUpdate(new GameSelectorItemViewModel(game));
});
_gamesList.Connect()
@ -118,7 +91,7 @@ namespace Wabbajack.App.Screens
.Bind(out _filteredGamesList)
.Subscribe();
IObservable<Func<BrowseItemViewModel, bool>> gameFilter = this.ObservableForProperty(vm => vm.SelectedGame)
var gameFilter = this.ObservableForProperty(vm => vm.SelectedGame)
.Select(v => v.Value)
.Select<GameSelectorItemViewModel?, Func<BrowseItemViewModel, bool>>(selected =>
{
@ -127,7 +100,7 @@ namespace Wabbajack.App.Screens
})
.StartWith(_ => true);
IObservable<Func<BrowseItemViewModel, bool>> onlyInstalledGamesFilter = this.ObservableForProperty(vm => vm.OnlyInstalledGames)
var onlyInstalledGamesFilter = this.ObservableForProperty(vm => vm.OnlyInstalledGames)
.Select(v => v.Value)
.Select<bool, Func<BrowseItemViewModel, bool>>(onlyInstalled =>
{
@ -136,25 +109,21 @@ namespace Wabbajack.App.Screens
})
.StartWith(_ => true);
IObservable<Func<BrowseItemViewModel, bool>> onlyUtilityListsFilter = this.ObservableForProperty(vm => vm.OnlyUtilityLists)
var onlyUtilityListsFilter = this.ObservableForProperty(vm => vm.OnlyUtilityLists)
.Select(v => v.Value)
.Select<bool, Func<BrowseItemViewModel, bool>>(utility =>
{
if (utility == false) return item => item.IsUtilityList == false ;
if (utility == false) return item => item.IsUtilityList == false;
return item => item.IsUtilityList;
})
.StartWith(item => item.IsUtilityList == false);
IObservable<Func<BrowseItemViewModel, bool>> showNSFWFilter = this.ObservableForProperty(vm => vm.ShowNSFW)
var showNSFWFilter = this.ObservableForProperty(vm => vm.ShowNSFW)
.Select(v => v.Value)
.Select<bool, Func<BrowseItemViewModel, bool>>(showNSFW =>
{
return item => item.IsNSFW == showNSFW;
})
.Select<bool, Func<BrowseItemViewModel, bool>>(showNSFW => { return item => item.IsNSFW == showNSFW; })
.StartWith(item => item.IsNSFW == false);
_modLists.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Filter(searchTextPredicates)
@ -177,10 +146,7 @@ namespace Wabbajack.App.Screens
LoadSettings().FireAndForget();
LoadData().FireAndForget();
Disposable.Create(() =>
{
SaveSettings().FireAndForget();
}).DisposeWith(disposables);
Disposable.Create(() => { SaveSettings().FireAndForget(); }).DisposeWith(disposables);
/*
var searchTextFilter = this.ObservableForProperty(view => view.SearchText)
@ -190,13 +156,30 @@ namespace Wabbajack.App.Screens
return lst => true;
return
})*/
});
}
public ReadOnlyObservableCollection<BrowseItemViewModel> ModLists => _filteredModLists;
public ReadOnlyObservableCollection<GameSelectorItemViewModel> GamesList => _filteredGamesList;
[Reactive]
public ReactiveCommand<Unit, Unit> ResetFiltersCommand { get; set; }
[Reactive] public GameSelectorItemViewModel? SelectedGame { get; set; }
[Reactive] public string SearchText { get; set; }
[Reactive] public bool OnlyInstalledGames { get; set; }
[Reactive] public bool OnlyUtilityLists { get; set; }
[Reactive] public bool ShowNSFW { get; set; }
[Reactive] public bool IsLoading { get; set; } = false;
[Reactive] public LoadingLock LoadingLock { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> ResetFiltersCommand { get; set; }
private AbsolutePath SavedSettingsLocation => _configuration.SavedSettingsLocation.Combine("browse_view.json");
private async Task LoadData()
{
@ -205,12 +188,10 @@ namespace Wabbajack.App.Screens
var summaries = (await _wjClient.GetListStatuses()).ToDictionary(m => m.MachineURL);
var vms = modlists.Select(m =>
{
if (!summaries.TryGetValue(m.Links.MachineURL, out var summary))
{
summary = new ModListSummary();
}
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);
return new BrowseItemViewModel(m, summary, _httpClient, _limiter, _hashCache, _configuration, _dispatcher,
_dispatcherLimiter, _gameLocator, _dtos, _logger);
});
_modLists.Edit(lsts =>
@ -233,7 +214,9 @@ namespace Wabbajack.App.Screens
var data = (await JsonSerializer.DeserializeAsync<SavedSettings>(stream))!;
SearchText = data.SearchText;
SelectedGame = data.SelectedGame == null ? null : _gamesList.Lookup(data.SelectedGame.Value.MetaData().HumanFriendlyGameName).Value;
SelectedGame = data.SelectedGame == null
? null
: _gamesList.Lookup(data.SelectedGame.Value.MetaData().HumanFriendlyGameName).Value;
ShowNSFW = data.ShowNSFW;
OnlyUtilityLists = data.OnlyUtility;
@ -268,8 +251,6 @@ namespace Wabbajack.App.Screens
}
}
private AbsolutePath SavedSettingsLocation => _configuration.SavedSettingsLocation.Combine("browse_view.json");
private class SavedSettings
{
public string SearchText { get; set; }
@ -278,5 +259,4 @@ namespace Wabbajack.App.Screens
public bool OnlyInstalled { get; set; }
public Game? SelectedGame { get; set; }
}
}
}

View File

@ -3,13 +3,12 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:i="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:controls="clr-namespace:Wabbajack.App.Controls"
x:Class="Wabbajack.App.Screens.CompilationView">
<Grid RowDefinitions="40, 5, 5, *, 40">
<TextBlock Grid.Row="0" x:Name="StatusText" FontSize="20" FontWeight="Bold">[20/30] Installing Files</TextBlock>
<ProgressBar Grid.Row="1" x:Name="StepsProgress" Maximum="1000" Value="40"></ProgressBar>
<ProgressBar Grid.Row="2" x:Name="StepProgress" Maximum="10000" Value="30"></ProgressBar>
<controls:LogView Grid.Row="3" x:Name="LogView"></controls:LogView>
<ProgressBar Grid.Row="1" x:Name="StepsProgress" Maximum="1000" Value="40" />
<ProgressBar Grid.Row="2" x:Name="StepProgress" Maximum="10000" Value="30" />
<controls:LogView Grid.Row="3" x:Name="LogView" />
</Grid>
</UserControl>

View File

@ -1,6 +1,5 @@
using Avalonia.Controls.Mixins;
using ReactiveUI;
using Wabbajack.App.ViewModels;
using Wabbajack.App.Views;
namespace Wabbajack.App.Screens;

View File

@ -16,13 +16,9 @@ namespace Wabbajack.App.Screens;
public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<StartCompilation>
{
private readonly ILogger<CompilationViewModel> _logger;
private readonly IServiceProvider _provider;
private ACompiler _compiler;
private readonly ILogger<CompilationViewModel> _logger;
[Reactive] public string StatusText { get; set; } = "";
[Reactive] public Percent StepsProgress { get; set; } = Percent.Zero;
[Reactive] public Percent StepProgress { get; set; } = Percent.Zero;
public CompilationViewModel(ILogger<CompilationViewModel> logger, IServiceProvider provider)
@ -30,9 +26,12 @@ public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<St
_logger = logger;
_provider = provider;
Activator = new ViewModelActivator();
}
[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)
{
if (val.Settings is MO2CompilerSettings mo2)
@ -50,6 +49,7 @@ public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver<St
});
};
}
Compile().FireAndForget();
}

View File

@ -8,42 +8,42 @@
x:Class="Wabbajack.App.Screens.CompilerConfigurationView">
<Grid RowDefinitions="40, *, 40">
<TextBlock Grid.Row="0" x:Name="StatusText" FontSize="20" FontWeight="Bold">Compiler Configuration</TextBlock>
<Grid Grid.Row="1" ColumnDefinitions="Auto, *" RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto" Margin="4">
<Grid Grid.Row="1" ColumnDefinitions="Auto, *" RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto"
Margin="4">
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right">Title:</Label>
<TextBox Grid.Column="1" Grid.Row="0" x:Name="Title"></TextBox>
<TextBox Grid.Column="1" Grid.Row="0" x:Name="Title" />
<Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right">Settings File:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="1" x:Name="SettingsFile"
AllowedExtensions=".txt|.json">
</controls:FileSelectionBox>
AllowedExtensions=".txt|.json" />
<Label Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right">Source:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="2" x:Name="Source" SelectFolder="True"></controls:FileSelectionBox>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="2" x:Name="Source" SelectFolder="True" />
<Label Grid.Column="0" Grid.Row="3" HorizontalAlignment="Right">Downloads Folder:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="3" x:Name="DownloadsFolder" SelectFolder="True"></controls:FileSelectionBox>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="3" x:Name="DownloadsFolder" SelectFolder="True" />
<Label Grid.Column="0" Grid.Row="4" HorizontalAlignment="Right">Base Game:</Label>
<ComboBox Grid.Column="1" Grid.Row="4" x:Name="BaseGame">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=HumanFriendlyGameName}"></TextBlock>
<TextBlock Text="{Binding Path=HumanFriendlyGameName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Label Grid.Column="0" Grid.Row="5" HorizontalAlignment="Right">Output Folder:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="5" x:Name="OutputFolder" SelectFolder="True"></controls:FileSelectionBox>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="5" x:Name="OutputFolder" SelectFolder="True" />
<Label Grid.Column="0" Grid.Row="6" HorizontalAlignment="Right" VerticalAlignment="Top">Always Enabled:</Label>
<StackPanel Grid.Column="1" Grid.Row="6" Orientation="Vertical">
<Button x:Name="AddAlwaysEnabled">
<i:MaterialIcon Kind="AddCircle"></i:MaterialIcon>
<i:MaterialIcon Kind="AddCircle" />
</Button>
<ItemsControl x:Name="AlwaysEnabledList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:RemovableListItem></controls:RemovableListItem>
<controls:RemovableListItem />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

View File

@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
@ -12,10 +11,10 @@ using Wabbajack.App.Views;
using Wabbajack.Common;
using Wabbajack.Paths;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public partial class CompilerConfigurationView : ScreenBase<CompilerConfigurationViewModel>
{
public partial class CompilerConfigurationView : ScreenBase<CompilerConfigurationViewModel>
{
public CompilerConfigurationView()
{
InitializeComponent();
@ -51,7 +50,7 @@ namespace Wabbajack.App.Screens
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.AlwaysEnabled, view => view.AlwaysEnabledList.Items,
d => d!.Select(itm => new RemovableItemViewModel()
d => d!.Select(itm => new RemovableItemViewModel
{
Text = itm.ToString(),
DeleteCommand = ReactiveCommand.Create(() => { ViewModel?.RemoveAlwaysExcluded(itm); })
@ -62,9 +61,9 @@ namespace Wabbajack.App.Screens
private async Task AddAlwaysEnabled_Command()
{
var dialog = new OpenFolderDialog()
var dialog = new OpenFolderDialog
{
Title = "Select a folder",
Title = "Select a folder"
};
var result = await dialog.ShowAsync(App.MainWindow);
if (!string.IsNullOrWhiteSpace(result))
@ -75,16 +74,16 @@ namespace Wabbajack.App.Screens
{
Dispatcher.UIThread.InvokeAsync(async () =>
{
var dialog = new OpenFileDialog()
var dialog = new OpenFileDialog
{
Title = "Select a modlist.txt file",
Filters = new List<FileDialogFilter> { new() {Extensions = new List<string> {"txt"}, Name = "modlist.txt"}},
Filters = new List<FileDialogFilter>
{new() {Extensions = new List<string> {"txt"}, Name = "modlist.txt"}},
AllowMultiple = false
};
var result = await dialog.ShowAsync(App.MainWindow);
if (result is { Length: > 0 })
if (result is {Length: > 0})
await ViewModel!.InferSettingsFromModlistTxt(result.First().ToAbsolutePath());
});
}
}
}

View File

@ -27,44 +27,6 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
private readonly DTOSerializer _dtos;
private readonly SettingsManager _settingsManager;
[Reactive]
public string Title { get; set; }
[Reactive]
public AbsolutePath SettingsFile { get; set; }
[Reactive]
public AbsolutePath Downloads { get; set; }
[Reactive]
public GameMetaData BaseGame { get; set; }
[Reactive]
public AbsolutePath Source { get; set; }
[Reactive]
public AbsolutePath GamePath { get; set; }
[Reactive]
public string SelectedProfile { get; set; }
[Reactive]
public AbsolutePath OutputFolder { get; set; }
[Reactive]
public IEnumerable<GameMetaData> AllGames { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> StartCompilation { get; set; }
[Reactive]
public IEnumerable<RelativePath> AlwaysEnabled { get; set; } = Array.Empty<RelativePath>();
public AbsolutePath SettingsOutputLocation => Source.Combine(Title).WithExtension(IsMO2Compilation ? Ext.MO2CompilerSettings : Ext.CompilerSettings);
[Reactive]
public bool IsMO2Compilation { get; set; }
public CompilerConfigurationViewModel(DTOSerializer dtos, SettingsManager settingsManager)
{
@ -82,15 +44,38 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
{
LoadLastCompilation().FireAndForget();
this.WhenAnyValue(v => v.SettingsFile)
.Subscribe( location =>
{
LoadNewSettingsFile(location).FireAndForget();
})
.Subscribe(location => { LoadNewSettingsFile(location).FireAndForget(); })
.DisposeWith(disposables);
});
}
[Reactive] public string Title { get; set; }
[Reactive] public AbsolutePath SettingsFile { get; set; }
[Reactive] public AbsolutePath Downloads { get; set; }
[Reactive] public GameMetaData BaseGame { get; set; }
[Reactive] public AbsolutePath Source { get; set; }
[Reactive] public AbsolutePath GamePath { get; set; }
[Reactive] public string SelectedProfile { get; set; }
[Reactive] public AbsolutePath OutputFolder { get; set; }
[Reactive] public IEnumerable<GameMetaData> AllGames { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> StartCompilation { get; set; }
[Reactive] public IEnumerable<RelativePath> AlwaysEnabled { get; set; } = Array.Empty<RelativePath>();
public AbsolutePath SettingsOutputLocation => Source.Combine(Title)
.WithExtension(IsMO2Compilation ? Ext.MO2CompilerSettings : Ext.CompilerSettings);
[Reactive] public bool IsMO2Compilation { get; set; }
private async Task LoadNewSettingsFile(AbsolutePath location)
{
if (location == default) return;
@ -174,19 +159,15 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
var generalModData = data["General"];
if ((generalModData["notes"]?.Contains("WABBAJACK_ALWAYS_ENABLE") ?? false) ||
(generalModData["comments"]?.Contains("WABBAJACK_ALWAYS_ENABLE") ?? false))
{
AlwaysEnabled = AlwaysEnabled.Append(modFolder.RelativeTo(mo2Folder)).ToArray();
}
}
if (mo2Folder.Depth > 1)
OutputFolder = mo2Folder.Parent;
await SaveSettingsFile();
SettingsFile = SettingsOutputLocation;
}
}
}
@ -194,7 +175,7 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
{
await using var st = SettingsOutputLocation.Open(FileMode.Create, FileAccess.Write, FileShare.None);
if (IsMO2Compilation)
await JsonSerializer.SerializeAsync(st, (MO2CompilerSettings)GetSettings(), _dtos.Options);
await JsonSerializer.SerializeAsync(st, (MO2CompilerSettings) GetSettings(), _dtos.Options);
else
await JsonSerializer.SerializeAsync(st, GetSettings(), _dtos.Options);
}

View File

@ -6,8 +6,8 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Screens.ErrorPageView">
<Grid RowDefinitions="Auto, Auto, *">
<TextBlock Grid.Row="0" x:Name="Prefix"></TextBlock>
<TextBlock Grid.Row="1" x:Name="Message"></TextBlock>
<controls:LogView Grid.Row="3"></controls:LogView>
<TextBlock Grid.Row="0" x:Name="Prefix" />
<TextBlock Grid.Row="1" x:Name="Message" />
<controls:LogView Grid.Row="3" />
</Grid>
</UserControl>

View File

@ -1,24 +1,22 @@
using System;
using DynamicData.Kernel;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Messages;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public class ErrorPageViewModel : ViewModelBase, IActivatableViewModel, IReceiver<Error>
{
public class ErrorPageViewModel : ViewModelBase, IActivatableViewModel, IReceiver<Error>
{
[Reactive]
public string ShortMessage { get; set; }
[Reactive]
public string Prefix { get; set; }
public ErrorPageViewModel()
{
Activator = new ViewModelActivator();
}
[Reactive] public string ShortMessage { get; set; }
[Reactive] public string Prefix { get; set; }
public void Receive(Error val)
{
Prefix = val.Prefix;
@ -30,5 +28,4 @@ namespace Wabbajack.App.Screens
MessageBus.Instance.Send(new Error(prefix, ex));
MessageBus.Instance.Send(new NavigateTo(typeof(ErrorPageViewModel)));
}
}
}

View File

@ -14,14 +14,14 @@
<Image x:Name="ModListImage" Margin="0,0,0,0" Source="../Assets/Wabba_Mouth.png" />
</Viewbox>
<Grid Grid.Row="0" RowDefinitions="40, 40" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<TextBlock x:Name="ModListName"></TextBlock>
<TextBlock x:Name="ModListName" />
</Grid>
<Grid Margin="40" RowDefinitions="40, 40, 40, *" ColumnDefinitions="100, *, 200" Grid.Row="1">
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center">ModList:</Label>
<TextBox Grid.Column="1" Grid.Row="0" IsEnabled="False" Height="20" x:Name="ModList"></TextBox>
<TextBox Grid.Column="1" Grid.Row="0" IsEnabled="False" Height="20" x:Name="ModList" />
<Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center">Location:</Label>
<TextBox Grid.Column="1" Grid.Row="1" IsEnabled="False" Height="20" x:Name="InstallPath"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" IsEnabled="False" Height="20" x:Name="InstallPath" />
<Grid Grid.Column="1" Grid.Row="3" Grid.ColumnDefinitions="*, *, *" HorizontalAlignment="Center">
<Button Grid.Column="0" x:Name="WebsiteButton">Website</Button>
@ -29,9 +29,8 @@
<Button Grid.Column="2" x:Name="LocalFilesButton">Local Files</Button>
</Grid>
<controls:LargeIconButton x:Name="PlayGame" Margin="40, 0, 0, 0" Grid.Row="0" Grid.Column="2" Grid.RowSpan="4" Icon="PlayCircle" Text="Play">
</controls:LargeIconButton>
<controls:LargeIconButton x:Name="PlayGame" Margin="40, 0, 0, 0" Grid.Row="0" Grid.Column="2"
Grid.RowSpan="4" Icon="PlayCircle" Text="Play" />
</Grid>
</Grid>
</UserControl>

View File

@ -1,14 +1,11 @@
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using ReactiveUI;
using Wabbajack.App.Views;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public partial class LauncherView : ScreenBase<LauncherViewModel>
{
public partial class LauncherView : ScreenBase<LauncherViewModel>
{
public LauncherView()
{
InitializeComponent();
@ -28,6 +25,4 @@ namespace Wabbajack.App.Screens
.DisposeWith(disposables);
});
}
}
}

View File

@ -5,8 +5,6 @@ using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using GameFinder.StoreHandlers.Origin.DTO;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
@ -20,33 +18,18 @@ using Wabbajack.DTOs.SavedSettings;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public class LauncherViewModel : ViewModelBase, IActivatableViewModel, IReceiver<ConfigureLauncher>
{
public class LauncherViewModel : ViewModelBase, IActivatableViewModel, IReceiver<ConfigureLauncher>
{
[Reactive]
public AbsolutePath InstallFolder { get; set; }
[Reactive]
public IBitmap Image { get; set; }
[Reactive]
public InstallationConfigurationSetting? Setting { get; set; }
[Reactive]
public string Title { get; set; }
private readonly ILogger<LauncherViewModel> _logger;
public ReactiveCommand<Unit, Unit> PlayButton;
private readonly ILogger<LauncherViewModel> _logger;
public LauncherViewModel(ILogger<LauncherViewModel> logger, InstallationStateManager manager)
{
Activator = new ViewModelActivator();
PlayButton = ReactiveCommand.Create(() =>
{
StartGame().FireAndForget();
});
PlayButton = ReactiveCommand.Create(() => { StartGame().FireAndForget(); });
_logger = logger;
this.WhenActivated(disposables =>
@ -60,19 +43,31 @@ namespace Wabbajack.App.Screens
this.WhenAnyValue(v => v.Setting)
.Where(v => v != default)
.Select(v => new Bitmap((v!.Image).ToString()))
.Select(v => new Bitmap(v!.Image.ToString()))
.BindTo(this, vm => vm.Image)
.DisposeWith(disposables);
this.WhenAnyValue(v => v.Setting)
.Where(v => v is { Metadata: { } })
.Where(v => v is {Metadata: { }})
.Select(v => $"{v!.Metadata!.Title} v{v!.Metadata.Version}")
.BindTo(this, vm => vm.Title)
.DisposeWith(disposables);
});
}
[Reactive] public AbsolutePath InstallFolder { get; set; }
[Reactive] public IBitmap Image { get; set; }
[Reactive] public InstallationConfigurationSetting? Setting { get; set; }
[Reactive] public string Title { get; set; }
public void Receive(ConfigureLauncher val)
{
InstallFolder = val.InstallFolder;
}
private async Task StartGame()
{
var mo2Path = InstallFolder.Combine("ModOrganizer.exe");
@ -81,22 +76,10 @@ namespace Wabbajack.App.Screens
.Select(ge => InstallFolder.Combine(ge!))
.FirstOrDefault(ge => ge.FileExists());
if (mo2Path.FileExists())
{
Process.Start(mo2Path.ToString());
}
else if (gamePath.FileExists())
{
Process.Start(gamePath.ToString());
}
else
{
_logger.LogError("No way to launch game, no acceptable executable found");
}
}
public void Receive(ConfigureLauncher val)
{
InstallFolder = val.InstallFolder;
}
}
}

View File

@ -6,6 +6,6 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Screens.LogScreenView">
<Grid RowDefinitions="*">
<controls:LogView></controls:LogView>
<controls:LogView />
</Grid>
</UserControl>

View File

@ -1,4 +1,3 @@
using ReactiveUI;
using Wabbajack.App.Views;
namespace Wabbajack.App.Screens;

View File

@ -1,8 +1,4 @@
using System.Reactive;
using Avalonia;
using Avalonia.Input;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Utilities;
using Wabbajack.App.ViewModels;
@ -11,11 +7,10 @@ namespace Wabbajack.App.Screens;
public class LogScreenViewModel : ViewModelBase, IActivatableViewModel
{
private readonly LoggerProvider _provider;
public LogScreenViewModel(LoggerProvider provider)
{
_provider = provider;
Activator = new ViewModelActivator();
}
}

View File

@ -9,12 +9,12 @@
<ItemsControl x:Name="Lists">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:InstalledListView></controls:InstalledListView>
<controls:InstalledListView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

View File

@ -15,5 +15,4 @@ public partial class PlaySelectView : ScreenBase<PlaySelectViewModel>
.DisposeWith(disposables);
});
}
}

View File

@ -8,7 +8,6 @@ using Wabbajack.App.Controls;
using Wabbajack.App.Models;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.DTOs.SavedSettings;
namespace Wabbajack.App.Screens;
@ -16,9 +15,6 @@ public class PlaySelectViewModel : ViewModelBase, IActivatableViewModel
{
private readonly InstallationStateManager _manager;
[Reactive]
public IEnumerable<InstalledListViewModel> Items { get; set; }
public PlaySelectViewModel(InstallationStateManager manager)
{
_manager = manager;
@ -31,10 +27,11 @@ public class PlaySelectViewModel : ViewModelBase, IActivatableViewModel
});
}
[Reactive] public IEnumerable<InstalledListViewModel> Items { get; set; }
public async Task LoadAndSetItems()
{
var items = await _manager.GetAll();
Items = items.Settings.Select(a => new InstalledListViewModel(a)).ToArray();
}
}

View File

@ -10,18 +10,24 @@
<Grid RowDefinitions="Auto, Auto, Auto, Auto" ColumnDefinitions="20, 100, Auto, Auto">
<TextBlock FontSize="20" Grid.ColumnSpan="4">Logins</TextBlock>
<Image Grid.Row="1" Grid.Column="0" Width="16" Height="16" Margin="4" Source="../Assets/Downloaders/nexus.ico" HorizontalAlignment="Right"></Image>
<TextBlock Grid.Row="1" Grid.Column="1" Text="Nexus" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
<Image Grid.Row="1" Grid.Column="0" Width="16" Height="16" Margin="4"
Source="../Assets/Downloaders/nexus.ico" HorizontalAlignment="Right" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="Nexus" VerticalAlignment="Center"
HorizontalAlignment="Left" />
<Button Grid.Row="1" Grid.Column="2" x:Name="NexusLogIn">Log In</Button>
<Button Grid.Row="1" Grid.Column="3" x:Name="NexusLogOut">Log Out</Button>
<Image Grid.Row="2" Grid.Column="0" Width="16" Height="16" Margin="4" Source="../Assets/Downloaders/loverslab.ico" HorizontalAlignment="Right"></Image>
<TextBlock Grid.Row="2" Grid.Column="1" Text="Lovers Lab" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
<Image Grid.Row="2" Grid.Column="0" Width="16" Height="16" Margin="4"
Source="../Assets/Downloaders/loverslab.ico" HorizontalAlignment="Right" />
<TextBlock Grid.Row="2" Grid.Column="1" Text="Lovers Lab" VerticalAlignment="Center"
HorizontalAlignment="Left" />
<Button Grid.Row="2" Grid.Column="2" x:Name="LoversLabLogIn">Log In</Button>
<Button Grid.Row="2" Grid.Column="3" x:Name="LoversLabLogOut">Log Out</Button>
<Image Grid.Row="3" Grid.Column="0" Width="16" Height="16" Margin="4" Source="../Assets/Downloaders/vectorplexus.ico" HorizontalAlignment="Right"></Image>
<TextBlock Grid.Row="3" Grid.Column="1" Text="Vector Plexus" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
<Image Grid.Row="3" Grid.Column="0" Width="16" Height="16" Margin="4"
Source="../Assets/Downloaders/vectorplexus.ico" HorizontalAlignment="Right" />
<TextBlock Grid.Row="3" Grid.Column="1" Text="Vector Plexus" VerticalAlignment="Center"
HorizontalAlignment="Left" />
<Button Grid.Row="3" Grid.Column="2" x:Name="VectorPlexusLogIn">Log In</Button>
<Button Grid.Row="3" Grid.Column="3" x:Name="VectorPlexusLogOut">Log Out</Button>
@ -35,12 +41,12 @@
<ItemsControl Grid.Row="1" x:Name="ResourceList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:ResourceView></controls:ResourceView>
<controls:ResourceView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

View File

@ -1,12 +1,11 @@
using System.Reactive.Disposables;
using ReactiveUI;
using Wabbajack.App.ViewModels;
using Wabbajack.App.Views;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public partial class SettingsView : ScreenBase<SettingsViewModel>
{
public partial class SettingsView : ScreenBase<SettingsViewModel>
{
public SettingsView()
{
InitializeComponent();
@ -18,9 +17,6 @@ namespace Wabbajack.App.Screens
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourceList.Items)
.DisposeWith(disposables);
});
}
}
}

View File

@ -15,21 +15,16 @@ using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.Services.OSIntegrated.TokenProviders;
namespace Wabbajack.App.Screens
namespace Wabbajack.App.Screens;
public class SettingsViewModel : ViewModelBase, IReceiverMarker
{
public class SettingsViewModel : ViewModelBase, IReceiverMarker
{
private readonly ILogger<SettingsViewModel> _logger;
public ReactiveCommand<Unit, Unit> NexusLogin { get; set; }
public ReactiveCommand<Unit, Unit> NexusLogout { get; set; }
public FileSystemWatcher Watcher { get; set; }
private readonly Subject<AbsolutePath> _fileSystemEvents = new();
private readonly ILogger<SettingsViewModel> _logger;
public readonly IEnumerable<ResourceViewModel> Resources;
public SettingsViewModel(ILogger<SettingsViewModel> logger, Configuration configuration, NexusApiTokenProvider nexusProvider, IEnumerable<IResource> resources)
public SettingsViewModel(ILogger<SettingsViewModel> logger, Configuration configuration,
NexusApiTokenProvider nexusProvider, IEnumerable<IResource> resources)
{
_logger = logger;
Resources = resources.Select(r => new ResourceViewModel(r)).ToArray();
@ -47,24 +42,24 @@ namespace Wabbajack.App.Screens
Watcher.EnableRaisingEvents = true;
var haveNexusToken = this._fileSystemEvents
var haveNexusToken = _fileSystemEvents
.StartWith(AbsolutePath.Empty)
.Select(_ => nexusProvider.HaveToken());
NexusLogin = ReactiveCommand.Create(() =>
{
MessageBus.Instance.Send(new NavigateTo(typeof(NexusLoginViewModel)));
}, haveNexusToken.Select(x => !x));
NexusLogin =
ReactiveCommand.Create(() => { MessageBus.Instance.Send(new NavigateTo(typeof(NexusLoginViewModel))); },
haveNexusToken.Select(x => !x));
NexusLogout = ReactiveCommand.Create(nexusProvider.DeleteToken, haveNexusToken.Select(x => x));
});
}
public ReactiveCommand<Unit, Unit> NexusLogin { get; set; }
public ReactiveCommand<Unit, Unit> NexusLogout { get; set; }
public FileSystemWatcher Watcher { get; set; }
private void Pulse(object sender, FileSystemEventArgs e)
{
_fileSystemEvents.OnNext(e.FullPath?.ToAbsolutePath() ?? default);
}
}
}

View File

@ -7,18 +7,26 @@
x:Class="Wabbajack.App.Views.StandardInstallationView">
<Grid RowDefinitions="40, 5, 5, *, 40">
<TextBlock Grid.Row="0" x:Name="StatusText" FontSize="20" FontWeight="Bold">[20/30] Installing Files</TextBlock>
<ProgressBar Grid.Row="1" x:Name="StepsProgress" Maximum="1000" Value="40"></ProgressBar>
<ProgressBar Grid.Row="2" x:Name="StepProgress" Maximum="10000" Value="30"></ProgressBar>
<ProgressBar Grid.Row="1" x:Name="StepsProgress" Maximum="1000" Value="40" />
<ProgressBar Grid.Row="2" x:Name="StepProgress" Maximum="10000" Value="30" />
<Viewbox Grid.Row="3" HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="Uniform">
<Image x:Name="SlideImage"></Image>
<Image x:Name="SlideImage" />
</Viewbox>
<Grid Grid.Row="4" HorizontalAlignment="Center" ColumnDefinitions="40, 40, 40, 40">
<Button Grid.Column="0" x:Name="PrevSlide"><i:MaterialIcon Kind="ArrowLeft"></i:MaterialIcon></Button>
<Button Grid.Column="1" x:Name="PauseSlides"><i:MaterialIcon Kind="Pause"></i:MaterialIcon></Button>
<Button Grid.Column="2" x:Name="PlaySlides"><i:MaterialIcon Kind="PlayArrow"></i:MaterialIcon></Button>
<Button Grid.Column="3" x:Name="NextSlide"><i:MaterialIcon Kind="ArrowRight"></i:MaterialIcon></Button>
<Button Grid.Column="0" x:Name="PrevSlide">
<i:MaterialIcon Kind="ArrowLeft" />
</Button>
<Button Grid.Column="1" x:Name="PauseSlides">
<i:MaterialIcon Kind="Pause" />
</Button>
<Button Grid.Column="2" x:Name="PlaySlides">
<i:MaterialIcon Kind="PlayArrow" />
</Button>
<Button Grid.Column="3" x:Name="NextSlide">
<i:MaterialIcon Kind="ArrowRight" />
</Button>
</Grid>
</Grid>
</UserControl>

View File

@ -2,10 +2,10 @@ using System.Reactive.Disposables;
using ReactiveUI;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Views
namespace Wabbajack.App.Views;
public partial class StandardInstallationView : ScreenBase<StandardInstallationViewModel>
{
public partial class StandardInstallationView : ScreenBase<StandardInstallationViewModel>
{
public StandardInstallationView()
{
InitializeComponent();
@ -35,9 +35,6 @@ namespace Wabbajack.App.Views
this.OneWayBind(ViewModel, vm => vm.StepProgress, view => view.StepProgress.Value, p => p.Value * 10000)
.DisposeWith(disposables);
});
}
}
}

View File

@ -8,7 +8,6 @@ using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Media;
using Avalonia.Threading;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -29,45 +28,25 @@ using Wabbajack.Installer;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
namespace Wabbajack.App.ViewModels
namespace Wabbajack.App.ViewModels;
public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInstallation>
{
public class StandardInstallationViewModel : ViewModelBase, IReceiver<StartInstallation>
{
private readonly IServiceProvider _provider;
private readonly GameLocator _locator;
private IServiceScope _scope;
private InstallerConfiguration _config;
private StandardInstaller _installer;
private readonly ILogger<StandardInstallationViewModel> _logger;
private readonly DTOSerializer _dtos;
private SlideViewModel[] _slides = Array.Empty<SlideViewModel>();
private readonly HttpClient _httpClient;
private Timer _slideTimer;
private int _currentSlideIndex;
private readonly InstallationStateManager _installStateManager;
private readonly GameLocator _locator;
private readonly ILogger<StandardInstallationViewModel> _logger;
private readonly IServiceProvider _provider;
private InstallerConfiguration _config;
private int _currentSlideIndex;
private StandardInstaller _installer;
private IServiceScope _scope;
private SlideViewModel[] _slides = Array.Empty<SlideViewModel>();
private Timer _slideTimer;
[Reactive]
public SlideViewModel Slide { get; set; }
[Reactive]
public ReactiveCommand<Unit,Unit> NextCommand { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> PrevCommand { get; set; }
[Reactive]
public ReactiveCommand<Unit, bool> PauseCommand { get; set; }
[Reactive]
public ReactiveCommand<Unit, bool> PlayCommand { get; set; }
[Reactive] public bool IsPlaying { get; set; } = true;
[Reactive] public string StatusText { get; set; } = "";
[Reactive] public Percent StepsProgress { get; set; } = Percent.Zero;
[Reactive] public Percent StepProgress { get; set; } = Percent.Zero;
public StandardInstallationViewModel(ILogger<StandardInstallationViewModel> logger, IServiceProvider provider, GameLocator locator, DTOSerializer dtos,
public StandardInstallationViewModel(ILogger<StandardInstallationViewModel> logger, IServiceProvider provider,
GameLocator locator, DTOSerializer dtos,
HttpClient httpClient, InstallationStateManager manager)
{
_provider = provider;
@ -78,7 +57,8 @@ namespace Wabbajack.App.ViewModels
_installStateManager = manager;
Activator = new ViewModelActivator();
this.WhenActivated(disposables => {
this.WhenActivated(disposables =>
{
_slideTimer = new Timer(_ =>
{
if (IsPlaying) NextSlide(1);
@ -92,18 +72,37 @@ namespace Wabbajack.App.ViewModels
PrevCommand = ReactiveCommand.Create(() => NextSlide(-1))
.DisposeWith(disposables);
PauseCommand = ReactiveCommand.Create(() => IsPlaying = false,
this.ObservableForProperty(vm => vm.IsPlaying, skipInitial:false)
this.ObservableForProperty(vm => vm.IsPlaying, skipInitial: false)
.Select(v => v.Value))
.DisposeWith(disposables);
PlayCommand = ReactiveCommand.Create(() => IsPlaying = true,
this.ObservableForProperty(vm => vm.IsPlaying, skipInitial:false)
this.ObservableForProperty(vm => vm.IsPlaying, skipInitial: false)
.Select(v => !v.Value))
.DisposeWith(disposables);
});
}
[Reactive] public SlideViewModel Slide { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> NextCommand { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> PrevCommand { get; set; }
[Reactive] public ReactiveCommand<Unit, bool> PauseCommand { get; set; }
[Reactive] public ReactiveCommand<Unit, bool> PlayCommand { get; set; }
[Reactive] public bool IsPlaying { get; set; } = true;
[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(StartInstallation msg)
{
Install(msg).FireAndForget();
}
private void NextSlide(int direction)
@ -123,10 +122,7 @@ namespace Wabbajack.App.ViewModels
//if (prevSlide.Image != null)
// prevSlide.Image = null;
Dispatcher.UIThread.InvokeAsync(() =>
{
Slide = thisSlide;
});
Dispatcher.UIThread.InvokeAsync(() => { Slide = thisSlide; });
}
private int InSlideRange(int i)
@ -140,12 +136,6 @@ namespace Wabbajack.App.ViewModels
return i;
}
public void Receive(StartInstallation msg)
{
Install(msg).FireAndForget();
}
private async Task Install(StartInstallation msg)
{
_scope = _provider.CreateScope();
@ -160,7 +150,7 @@ namespace Wabbajack.App.ViewModels
_config.Game = _config.ModList.GameType;
_slides = _config.ModList.Archives.Select(a => a.State).OfType<IMetaState>()
.Select(m => new SlideViewModel { MetaState = m })
.Select(m => new SlideViewModel {MetaState = m})
.Shuffle()
.ToArray();
@ -198,10 +188,7 @@ namespace Wabbajack.App.ViewModels
var result = await _installer.Begin(CancellationToken.None);
if (!result) throw new Exception("Installation failed");
if (result)
{
await SaveConfigAndContinue(_config);
}
if (result) await SaveConfigAndContinue(_config);
}
catch (Exception ex)
{
@ -230,5 +217,4 @@ namespace Wabbajack.App.ViewModels
MessageBus.Instance.Send(new ConfigureLauncher(config.Install));
MessageBus.Instance.Send(new NavigateTo(typeof(LauncherViewModel)));
}
}
}

View File

@ -1,6 +1,5 @@
using System;
using System.Net.Http;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Threading;
@ -20,16 +19,19 @@ using Wabbajack.Downloaders.Interfaces;
using Wabbajack.DTOs;
using Wabbajack.DTOs.DownloadStates;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Networking.NexusApi;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
using SettingsView = Wabbajack.App.Screens.SettingsView;
namespace Wabbajack.App
namespace Wabbajack.App;
public static class ServiceExtensions
{
public static class ServiceExtensions
{
private const int messagePumpDelay = 10;
private static CefAppImpl app;
private static Timer messagePump;
public static IServiceCollection AddAppServices(this IServiceCollection services)
{
services.AddAllSingleton<ILoggerProvider, LoggerProvider>();
@ -78,7 +80,7 @@ namespace Wabbajack.App
services.AddAllSingleton<IDownloader, IDownloader<Manual>, ManualDownloader>();
var resources = KnownFolders.EntryPoint;
services.AddSingleton(s => new CefSettings()
services.AddSingleton(s => new CefSettings
{
NoSandbox = true,
PersistSessionCookies = true,
@ -121,26 +123,19 @@ namespace Wabbajack.App
private static async void OnScheduleMessagePumpWork(long delayMs)
{
await Task.Delay((int)delayMs);
await Task.Delay((int) delayMs);
Dispatcher.UIThread.Post(CefApi.DoMessageLoopWork);
}
private static void App_CefProcessMessageReceived(object? sender, CefProcessMessageReceivedEventArgs e)
{
var msg = e.Name;
}
private static CefAppImpl app;
private static Timer messagePump;
private const int messagePumpDelay = 10;
private static void App_FrameworkInitialized(object? sender, EventArgs e)
{
if (CefNetApplication.Instance.UsesExternalMessageLoop)
{
messagePump = new Timer(_ => Dispatcher.UIThread.Post(CefApi.DoMessageLoopWork), null, messagePumpDelay, messagePumpDelay);
}
}
messagePump = new Timer(_ => Dispatcher.UIThread.Post(CefApi.DoMessageLoopWork), null, messagePumpDelay,
messagePumpDelay);
}
}

View File

@ -11,13 +11,16 @@ using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths;
using Wabbajack.RateLimiter;
namespace Wabbajack.App.Services
namespace Wabbajack.App.Services;
public class ManualDownloader : ADownloader<Manual>
{
public class ManualDownloader : ADownloader<Manual>
public override Priority Priority { get; }
public override Task<Hash> Download(Archive archive, Manual state, AbsolutePath destination, IJob job,
CancellationToken token)
{
public override Task<Hash> Download(Archive archive, Manual state, AbsolutePath destination, IJob job, CancellationToken token)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
public override Task<bool> Prepare()
@ -27,20 +30,16 @@ namespace Wabbajack.App.Services
public override bool IsAllowed(ServerAllowList allowList, IDownloadState state)
{
var manual = (Manual)state;
var manual = (Manual) state;
return allowList.AllowedPrefixes.Any(p => manual.Url.ToString().StartsWith(p));
}
public override IDownloadState? Resolve(IReadOnlyDictionary<string, string> iniData)
{
if (iniData.TryGetValue("manualURL", out var manual))
{
return new Manual { Url = new Uri(manual) };
}
if (iniData.TryGetValue("manualURL", out var manual)) return new Manual {Url = new Uri(manual)};
return null;
}
public override Priority Priority { get; }
public override Task<bool> Verify(Archive archive, Manual archiveState, IJob job, CancellationToken token)
{
return Task.FromResult(true);
@ -48,7 +47,6 @@ namespace Wabbajack.App.Services
public override IEnumerable<string> MetaIni(Archive a, Manual state)
{
return new[] { $"manualURL={state.Url}" };
}
return new[] {$"manualURL={state.Url}"};
}
}

View File

@ -2,10 +2,12 @@ using System;
using System.Runtime.InteropServices;
using CefNet;
namespace Wabbajack.App.Utilities
namespace Wabbajack.App.Utilities;
internal class CefAppImpl : CefNetApplication
{
class CefAppImpl : CefNetApplication
{
public Action<long> ScheduleMessagePumpWorkCallback { get; set; }
protected override void OnBeforeCommandLineProcessing(string processType, CefCommandLine commandLine)
{
base.OnBeforeCommandLineProcessing(processType, commandLine);
@ -50,7 +52,6 @@ const newProto = navigator.__proto__;
delete newProto.webdriver;
navigator.__proto__ = newProto;
}", frame.Url, 0);
}
protected override void OnCefProcessMessageReceived(CefProcessMessageReceivedEventArgs e)
@ -58,8 +59,6 @@ navigator.__proto__ = newProto;
base.OnCefProcessMessageReceived(e);
}
public Action<long> ScheduleMessagePumpWorkCallback { get; set; }
protected override CefRenderProcessHandler GetRenderProcessHandler()
{
return base.GetRenderProcessHandler();
@ -69,5 +68,4 @@ navigator.__proto__ = newProto;
{
ScheduleMessagePumpWorkCallback(delayMs);
}
}
}

View File

@ -8,7 +8,6 @@ using System.Text;
using System.Threading;
using DynamicData;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
@ -16,21 +15,18 @@ namespace Wabbajack.App.Utilities;
public class LoggerProvider : ILoggerProvider
{
private Subject<ILogMessage> _messages = new();
public IObservable<ILogMessage> Messages => _messages;
private long _messageId = 0;
private SourceCache<ILogMessage, long> _messageLog = new(m => m.MessageId);
public readonly ReadOnlyObservableCollection<ILogMessage> _messagesFiltered;
private readonly CompositeDisposable _disposables;
private readonly Configuration _configuration;
private readonly DateTime _startupTime;
private readonly RelativePath _appName;
public AbsolutePath LogPath { get; }
private readonly Configuration _configuration;
private readonly CompositeDisposable _disposables;
private readonly Stream _logFile;
private readonly StreamWriter _logStream;
public ReadOnlyObservableCollection<ILogMessage> MessageLog => _messagesFiltered;
public readonly ReadOnlyObservableCollection<ILogMessage> _messagesFiltered;
private readonly DateTime _startupTime;
private long _messageId;
private readonly SourceCache<ILogMessage, long> _messageLog = new(m => m.MessageId);
private readonly Subject<ILogMessage> _messages = new();
public LoggerProvider(Configuration configuration)
{
@ -55,11 +51,24 @@ public class LoggerProvider : ILoggerProvider
_appName = typeof(LoggerProvider).Assembly.Location.ToAbsolutePath().FileName;
LogPath = _configuration.LogLocation.Combine($"{_appName}.current.log");
_logFile = LogPath.Open(FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
_logFile = LogPath.Open(FileMode.Append, FileAccess.Write);
_logFile.DisposeWith(_disposables);
_logStream = new StreamWriter(_logFile, Encoding.UTF8);
}
public IObservable<ILogMessage> Messages => _messages;
public AbsolutePath LogPath { get; }
public ReadOnlyObservableCollection<ILogMessage> MessageLog => _messagesFiltered;
public void Dispose()
{
_disposables.Dispose();
}
public ILogger CreateLogger(string categoryName)
{
return new Logger(this, categoryName);
}
private void LogToFile(ILogMessage logMessage)
@ -77,21 +86,11 @@ public class LoggerProvider : ILoggerProvider
return Interlocked.Increment(ref _messageId);
}
public void Dispose()
{
_disposables.Dispose();
}
public ILogger CreateLogger(string categoryName)
{
return new Logger(this, categoryName);
}
public class Logger : ILogger
{
private readonly string _categoryName;
private readonly LoggerProvider _provider;
private ImmutableList<object> Scopes = ImmutableList<object>.Empty;
private readonly string _categoryName;
public Logger(LoggerProvider provider, string categoryName)
{
@ -99,9 +98,11 @@ public class LoggerProvider : ILoggerProvider
_provider = provider;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception,
Func<TState, Exception?, string> formatter)
{
_provider._messages.OnNext(new LogMessage<TState>(DateTime.UtcNow, _provider.NextMessageId(), logLevel, eventId, state, exception, formatter));
_provider._messages.OnNext(new LogMessage<TState>(DateTime.UtcNow, _provider.NextMessageId(), logLevel,
eventId, state, exception, formatter));
}
public bool IsEnabled(LogLevel logLevel)
@ -125,7 +126,8 @@ public class LoggerProvider : ILoggerProvider
string LongMessage { get; }
}
record LogMessage<TState>(DateTime TimeStamp, long MessageId, LogLevel LogLevel, EventId EventId, TState State, Exception? Exception, Func<TState, Exception?, string> Formatter) : ILogMessage
private record LogMessage<TState>(DateTime TimeStamp, long MessageId, LogLevel LogLevel, EventId EventId,
TState State, Exception? Exception, Func<TState, Exception?, string> Formatter) : ILogMessage
{
public string ShortMessage => Formatter(State, Exception);

View File

@ -5,10 +5,10 @@ using Wabbajack.Common;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.App.Utilities
namespace Wabbajack.App.Utilities;
public class ModListUtilities
{
public class ModListUtilities
{
public static async Task<MemoryStream> GetModListImageStream(AbsolutePath modList)
{
await using var fs = modList.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
@ -17,5 +17,4 @@ namespace Wabbajack.App.Utilities
await using var stream = entry!.Open();
return new MemoryStream(await stream.ReadAllAsync());
}
}
}

View File

@ -1,13 +1,12 @@
using System;
using Wabbajack.Common;
using System.Diagnostics;
namespace Wabbajack.App
namespace Wabbajack.App;
public static class Utils
{
public static class Utils
{
public static void OpenWebsiteInExternalBrowser(Uri uri)
{
System.Diagnostics.Process.Start(uri.ToString());
}
Process.Start(uri.ToString());
}
}

View File

@ -3,10 +3,10 @@ using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App
namespace Wabbajack.App;
public class ViewLocator : IDataTemplate
{
public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;
public IControl Build(object data)
@ -15,18 +15,12 @@ namespace Wabbajack.App
var type = Type.GetType(name);
if (type != null)
{
return (Control)Activator.CreateInstance(type)!;
}
else
{
return new TextBlock { Text = "Not Found: " + name };
}
return (Control) Activator.CreateInstance(type)!;
return new TextBlock {Text = "Not Found: " + name};
}
public bool Match(object data)
{
return data is ViewModelBase;
}
}
}

View File

@ -1,36 +1,29 @@
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
using CefNet;
using CefNet.Avalonia;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Messages;
using Wabbajack.Common;
namespace Wabbajack.App.ViewModels
namespace Wabbajack.App.ViewModels;
public abstract class GuidedWebViewModel : ViewModelBase, IReceiverMarker
{
public abstract class GuidedWebViewModel : ViewModelBase, IReceiverMarker
{
protected ILogger _logger;
[Reactive]
public string Instructions { get; set; }
public GuidedWebViewModel(ILogger logger)
{
_logger = logger;
Activator = new ViewModelActivator();
this.WhenActivated(disposables =>
{
Disposable.Empty.DisposeWith(disposables);
});
this.WhenActivated(disposables => { Disposable.Empty.DisposeWith(disposables); });
}
[Reactive] public string Instructions { get; set; }
public WebView Browser { get; set; }
public abstract Task Run(CancellationToken token);
}
}

View File

@ -1,5 +1,3 @@
using System.IO;
using System.IO.Compression;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
@ -21,35 +19,13 @@ using Wabbajack.Installer;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.App.ViewModels
namespace Wabbajack.App.ViewModels;
public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewModel, IReceiver<StartInstallConfiguration>
{
public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewModel, IReceiver<StartInstallConfiguration>
{
private readonly DTOSerializer _dtos;
private readonly InstallationStateManager _stateManager;
[Reactive]
public AbsolutePath ModListPath { get; set; }
[Reactive]
public AbsolutePath Install { get; set; }
[Reactive]
public AbsolutePath Download { get; set; }
[Reactive]
public ModList? ModList { get; set; }
[Reactive]
public IBitmap? ModListImage { get; set; }
[Reactive]
public bool IsReady { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> BeginCommand { get; set; }
public InstallConfigurationViewModel(DTOSerializer dtos, InstallationStateManager stateManager)
{
@ -59,12 +35,11 @@ namespace Wabbajack.App.ViewModels
Activator = new ViewModelActivator();
this.WhenActivated(disposables =>
{
this.ValidationRule(x => x.ModListPath, p => p.FileExists(), "Wabbajack file must exist");
this.ValidationRule(x => x.Install, p => p.DirectoryExists(), "Install folder file must exist");
this.ValidationRule(x => x.Download, p => p != default, "Download folder must be set");
BeginCommand = ReactiveCommand.Create(() => {StartInstall().FireAndForget();}, this.IsValid());
BeginCommand = ReactiveCommand.Create(() => { StartInstall().FireAndForget(); }, this.IsValid());
this.WhenAnyValue(t => t.ModListPath)
@ -95,8 +70,27 @@ namespace Wabbajack.App.ViewModels
.BindTo(this, vm => vm.Download)
.DisposeWith(disposables);
});
}
[Reactive] public AbsolutePath ModListPath { get; set; }
[Reactive] public AbsolutePath Install { get; set; }
[Reactive] public AbsolutePath Download { get; set; }
[Reactive] public ModList? ModList { get; set; }
[Reactive] public IBitmap? ModListImage { get; set; }
[Reactive] public bool IsReady { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> BeginCommand { get; set; }
public ViewModelActivator Activator { get; }
public void Receive(StartInstallConfiguration val)
{
ModListPath = val.ModList;
}
private async Task StartInstall()
@ -104,9 +98,7 @@ namespace Wabbajack.App.ViewModels
ModlistMetadata? metadata = null;
var metadataPath = ModListPath.WithExtension(Ext.MetaData);
if (metadataPath.FileExists())
{
metadata = _dtos.Deserialize<ModlistMetadata>(await metadataPath.ReadAllTextAsync());
}
_stateManager.SetLastState(new InstallationConfigurationSetting
{
@ -127,15 +119,7 @@ namespace Wabbajack.App.ViewModels
private async Task<ModList> LoadModList(AbsolutePath modlist)
{
var definition= await StandardInstaller.LoadFromFile(_dtos, modlist);
var definition = await StandardInstaller.LoadFromFile(_dtos, modlist);
return definition;
}
public ViewModelActivator Activator { get; }
public void Receive(StartInstallConfiguration val)
{
ModListPath = val.ModList;
}
}
}

View File

@ -1,20 +1,15 @@
using System;
using System.Net.Http;
using CefNet;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Wabbajack.DTOs.Logins;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.Services.OSIntegrated.TokenProviders;
namespace Wabbajack.App.ViewModels
namespace Wabbajack.App.ViewModels;
public class LoversLabOAuthLoginViewModel : OAuthLoginViewModel<LoversLabLoginState>
{
public class LoversLabOAuthLoginViewModel : OAuthLoginViewModel<LoversLabLoginState>
{
public LoversLabOAuthLoginViewModel(ILogger<LoversLabOAuthLoginViewModel> logger, HttpClient client,
LoversLabTokenProvider tokenProvider)
: base(logger, client, tokenProvider)
{
}
}
}

View File

@ -8,7 +8,6 @@ using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;
using Microsoft.Extensions.DependencyInjection;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using ReactiveUI.Validation.Helpers;
@ -21,36 +20,20 @@ using Wabbajack.Common;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
namespace Wabbajack.App.ViewModels
namespace Wabbajack.App.ViewModels;
public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewModel, IReceiver<NavigateTo>,
IReceiver<NavigateBack>
{
public class MainWindowViewModel : ReactiveValidationObject, IActivatableViewModel, IReceiver<NavigateTo>, IReceiver<NavigateBack>
{
private readonly IEnumerable<IScreenView> _screens;
private readonly IServiceProvider _provider;
private readonly IResource[] _resources;
private StatusReport[] _prevReport;
private readonly Task _resourcePoller;
private readonly InstallationStateManager _manager;
private readonly IServiceProvider _provider;
private readonly Task _resourcePoller;
private readonly IResource[] _resources;
private readonly IEnumerable<IScreenView> _screens;
private StatusReport[] _prevReport;
[Reactive]
public Control CurrentScreen { get; set; }
[Reactive]
private ImmutableStack<Control> BreadCrumbs { get; set; } = ImmutableStack<Control>.Empty;
[Reactive]
public ReactiveCommand<Unit, Unit> BackButton { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> SettingsButton { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> LogViewButton { get; set; }
[Reactive]
public string ResourceStatus { get; set; }
public MainWindowViewModel(IEnumerable<IScreenView> screens, IEnumerable<IResource> resources, IServiceProvider provider,
public MainWindowViewModel(IEnumerable<IScreenView> screens, IEnumerable<IResource> resources,
IServiceProvider provider,
InstallationStateManager manager)
{
_provider = provider;
@ -66,31 +49,50 @@ namespace Wabbajack.App.ViewModels
this.WhenActivated(disposables =>
{
BackButton = ReactiveCommand.Create(() =>
{
Receive(new NavigateBack());
},
BackButton = ReactiveCommand.Create(() => { Receive(new NavigateBack()); },
this.ObservableForProperty(vm => vm.BreadCrumbs)
.Select(bc => bc.Value.Count() > 1))
.DisposeWith(disposables);
SettingsButton = ReactiveCommand.Create(() =>
{
Receive(new NavigateTo(typeof(SettingsViewModel)));
})
SettingsButton = ReactiveCommand.Create(() => { Receive(new NavigateTo(typeof(SettingsViewModel))); })
.DisposeWith(disposables);
LogViewButton = ReactiveCommand.Create(() =>
{
Receive(new NavigateTo(typeof(LogScreenViewModel)));
})
LogViewButton = ReactiveCommand.Create(() => { Receive(new NavigateTo(typeof(LogScreenViewModel))); })
.DisposeWith(disposables);
});
CurrentScreen = (Control)_screens.First(s => s.ViewModelType == typeof(ModeSelectionViewModel));
CurrentScreen = (Control) _screens.First(s => s.ViewModelType == typeof(ModeSelectionViewModel));
LoadFirstScreen().FireAndForget();
}
[Reactive] public Control CurrentScreen { get; set; }
[Reactive] private ImmutableStack<Control> BreadCrumbs { get; set; } = ImmutableStack<Control>.Empty;
[Reactive] public ReactiveCommand<Unit, Unit> BackButton { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> SettingsButton { get; set; }
[Reactive] public ReactiveCommand<Unit, Unit> LogViewButton { get; set; }
[Reactive] public string ResourceStatus { get; set; }
public ViewModelActivator Activator { get; }
public void Receive(NavigateBack val)
{
CurrentScreen = BreadCrumbs.Peek();
BreadCrumbs = BreadCrumbs.Pop();
}
public void Receive(NavigateTo val)
{
BreadCrumbs = BreadCrumbs.Push(CurrentScreen);
if (val.ViewModel.IsAssignableTo(typeof(GuidedWebViewModel)))
CurrentScreen = new GuidedWebView {ViewModel = (GuidedWebViewModel) _provider.GetService(val.ViewModel)!};
else
CurrentScreen = (Control) _screens.First(s => s.ViewModelType == val.ViewModel);
}
private async Task LoadFirstScreen()
@ -99,7 +101,7 @@ namespace Wabbajack.App.ViewModels
if (setting.Install != default && setting.Install.DirectoryExists())
{
BreadCrumbs =
BreadCrumbs.Push((Control)_screens.First(s => s.ViewModelType == typeof(ModeSelectionViewModel)));
BreadCrumbs.Push((Control) _screens.First(s => s.ViewModelType == typeof(ModeSelectionViewModel)));
MessageBus.Instance.Send(new ConfigureLauncher(setting.Install));
Receive(new NavigateTo(typeof(LauncherViewModel)));
@ -125,11 +127,9 @@ namespace Wabbajack.App.ViewModels
{
var throughput = next.Transferred - prev.Transferred;
if (throughput != 0)
{
sb.Append(
$"{limiter.Name}: [{next.Running}/{next.Pending + next.Running}] {throughput.ToFileSizeString()}/sec ");
}
}
ResourceStatus = sb.ToString();
_prevReport = report;
@ -137,26 +137,4 @@ namespace Wabbajack.App.ViewModels
await Task.Delay(TimeSpan.FromSeconds(0.5));
}
}
public ViewModelActivator Activator { get; }
public void Receive(NavigateTo val)
{
BreadCrumbs = BreadCrumbs.Push(CurrentScreen);
if (val.ViewModel.IsAssignableTo(typeof(GuidedWebViewModel)))
{
CurrentScreen = new GuidedWebView() { ViewModel = (GuidedWebViewModel)_provider.GetService(val.ViewModel)! };
}
else
{
CurrentScreen = (Control)_screens.First(s => s.ViewModelType == val.ViewModel);
}
}
public void Receive(NavigateBack val)
{
CurrentScreen = BreadCrumbs.Peek();
BreadCrumbs = BreadCrumbs.Pop();
}
}
}

View File

@ -1,14 +1,11 @@
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
namespace Wabbajack.App.ViewModels
namespace Wabbajack.App.ViewModels;
public class ModeSelectionViewModel : ViewModelBase
{
public class ModeSelectionViewModel : ViewModelBase
{
public ModeSelectionViewModel()
{
Activator = new ViewModelActivator();
}
}
}

View File

@ -9,10 +9,10 @@ using Wabbajack.App.Messages;
using Wabbajack.DTOs.Logins;
using Wabbajack.Services.OSIntegrated.TokenProviders;
namespace Wabbajack.App.ViewModels
namespace Wabbajack.App.ViewModels;
public class NexusLoginViewModel : GuidedWebViewModel
{
public class NexusLoginViewModel : GuidedWebViewModel
{
private readonly NexusApiTokenProvider _tokenProvider;
public NexusLoginViewModel(ILogger<NexusLoginViewModel> logger, NexusApiTokenProvider tokenProvider) : base(logger)
@ -28,10 +28,11 @@ namespace Wabbajack.App.ViewModels
await Browser.WaitForReady();
await Browser.NavigateTo(new Uri("https://users.nexusmods.com/auth/continue?client_id=nexus&redirect_uri=https://www.nexusmods.com/oauth/callback&response_type=code&referrer=//www.nexusmods.com"));
await Browser.NavigateTo(new Uri(
"https://users.nexusmods.com/auth/continue?client_id=nexus&redirect_uri=https://www.nexusmods.com/oauth/callback&response_type=code&referrer=//www.nexusmods.com"));
Cookie[] cookies = {};
Cookie[] cookies = { };
while (true)
{
cookies = await Browser.Cookies("nexusmods.com", token);
@ -50,7 +51,6 @@ namespace Wabbajack.App.ViewModels
while (true)
{
try
{
key = (await Browser.GetDom(token))
@ -78,8 +78,6 @@ namespace Wabbajack.App.ViewModels
"found.remove(); found = undefined;"
);
Instructions = "Generating API Key, Please Wait...";
}
catch (Exception)
{
@ -90,7 +88,6 @@ namespace Wabbajack.App.ViewModels
await Task.Delay(500, token);
MessageBus.Instance.Send(new NavigateBack());
}
Instructions = "Success, saving information...";
@ -99,7 +96,5 @@ namespace Wabbajack.App.ViewModels
Cookies = cookies,
ApiKey = key
});
}
}
}

View File

@ -12,53 +12,20 @@ using Wabbajack.App.Extensions;
using Wabbajack.DTOs.Logins;
using Wabbajack.Services.OSIntegrated;
namespace Wabbajack.App.ViewModels
{
public abstract class OAuthLoginViewModel<TLoginType> : GuidedWebViewModel
namespace Wabbajack.App.ViewModels;
public abstract class OAuthLoginViewModel<TLoginType> : GuidedWebViewModel
where TLoginType : OAuth2LoginState, new()
{
{
private readonly HttpClient _httpClient;
private readonly EncryptedJsonTokenProvider<TLoginType> _tokenProvider;
public OAuthLoginViewModel(ILogger logger, HttpClient httpClient, EncryptedJsonTokenProvider<TLoginType> tokenProvider) : base(logger)
public OAuthLoginViewModel(ILogger logger, HttpClient httpClient,
EncryptedJsonTokenProvider<TLoginType> tokenProvider) : base(logger)
{
_logger = logger;
_httpClient = httpClient;
_tokenProvider = tokenProvider;
}
private class AsyncSchemeHandler : CefSchemeHandlerFactory
{
private TaskCompletionSource<Uri> _tcs = new();
public Task<Uri> Task => _tcs.Task;
public AsyncSchemeHandler()
{
}
protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName,
CefRequest request)
{
return new Handler(_tcs);
}
}
private class Handler : CefResourceHandler
{
private readonly TaskCompletionSource<Uri> _tcs;
public Handler(TaskCompletionSource<Uri> tcs)
{
_tcs = tcs;
}
protected override bool ProcessRequest(CefRequest request, CefCallback callback)
{
_tcs.TrySetResult(new Uri(request.Url));
return false;
}
}
public override async Task Run(CancellationToken token)
@ -107,7 +74,8 @@ namespace Wabbajack.App.ViewModels
var msg = new HttpRequestMessage();
msg.Method = HttpMethod.Post;
msg.RequestUri = tlogin.TokenEndpoint;
msg.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36");
msg.Headers.Add("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36");
msg.Headers.Add("Cookie", string.Join(";", cookies.Select(c => $"{c.Name}={c.Value}")));
msg.Content = new FormUrlEncodedContent(formData.ToList());
@ -119,11 +87,34 @@ namespace Wabbajack.App.ViewModels
Cookies = cookies,
ResultState = data!
});
}
private class AsyncSchemeHandler : CefSchemeHandlerFactory
{
private readonly TaskCompletionSource<Uri> _tcs = new();
public Task<Uri> Task => _tcs.Task;
protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName,
CefRequest request)
{
return new Handler(_tcs);
}
}
private class Handler : CefResourceHandler
{
private readonly TaskCompletionSource<Uri> _tcs;
public Handler(TaskCompletionSource<Uri> tcs)
{
_tcs = tcs;
}
protected override bool ProcessRequest(CefRequest request, CefCallback callback)
{
_tcs.TrySetResult(new Uri(request.Url));
return false;
}
}
}

View File

@ -8,37 +8,30 @@ using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.DTOs.DownloadStates;
namespace Wabbajack.App.ViewModels.SubViewModels
namespace Wabbajack.App.ViewModels.SubViewModels;
public class SlideViewModel : ViewModelBase
{
public class SlideViewModel : ViewModelBase
{
[Reactive]
public IMetaState MetaState { get; set; }
[Reactive]
public IImage? Image { get; set; }
public bool Loading { get; set; } = false;
public SlideViewModel()
{
Activator = new ViewModelActivator();
Image = null;
}
[Reactive] public IMetaState MetaState { get; set; }
[Reactive] public IImage? Image { get; set; }
public bool Loading { get; set; }
public async Task PreCache(HttpClient client)
{
Loading = true;
var url = await client.GetByteArrayAsync(MetaState.ImageURL);
var img = new Bitmap(new MemoryStream(url));
await Dispatcher.UIThread.InvokeAsync(() =>
{
Image = img;
});
await Dispatcher.UIThread.InvokeAsync(() => { Image = img; });
Loading = false;
}
}
}

Some files were not shown because too many files have changed in this diff Show More