Port ModVM, GameVM, etc

This commit is contained in:
Timothy Baldridge 2021-12-26 22:18:52 -07:00
parent 475e44c895
commit 761b5195fb
8 changed files with 28 additions and 21 deletions

View File

@ -10,7 +10,7 @@ namespace Wabbajack
public GameVM(Game game)
{
Game = game;
DisplayName = game.ToDescriptionString();
DisplayName = game.MetaData().HumanFriendlyGameName;
}
}
}

View File

@ -1,23 +1,18 @@
using DynamicData;
using DynamicData.Binding;
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using Alphaleonis.Win32.Filesystem;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.Interventions;
using Wabbajack.Paths;
using Wabbajack.View_Models;
namespace Wabbajack
{

View File

@ -3,12 +3,13 @@ using System.Collections.ObjectModel;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text.RegularExpressions;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Lib;
using DynamicData;
using DynamicData.Binding;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.DTOs;
namespace Wabbajack
namespace Wabbajack.View_Models
{
public class ModListContentsVM : BackNavigatingVM
{

View File

@ -2,14 +2,15 @@
using System;
using System.Reactive.Linq;
using System.Windows.Media.Imaging;
using Wabbajack.Common;
using Microsoft.Extensions.Logging;
using Wabbajack.DTOs.DownloadStates;
using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders;
namespace Wabbajack
{
public class ModVM : ViewModel
{
private readonly ILogger<ModVM> _logger;
public IMetaState State { get; }
// Image isn't exposed as a direct property, but as an observable.
@ -17,13 +18,14 @@ namespace Wabbajack
// and the cached image will automatically be released when the last interested party is gone.
public IObservable<BitmapImage> ImageObservable { get; }
public ModVM(IMetaState state)
public ModVM(ILogger<ModVM> logger, IMetaState state)
{
_logger = logger;
State = state;
ImageObservable = Observable.Return(State.ImageURL.ToString())
ImageObservable = Observable.Return(State.ImageURL?.ToString())
.ObserveOn(RxApp.TaskpoolScheduler)
.DownloadBitmapImage((ex) => Utils.Log($"Skipping slide for mod {State.Name}"))
.DownloadBitmapImage(ex => _logger.LogError(ex, "Skipping slide for mod {Name}", State.Name))
.Replay(1)
.RefCount(TimeSpan.FromMilliseconds(5000));
}

View File

@ -8,6 +8,7 @@ using System.Reactive.Linq;
using System.Windows.Input;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Paths.IO;
namespace Wabbajack
{
@ -27,9 +28,9 @@ namespace Wabbajack
execute: () =>
{
var path = mainVM.Settings.Installer.LastInstalledListLocation;
if (path == default || !path.Exists)
if (path == default || !path.FileExists())
{
path = UIUtils.OpenFileDialog($"*{Consts.ModListExtension}|*{Consts.ModListExtension}");
path = UIUtils.OpenFileDialog($"*{Ext.Wabbajack}|*{Ext.Wabbajack}");
}
_mainVM.OpenInstaller(path);
});

View File

@ -7,6 +7,7 @@
xmlns:local="clr-namespace:Wabbajack"
xmlns:mahapps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Wabbajack.View_Models"
Title="Wabbajack"
Width="1280"
Height="960"
@ -40,7 +41,7 @@
<DataTemplate DataType="{x:Type local:SettingsVM}">
<local:SettingsView ViewModel="{Binding}" />
</DataTemplate>
<DataTemplate DataType="{x:Type local:ModListContentsVM}">
<DataTemplate DataType="{x:Type viewModels:ModListContentsVM}">
<local:ModListContentsView ViewModel="{Binding}" />
</DataTemplate>
</ContentPresenter.Resources>

View File

@ -7,7 +7,8 @@
xmlns:local="clr-namespace:Wabbajack"
xmlns:rxui="http://reactiveui.net"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
x:TypeArguments="local:ModListContentsVM"
xmlns:viewModels="clr-namespace:Wabbajack.View_Models"
x:TypeArguments="viewModels:ModListContentsVM"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>

View File

@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
@ -18,4 +19,9 @@ public static class StringExtensions
return sha.Hash!.ToHex();
}
public static bool ContainsCaseInsensitive(this string src, string contains)
{
return src.Contains(contains, StringComparison.InvariantCultureIgnoreCase);
}
}