From d070be4489b47dc120a3b9b279409e7a76785ab2 Mon Sep 17 00:00:00 2001 From: LaughingLeader Date: Sun, 19 Dec 2021 16:35:00 -0600 Subject: [PATCH] Add support for checking for nodes with the id "Version", in case the author didn't rename it "Version" should be "Version64" nowadays, according to Larian's meta.lsx changes, but this will help some mods that have the id incorrect to still display the correct version in the mod manager. --- .../Util/DivinityModDataLoader.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/DivinityModManagerCore/Util/DivinityModDataLoader.cs b/DivinityModManagerCore/Util/DivinityModDataLoader.cs index 7b67233e..2ab3b8e5 100644 --- a/DivinityModManagerCore/Util/DivinityModDataLoader.cs +++ b/DivinityModManagerCore/Util/DivinityModDataLoader.cs @@ -71,6 +71,19 @@ private static string GetAttributeWithId(XElement node, string id, string fallba return fallbackValue; } + private static string GetAttributeWithId(XElement node, string[] ids, string fallbackValue = "") + { + foreach (var id in ids) + { + var att = node.Descendants("attribute").FirstOrDefault(a => a.Attribute("id")?.Value == id)?.Attribute("value")?.Value; + if (att != null) + { + return att; + } + } + return fallbackValue; + } + private static bool TryGetAttribute(XElement node, string id, out string value, string fallbackValue = "") { var att = node.Attributes().FirstOrDefault(a => a.Name == id); @@ -142,6 +155,9 @@ public static string UnescapeXml(string str) return str; } + private static readonly string[] VersionAttributes = new string[] { "Version64", "Version" }; + + private static DivinityModData ParseMetaFile(string metaContents, bool isBaseGameMod = false) { try @@ -199,7 +215,7 @@ private static DivinityModData ParseMetaFile(string metaContents, bool isBaseGam UUID = uuid, Name = name, Author = author, - Version = DivinityModVersion2.FromInt(SafeConvertStringUnsigned(GetAttributeWithId(moduleInfoNode, "Version64", ""))), + Version = DivinityModVersion2.FromInt(SafeConvertStringUnsigned(GetAttributeWithId(moduleInfoNode, VersionAttributes, ""))), Folder = GetAttributeWithId(moduleInfoNode, "Folder", ""), Description = description, MD5 = GetAttributeWithId(moduleInfoNode, "MD5", ""), @@ -223,7 +239,7 @@ private static DivinityModData ParseMetaFile(string metaContents, bool isBaseGam { UUID = GetAttributeWithId(node, "UUID", ""), Name = UnescapeXml(GetAttributeWithId(node, "Name", "")), - Version = DivinityModVersion2.FromInt(SafeConvertStringUnsigned(GetAttributeWithId(node, "Version64", ""))), + Version = DivinityModVersion2.FromInt(SafeConvertStringUnsigned(GetAttributeWithId(node, VersionAttributes, ""))), Folder = GetAttributeWithId(node, "Folder", ""), MD5 = GetAttributeWithId(node, "MD5", "") }; @@ -238,7 +254,7 @@ private static DivinityModData ParseMetaFile(string metaContents, bool isBaseGam var publishVersionNode = moduleInfoNode.Descendants("node").Where(n => n.Attribute("id")?.Value == "PublishVersion").FirstOrDefault(); if (publishVersionNode != null) { - var publishVersion = DivinityModVersion2.FromInt(SafeConvertStringUnsigned(GetAttributeWithId(publishVersionNode, "Version64", ""))); + var publishVersion = DivinityModVersion2.FromInt(SafeConvertStringUnsigned(GetAttributeWithId(publishVersionNode, VersionAttributes, ""))); modData.PublishVersion = publishVersion; //DivinityApp.LogMessage($"{modData.Folder} PublishVersion is {publishVersion.Version}"); } @@ -1225,7 +1241,7 @@ private static FileInfo GetPlayerProfilesFile(string path) { InclusionFilter = (f) => { - if(f.FileName.IndexOf("playerprofiles", SCOMP) > -1 && LarianFileTypes.Any(e => e.Equals(f.Extension, SCOMP))) + if (f.FileName.IndexOf("playerprofiles", SCOMP) > -1 && LarianFileTypes.Any(e => e.Equals(f.Extension, SCOMP))) { return true; } @@ -1237,7 +1253,7 @@ private static FileInfo GetPlayerProfilesFile(string path) public static string GetSelectedProfileUUID(string profilePath) { - + FileInfo playerprofilesFile = GetPlayerProfilesFile(profilePath); string activeProfileUUID = ""; if (playerprofilesFile != null)