Merge pull request #230 from Noggog/modlist-image-fix

Modlist image and readme embedded in .wabbajack and displayable
This commit is contained in:
Timothy Baldridge 2019-12-03 21:41:31 -07:00 committed by GitHub
commit 38536a2061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 8 deletions

View File

@ -81,6 +81,17 @@ namespace Wabbajack.Lib
{
Utils.Log($"Exporting ModList to : {ModListOutputFile}");
// Modify readme and modlist image to relative paths if they exist
if (File.Exists(ModListImage))
{
ModList.Image = "modlist-image.png";
}
if (File.Exists(ModListReadme))
{
var readme = new FileInfo(ModListReadme);
ModList.Readme = $"readme{readme.Extension}";
}
//ModList.ToJSON(Path.Combine(ModListOutputFolder, "modlist.json"));
ModList.ToCERAS(Path.Combine(ModListOutputFolder, "modlist"), ref CerasConfig.Config);
@ -102,6 +113,28 @@ namespace Wabbajack.Lib
ins.CopyTo(os);
}
});
// Copy in modimage
if (File.Exists(ModListImage))
{
var ze = za.CreateEntry(ModList.Image);
using (var os = ze.Open())
using (var ins = File.OpenRead(ModListImage))
{
ins.CopyTo(os);
}
}
// Copy in readme
if (File.Exists(ModListReadme))
{
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;
@ -17,7 +18,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;
@ -40,20 +40,18 @@ namespace Wabbajack
Error = ex;
}
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(ImageURL)) return default(MemoryStream);
if (ImageURL.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(ImageURL);
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"