Readme opens after install, and after modlist download

This commit is contained in:
Justin Swanson 2019-12-19 23:09:53 -06:00
parent a4a149d01c
commit 74bbb5a4ec
3 changed files with 59 additions and 35 deletions

View File

@ -263,7 +263,7 @@ namespace Wabbajack
// Define commands
ShowReportCommand = ReactiveCommand.Create(ShowReport);
OpenReadmeCommand = ReactiveCommand.Create(
execute: OpenReadmeWindow,
execute: () => this.ModList?.OpenReadmeWindow(),
canExecute: this.WhenAny(x => x.ModList)
.Select(modList => !string.IsNullOrEmpty(modList?.Readme))
.ObserveOnGuiThread());
@ -316,6 +316,14 @@ namespace Wabbajack
{
await this.Installer.Install();
Completed = ErrorResponse.Success;
try
{
this.ModList?.OpenReadmeWindow();
}
catch (Exception ex)
{
Utils.Error(ex);
}
}
catch (Exception ex)
{
@ -377,31 +385,5 @@ namespace Wabbajack
File.WriteAllText(file, HTMLReport);
Process.Start(file);
}
private void OpenReadmeWindow()
{
if (string.IsNullOrEmpty(ModList.Readme)) return;
using (var fs = new FileStream(ModListLocation.TargetPath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
using (var ms = new MemoryStream())
{
var entry = ar.GetEntry(ModList.Readme);
if (entry == null)
{
Utils.Log($"Tried to open a non-existant readme: {ModList.Readme}");
return;
}
using (var e = entry.Open())
{
e.CopyTo(ms);
}
ms.Seek(0, SeekOrigin.Begin);
using (var reader = new StreamReader(ms))
{
var viewer = new TextViewer(reader.ReadToEnd(), ModList.Name);
viewer.Show();
}
}
}
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -44,7 +44,7 @@ namespace Wabbajack
Metadata = metadata;
IsBroken = metadata.ValidationSummary.HasFailures;
OpenWebsiteCommand = ReactiveCommand.Create(() => Process.Start($"https://www.wabbajack.org/modlist/{Metadata.Links.MachineURL}"));
ExecuteCommand = ReactiveCommand.CreateFromObservable<Unit, bool>(
ExecuteCommand = ReactiveCommand.CreateFromObservable<Unit, Unit>(
canExecute: this.WhenAny(x => x.IsBroken).Select(x => !x),
execute: (unit) =>
Observable.Return(unit)
@ -63,15 +63,31 @@ namespace Wabbajack
}
return exists;
})
.Where(exists => exists)
// Do any install page swap over on GUI thread
.ObserveOnGuiThread()
.Do(exists =>
.Select(_ =>
{
if (exists)
{
_parent.MWVM.OpenInstaller(Path.GetFullPath(Location));
}
}));
_parent.MWVM.OpenInstaller(Path.GetFullPath(Location));
// Wait for modlist member to be filled, then open its readme
return _parent.MWVM.Installer.Value.WhenAny(x => x.ModList)
.NotNull()
.Take(1)
.Do(modList =>
{
try
{
modList.OpenReadmeWindow();
}
catch (Exception ex)
{
Utils.Error(ex);
}
});
})
.Switch()
.Unit());
_Exists = Observable.Interval(TimeSpan.FromSeconds(0.5))
.Unit()

View File

@ -82,5 +82,31 @@ namespace Wabbajack
.Replay(1)
.RefCount();
}
public void OpenReadmeWindow()
{
if (string.IsNullOrEmpty(Readme)) return;
using (var fs = new FileStream(ModListPath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
using (var ms = new MemoryStream())
{
var entry = ar.GetEntry(Readme);
if (entry == null)
{
Utils.Log($"Tried to open a non-existant readme: {Readme}");
return;
}
using (var e = entry.Open())
{
e.CopyTo(ms);
}
ms.Seek(0, SeekOrigin.Begin);
using (var reader = new StreamReader(ms))
{
var viewer = new TextViewer(reader.ReadToEnd(), Name);
viewer.Show();
}
}
}
}
}