From dffe2a68de34e0891add47d6233f2aa38d33886d Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Mon, 22 Jul 2019 22:27:26 -0600 Subject: [PATCH] Can install loose files as well --- Wabbajack.Common/Consts.cs | 13 ++++++++++ Wabbajack.Common/Utils.cs | 36 ++++++++++++++++++++++++++ Wabbajack/AppState.cs | 2 +- Wabbajack/Compiler.cs | 50 ++++++++++++++++++++++++++++++++---- Wabbajack/Installer.cs | 16 ++++++++++++ Wabbajack/MainWindow.xaml | 22 +++++++++++----- Wabbajack/MainWindow.xaml.cs | 4 +++ Wabbajack/Wabbajack.csproj | 5 ++++ Wabbajack/packages.config | 1 + 9 files changed, 136 insertions(+), 13 deletions(-) diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index d112471f..c8119fd9 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -10,5 +12,16 @@ namespace Wabbajack.Common { public static string GameFolderFilesDir = "Game Folder Files"; public static string ModPackMagic = "Celebration!, Cheese for Everyone!"; + + public static HashSet SupportedArchives = new HashSet() { ".zip", ".rar", ".7z", ".7zip" }; + + public static String UserAgent { + get + { + var platformType = Environment.Is64BitOperatingSystem ? "x64" : "x86"; + var headerString = $"Wabbajack/{Assembly.GetEntryAssembly().GetName().Version} ({Environment.OSVersion.VersionString}; {platformType}) {RuntimeInformation.FrameworkDescription}"; + return headerString; + } + } } } diff --git a/Wabbajack.Common/Utils.cs b/Wabbajack.Common/Utils.cs index 937f932a..fa080bbb 100644 --- a/Wabbajack.Common/Utils.cs +++ b/Wabbajack.Common/Utils.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Http; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -43,6 +44,16 @@ namespace Wabbajack.Common return Convert.ToBase64String(data); } + /// + /// Returns data from a base64 stream + /// + /// + /// + public static byte[] FromBase64(this string data) + { + return Convert.FromBase64String(data); + } + /// /// Executes the action for every item in coll /// @@ -74,6 +85,11 @@ namespace Wabbajack.Common { return JsonConvert.DeserializeObject(File.ReadAllText(filename)); } + public static T FromJSON(this Stream data) + { + var s = Encoding.UTF8.GetString(data.ReadAll()); + return JsonConvert.DeserializeObject(s); + } public static bool FileExists(this string filename) { @@ -183,5 +199,25 @@ namespace Wabbajack.Common return; } + public static HttpResponseMessage GetSync(this HttpClient client, string url) + { + var result = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); + result.Wait(); + return result.Result; + } + public static string GetStringSync(this HttpClient client, string url) + { + var result = client.GetStringAsync(url); + result.Wait(); + return result.Result; + } + + public static Stream GetStreamSync(this HttpClient client, string url) + { + var result = client.GetStreamAsync(url); + result.Wait(); + return result.Result; + } + } } diff --git a/Wabbajack/AppState.cs b/Wabbajack/AppState.cs index f99e4510..974ddbdf 100644 --- a/Wabbajack/AppState.cs +++ b/Wabbajack/AppState.cs @@ -73,7 +73,7 @@ namespace Wabbajack Dirty = false; } } - Thread.Sleep(250); + Thread.Sleep(1000); } } diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index c22bf6c9..37123fe7 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -15,7 +15,7 @@ namespace Wabbajack { public class Compiler { - public static HashSet SupportedArchives = new HashSet() { ".zip", ".rar", ".7z", ".7zip" }; + public string MO2Folder; @@ -39,7 +39,7 @@ namespace Wabbajack { get { - return Path.Combine(MO2Folder, MO2Profile); + return Path.Combine(MO2Folder, "profiles", MO2Profile); } } @@ -47,6 +47,7 @@ namespace Wabbajack public List InstallDirectives { get; private set; } public List SelectedArchives { get; private set; } public List AllFiles { get; private set; } + public ModList ModList { get; private set; } public List IndexedArchives; @@ -86,7 +87,7 @@ namespace Wabbajack public void LoadArchives() { IndexedArchives = Directory.EnumerateFiles(MO2DownloadsFolder) - .Where(file => SupportedArchives.Contains(Path.GetExtension(file))) + .Where(file => Consts.SupportedArchives.Contains(Path.GetExtension(file))) .PMap(file => LoadArchive(file)); } @@ -171,11 +172,31 @@ namespace Wabbajack GatherArchives(); BuildPatches(); + + ModList = new ModList() + { + Archives = SelectedArchives, + Directives = InstallDirectives + }; + PatchExecutable(); - + + ResetMembers(); + Info("Done Building Modpack"); } + /// + /// Clear references to lists that hold a lot of data. + /// + private void ResetMembers() + { + AllFiles = null; + IndexedArchives = null; + InstallDirectives = null; + SelectedArchives = null; + } + /// /// Fills in the Patch fields in files that require them @@ -320,6 +341,7 @@ namespace Wabbajack IgnoreStartsWith("nxmhandler."), IgnoreEndsWith(".pyc"), IgnoreOtherProfiles(), + IgnoreDisabledMods(), IncludeThisProfile(), // Ignore the ModOrganizer.ini file it contains info created by MO2 on startup IgnoreStartsWith("ModOrganizer.ini"), @@ -334,6 +356,24 @@ namespace Wabbajack }; } + private Func IgnoreDisabledMods() + { + var disabled_mods = File.ReadAllLines(Path.Combine(MO2ProfileDir, "modlist.txt")) + .Where(line => line.StartsWith("-") && !line.EndsWith("_separator")) + .Select(line => Path.Combine("mods", line.Substring(1))) + .ToList(); + return source => + { + if (disabled_mods.FirstOrDefault(mod => source.Path.StartsWith(mod)) != null) + { + var r = source.EvolveTo(); + r.Reason = "Disabled Mod"; + return r; + } + return null; + }; + } + private Func IncludePatches() { var indexed = (from archive in IndexedArchives @@ -514,7 +554,7 @@ namespace Wabbajack internal void PatchExecutable() { - var data = JsonConvert.SerializeObject(InstallDirectives).BZip2String(); + var data = JsonConvert.SerializeObject(ModList).BZip2String(); var executable = Assembly.GetExecutingAssembly().Location; var out_path = Path.Combine(Path.GetDirectoryName(executable), MO2Profile + ".exe"); Info("Patching Executable {0}", Path.GetFileName(out_path)); diff --git a/Wabbajack/Installer.cs b/Wabbajack/Installer.cs index f3c60d8c..31c81eef 100644 --- a/Wabbajack/Installer.cs +++ b/Wabbajack/Installer.cs @@ -78,10 +78,26 @@ namespace Wabbajack } BuildFolderStructure(); InstallArchives(); + InstallIncludedFiles(); Info("Installation complete! You may exit the program."); } + private void InstallIncludedFiles() + { + Info("Writing inline files"); + ModList.Directives + .OfType() + .PMap(directive => + { + Status("Writing included file {0}", directive.To); + var out_path = Path.Combine(Outputfolder, directive.To); + if (File.Exists(out_path)) File.Delete(out_path); + + File.WriteAllBytes(out_path, directive.SourceData.FromBase64()); + }); + } + private void BuildFolderStructure() { Info("Building Folder Structure"); diff --git a/Wabbajack/MainWindow.xaml b/Wabbajack/MainWindow.xaml index 960a2936..e5d91383 100644 --- a/Wabbajack/MainWindow.xaml +++ b/Wabbajack/MainWindow.xaml @@ -18,15 +18,23 @@ - + - - - - - - + + + + + + + + + + + + + + diff --git a/Wabbajack/MainWindow.xaml.cs b/Wabbajack/MainWindow.xaml.cs index 2a1e2153..9867bb49 100644 --- a/Wabbajack/MainWindow.xaml.cs +++ b/Wabbajack/MainWindow.xaml.cs @@ -34,6 +34,10 @@ namespace Wabbajack compiler.LoadArchives(); compiler.MO2Profile = "Lexy's Legacy of The Dragonborn Special Edition"; compiler.Compile(); + + var installer = new Installer(compiler.ModList, "c:\\tmp\\install\\", msg => context.LogMsg(msg)); + installer.Install(); + }).Start(); diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index 8da3b5f9..50f8671f 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -55,6 +55,9 @@ 4.0 + + ..\packages\WebSocketSharpFork.1.0.4.0\lib\net35\websocket-sharp.dll + @@ -75,12 +78,14 @@ + MainWindow.xaml Code + Code diff --git a/Wabbajack/packages.config b/Wabbajack/packages.config index d3422849..e0797ff5 100644 --- a/Wabbajack/packages.config +++ b/Wabbajack/packages.config @@ -3,4 +3,5 @@ + \ No newline at end of file