From ab3c87975c74e448fe74f67586351a300b69f32a Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Fri, 30 Aug 2019 17:57:56 -0600 Subject: [PATCH] fixes #19 - Add installation summary --- CHANGELOG.md | 3 ++ Wabbajack.Common/Wabbajack.Common.csproj | 1 + Wabbajack/AppState.cs | 41 ++++++++++++++++++++++++ Wabbajack/Compiler.cs | 34 ++++++++++++++++++-- Wabbajack/Data.cs | 8 +++++ Wabbajack/MainWindow.xaml | 6 ++-- Wabbajack/MainWindow.xaml.cs | 2 ++ Wabbajack/NexusAPI.cs | 31 ++++++++++++++++-- Wabbajack/Wabbajack.csproj | 4 +++ Wabbajack/packages.config | 1 + 10 files changed, 123 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a109b235..f68e7d35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ #### Version 0.9 - ???? * Added log information for when modlists start parsing during installation * Check all links during mod list creation +* Generate a installation report during compilation +* Show the report after compiling +* Added a button to view the report before installing #### Version 0.8.1 - 8/29/2019 * Fixed a bug that was causing VFS temp folders not to be cleaned diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index 06ebff3c..1c16fa7d 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -85,6 +85,7 @@ + diff --git a/Wabbajack/AppState.cs b/Wabbajack/AppState.cs index a16f0d7e..7dfb60d4 100644 --- a/Wabbajack/AppState.cs +++ b/Wabbajack/AppState.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; @@ -106,6 +107,20 @@ namespace Wabbajack } } + private string _htmlReport; + public Visibility ShowReportButton => _htmlReport == null ? Visibility.Collapsed : Visibility.Visible; + + public string HTMLReport + { + get { return _htmlReport; } + set + { + _htmlReport = value; + OnPropertyChanged("HTMLReport"); + OnPropertyChanged("ShowReportButton"); + } + } + private int _queueProgress; public int QueueProgress { @@ -179,6 +194,7 @@ namespace Wabbajack _modList = modlist.FromJSONString(); Mode = "Installing"; ModListName = _modList.Name; + HTMLReport = _modList.ReportHTML; Location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } @@ -280,6 +296,27 @@ namespace Wabbajack } } + private ICommand _showReportCommand; + public ICommand ShowReportCommand + { + get + { + if (_showReportCommand == null) + { + _showReportCommand = new LambdaCommand(() => true, () => this.ShowReport()); + } + return _showReportCommand; + } + } + + private void ShowReport() + { + var file = Path.GetTempFileName() + ".html"; + File.WriteAllText(file, HTMLReport); + Process.Start(file); + } + + private void ExecuteBegin() { if (Mode == "Installing") @@ -313,6 +350,10 @@ namespace Wabbajack try { compiler.Compile(); + if (compiler.ModList != null && compiler.ModList.ReportHTML != null) + { + HTMLReport = compiler.ModList.ReportHTML; + } } catch (Exception ex) { diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index e2e148c2..c0a27375 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -3,13 +3,16 @@ using Newtonsoft.Json; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; +using System.Net; using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Web; +using CommonMark; using Wabbajack.Common; using static Wabbajack.NexusAPI; using VFS; @@ -252,12 +255,32 @@ namespace Wabbajack Name = MO2Profile }; + GenerateReport(); PatchExecutable(); - + ResetMembers(); + ShowReport(); + Info("Done Building Modpack"); } + private void ShowReport() + { + var file = Path.GetTempFileName() + ".html"; + File.WriteAllText(file, ModList.ReportHTML); + Process.Start(file); + } + + private void GenerateReport() + { + using (var fs = File.OpenWrite($"{ModList.Name}.md")) + { + fs.SetLength(0); + using (var reporter = new ReportBuilder(fs)) + reporter.Build(ModList); + } + ModList.ReportHTML = CommonMarkConverter.Convert(File.ReadAllText($"{ModList.Name}.md")); + } /// /// Clear references to lists that hold a lot of data. @@ -436,13 +459,18 @@ namespace Wabbajack } else if (general.modID != null && general.fileID != null && general.gameName != null) { - result = new NexusMod() + var nm = new NexusMod() { GameName = general.gameName, FileID = general.fileID, ModID = general.modID, Version = general.version ?? "0.0.0.0" }; + var info = NexusAPI.GetModInfo(nm, NexusKey); + nm.Author = info.author; + nm.UploadedBy = info.uploaded_by; + nm.UploaderProfile = info.uploaded_users_profile_url; + result = nm; } else { @@ -552,7 +580,7 @@ namespace Wabbajack Status($"Generating patch of {filename}"); using (var ms = new MemoryStream()) { - BSDiff.Create(File.ReadAllBytes(game_file), File.ReadAllBytes(source.AbsolutePath), ms); + //BSDiff.Create(File.ReadAllBytes(game_file), File.ReadAllBytes(source.AbsolutePath), ms); result.SourceData = ms.ToArray().ToBase64(); } Info($"Generated a {result.SourceData.Length} byte patch for {filename}"); diff --git a/Wabbajack/Data.cs b/Wabbajack/Data.cs index 39d96fef..c4349350 100644 --- a/Wabbajack/Data.cs +++ b/Wabbajack/Data.cs @@ -68,6 +68,11 @@ namespace Wabbajack /// Archives required by this modlist /// public List Archives; + + /// + /// Content Report in HTML form + /// + public string ReportHTML; } public class Directive @@ -175,6 +180,9 @@ namespace Wabbajack public string ModID; public string FileID; public string Version; + public string UploaderProfile; + public string UploadedBy; + public string Author; } public class GoogleDriveMod : Archive diff --git a/Wabbajack/MainWindow.xaml b/Wabbajack/MainWindow.xaml index 982f9966..599cb6de 100644 --- a/Wabbajack/MainWindow.xaml +++ b/Wabbajack/MainWindow.xaml @@ -17,6 +17,7 @@ + @@ -68,7 +69,8 @@ - - + + + diff --git a/Wabbajack/MainWindow.xaml.cs b/Wabbajack/MainWindow.xaml.cs index 566d91f0..4fa1bd7b 100644 --- a/Wabbajack/MainWindow.xaml.cs +++ b/Wabbajack/MainWindow.xaml.cs @@ -79,10 +79,12 @@ namespace Wabbajack var modlist = Installer.CheckForModPack(); if (modlist == null) { + Utils.Log("No Modlist found, running in Compiler mode."); } else { context.ConfigureForInstall(modlist); + } }).Start(); diff --git a/Wabbajack/NexusAPI.cs b/Wabbajack/NexusAPI.cs index 916df916..de4639a0 100644 --- a/Wabbajack/NexusAPI.cs +++ b/Wabbajack/NexusAPI.cs @@ -99,12 +99,11 @@ namespace Wabbajack return true; } - private static string ConvertGameName(string gameName) + public static string ConvertGameName(string gameName) { if (gameName == "SkyrimSE") return "skyrimspecialedition"; if (gameName == "FalloutNV") return "newvegas"; - return gameName; - + return gameName.ToLower(); } @@ -162,6 +161,32 @@ namespace Wabbajack } } + public class ModInfo + { + public string author; + public string uploaded_by; + public string uploaded_users_profile_url; + } + + public static ModInfo GetModInfo(NexusMod archive, string apikey) + { + string path = Path.Combine(Consts.NexusCacheDirectory, $"mod-info-{archive.GameName}-{archive.ModID}.json"); + if (File.Exists(path)) + return path.FromJSON(); + + + var url = $"https://api.nexusmods.com/v1/games/{ConvertGameName(archive.GameName)}/mods/{archive.ModID}.json"; + var client = BaseNexusClient(apikey); + + using (var s = client.GetStreamSync(url)) + { + var result = s.FromJSON(); + result.ToJSON(path); + return result; + } + } + + public static EndorsementResponse EndorseMod(NexusMod mod, string apikey) { Utils.Status($"Endorsing ${mod.GameName} - ${mod.ModID}"); diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index a2a88031..df5af4e4 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -96,6 +96,9 @@ true + + ..\packages\CommonMark.NET.0.15.1\lib\net45\CommonMark.dll + ..\packages\Costura.Fody.4.0.0\lib\net40\Costura.dll @@ -141,6 +144,7 @@ + diff --git a/Wabbajack/packages.config b/Wabbajack/packages.config index ca6470ce..da413300 100644 --- a/Wabbajack/packages.config +++ b/Wabbajack/packages.config @@ -1,5 +1,6 @@  +