Modlist image and readme embedded in .wabbajack and displayable

This commit is contained in:
Justin Swanson 2019-12-02 22:56:06 -06:00
parent 57c421967d
commit b74c8bf544
4 changed files with 44 additions and 8 deletions

View File

@ -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);
}
}
}
}

View File

@ -40,6 +40,10 @@ namespace Wabbajack
{
PathType = FilePickerVM.PathTypeOptions.File,
ExistCheckOption = FilePickerVM.ExistCheckOptions.IfNotEmpty,
Filters =
{
new CommonFileDialogFilter("Text", "*.txt"),
}
};
}

View File

@ -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);

View File

@ -146,7 +146,7 @@
Style="{StaticResource PickerStyle}"
ToolTip="Path to an image to display for the modlist." />
<TextBlock Margin="{StaticResource TitleMargin}" Text="Website" />
<TextBox Style="{StaticResource ValueStyle}" Text="{Binding Website}" />
<TextBox Style="{StaticResource ValueStyle}" Text="{Binding Website, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock
Margin="{StaticResource TitleMargin}"
Text="Readme Path"