Hook up discord and archive search buttons

This commit is contained in:
Timothy Baldridge 2022-05-16 21:27:23 -06:00
parent 480710890e
commit 92f5618066
7 changed files with 119 additions and 42 deletions

View File

@ -122,25 +122,7 @@ namespace Wabbajack
ModListContentsCommend = ReactiveCommand.Create(async () =>
{
_parent.MWVM.ModListContentsVM.Value.Name = metadata.Title;
IsLoadingIdle.OnNext(false);
try
{
var status = await wjClient.GetDetailedStatus(metadata.NamespacedName);
var coll = _parent.MWVM.ModListContentsVM.Value.Status;
coll.Clear();
coll.AddRange(status.Archives.Select(a => new DetailedStatusItem
{
Archive = a.Original,
ArchiveStatus = a.Status,
IsFailing = a.Status != ArchiveStatus.InValid
}));
NavigateToGlobal.Send(NavigateToGlobal.ScreenType.ModListContents);
}
finally
{
IsLoadingIdle.OnNext(true);
}
UIUtils.OpenWebsite(new Uri("https://www.wabbajack.org/search/" + Metadata.NamespacedName));
}, IsLoadingIdle.StartWith(true));
ExecuteCommand = ReactiveCommand.CreateFromTask(async () =>

View File

@ -6,6 +6,8 @@ using System.Windows.Media.Imaging;
using ReactiveUI.Fody.Helpers;
using DynamicData;
using System.Reactive;
using System.Reactive.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Shell;
@ -112,6 +114,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
// Command properties
public ReactiveCommand<Unit, Unit> ShowManifestCommand { get; }
public ReactiveCommand<Unit, Unit> OpenReadmeCommand { get; }
public ReactiveCommand<Unit, Unit> OpenDiscordButton { get; }
public ReactiveCommand<Unit, Unit> VisitModListWebsiteCommand { get; }
public ReactiveCommand<Unit, Unit> CloseWhenCompleteCommand { get; }
@ -163,7 +166,21 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
{
UIUtils.OpenFolder(_configuration.LogLocation);
});
OpenDiscordButton = ReactiveCommand.Create(() =>
{
UIUtils.OpenWebsite(new Uri(ModlistMetadata.Links.DiscordURL));
}, this.WhenAnyValue(x => x.ModlistMetadata)
.WhereNotNull()
.Select(md => !string.IsNullOrWhiteSpace(md.Links.DiscordURL)));
ShowManifestCommand = ReactiveCommand.Create(() =>
{
UIUtils.OpenWebsite(new Uri("https://www.wabbajack.org/search/" + ModlistMetadata.NamespacedName));
}, this.WhenAnyValue(x => x.ModlistMetadata)
.WhereNotNull()
.Select(md => !string.IsNullOrWhiteSpace(md.Links.MachineURL)));
CloseWhenCompleteCommand = ReactiveCommand.Create(() =>
{
Environment.Exit(0);
@ -219,6 +236,20 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
var hex = (await ModListLocation.TargetPath.ToString().Hash()).ToHex();
var prevSettings = await _settingsManager.Load<SavedInstallSettings>(InstallSettingsPrefix + hex);
if (path.WithExtension(Ext.MetaData).FileExists())
{
try
{
metadata = JsonSerializer.Deserialize<ModlistMetadata>(await path.WithExtension(Ext.MetaData)
.ReadAllTextAsync());
ModlistMetadata = metadata;
}
catch (Exception ex)
{
_logger.LogInformation(ex, "Can't load metadata cached next to file");
}
}
if (prevSettings.ModListLocation == path)
{
ModListLocation.TargetPath = prevSettings.ModListLocation;

View File

@ -212,37 +212,60 @@
<ColumnDefinition Width="4" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Margin="10">
<Grid Grid.Column="0" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Row="0"
x:Name="OpenReadmePreInstallButton"
Margin="30,5"
FontSize="20"
Style="{StaticResource LargeButtonStyle}"
ToolTip="Open the readme for the modlist">
x:Name="OpenDiscordPreInstallButton"
Margin="30,2"
FontSize="20"
Style="{StaticResource LargeButtonStyle}"
ToolTip="Open the Discord for this Modlist">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="82" />
</Grid.ColumnDefinitions>
<icon:PackIconFontAwesome Grid.Column="0"
Width="30"
Height="30"
VerticalAlignment="Center"
Kind="ReadmeBrands" />
Width="30"
Height="30"
VerticalAlignment="Center"
Kind="DiscordBrands" />
<TextBlock Grid.Column="1"
Margin="10,0,0,0"
VerticalAlignment="Center"
Text="Readme" />
Margin="10,0,0,0"
VerticalAlignment="Center"
Text="Discord" />
</Grid>
</Button>
<Button Grid.Row="1"
x:Name="OpenReadmePreInstallButton"
Margin="30,2"
FontSize="20"
Style="{StaticResource LargeButtonStyle}"
ToolTip="Open the readme for the modlist">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="82" />
</Grid.ColumnDefinitions>
<icon:PackIconFontAwesome Grid.Column="0"
Width="30"
Height="30"
VerticalAlignment="Center"
Kind="ReadmeBrands" />
<TextBlock Grid.Column="1"
Margin="10,0,0,0"
VerticalAlignment="Center"
Text="Readme" />
</Grid>
</Button>
<Button Grid.Row="2"
x:Name="VisitWebsitePreInstallButton"
Margin="30,5"
Margin="30,2"
FontSize="20"
Style="{StaticResource LargeButtonStyle}"
ToolTip="Open the webpage for the modlist">
@ -262,9 +285,9 @@
Text="Website" />
</Grid>
</Button>
<Button Grid.Row="2"
<Button Grid.Row="3"
x:Name="ShowManifestPreInstallButton"
Margin="30,5"
Margin="30,2"
FontSize="20"
Style="{StaticResource LargeButtonStyle}"
ToolTip="Open an explicit listing of all actions this modlist will take">

View File

@ -42,10 +42,22 @@ namespace Wabbajack
ViewModel.WhenAnyValue(vm => vm.OpenReadmeCommand)
.BindToStrict(this, view => view.OpenReadmePreInstallButton.Command)
.DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.OpenDiscordButton)
.BindToStrict(this, view => view.OpenDiscordPreInstallButton.Command)
.DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.VisitModListWebsiteCommand)
.BindToStrict(this, view => view.OpenWebsite.Command)
.DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.VisitModListWebsiteCommand)
.BindToStrict(this, view => view.VisitWebsitePreInstallButton.Command)
.DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.ShowManifestCommand)
.BindToStrict(this, view => view.ShowManifestPreInstallButton.Command)
.DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.LoadingLock.IsLoading)
.Select(loading => loading ? Visibility.Visible : Visibility.Collapsed)

