From b74c8bf54491eedb6d4bdf5e4daa2e6f9564afd2 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Mon, 2 Dec 2019 22:56:06 -0600 Subject: [PATCH] Modlist image and readme embedded in .wabbajack and displayable --- Wabbajack.Lib/ACompiler.cs | 34 +++++++++++++++++++ .../Compilers/ModlistSettingsEditorVM.cs | 4 +++ Wabbajack/View Models/ModListVM.cs | 12 +++---- Wabbajack/Views/Compilers/CompilerView.xaml | 2 +- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/Wabbajack.Lib/ACompiler.cs b/Wabbajack.Lib/ACompiler.cs index 95cd7f4d..0a98eb24 100644 --- a/Wabbajack.Lib/ACompiler.cs +++ b/Wabbajack.Lib/ACompiler.cs @@ -81,6 +81,18 @@ namespace Wabbajack.Lib { Utils.Log($"Exporting ModList to : {ModListOutputFile}"); + // Modify readme and modlist image to relative paths if they exist + var modlistImage = new FileInfo(ModListImage); + var readme = new FileInfo(ModListReadme); + if (modlistImage.Exists) + { + ModList.Image = "modlist-image.png"; + } + if (readme.Exists) + { + ModList.Readme = $"readme{readme.Extension}"; + } + //ModList.ToJSON(Path.Combine(ModListOutputFolder, "modlist.json")); ModList.ToCERAS(Path.Combine(ModListOutputFolder, "modlist"), ref CerasConfig.Config); @@ -102,6 +114,28 @@ namespace Wabbajack.Lib ins.CopyTo(os); } }); + + // Copy in modimage + if (modlistImage.Exists) + { + var ze = za.CreateEntry(ModList.Image); + using (var os = ze.Open()) + using (var ins = File.OpenRead(ModListImage)) + { + ins.CopyTo(os); + } + } + + // Copy in readme + if (readme.Exists) + { + var ze = za.CreateEntry(ModList.Readme); + using (var os = ze.Open()) + using (var ins = File.OpenRead(ModListReadme)) + { + ins.CopyTo(os); + } + } } } diff --git a/Wabbajack/View Models/Compilers/ModlistSettingsEditorVM.cs b/Wabbajack/View Models/Compilers/ModlistSettingsEditorVM.cs index 7747bbe8..b7cc89bc 100644 --- a/Wabbajack/View Models/Compilers/ModlistSettingsEditorVM.cs +++ b/Wabbajack/View Models/Compilers/ModlistSettingsEditorVM.cs @@ -40,6 +40,10 @@ namespace Wabbajack { PathType = FilePickerVM.PathTypeOptions.File, ExistCheckOption = FilePickerVM.ExistCheckOptions.IfNotEmpty, + Filters = + { + new CommonFileDialogFilter("Text", "*.txt"), + } }; } diff --git a/Wabbajack/View Models/ModListVM.cs b/Wabbajack/View Models/ModListVM.cs index f9c01bd1..2047a267 100644 --- a/Wabbajack/View Models/ModListVM.cs +++ b/Wabbajack/View Models/ModListVM.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.IO.Compression; +using System.Reactive; using System.Reactive.Linq; using System.Windows.Media.Imaging; using Wabbajack.Common; @@ -16,7 +17,6 @@ namespace Wabbajack public string Name => SourceModList.Name; public string ReportHTML => SourceModList.ReportHTML; public string Readme => SourceModList.Readme; - public string ImageURL => SourceModList.Image; public string Author => SourceModList.Author; public string Description => SourceModList.Description; public string Website => SourceModList.Website; @@ -32,20 +32,18 @@ namespace Wabbajack ModListPath = modListPath; SourceModList = sourceModList; - ImageObservable = Observable.Return(ImageURL) + ImageObservable = Observable.Return(Unit.Default) .ObserveOn(RxApp.TaskpoolScheduler) - .Select(url => + .Select(filePath => { try { - if (!File.Exists(url)) return default(MemoryStream); - if (string.IsNullOrWhiteSpace(sourceModList.Image)) return default(MemoryStream); - if (sourceModList.Image.Length != 36) return default(MemoryStream); using (var fs = new FileStream(ModListPath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var ar = new ZipArchive(fs, ZipArchiveMode.Read)) { var ms = new MemoryStream(); - var entry = ar.GetEntry(sourceModList.Image); + var entry = ar.GetEntry("modlist-image.png"); + if (entry == null) return default(MemoryStream); using (var e = entry.Open()) { e.CopyTo(ms); diff --git a/Wabbajack/Views/Compilers/CompilerView.xaml b/Wabbajack/Views/Compilers/CompilerView.xaml index 2513966e..fef694b4 100644 --- a/Wabbajack/Views/Compilers/CompilerView.xaml +++ b/Wabbajack/Views/Compilers/CompilerView.xaml @@ -146,7 +146,7 @@ Style="{StaticResource PickerStyle}" ToolTip="Path to an image to display for the modlist." /> - +