From 10dfe343dfe1f7fc3b34125dd5e5198690f98690 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 17:01:59 +0200 Subject: [PATCH 1/9] Switching TextViewer from Window to mahWindow --- Wabbajack/View Models/ModListVM.cs | 38 +++++++++++++++--------------- Wabbajack/Views/TextViewer.xaml | 9 +++---- Wabbajack/Views/TextViewer.xaml.cs | 6 ++--- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Wabbajack/View Models/ModListVM.cs b/Wabbajack/View Models/ModListVM.cs index 14370c33..7a846dca 100644 --- a/Wabbajack/View Models/ModListVM.cs +++ b/Wabbajack/View Models/ModListVM.cs @@ -100,27 +100,27 @@ namespace Wabbajack } else { - 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()) + 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) { - var entry = ar.GetEntry(Readme); - if (entry == null) - { - Utils.Log($"Tried to open a non-existent 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(); - } + Utils.Log($"Tried to open a non-existent 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(); } } diff --git a/Wabbajack/Views/TextViewer.xaml b/Wabbajack/Views/TextViewer.xaml index a4954259..19c3714a 100644 --- a/Wabbajack/Views/TextViewer.xaml +++ b/Wabbajack/Views/TextViewer.xaml @@ -1,14 +1,15 @@ - @@ -17,4 +18,4 @@ FontSize="20" TextWrapping="Wrap" /> - + diff --git a/Wabbajack/Views/TextViewer.xaml.cs b/Wabbajack/Views/TextViewer.xaml.cs index 28d72054..0677212b 100644 --- a/Wabbajack/Views/TextViewer.xaml.cs +++ b/Wabbajack/Views/TextViewer.xaml.cs @@ -1,8 +1,6 @@ -using System.Windows; - -namespace Wabbajack +namespace Wabbajack { - public partial class TextViewer : Window + public partial class TextViewer { public TextViewer(string text, string title) { From 878eff002cb022298f652f920c81db4ea2d9ac5c Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 18:04:42 +0200 Subject: [PATCH 2/9] Updated zEditIntegration merges.json detection --- Wabbajack.Lib/zEditIntegration.cs | 78 +++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/Wabbajack.Lib/zEditIntegration.cs b/Wabbajack.Lib/zEditIntegration.cs index 54dedf18..ba88104c 100644 --- a/Wabbajack.Lib/zEditIntegration.cs +++ b/Wabbajack.Lib/zEditIntegration.cs @@ -1,5 +1,4 @@ using Alphaleonis.Win32.Filesystem; -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -37,26 +36,78 @@ namespace Wabbajack.Lib public class IncludeZEditPatches : ACompilationStep { - private Dictionary _mergesIndexed; + private readonly Dictionary _mergesIndexed; + + private bool _disabled = true; public IncludeZEditPatches(ACompiler compiler) : base(compiler) { var zEditPath = FindzEditPath(compiler); var havezEdit = zEditPath != null; - Utils.Log(havezEdit ? $"Found zEdit at {zEditPath}" : $"zEdit not detected, disabling zEdit routines"); + Utils.Log(havezEdit ? $"Found zEdit at {zEditPath}" : "zEdit not detected, disabling zEdit routines"); if (!havezEdit) { _mergesIndexed = new Dictionary(); return; } - - var merges = Directory.EnumerateFiles(Path.Combine(zEditPath, "profiles"), + _mo2Compiler = (MO2Compiler) compiler; + + var settingsFiles = Directory.EnumerateFiles(Path.Combine(zEditPath, "profiles"), DirectoryEnumerationOptions.Files | DirectoryEnumerationOptions.Recursive) - .Where(f => f.EndsWith("\\merges.json")) - .SelectMany(f => f.FromJSON>()) - .GroupBy(f => (f.name, f.filename)); + .Where(f => f.EndsWith("settings.json")) + .Where(f => + { + var settings = f.FromJSON(); + + if (settings.modManager != "Mod Organizer 2") + { + Utils.Log($"zEdit settings file {f}: modManager is not Mod Organizer 2 but {settings.modManager}!"); + return false; + } + + if (settings.managerPath != _mo2Compiler.MO2Folder) + { + Utils.Log($"zEdit settings file {f}: managerPath is not {_mo2Compiler.MO2Folder} but {settings.managerPath}!"); + return false; + } + + if (settings.modsPath != Path.Combine(_mo2Compiler.MO2Folder, "mods")) + { + Utils.Log($"zEdit settings file {f}: modsPath is not {_mo2Compiler.MO2Folder}\\mods but {settings.modsPath}!"); + return false; + } + + if (settings.mergePath != Path.Combine(_mo2Compiler.MO2Folder, "mods")) + { + Utils.Log($"zEdit settings file {f}: modsPath is not {_mo2Compiler.MO2Folder}\\mods but {settings.modsPath}!"); + return false; + } + + return true; + }); + + if (!settingsFiles.Any()) + { + Utils.Log($"Found not acceptable settings.json file for zEdit!"); + return; + } + + var profileFolder = + settingsFiles.Where(x => File.Exists(Path.Combine(Path.GetDirectoryName(x), "merges.json")))?.Select(x => string.IsNullOrWhiteSpace(x) ? "" : Path.GetDirectoryName(x)).FirstOrDefault(); + + if (string.IsNullOrWhiteSpace(profileFolder)) + { + Utils.Log("Found no acceptable profiles folder for zEdit!"); + return; + } + + var mergeFile = Path.Combine(profileFolder, "merges.json"); + + Utils.Log($"Using merge file {mergeFile}"); + + var merges = mergeFile.FromJSON>().GroupBy(f => (f.name, f.filename)); merges.Where(m => m.Count() > 1) .Do(m => @@ -69,10 +120,13 @@ namespace Wabbajack.Lib merges.ToDictionary( m => Path.Combine(_mo2Compiler.MO2Folder, Consts.MO2ModFolderName, m.Key.name, m.Key.filename), m => m.First()); + + _disabled = false; } public override async ValueTask Run(RawSourceFile source) { + if (_disabled) return null; if (!_mergesIndexed.TryGetValue(source.AbsolutePath, out var merge)) return null; var result = source.EvolveTo(); result.Sources = merge.plugins.Select(f => @@ -138,6 +192,14 @@ namespace Wabbajack.Lib } } + public class zEditSettings + { + public string modManager; + public string managerPath; + public string modsPath; + public string mergePath; + } + public class zEditMerge { public string name; From fa5f5be73bfed84682ae50348a836e442ec88eab Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 18:30:42 +0200 Subject: [PATCH 3/9] Seq files from merges are now inlined --- Wabbajack.Lib/zEditIntegration.cs | 53 +++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/Wabbajack.Lib/zEditIntegration.cs b/Wabbajack.Lib/zEditIntegration.cs index ba88104c..9187aed7 100644 --- a/Wabbajack.Lib/zEditIntegration.cs +++ b/Wabbajack.Lib/zEditIntegration.cs @@ -107,7 +107,7 @@ namespace Wabbajack.Lib Utils.Log($"Using merge file {mergeFile}"); - var merges = mergeFile.FromJSON>().GroupBy(f => (f.name, f.filename)); + var merges = mergeFile.FromJSON>().GroupBy(f => (f.name, f.filename)).ToArray(); merges.Where(m => m.Count() > 1) .Do(m => @@ -127,7 +127,27 @@ namespace Wabbajack.Lib public override async ValueTask Run(RawSourceFile source) { if (_disabled) return null; - if (!_mergesIndexed.TryGetValue(source.AbsolutePath, out var merge)) return null; + if (!_mergesIndexed.TryGetValue(source.AbsolutePath, out var merge)) + { + if(!source.AbsolutePath.EndsWith(".seq")) + return null; + + var seqFolder = Path.GetDirectoryName(source.AbsolutePath); + + if (!seqFolder.EndsWith("seq")) + return null; + + var mergeFolder = Path.GetDirectoryName(seqFolder); + var split = mergeFolder.Split("\\"); + var mergeName = split[^1]; + + if (!File.Exists(Path.Combine(mergeFolder, mergeName + ".esp"))) + return null; + + var inline = source.EvolveTo(); + inline.SourceDataID = _compiler.IncludeFile(File.ReadAllBytes(source.AbsolutePath)); + return inline; + } var result = source.EvolveTo(); result.Sources = merge.plugins.Select(f => { @@ -162,14 +182,14 @@ namespace Wabbajack.Lib }; }).ToList(); - var src_data = result.Sources.Select(f => File.ReadAllBytes(Path.Combine(_mo2Compiler.MO2Folder, f.RelativePath))) + var srcData = result.Sources.Select(f => File.ReadAllBytes(Path.Combine(_mo2Compiler.MO2Folder, f.RelativePath))) .ConcatArrays(); - var dst_data = File.ReadAllBytes(source.AbsolutePath); + var dstData = File.ReadAllBytes(source.AbsolutePath); await using (var ms = new MemoryStream()) { - await Utils.CreatePatch(src_data, dst_data, ms); + await Utils.CreatePatch(srcData, dstData, ms); result.PatchID = _compiler.IncludeFile(ms.ToArray()); } @@ -216,19 +236,18 @@ namespace Wabbajack.Lib public static void VerifyMerges(MO2Compiler compiler) { - var by_name = compiler.InstallDirectives.ToDictionary(f => f.To); + var byName = compiler.InstallDirectives.ToDictionary(f => f.To); foreach (var directive in compiler.InstallDirectives.OfType()) { foreach (var source in directive.Sources) { - if (by_name.TryGetValue(source.RelativePath, out var result)) - { - if (result.Hash != source.Hash) - throw new InvalidDataException($"Hashes for {result.To} needed for zEdit merge sources don't match, this shouldn't happen"); - continue; - } - throw new InvalidDataException($"{source.RelativePath} is needed for merged patch {directive.To} but is not included in the install."); + if (!byName.TryGetValue(source.RelativePath, out var result)) + throw new InvalidDataException( + $"{source.RelativePath} is needed for merged patch {directive.To} but is not included in the install."); + + if (result.Hash != source.Hash) + throw new InvalidDataException($"Hashes for {result.To} needed for zEdit merge sources don't match, this shouldn't happen"); } } } @@ -242,13 +261,13 @@ namespace Wabbajack.Lib { Utils.LogStatus($"Generating zEdit merge: {m.To}"); - var src_data = m.Sources.Select(s => File.ReadAllBytes(Path.Combine(installer.OutputFolder, s.RelativePath))) + var srcData = m.Sources.Select(s => File.ReadAllBytes(Path.Combine(installer.OutputFolder, s.RelativePath))) .ConcatArrays(); - var patch_data = installer.LoadBytesFromPath(m.PatchID); + var patchData = installer.LoadBytesFromPath(m.PatchID); - using (var fs = File.Open(Path.Combine(installer.OutputFolder, m.To), FileMode.Create)) - Utils.ApplyPatch(new MemoryStream(src_data), () => new MemoryStream(patch_data), fs); + using var fs = File.Open(Path.Combine(installer.OutputFolder, m.To), FileMode.Create); + Utils.ApplyPatch(new MemoryStream(srcData), () => new MemoryStream(patchData), fs); }); } } From 03dacb1e42b35690444736217d8db30aca4abce1 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 19:10:13 +0200 Subject: [PATCH 4/9] Fixed zEditIntegration Test --- Wabbajack.Lib/zEditIntegration.cs | 8 ++++---- Wabbajack.Test/ZEditIntegrationTests.cs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Wabbajack.Lib/zEditIntegration.cs b/Wabbajack.Lib/zEditIntegration.cs index 9187aed7..15c583ea 100644 --- a/Wabbajack.Lib/zEditIntegration.cs +++ b/Wabbajack.Lib/zEditIntegration.cs @@ -73,15 +73,15 @@ namespace Wabbajack.Lib return false; } - if (settings.modsPath != Path.Combine(_mo2Compiler.MO2Folder, "mods")) + if (settings.modsPath != Path.Combine(_mo2Compiler.MO2Folder, Consts.MO2ModFolderName)) { - Utils.Log($"zEdit settings file {f}: modsPath is not {_mo2Compiler.MO2Folder}\\mods but {settings.modsPath}!"); + Utils.Log($"zEdit settings file {f}: modsPath is not {_mo2Compiler.MO2Folder}\\{Consts.MO2ModFolderName} but {settings.modsPath}!"); return false; } - if (settings.mergePath != Path.Combine(_mo2Compiler.MO2Folder, "mods")) + if (settings.mergePath != Path.Combine(_mo2Compiler.MO2Folder, Consts.MO2ModFolderName)) { - Utils.Log($"zEdit settings file {f}: modsPath is not {_mo2Compiler.MO2Folder}\\mods but {settings.modsPath}!"); + Utils.Log($"zEdit settings file {f}: modsPath is not {_mo2Compiler.MO2Folder}\\{Consts.MO2ModFolderName} but {settings.modsPath}!"); return false; } diff --git a/Wabbajack.Test/ZEditIntegrationTests.cs b/Wabbajack.Test/ZEditIntegrationTests.cs index df601c14..d720ab38 100644 --- a/Wabbajack.Test/ZEditIntegrationTests.cs +++ b/Wabbajack.Test/ZEditIntegrationTests.cs @@ -27,6 +27,18 @@ namespace Wabbajack.Test Directory.CreateDirectory(Path.Combine(utils.MO2Folder, "tools", "mator", "bleh", "profiles", "myprofile")); + + var settings = new zEditIntegration.zEditSettings() + { + modManager = "Mod Organizer 2", + managerPath = utils.MO2Folder, + modsPath = Path.Combine(utils.MO2Folder, Consts.MO2ModFolderName), + mergePath = Path.Combine(utils.MO2Folder, Consts.MO2ModFolderName) + }; + + settings.ToJSON(Path.Combine(utils.MO2Folder, "tools", "mator", "bleh", "profiles", "myprofile", + "settings.json")); + new List() { new zEditIntegration.zEditMerge() From 05399c4632f209b921038f4021576670137b046f Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 19:40:58 +0200 Subject: [PATCH 5/9] Attachments from IPS4 sites can now be downloaded --- .../Downloaders/AbstractIPS4Downloader.cs | 90 ++++++++++++------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs index 4df8f011..2ab97779 100644 --- a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs +++ b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs @@ -5,7 +5,6 @@ using System.Net; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; -using HtmlAgilityPack; using Newtonsoft.Json; using Wabbajack.Common; using Wabbajack.Lib.Validation; @@ -29,7 +28,16 @@ namespace Wabbajack.Lib.Downloaders var absolute = true; if (url == null || url.Host != SiteURL.Host) return null; - + + if (url.PathAndQuery.StartsWith("/applications/core/interface/file/attachment")) + { + return new TState + { + IsAttachment = true, + FullURL = url.ToString() + }; + } + if (url.PathAndQuery.StartsWith("/index.php?")) { var id2 = HttpUtility.ParseQueryString(url.Query)["r"]; @@ -37,6 +45,7 @@ namespace Wabbajack.Lib.Downloaders var name = parsed[null].Split("/", StringSplitOptions.RemoveEmptyEntries).Last(); return new TState { + FullURL = url.AbsolutePath, FileID = id2, FileName = name }; @@ -56,6 +65,7 @@ namespace Wabbajack.Lib.Downloaders return new TState { + FullURL = url.AbsolutePath, FileID = id, FileName = file }; @@ -64,6 +74,8 @@ namespace Wabbajack.Lib.Downloaders public class State : AbstractDownloadState, IMetaState where TDownloader : IDownloader { + public string FullURL { get; set; } + public bool IsAttachment { get; set; } public string FileID { get; set; } public string FileName { get; set; } @@ -81,7 +93,9 @@ namespace Wabbajack.Lib.Downloaders get { return FileID == null - ? new object[] {Downloader.SiteURL, FileName} + ? IsAttachment + ? new object[] {Downloader.SiteURL, IsAttachment, FullURL} + : new object[] {Downloader.SiteURL, FileName} : new object[] {Downloader.SiteURL, FileName, FileID}; } } @@ -103,27 +117,32 @@ namespace Wabbajack.Lib.Downloaders private async Task ResolveDownloadStream() { - //var downloader = (AbstractNeedsLoginDownloader)(object)DownloadDispatcher.GetInstance(); - TOP: - var csrfurl = FileID == null - ? $"{Site}/files/file/{FileName}/?do=download" - : $"{Site}/files/file/{FileName}/?do=download&r={FileID}"; - var html = await Downloader.AuthedClient.GetStringAsync(csrfurl); + string url; + if (IsAttachment) + { + url = FullURL; + } + else + { + var csrfURL = FileID == null + ? $"{Site}/files/file/{FileName}/?do=download" + : $"{Site}/files/file/{FileName}/?do=download&r={FileID}"; + var html = await Downloader.AuthedClient.GetStringAsync(csrfURL); - var pattern = new Regex("(?<=csrfKey=).*(?=[&\"\'])|(?<=csrfKey: \").*(?=[&\"\'])"); - var matches = pattern.Matches(html).Cast(); + var pattern = new Regex("(?<=csrfKey=).*(?=[&\"\'])|(?<=csrfKey: \").*(?=[&\"\'])"); + var matches = pattern.Matches(html).Cast(); var csrfKey = matches.Where(m => m.Length == 32).Select(m => m.ToString()).FirstOrDefault(); - if (csrfKey == null) - return null; + if (csrfKey == null) + return null; - var sep = Site.EndsWith("?") ? "&" : "?"; - var url = FileID == null - ? $"{Site}/files/file/{FileName}/{sep}do=download&confirm=1&t=1&csrfKey={csrfKey}" - : $"{Site}/files/file/{FileName}/{sep}do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}"; - + var sep = Site.EndsWith("?") ? "&" : "?"; + url = FileID == null + ? $"{Site}/files/file/{FileName}/{sep}do=download&confirm=1&t=1&csrfKey={csrfKey}" + : $"{Site}/files/file/{FileName}/{sep}do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}"; + } var streamResult = await Downloader.AuthedClient.GetAsync(url); if (streamResult.StatusCode != HttpStatusCode.OK) @@ -174,37 +193,42 @@ namespace Wabbajack.Lib.Downloaders public override string GetManifestURL(Archive a) { - return $"{Site}/files/file/{FileName}/?do=download&r={FileID}"; + return IsAttachment ? "" : $"{Site}/files/file/{FileName}/?do=download&r={FileID}"; } public override string[] GetMetaIni() { - if (FileID != null) - { - if (Site.EndsWith("?")) - { - return new[] - { - "[General]", $"directURL={Site}/files/file/{FileName}&do=download&r={FileID}&confirm=1&t=1" - }; - - } + if (IsAttachment) + return new[] {"[General]", $"directURL={FullURL}"}; + if (FileID == null) + return new[] {"[General]", $"directURL={Site}/files/file/{FileName}"}; + + if (Site.EndsWith("?")) + { return new[] { - "[General]", $"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1" + "[General]", $"directURL={Site}/files/file/{FileName}&do=download&r={FileID}&confirm=1&t=1" }; + } return new[] { - "[General]", - $"directURL={Site}/files/file/{FileName}" + "[General]", $"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1" }; + } // from IMetaState - public string URL => $"{Site}/files/file/{FileName}"; + public string URL + { + get + { + return !IsAttachment ? $"{Site}/files/file/{FileName}" : ""; + } + } + public string Name { get; set; } public string Author { get; set; } public string Version { get; set; } From d58fcab92efceeb5c8f031f1f2f9b59a3f0ff92a Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 19:53:05 +0200 Subject: [PATCH 6/9] Fixed ManifestURL --- Wabbajack.Lib/ACompiler.cs | 3 +++ Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Wabbajack.Lib/ACompiler.cs b/Wabbajack.Lib/ACompiler.cs index f389ec69..86272a36 100644 --- a/Wabbajack.Lib/ACompiler.cs +++ b/Wabbajack.Lib/ACompiler.cs @@ -91,6 +91,9 @@ namespace Wabbajack.Lib { if (a.State is IMetaState metaState) { + if (string.IsNullOrWhiteSpace(metaState.URL)) + return; + var b = await metaState.LoadMetaData(); Utils.Log(b ? $"Getting meta data for {a.Name} was successful!" diff --git a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs index 2ab97779..d940b23a 100644 --- a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs +++ b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs @@ -193,7 +193,7 @@ namespace Wabbajack.Lib.Downloaders public override string GetManifestURL(Archive a) { - return IsAttachment ? "" : $"{Site}/files/file/{FileName}/?do=download&r={FileID}"; + return IsAttachment ? FullURL : $"{Site}/files/file/{FileName}/?do=download&r={FileID}"; } public override string[] GetMetaIni() From 73e17931dc17f17ac33ba46c214a9306db5e79f0 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 19:56:21 +0200 Subject: [PATCH 7/9] Fixed empty images in slideshow --- Wabbajack/View Models/SlideShow.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Wabbajack/View Models/SlideShow.cs b/Wabbajack/View Models/SlideShow.cs index 7f60f259..9902a08c 100644 --- a/Wabbajack/View Models/SlideShow.cs +++ b/Wabbajack/View Models/SlideShow.cs @@ -89,6 +89,7 @@ namespace Wabbajack return modList.SourceModList.Archives .Select(m => m.State) .OfType() + .Where(x => !string.IsNullOrEmpty(x.URL) && !string.IsNullOrEmpty(x.ImageURL)) .DistinctBy(x => x.URL) // Shuffle it .Shuffle(_random) From 7fba212ba365bf2d8906df8be0178c3952199020 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 20:34:00 +0200 Subject: [PATCH 8/9] Fixed modlist.txt order --- .../CompilationSteps/IgnoreDisabledMods.cs | 3 +- .../CompilationSteps/IncludeThisProfile.cs | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs b/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs index 7cb8f350..c85b3645 100644 --- a/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs +++ b/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs @@ -40,8 +40,7 @@ namespace Wabbajack.Lib.CompilationSteps return new State(); } - - private static bool IsAlwaysEnabled(dynamic data) + public static bool IsAlwaysEnabled(dynamic data) { if (data == null) return false; diff --git a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs index e2ab4dd1..982ca552 100644 --- a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs +++ b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs @@ -10,7 +10,7 @@ namespace Wabbajack.Lib.CompilationSteps public class IncludeThisProfile : ACompilationStep { private readonly IEnumerable _correctProfiles; - private readonly MO2Compiler _mo2Compiler; + private MO2Compiler _mo2Compiler; public IncludeThisProfile(ACompiler compiler) : base(compiler) { @@ -20,18 +20,17 @@ namespace Wabbajack.Lib.CompilationSteps public override async ValueTask Run(RawSourceFile source) { - if (_correctProfiles.Any(p => source.Path.StartsWith(p))) - { - var data = source.Path.EndsWith("\\modlist.txt") - ? ReadAndCleanModlist(source.AbsolutePath) - : File.ReadAllBytes(source.AbsolutePath); + if (!_correctProfiles.Any(p => source.Path.StartsWith(p))) + return null; - var e = source.EvolveTo(); - e.SourceDataID = _compiler.IncludeFile(data); - return e; - } + var data = source.Path.EndsWith("\\modlist.txt") + ? ReadAndCleanModlist(source.AbsolutePath) + : File.ReadAllBytes(source.AbsolutePath); + + var e = source.EvolveTo(); + e.SourceDataID = _compiler.IncludeFile(data); + return e; - return null; } public override IState GetState() @@ -39,12 +38,17 @@ namespace Wabbajack.Lib.CompilationSteps return new State(); } - private static byte[] ReadAndCleanModlist(string absolutePath) + private byte[] ReadAndCleanModlist(string absolutePath) { - var lines = File.ReadAllLines(absolutePath); - lines = (from line in lines - where !(line.StartsWith("-") && !line.EndsWith("_separator")) - select line).ToArray(); + var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IgnoreDisabledMods.IsAlwaysEnabled(f.Value)) + .Select(f => f.Key) + .Distinct(); + var lines = File.ReadAllLines(absolutePath).Where(l => + { + return l.StartsWith("+") + || alwaysEnabled.Any(x => x == l.Substring(1)) + || l.EndsWith("_separator"); + }).ToArray(); return Encoding.UTF8.GetBytes(string.Join("\r\n", lines)); } From f1f06590120e77cd23f16dc3b5385a6c0ad3e933 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 20:47:07 +0200 Subject: [PATCH 9/9] Added /select param when opening the log folder or finished modlist --- Wabbajack/View Models/Compilers/CompilerVM.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Wabbajack/View Models/Compilers/CompilerVM.cs b/Wabbajack/View Models/Compilers/CompilerVM.cs index a7bee90f..d5da210a 100644 --- a/Wabbajack/View Models/Compilers/CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/CompilerVM.cs @@ -233,14 +233,14 @@ namespace Wabbajack { if (Completed?.Failed ?? false) { - Process.Start("explorer.exe", Utils.LogFolder); + Process.Start("explorer.exe", $"/select,\"{Utils.LogFolder}\""); } else { Process.Start("explorer.exe", string.IsNullOrWhiteSpace(OutputLocation.TargetPath) - ? Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) - : OutputLocation.TargetPath); + ? $"/select,\"{Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)}\"" + : $"/select,\"{OutputLocation.TargetPath}\""); } });