View File

@ -57,6 +57,10 @@ namespace Wabbajack
.BindToStrict(this, x => x.OpenWebsiteButton.Command)
.DisposeWith(disposables);
ViewModel.WhenAnyValue(x => x.ModListContentsCommend)
.BindToStrict(this, x => x.ModListContentsButton.Command)
.DisposeWith(disposables);
ViewModel.WhenAnyValue(x => x.ExecuteCommand)
.BindToStrict(this, x => x.ExecuteButton.Command)
.DisposeWith(disposables);

View File

@ -6,6 +6,7 @@ using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Wabbajack.Common;
using Wabbajack.Downloaders.Interfaces;
using Wabbajack.DTOs;
using Wabbajack.DTOs.CDN;
@ -33,12 +34,14 @@ public class WabbajackCDNDownloader : ADownloader<WabbajackCDN>, IUrlDownloader,
private readonly DTOSerializer _dtos;
private readonly ILogger<WabbajackCDNDownloader> _logger;
private readonly ParallelOptions _parallelOptions;
private readonly IResource<HttpClient> _limiter;
public WabbajackCDNDownloader(ILogger<WabbajackCDNDownloader> logger, HttpClient client, DTOSerializer dtos)
public WabbajackCDNDownloader(ILogger<WabbajackCDNDownloader> logger, HttpClient client, IResource<HttpClient> limiter, DTOSerializer dtos)
{
_client = client;
_logger = logger;
_dtos = dtos;
_limiter = limiter;
}
public override Task<bool> Prepare()
@ -78,8 +81,11 @@ public class WabbajackCDNDownloader : ADownloader<WabbajackCDN>, IUrlDownloader,
var definition = (await GetDefinition(state, token))!;
await using var fs = destination.Open(FileMode.Create, FileAccess.Write, FileShare.None);
foreach (var part in definition.Parts)
await definition.Parts.PMapAll(async part =>
{
using var partJob = await _limiter.Begin(
$"Downloading {definition.MungedName} ({part.Index}/{definition.Size})",
part.Size, token);
var msg = MakeMessage(new Uri(state.Url + $"/parts/{part.Index}"));
using var response = await _client.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead, token);
if (!response.IsSuccessStatusCode)
@ -92,12 +98,26 @@ public class WabbajackCDNDownloader : ADownloader<WabbajackCDN>, IUrlDownloader,
await using var data = await response.Content.ReadAsStreamAsync(token);
fs.Position = part.Offset;
var hash = await data.HashingCopy(fs, token, job);
var ms = new MemoryStream();
var hash = await data.HashingCopy(ms, token, partJob);
ms.Position = 0;
if (hash != part.Hash)
throw new InvalidDataException($"Bad part hash, got {hash} expected {part.Hash} for part {part.Index}");
{
throw new Exception(
$"Invalid part hash {part.Index} got {hash} instead of {part.Hash} for {definition.MungedName}");
}
return (ms, part);
}).Do(async rec =>
{
var (ms, part) = rec;
fs.Position = part.Offset;
await job.Report((int)part.Size, token);
await ms.CopyToAsync(fs, token);
await fs.FlushAsync(token);
}
});
return definition.Hash;
}

View File

@ -1,11 +1,13 @@
using System;
using System.Reactive.Subjects;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Wabbajack.Common;
using Wabbajack.Downloaders;
using Wabbajack.DTOs;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
@ -21,9 +23,10 @@ public class ModListDownloadMaintainer
private readonly FileHashCache _hashCache;
private readonly IResource<DownloadDispatcher> _rateLimiter;
private int _downloadingCount;
private readonly DTOSerializer _dtos;
public ModListDownloadMaintainer(ILogger<ModListDownloadMaintainer> logger, Configuration configuration,
DownloadDispatcher dispatcher, FileHashCache hashCache, IResource<DownloadDispatcher> rateLimiter)
DownloadDispatcher dispatcher, FileHashCache hashCache, DTOSerializer dtos, IResource<DownloadDispatcher> rateLimiter)
{
_logger = logger;
_configuration = configuration;
@ -31,6 +34,7 @@ public class ModListDownloadMaintainer
_hashCache = hashCache;
_rateLimiter = rateLimiter;
_downloadingCount = 0;
_dtos = dtos;
}
public AbsolutePath ModListPath(ModlistMetadata metadata)
@ -77,6 +81,7 @@ public class ModListDownloadMaintainer
}, path, job, token.Value);
_hashCache.FileHashWriteCache(path, hash);
await path.WithExtension(Ext.MetaData).WriteAllTextAsync(JsonSerializer.Serialize(metadata));
}
finally
{