Skip to content

Commit

Permalink
Add support for checking for nodes with the id "Version", in case the…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
LaughingLeader committed Dec 19, 2021
1 parent 954ad75 commit d070be4
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions DivinityModManagerCore/Util/DivinityModDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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", ""),
Expand All @@ -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", "")
};
Expand All @@ -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}");
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down

0 comments on commit d070be4

Please sign in to comment.