From 5c7acc5e18aeaff3458e0ac0b7f519d17095e94c Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sat, 24 Aug 2019 17:20:54 -0600 Subject: [PATCH] We now remap ModOrganizer.ini files --- Wabbajack.Common/Consts.cs | 9 +++++++ Wabbajack/Compiler.cs | 31 +++++++++++++++++++++++- Wabbajack/Data.cs | 7 ++++++ Wabbajack/Installer.cs | 49 +++++++++++++++++++++++++++++++++++--- 4 files changed, 92 insertions(+), 4 deletions(-) diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index b7539631..2b1bd260 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -31,6 +31,15 @@ namespace Wabbajack.Common public static string WABBAJACK_INCLUDE = "WABBAJACK_INCLUDE"; + public static string GAME_PATH_MAGIC_BACK = "{--||GAME_PATH_MAGIC_BACK||--}"; + public static string GAME_PATH_MAGIC_DOUBLE_BACK = "{--||GAME_PATH_MAGIC_DOUBLE_BACK||--}"; + public static string GAME_PATH_MAGIC_FORWARD = "{--||GAME_PATH_MAGIC_FORWARD||--}"; + + public static string MO2_PATH_MAGIC_BACK = "{--||MO2_PATH_MAGIC_BACK||--}"; + public static string MO2_PATH_MAGIC_DOUBLE_BACK = "{--||MO2_PATH_MAGIC_DOUBLE_BACK||--}"; + public static string MO2_PATH_MAGIC_FORWARD = "{--||MO2_PATH_MAGIC_FORWARD||--}"; + + public static String AppName = "Wabbajack"; public static string HashCacheName = "Wabbajack.hash_cache"; } diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index d984d8d8..a8507cfd 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -495,7 +495,7 @@ namespace Wabbajack IgnoreDisabledMods(), IncludeThisProfile(), // Ignore the ModOrganizer.ini file it contains info created by MO2 on startup - IgnoreStartsWith("ModOrganizer.ini"), + IncludeStubbedMO2Ini(), IgnoreStartsWith(Path.Combine(Consts.GameFolderFilesDir, "Data")), IgnoreStartsWith(Path.Combine(Consts.GameFolderFilesDir, "Papyrus Compiler")), IgnoreStartsWith(Path.Combine(Consts.GameFolderFilesDir, "Skyrim")), @@ -524,6 +524,35 @@ namespace Wabbajack }; } + private Func IncludeStubbedMO2Ini() + { + return source => + { + if (source.Path == "ModOrganizer.ini") + { + return RemapIni(source, GamePath); + } + return null; + }; + } + + private Directive RemapIni(RawSourceFile source, string gamePath) + { + var data = File.ReadAllText(source.AbsolutePath); + + data = data.Replace(GamePath, Consts.GAME_PATH_MAGIC_BACK); + data = data.Replace(GamePath.Replace("\\", "\\\\"), Consts.GAME_PATH_MAGIC_DOUBLE_BACK); + data = data.Replace(GamePath.Replace("\\", "/"), Consts.GAME_PATH_MAGIC_FORWARD); + + data = data.Replace(MO2Folder, Consts.MO2_PATH_MAGIC_BACK); + data = data.Replace(MO2Folder.Replace("\\", "\\\\"), Consts.MO2_PATH_MAGIC_DOUBLE_BACK); + data = data.Replace(MO2Folder.Replace("\\", "/"), Consts.MO2_PATH_MAGIC_FORWARD); + var result = source.EvolveTo(); + result.SourceData = Encoding.UTF8.GetBytes(data).ToBase64(); + return result; + + } + private Func IgnorePathContains(string v) { v = $"\\{v.Trim('\\')}\\"; diff --git a/Wabbajack/Data.cs b/Wabbajack/Data.cs index 087d8bf5..d85172ed 100644 --- a/Wabbajack/Data.cs +++ b/Wabbajack/Data.cs @@ -96,6 +96,13 @@ namespace Wabbajack public string SourceData; } + /// + /// A file that has the game and MO2 folders remapped on installation + /// + public class RemappedInlineFile : InlineFile + { + } + public class FromArchive : Directive { /// diff --git a/Wabbajack/Installer.cs b/Wabbajack/Installer.cs index ed0c66ea..45a66e25 100644 --- a/Wabbajack/Installer.cs +++ b/Wabbajack/Installer.cs @@ -1,5 +1,6 @@ using CG.Web.MegaApiClient; using Compression.BSA; +using Ookii.Dialogs.Wpf; using System; using System.Collections.Generic; using System.IO; @@ -45,6 +46,7 @@ namespace Wabbajack public string NexusAPIKey { get; private set; } public bool IgnoreMissingFiles { get; internal set; } + public string GameFolder { get; private set; } public void Info(string msg, params object[] args) { @@ -79,6 +81,12 @@ namespace Wabbajack Directory.CreateDirectory(Outputfolder); Directory.CreateDirectory(DownloadFolder); + if (ModList.Directives.OfType().FirstOrDefault() != null && !LocateGameFolder()) + { + Info("Stopping installation because game folder was not selected"); + return; + } + HashArchives(); DownloadArchives(); HashArchives(); @@ -108,7 +116,20 @@ namespace Wabbajack Info("Installation complete! You may exit the program."); } - + private bool LocateGameFolder() + { + var vf = new VistaFolderBrowserDialog(); + vf.Description = "Please Locate Your Game Installation Path"; + vf.UseDescriptionForTitle = true; + if (vf.ShowDialog() == true) + { + GameFolder = vf.SelectedPath; + return true; + } + return false; + } + + /// /// We don't want to make the installer index all the archives, that's just a waste of time, so instead /// we'll pass just enough information to VFS to let it know about the files we have. @@ -192,11 +213,33 @@ namespace Wabbajack 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()); + if (directive is RemappedInlineFile) + { + WriteRemappedFile((RemappedInlineFile)directive); + } + else + { + File.WriteAllBytes(out_path, directive.SourceData.FromBase64()); + } }); } + private void WriteRemappedFile(RemappedInlineFile directive) + { + var data = Encoding.UTF8.GetString(directive.SourceData.FromBase64()); + + data = data.Replace(Consts.GAME_PATH_MAGIC_BACK, GameFolder); + data = data.Replace(Consts.GAME_PATH_MAGIC_DOUBLE_BACK, GameFolder.Replace("\\", "\\\\")); + data = data.Replace(Consts.GAME_PATH_MAGIC_FORWARD, GameFolder.Replace("\\", "/")); + + data = data.Replace(Consts.MO2_PATH_MAGIC_BACK, Outputfolder); + data = data.Replace(Consts.MO2_PATH_MAGIC_DOUBLE_BACK, Outputfolder.Replace("\\", "\\\\")); + data = data.Replace(Consts.MO2_PATH_MAGIC_FORWARD, Outputfolder.Replace("\\", "/")); + + File.WriteAllText(Path.Combine(Outputfolder, directive.To), data); + return; + } + private void BuildFolderStructure() { Info("Building Folder Structure");