mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Implement basic total modlist size filter
This commit is contained in:
parent
a908c49f26
commit
95ff0dac6d
@ -14,7 +14,7 @@ namespace Wabbajack.Models;
|
||||
|
||||
public class ResourceMonitor : IDisposable
|
||||
{
|
||||
private readonly TimeSpan _pollInterval = TimeSpan.FromMilliseconds(250);
|
||||
private readonly TimeSpan _pollInterval = TimeSpan.FromMilliseconds(1000);
|
||||
|
||||
private readonly IResource[] _resources;
|
||||
|
||||
|
@ -87,7 +87,7 @@
|
||||
<SolidColorBrush
|
||||
x:Key="MahApps.Brushes.AccentBase"
|
||||
options:Freeze="True"
|
||||
Color="{StaticResource MahApps.Colors.AccentBase}" />
|
||||
Color="{StaticResource Primary}" />
|
||||
<SolidColorBrush
|
||||
x:Key="MahApps.Brushes.Accent"
|
||||
options:Freeze="True"
|
||||
|
@ -46,6 +46,11 @@ namespace Wabbajack
|
||||
[Reactive] public bool ShowUnofficialLists { get; set; }
|
||||
|
||||
[Reactive] public string GameType { get; set; }
|
||||
[Reactive] public double MinSizeFilter { get; set; }
|
||||
[Reactive] public double MaxSizeFilter { get; set; }
|
||||
|
||||
[Reactive] public ModListMetadataVM MinSizeModlist { get; set; }
|
||||
[Reactive] public ModListMetadataVM MaxSizeModlist { get; set; }
|
||||
|
||||
public class GameTypeEntry
|
||||
{
|
||||
@ -67,6 +72,8 @@ namespace Wabbajack
|
||||
|
||||
[Reactive] public List<GameTypeEntry> GameTypeEntries { get; set; }
|
||||
private bool _filteringOnGame;
|
||||
private bool _filteringOnMinSize;
|
||||
private bool _filteringOnMaxSize;
|
||||
private GameTypeEntry _selectedGameTypeEntry = null;
|
||||
|
||||
public GameTypeEntry SelectedGameTypeEntry
|
||||
@ -170,12 +177,29 @@ namespace Wabbajack
|
||||
})
|
||||
.StartWith(_ => true);
|
||||
|
||||
var minSizeFilter = this.ObservableForProperty(vm => vm.MinSizeFilter)
|
||||
.Select(v => v.Value)
|
||||
.Select<double, Func<ModListMetadataVM, bool>>(minSize =>
|
||||
{
|
||||
_filteringOnMinSize = true;
|
||||
return item => item.Metadata.DownloadMetadata.TotalSize > (minSize * Math.Pow(1024, 3));
|
||||
});
|
||||
|
||||
var maxSizeFilter = this.ObservableForProperty(vm => vm.MaxSizeFilter)
|
||||
.Select(v => v.Value)
|
||||
.Select<double, Func<ModListMetadataVM, bool>>(maxSize =>
|
||||
{
|
||||
_filteringOnMaxSize = true;
|
||||
return item => item.Metadata.DownloadMetadata.TotalSize < (maxSize * Math.Pow(1024, 3));
|
||||
});
|
||||
|
||||
|
||||
var searchSorter = this.WhenValueChanged(vm => vm.Search)
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s))
|
||||
.Throttle(searchThrottle, RxApp.MainThreadScheduler)
|
||||
.Select(s => SortExpressionComparer<ModListMetadataVM>
|
||||
.Descending(m => m.Metadata.Title.StartsWith(s, StringComparison.InvariantCultureIgnoreCase))
|
||||
.ThenByDescending(m => m.Metadata.Title.Contains(s, StringComparison.InvariantCultureIgnoreCase)));
|
||||
.ThenByDescending(m => m.Metadata.Title.Contains(s, StringComparison.InvariantCultureIgnoreCase))
|
||||
.ThenByDescending(m => !m.IsBroken));
|
||||
_modLists.Connect()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Filter(searchTextPredicates)
|
||||
@ -183,6 +207,8 @@ namespace Wabbajack
|
||||
.Filter(showUnofficial)
|
||||
.Filter(showNSFWFilter)
|
||||
.Filter(gameFilter)
|
||||
.Filter(minSizeFilter)
|
||||
.Filter(maxSizeFilter)
|
||||
.Sort(searchSorter)
|
||||
.TreatMovesAsRemoveAdd()
|
||||
.Bind(out _filteredModLists)
|
||||
@ -196,7 +222,16 @@ namespace Wabbajack
|
||||
var nextEntry = GameTypeEntries.FirstOrDefault(gte => previousGameType == gte.GameIdentifier);
|
||||
SelectedGameTypeEntry = nextEntry != default ? nextEntry : GameTypeEntries.FirstOrDefault(gte => GameType == ALL_GAME_IDENTIFIER);
|
||||
}
|
||||
/*
|
||||
if (!_filteringOnMinSize)
|
||||
MinSizeModlist = ModLists.MinBy(ml => ml.Metadata.DownloadMetadata.TotalSize);
|
||||
if(!_filteringOnMaxSize)
|
||||
MaxSizeModlist = ModLists.MaxBy(ml => ml.Metadata.DownloadMetadata.TotalSize);
|
||||
*/
|
||||
|
||||
_filteringOnGame = false;
|
||||
_filteringOnMinSize = false;
|
||||
_filteringOnMaxSize = false;
|
||||
})
|
||||
.DisposeWith(disposables);
|
||||
});
|
||||
@ -255,6 +290,8 @@ namespace Wabbajack
|
||||
e.AddOrUpdate(modLists.Select(m =>
|
||||
new ModListMetadataVM(_logger, this, m, _maintainer, _wjClient, _cancellationToken)));
|
||||
});
|
||||
MinSizeModlist = _modLists.Items.Any() ? _modLists.Items.MinBy(ml => ml.Metadata.DownloadMetadata.TotalSize) : null;
|
||||
MaxSizeModlist = _modLists.Items.Any() ? _modLists.Items.MaxBy(ml => ml.Metadata.DownloadMetadata.TotalSize) : null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -132,9 +132,7 @@ namespace Wabbajack
|
||||
|
||||
DownloadSizeText = "Download size : " + UIUtils.FormatBytes(Metadata.DownloadMetadata.SizeOfArchives);
|
||||
InstallSizeText = "Installation size : " + UIUtils.FormatBytes(Metadata.DownloadMetadata.SizeOfInstalledFiles);
|
||||
TotalSizeRequirementText = "Total size requirement: " + UIUtils.FormatBytes(
|
||||
Metadata.DownloadMetadata.SizeOfArchives + Metadata.DownloadMetadata.SizeOfInstalledFiles
|
||||
);
|
||||
TotalSizeRequirementText = "Total size requirement: " + UIUtils.FormatBytes( Metadata.DownloadMetadata.TotalSize );
|
||||
VersionText = "Modlist version : " + Metadata.Version;
|
||||
ImageContainsTitle = Metadata.ImageContainsTitle;
|
||||
DisplayVersionOnlyInInstallerView = Metadata.DisplayVersionOnlyInInstallerView;
|
||||
@ -181,8 +179,9 @@ namespace Wabbajack
|
||||
})
|
||||
.ToGuiProperty(this, nameof(Exists));
|
||||
|
||||
var imageObs = Observable.Return(Metadata.ValidationSummary.SmallImage.ToString())
|
||||
.DownloadBitmapImage((ex) => _logger.LogError("Error downloading modlist image {Title} from {ImageUri}: {Exception}", Metadata.Title, Metadata.ValidationSummary.SmallImage, ex.Message), LoadingImageLock);
|
||||
var modlistImageSource = Metadata.ValidationSummary?.SmallImage?.ToString() ?? Metadata.Links.ImageUri;
|
||||
var imageObs = Observable.Return(modlistImageSource)
|
||||
.DownloadBitmapImage((ex) => _logger.LogError("Error downloading modlist image {Title} from {ImageUri}: {Exception}", Metadata.Title, modlistImageSource, ex.Message), LoadingImageLock);
|
||||
|
||||
_Image = imageObs
|
||||
.ToGuiProperty(this, nameof(Image));
|
||||
|
@ -114,7 +114,7 @@ namespace Wabbajack
|
||||
|
||||
_resourceMonitor.Updates
|
||||
.Select(r => string.Join(", ", r.Where(r => r.Throughput > 0)
|
||||
.Select(s => $"{s.Name} - {s.Throughput.ToFileSizeString()}/sec")))
|
||||
.Select(s => $"{s.Name} - {s.Throughput.ToFileSizeString()}/s")))
|
||||
.BindToStrict(this, view => view.ResourceStatus);
|
||||
|
||||
|
||||
|
@ -86,6 +86,7 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
@ -136,7 +137,7 @@
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<Grid Grid.Row="2" Margin="0, 10, 0, 0">
|
||||
<Grid Grid.Row="2" Margin="0, 25, 0, 0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
@ -188,6 +189,16 @@
|
||||
<TextBlock Grid.Column="1" Margin="3, 0, 0, 0" Text="Show only modlists for installed games" FontSize="14" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="5" Margin="0, 25, 0, 0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock FontSize="14" Text="Modlist size"/>
|
||||
<mahapps:RangeSlider Margin="0, 10, 0, 0" x:Name="SizeSliderFilter" Grid.Row="1" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="1" />
|
||||
</Grid>
|
||||
|
||||
|
||||
<Button
|
||||
x:Name="ClearFiltersButton"
|
||||
Grid.Row="6"
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
@ -22,6 +23,19 @@ namespace Wabbajack
|
||||
this.WhenAny(x => x.ViewModel.ModLists)
|
||||
.BindToStrict(this, x => x.ModListGalleryControl.ItemsSource)
|
||||
.DisposeWith(dispose);
|
||||
|
||||
this.WhenAny(x => x.ViewModel.MinSizeModlist)
|
||||
.Where(x => x != null)
|
||||
.Select(modlist => Math.Round(modlist.Metadata.DownloadMetadata.TotalSize / Math.Pow(1024, 3), 1))
|
||||
.BindToStrict(this, x => x.SizeSliderFilter.Minimum)
|
||||
.DisposeWith(dispose);
|
||||
|
||||
this.WhenAny(x => x.ViewModel.MaxSizeModlist)
|
||||
.Where(x => x != null)
|
||||
.Select(modlist => Math.Round(modlist.Metadata.DownloadMetadata.TotalSize / Math.Pow(1024, 3), 1))
|
||||
.BindToStrict(this, x => x.SizeSliderFilter.Maximum)
|
||||
.DisposeWith(dispose);
|
||||
|
||||
|
||||
this.WhenAny(x => x.ViewModel.LoadingLock.IsLoading)
|
||||
.Select(x => x ? Visibility.Visible : Visibility.Collapsed)
|
||||
@ -61,6 +75,10 @@ namespace Wabbajack
|
||||
.DisposeWith(dispose);
|
||||
this.BindStrict(ViewModel, vm => vm.ShowUnofficialLists, x => x.ShowUnofficialLists.IsChecked)
|
||||
.DisposeWith(dispose);
|
||||
this.BindStrict(ViewModel, vm => vm.MinSizeFilter, x => x.SizeSliderFilter.LowerValue)
|
||||
.DisposeWith(dispose);
|
||||
this.BindStrict(ViewModel, vm => vm.MaxSizeFilter, x => x.SizeSliderFilter.UpperValue)
|
||||
.DisposeWith(dispose);
|
||||
|
||||
this.WhenAny(x => x.ViewModel.ClearFiltersCommand)
|
||||
.BindToStrict(this, x => x.ClearFiltersButton.Command)
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Wabbajack.Hashing.xxHash64;
|
||||
|
||||
namespace Wabbajack.DTOs;
|
||||
@ -10,4 +11,6 @@ public class DownloadMetadata
|
||||
public long SizeOfArchives { get; set; }
|
||||
public long NumberOfInstalledFiles { get; set; }
|
||||
public long SizeOfInstalledFiles { get; set; }
|
||||
|
||||
public long TotalSize => SizeOfArchives + SizeOfInstalledFiles;
|
||||
}
|
Loading…
Reference in New Issue
Block a user