Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
* Added export of the Load Order to a Novus Preset
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Dec 24, 2022
1 parent 2c9ad5d commit 604434c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<!--Development Variables-->
<PropertyGroup>
<Version>1.14.5</Version>
<Version>1.14.6</Version>
<HarmonyVersion>2.2.2</HarmonyVersion>
<BUTRSharedVersion>3.0.0.126</BUTRSharedVersion>
<BUTRModuleManagerVersion>5.0.163</BUTRModuleManagerVersion>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
64 changes: 59 additions & 5 deletions src/Bannerlord.BUTRLoader.LauncherEx/Helpers/ModuleListHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,55 @@ public void Import()
thread.Join();
}

private void SaveBMList(Stream stream, IReadOnlyList<ModuleInfoExtendedWithMetadata> 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<ModuleInfoExtendedWithMetadata> 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(() =>
Expand All @@ -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,
Expand All @@ -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) { }
}
Expand Down

0 comments on commit 604434c

Please sign in to comment.