Merge pull request #110 from wabbajack-tools/modlist-selection-ui

Modlist selection ui
This commit is contained in:
Timothy Baldridge 2019-10-22 18:17:48 -06:00 committed by GitHub
commit 3d5d2e0da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 314 additions and 16 deletions

View File

@ -13,6 +13,9 @@ namespace Wabbajack.Common
public static string GameFolderFilesDir = "Game Folder Files";
public static string LOOTFolderFilesDir = "LOOT Config Files";
public static string BSACreationDir = "TEMP_BSA_FILES";
public static string ModListDownloadFolder = "downloaded_mod_lists";
public static string MegaPrefix = "https://mega.nz/#!";
public static HashSet<string> SupportedArchives = new HashSet<string> {".zip", ".rar", ".7z", ".7zip", ".fomod", ".omod"};
@ -43,7 +46,6 @@ namespace Wabbajack.Common
public static string AppName = "Wabbajack";
public static string HashCacheName = "Wabbajack.hash_cache";
public static HashSet<string> GameESMs = new HashSet<string>
{
@ -67,7 +69,7 @@ namespace Wabbajack.Common
public static string ModPermissionsURL = "https://raw.githubusercontent.com/wabbajack-tools/opt-out-lists/master/NexusModPermissions.yml";
public static string ServerWhitelistURL = "https://raw.githubusercontent.com/wabbajack-tools/opt-out-lists/master/ServerWhitelist.yml";
public static string ModlistMetadataURL = "https://raw.githubusercontent.com/wabbajack-tools/wabbajack-tools.github.io/code/src/assets/states/modlistState.json";
public static string ModlistMetadataURL = "https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/modlists.json";
public static string UserAgent
{

View File

@ -76,7 +76,10 @@ namespace Wabbajack.Common
public static void Status(string msg, int progress = 0)
{
_statusFn?.Invoke(msg, progress);
if (WorkQueue.CustomReportFn != null)
WorkQueue.CustomReportFn(progress, msg);
else
_statusFn?.Invoke(msg, progress);
}

View File

@ -15,6 +15,8 @@ namespace Wabbajack.Common
[ThreadStatic] internal static bool WorkerThread;
[ThreadStatic] public static Action<int, string> CustomReportFn;
public static int MaxQueueSize;
public static int CurrentQueueSize;
private static bool _inited;
@ -64,7 +66,10 @@ namespace Wabbajack.Common
public static void Report(string msg, int progress)
{
ReportFunction(CpuId, msg, progress);
if (CustomReportFn != null)
CustomReportFn(progress, msg);
else
ReportFunction(CpuId, msg, progress);
}
public static void QueueTask(Action a)

View File

@ -59,7 +59,7 @@ namespace Wabbajack.Lib.Downloaders
var regex = new Regex("(?<=/uc\\?export=download&amp;confirm=).*(?=;id=)");
var confirm = regex.Match(result);
var url = $"https://drive.google.com/uc?export=download&confirm={confirm}&id={Id}";
var http_state = new HTTPDownloader.State {Url = url};
var http_state = new HTTPDownloader.State {Url = url, Client = client};
return http_state;
}

View File

@ -55,6 +55,9 @@ namespace Wabbajack.Lib.Downloaders
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<string> Headers { get; set; }
[JsonIgnore]
public HttpClient Client { get; set; }
public override bool IsWhitelisted(ServerWhitelist whitelist)
{
return whitelist.AllowedPrefixes.Any(p => Url.StartsWith(p));
@ -67,7 +70,7 @@ namespace Wabbajack.Lib.Downloaders
public bool DoDownload(Archive a, string destination, bool download)
{
var client = new HttpClient();
var client = Client ?? new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", Consts.UserAgent);
if (Headers != null)

View File

@ -83,7 +83,6 @@ namespace Wabbajack.Lib
{
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
using (var ms = new MemoryStream())
{
var entry = ar.GetEntry("modlist.json");
using (var e = entry.Open())

View File

@ -28,7 +28,7 @@ namespace Wabbajack.Test
{
var logo_state = DownloadDispatcher.ResolveArchive(modlist.ImageUri);
Assert.IsNotNull(logo_state);
Assert.IsTrue(logo_state.Verify(), $"{modlist.ImageUri} is not valid");
//Assert.IsTrue(logo_state.Verify(), $"{modlist.ImageUri} is not valid");
//modlist.LoadLogo();
//Assert.IsNotNull(modlist.Logo);

View File

@ -0,0 +1,22 @@
<Window x:Class="Wabbajack.UI.DownloadWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wabbajack.UI"
Style="{StaticResource {x:Type Window}}" Icon="Icons/wabbajack.ico" WindowStyle="ToolWindow"
mc:Ignorable="d"
Title="Downloading Modlist" Height="200" Width="800">
<StackPanel Margin="20">
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="30" Margin="0, 10">Downloading:</TextBlock>
<TextBlock FontSize="30" Margin="10, 10" Text="{Binding DownloadName}"></TextBlock>
</StackPanel>
<ProgressBar Margin="0, 10" Minimum="0" Maximum="100" Height="20" Value="{Binding DownloadProgress}"></ProgressBar>
<StackPanel HorizontalAlignment="Right">
<Button>
<TextBlock TextAlignment="Center" FontSize="20" Width="100">Cancel</TextBlock>
</Button>
</StackPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders;
namespace Wabbajack.UI
{
/// <summary>
/// Interaction logic for DownloadWindow.xaml
/// </summary>
public partial class DownloadWindow : Window
{
public enum WindowResult
{
Undefined,
Completed,
Canceled
}
public WindowResult Result { get; internal set; } = WindowResult.Undefined;
public DownloadWindow(string url, string name, string destination)
{
InitializeComponent();
DataContext = new DownloadWindowViewModel(this, url, name, destination);
}
}
public class DownloadWindowViewModel : ViewModel
{
private readonly string _destination;
private readonly DownloadWindow _parent;
public DownloadWindowViewModel(DownloadWindow parent, string url, string name, string destination)
{
_parent = parent;
_url = url;
_downloadName = name;
_destination = destination;
Start();
}
private void Start()
{
_downloadThread = new Thread(() =>
{
WorkQueue.CustomReportFn = (progress, msg) => { DownloadProgress = progress; };
var state = DownloadDispatcher.ResolveArchive(_url);
state.Download(new Archive {Name = _downloadName}, _destination);
_destination.FileSHA256();
_parent.Result = DownloadWindow.WindowResult.Completed;
_parent.Dispatcher.Invoke(() => _parent.Close());
});
_downloadThread.Start();
}
public void Cancel()
{
if (_downloadThread != null && _downloadThread.IsAlive)
{
_downloadThread.Abort();
}
File.Delete(_destination);
_parent.Result = DownloadWindow.WindowResult.Canceled;
}
private int _downloadProgress;
public int DownloadProgress
{
get => _downloadProgress;
set => RaiseAndSetIfChanged(ref _downloadProgress, value);
}
private string _url;
public string Url
{
get => _url;
set => RaiseAndSetIfChanged(ref _url, value);
}
private string _downloadName;
private Thread _downloadThread;
public string DownloadName
{
get => _downloadName;
set => RaiseAndSetIfChanged(ref _downloadName, value);
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.UI
{
public class ModListDefinition : ViewModel
{
private readonly ModlistMetadata _meta;
public ModListDefinition(ModlistMetadata meta)
{
_meta = meta;
}
}
}

View File

@ -6,7 +6,7 @@
Style="{StaticResource {x:Type Window}}" Icon="Icons/wabbajack.ico" WindowStyle="ToolWindow"
xmlns:local="clr-namespace:Wabbajack"
mc:Ignorable="d"
Title="Wabbajack" Height="500" Width="800" ResizeMode="NoResize"
Title="Wabbajack" Height="800" Width="1024" ResizeMode="CanResize"
Closing="Close_Window">
<Grid Margin="20">
<Grid.ColumnDefinitions>
@ -16,18 +16,52 @@
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="150"/>
<RowDefinition Height="*"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
</Grid.RowDefinitions>
<Image MouseLeftButtonDown="GitHub_MouseLeftButtonDown" Margin="5,0,0,0" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Name="GitHub"/>
<Image MouseLeftButtonDown="Patreon_MouseLeftButtonDown" Margin="5,0,0,0" Grid.Row="0" Grid.Column="1" Name="Patreon"/>
<Image MouseLeftButtonDown="Discord_MouseLeftButtonDown" Margin="5,0,0,0" Grid.Row="0" Grid.Column="2" Name="Discord"/>
<Image Grid.Row="1" Grid.ColumnSpan="3" Name="Banner" Stretch="Uniform" Margin="2,0,2,0"/>
<Button Name="InstallModlist" Grid.ColumnSpan="3" Grid.Row="2" Margin="2" Click="InstallModlist_Click">
<TextBlock FontSize="40">Install a ModList</TextBlock>
<ListBox ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Row="2" Grid.ColumnSpan="3"
ItemsSource="{Binding ModLists}" SelectedItem="{Binding Path=SelectedModList, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="15"></RowDefinition>
<RowDefinition Height="150"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="{Binding Links.ImageUri}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="4"></Image>
<TextBlock Text="{Binding Title}" FontSize="20" Grid.Column="2" Grid.Row="0"></TextBlock>
<TextBlock Text="{Binding Author}" Grid.Column="2" Grid.Row="1"></TextBlock>
<TextBlock Text="{Binding Game}" HorizontalAlignment="Right" TextAlignment="Right" Grid.Column="4" Grid.Row="1"></TextBlock>
<TextBlock Text="{Binding Description}" VerticalAlignment="Top" HorizontalAlignment="Left" TextWrapping="Wrap" Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="3"></TextBlock>
<Button Grid.Row="3" Grid.Column="2">More Info</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Name="InstallModlist" Grid.ColumnSpan="3" Grid.Row="3" Margin="2" Click="InstallModlist_Click" IsEnabled="{Binding CanInstall}">
<TextBlock FontSize="40">Download and Install</TextBlock>
</Button>
<Button Name="CreateModlist" Grid.ColumnSpan="3" Grid.Row="3" Margin="2" Click="CreateModlist_Click">
<Button Name="InstallFromList" Grid.ColumnSpan="3" Grid.Row="4" Margin="2" Click="InstallFromList_Click">
<TextBlock FontSize="40">Install from Disk</TextBlock>
</Button>
<Button Name="CreateModlist" Grid.ColumnSpan="3" Grid.Row="5" Margin="2" Click="CreateModlist_Click">
<TextBlock FontSize="40">Create a ModList</TextBlock>
</Button>
</Grid>

View File

@ -1,9 +1,12 @@
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
using Wabbajack.UI;
using static Wabbajack.MainWindow;
namespace Wabbajack
@ -13,6 +16,8 @@ namespace Wabbajack
/// </summary>
public partial class ModeSelectionWindow : Window
{
private List<ModlistMetadata> _lists;
public ModeSelectionWindow()
{
InitializeComponent();
@ -24,6 +29,8 @@ namespace Wabbajack
GitHub.Source = githubIcon;
var discordIcon = UIUtils.BitmapImageFromResource("Wabbajack.UI.Icons.discord.png");
Discord.Source = discordIcon;
DataContext = new ModeSelectionWindowViewModel();
}
private void CreateModlist_Click(object sender, RoutedEventArgs e)
@ -35,9 +42,15 @@ namespace Wabbajack
private void InstallModlist_Click(object sender, RoutedEventArgs e)
{
OpenMainWindow(
RunMode.Install,
UIUtils.OpenFileDialog($"Wabbajack Modlist (*{Consts.ModlistExtension})|*{Consts.ModlistExtension}"));
//OpenMainWindow(
// RunMode.Install,
// UIUtils.OpenFileDialog($"Wabbajack Modlist (*{Consts.ModlistExtension})|*{Consts.ModlistExtension}"));
var result = ((ModeSelectionWindowViewModel)DataContext).Download();
if (result != null)
{
OpenMainWindow(RunMode.Install, result);
}
}
private void OpenMainWindow(RunMode mode, string file)
@ -73,5 +86,11 @@ namespace Wabbajack
{
Process.Start("https://discord.gg/zgbrkmA");
}
private void InstallFromList_Click(object sender, RoutedEventArgs e)
{
OpenMainWindow(RunMode.Install,
UIUtils.OpenFileDialog($"*{Consts.ModlistExtension}|*{Consts.ModlistExtension}"));
}
}
}

View File

@ -0,0 +1,66 @@
using Alphaleonis.Win32.Filesystem;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.UI
{
public class ModeSelectionWindowViewModel : ViewModel
{
public ModeSelectionWindowViewModel()
{
_modLists = new ObservableCollection<ModlistMetadata>(ModlistMetadata.LoadFromGithub());
}
private ObservableCollection<ModlistMetadata> _modLists;
public ObservableCollection<ModlistMetadata> ModLists
{
get => _modLists;
}
private ModlistMetadata _selectedModList;
public ModlistMetadata SelectedModList
{
get => _selectedModList;
set
{
CanInstall = true;
RaiseAndSetIfChanged(ref _selectedModList, value);
}
}
private bool _canInstall;
public bool CanInstall
{
get => _canInstall;
set => RaiseAndSetIfChanged(ref _canInstall, value);
}
internal string Download()
{
if (!Directory.Exists(Consts.ModListDownloadFolder))
Directory.CreateDirectory(Consts.ModListDownloadFolder);
string dest = Path.Combine(Consts.ModListDownloadFolder, SelectedModList.Links.MachineURL + Consts.ModlistExtension);
var window = new DownloadWindow(SelectedModList.Links.Download, SelectedModList.Title, dest);
window.ShowDialog();
if (window.Result == DownloadWindow.WindowResult.Completed)
return dest;
return null;
}
}
}

View File

@ -227,6 +227,11 @@
<Compile Include="Converters\IsNotNullVisibilityConverter.cs" />
<Compile Include="Enums\RunMode.cs" />
<Compile Include="Extensions\ReactiveUIExt.cs" />
<Compile Include="UI\DownloadWindow.xaml.cs">
<DependentUpon>DownloadWindow.xaml</DependentUpon>
</Compile>
<Compile Include="UI\ModeSelectionWindowViewModel.cs" />
<Compile Include="UI\ModListDefinition.cs" />
<Compile Include="UI\SlideshowView.xaml.cs">
<DependentUpon>SlideshowView.xaml</DependentUpon>
</Compile>
@ -242,6 +247,10 @@
<Compile Include="UI\TextViewer.xaml.cs">
<DependentUpon>TextViewer.xaml</DependentUpon>
</Compile>
<Page Include="UI\DownloadWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\SlideshowView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>