From 604434c2e72c398686d4d9673df7ce191413960b Mon Sep 17 00:00:00 2001 From: Aragas Date: Sat, 24 Dec 2022 21:01:05 +0200 Subject: [PATCH] * Added export of the Load Order to a Novus Preset --- build/common.props | 2 +- changelog.txt | 4 ++ .../Helpers/ModuleListHandler.cs | 64 +++++++++++++++++-- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/build/common.props b/build/common.props index a45939a..c345dec 100644 --- a/build/common.props +++ b/build/common.props @@ -7,7 +7,7 @@ - 1.14.5 + 1.14.6 2.2.2 3.0.0.126 5.0.163 diff --git a/changelog.txt b/changelog.txt index 9977383..19fcd1d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 1.14.6 +Game Versions: v1.0.0,v1.0.1,v1.0.2 +* Added export of the Load Order to a Novus Preset +--------------------------------------------------------------------------------------------------- Version: 1.14.5 Game Versions: v1.0.0,v1.0.1,v1.0.2 * Added 'BUTRLoader_lasterror.log' file that will contain the error when the launcher is crashing diff --git a/src/Bannerlord.BUTRLoader.LauncherEx/Helpers/ModuleListHandler.cs b/src/Bannerlord.BUTRLoader.LauncherEx/Helpers/ModuleListHandler.cs index 4a1bddf..456866f 100644 --- a/src/Bannerlord.BUTRLoader.LauncherEx/Helpers/ModuleListHandler.cs +++ b/src/Bannerlord.BUTRLoader.LauncherEx/Helpers/ModuleListHandler.cs @@ -352,6 +352,55 @@ public void Import() thread.Join(); } + private void SaveBMList(Stream stream, IReadOnlyList modules) + { + using var writer = new StreamWriter(stream); + var content = Serialize(modules.Select(x => new ModuleListEntry(x.Id, x.Version)).ToArray()); + writer.Write(content); + } + private void SaveNovusPreset(Stream stream, IReadOnlyList modules) + { + var document = new XmlDocument(); + + var root = document.CreateElement("Preset"); + var nameAttribute = document.CreateAttribute("Name"); + nameAttribute.Value = "BUTRLoader Exported Load Order"; + var createdByAttribute = document.CreateAttribute("CreatedBy"); + createdByAttribute.Value = "BUTRLoader"; + var lastUpdatedAttribute = document.CreateAttribute("LastUpdated"); + lastUpdatedAttribute.Value = DateTime.Now.ToString("dd/MM/yyyy"); + root.Attributes.Append(nameAttribute); + root.Attributes.Append(createdByAttribute); + root.Attributes.Append(lastUpdatedAttribute); + foreach (var module in modules) + { + var entryNode = document.CreateElement("PresetModule"); + + var idAttribute = document.CreateAttribute("Id"); + idAttribute.Value = module.Id; + var versionAttribute = document.CreateAttribute("RequiredVersion"); + versionAttribute.Value = module.Version.ToString(); + var urlAttribute = document.CreateAttribute("URL"); + urlAttribute.Value = module.Url; + + entryNode.Attributes.Append(idAttribute); + entryNode.Attributes.Append(versionAttribute); + entryNode.Attributes.Append(urlAttribute); + + root.AppendChild(entryNode); + } + document.AppendChild(root); + + using var writer = XmlWriter.Create(stream, new XmlWriterSettings + { + Indent = true, + IndentChars = " ", + NewLineChars = "\r\n", + NewLineHandling = NewLineHandling.Replace + }); + document.Save(writer); + } + public void Export() { var thread = new Thread(() => @@ -367,7 +416,7 @@ public void Export() var dialog = new SaveFileDialog { FileName = "MyList.bmlist", - Filter = "Bannerlord Module List (*.bmlist)|*.bmlist", + Filter = "Bannerlord Module List (*.bmlist)|*.bmlist|Novus Preset (*.xml)|*.xml", Title = "Save a Bannerlord Module List File", CheckFileExists = false, @@ -383,13 +432,18 @@ public void Export() var modules = mixin.Modules2 .Where(x => x.IsSelected) .Select(x => x.ModuleInfoExtended) - .Select(x => new ModuleListEntry(x.Id, x.Version)) .ToArray(); using var fs = dialog.OpenFile(); - using var writer = new StreamWriter(fs); - var content = Serialize(modules); - writer.Write(content); + switch (Path.GetExtension(dialog.FileName)) + { + case ".bmlist": + SaveBMList(fs, modules); + break; + case ".xml": + SaveNovusPreset(fs, modules); + break; + } } catch (Exception) { } }