diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index 710ecc42..38cb8d1c 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -29,6 +29,16 @@ namespace Wabbajack } } + public string MO2Profile; + + public string MO2ProfileDir + { + get + { + return Path.Combine(MO2Folder, MO2Profile); + } + } + public Action Log_Fn { get; } public Action Progress_Function { get; } @@ -50,6 +60,8 @@ namespace Wabbajack GamePath = ((string)MO2Ini.General.gamePath).Replace("\\\\", "\\"); } + + public void LoadArchives() { IndexedArchives = Directory.EnumerateFiles(MO2DownloadsFolder) @@ -155,15 +167,96 @@ namespace Wabbajack IgnoreStartsWith("logs\\"), IgnoreStartsWith("downloads\\"), IgnoreStartsWith("webcache\\"), + IgnoreStartsWith("nxmhandler."), IgnoreEndsWith(".pyc"), + IgnoreOtherProfiles(), + IncludeThisProfile(), // Ignore the ModOrganizer.ini file it contains info created by MO2 on startup IgnoreStartsWith("ModOrganizer.ini"), IgnoreRegex(Consts.GameFolderFilesDir + "\\\\.*\\.bsa"), + IncludeModIniData(), DirectMatch(), + + // If we have no match at this point for a game folder file, skip them, we can't do anything about them + IgnoreGameFiles(), DropAll() }; } + private Func IncludeModIniData() + { + return source => + { + if (source.Path.StartsWith("mods\\") && source.Path.EndsWith("\\meta.ini")) + { + var e = source.EvolveTo(); + e.SourceData = File.ReadAllBytes(source.AbsolutePath).ToBase64(); + return e; + } + return null; + }; + } + + private Func IgnoreGameFiles() + { + var start_dir = Consts.GameFolderFilesDir + "\\"; + return source => + { + if (source.Path.StartsWith(start_dir)) + { + var i = source.EvolveTo(); + i.Reason = "Default game file"; + return i; + } + return null; + }; + } + + private Func IncludeThisProfile() + { + var correct_profile = Path.Combine("profiles", MO2Profile) + "\\"; + return source => + { + if (source.Path.StartsWith(correct_profile)) + { + byte[] data; + if (source.Path.EndsWith("\\modlist.txt")) + data = ReadAndCleanModlist(source.AbsolutePath); + else + data = File.ReadAllBytes(source.AbsolutePath); + + var e = source.EvolveTo(); + e.SourceData = data.ToBase64(); + return e; + } + return null; + }; + } + + private byte[] ReadAndCleanModlist(string absolutePath) + { + var lines = File.ReadAllLines(absolutePath); + lines = (from line in lines + where !(line.StartsWith("-") && !line.EndsWith("_separator")) + select line).ToArray(); + return Encoding.UTF8.GetBytes(String.Join("\r\n", lines)); + } + + private Func IgnoreOtherProfiles() + { + var correct_profile = Path.Combine("profiles", MO2Profile) + "\\"; + return source => + { + if (source.Path.StartsWith("profiles\\") && !source.Path.StartsWith(correct_profile)) + { + var c = source.EvolveTo(); + c.Reason = "File not for this profile"; + return c; + } + return null; + }; + } + private Func IgnoreEndsWith(string v) { var reason = String.Format("Ignored because path ends with {0}", v); diff --git a/Wabbajack/Program.cs b/Wabbajack/Program.cs index 8cbe29a7..8c749794 100644 --- a/Wabbajack/Program.cs +++ b/Wabbajack/Program.cs @@ -13,6 +13,7 @@ namespace Wabbajack { var compiler = new Compiler("c:\\Mod Organizer 2", msg => Console.WriteLine(msg), (msg, id, prog) => Console.WriteLine(msg)); compiler.LoadArchives(); + compiler.MO2Profile = "Lexy's Legacy of The Dragonborn Special Edition"; compiler.Compile(); }