public static ModIdentity ParseModIdentity(ManagedMod mod, XElement node) { var uniqueAttr = node.Attribute("unique"); if (uniqueAttr == null) { throw new FormatException("A mod must have a 'unique' attribute"); } var identity = new ModIdentity(mod, uniqueAttr.Value); var displayAttr = node.Attribute("displayName"); if (displayAttr != null) { identity.DisplayName = displayAttr.Value; } var descAttr = node.Attribute("description"); if (descAttr != null) { identity.Description = descAttr.Value; } var modVersionAttr = node.Attribute("modVersion"); if (modVersionAttr != null) { if (Version.TryParse(modVersionAttr.Value, out Version version)) { identity.ModVersion = version; } else { throw new FormatException(Settings.GetLanguageString(3, "ModIdentityCantParseValue").Replace("%ATTRIBUTE%", "modVersion").Replace("%VALUE%", modVersionAttr.Value).Replace("%TYPE%", "version")); } } var xmlVersionAttr = node.Attribute("installerSystemVersion"); if (xmlVersionAttr != null) { if (Version.TryParse(xmlVersionAttr.Value, out Version version)) { identity.InstallerSystemVersion = version; } else { throw new FormatException(Settings.GetLanguageString(3, "ModIdentityCantParseValue").Replace("%ATTRIBUTE%", "installerSystemVersion").Replace("%VALUE%", xmlVersionAttr.Value).Replace("%TYPE%", "Version")); //throw new FormatException("Mod identity 'installerSystemVersion': '" + xmlVersionAttr.Value + "' is not a valid version"); } } var canDisableAttr = node.Attribute("canDisableMod"); if (canDisableAttr != null) { if (bool.TryParse(canDisableAttr.Value, out bool canDisable)) { identity.CanDisable = canDisable; } else { throw new FormatException(Settings.GetLanguageString(3, "ModIdentityCantParseValue").Replace("%ATTRIBUTE%", "canDisableMod").Replace("%VALUE%", canDisableAttr.Value).Replace("%TYPE%", "bool")); //throw new FormatException("Mod identity 'canDisableMod': '" + canDisableAttr.Value + "' is not a boolean"); } } var hasCustomInstallerAttr = node.Attribute("hasCustomInstaller"); if (hasCustomInstallerAttr != null) { if (bool.TryParse(hasCustomInstallerAttr.Value, out bool hasCustomInstaller)) { identity.HasCustomInstaller = hasCustomInstaller; } else { throw new FormatException(Settings.GetLanguageString(3, "ModIdentityCantParseValue").Replace("%ATTRIBUTE%", "hasCustomInstaller").Replace("%VALUE%", hasCustomInstallerAttr.Value).Replace("%TYPE%", "bool")); //throw new FormatException("Mod identity 'hasCustomInstaller': '" + hasCustomInstallerAttr.Value + "' is not a boolean"); } } else if (identity.InstallerSystemVersion == ModIdentity.XmlModIdentityVersion1_0_0_0) { identity.HasCustomInstaller = true; var compatOnlyAttr = node.Attribute("compatOnly"); if (compatOnlyAttr != null) { if (bool.TryParse(compatOnlyAttr.Value, out bool compatOnly)) { identity.HasCustomInstaller = !compatOnly; } else { throw new FormatException(Settings.GetLanguageString(3, "ModIdentityCantParseValue").Replace("%ATTRIBUTE%", "compatOnly").Replace("%VALUE%", compatOnlyAttr.Value).Replace("%TYPE%", "bool").Replace("%TYPE%", "bool")); //throw new FormatException("Mod identity 'compatOnly': '" + compatOnlyAttr.Value + "' is not a boolean"); } } } var warnAttr = node.Attribute("isExperimental"); if (warnAttr != null) { if (bool.TryParse(warnAttr.Value, out bool isExperimental) && isExperimental) { identity.IsExperimental = isExperimental; } } warnAttr = node.Attribute("requiresGalaxyReset"); if (warnAttr != null) { if (bool.TryParse(warnAttr.Value, out bool requiresGalaxyReset) && requiresGalaxyReset) { identity.RequiresGalaxyReset = requiresGalaxyReset; } } warnAttr = node.Attribute("causesSaveDataDependency"); if (warnAttr != null) { if (bool.TryParse(warnAttr.Value, out bool causesSaveDataDependency) && causesSaveDataDependency) { identity.CausesSaveDataDependency = causesSaveDataDependency; } } var tagsElem = node.Element("tags"); if (tagsElem != null) { foreach (XElement element in tagsElem.Elements("tag")) { identity.Tags.Add(element.Value); } } foreach (XElement subNode in node.Elements()) { string nodeName = subNode.Name.LocalName.ToLowerInvariant(); if (nodeName == "prerequisite") { var gameAttr = subNode.Attribute("game"); identity.Files.AddRange(ParseFiles(subNode.Value, gameAttr == null ? null : gameAttr.Value, "Mod 'prerequisite'", "game")); } else if (nodeName == "remove") { var gameAttr = subNode.Attribute("game"); identity.FilesToRemove.AddRange(ParseFiles(subNode.Value, gameAttr == null ? null : gameAttr.Value, "Mod 'remove'", "game")); } else if (nodeName == "compatfile") { var targetAttr = subNode.Attribute("compatTargetFileName"); var targetGameAttr = subNode.Attribute("compatTargetGame"); var gameAttr = subNode.Attribute("game"); var compatibility = new ModCompatibilityFix(); identity.CompatibilityFixes.Add(compatibility); compatibility.FilesToAdd.AddRange(ParseFiles(subNode.Value, gameAttr == null ? null : gameAttr.Value, "'compatFile' files", "game")); compatibility.RequiredFiles.AddRange(ParseFiles(targetAttr.Value, targetGameAttr == null ? null : targetGameAttr.Value, "'compatFile' target files", "compatTargetGame")); var removeTargetAttr = subNode.Attribute("removeTargets"); if (removeTargetAttr != null) { if (bool.TryParse(removeTargetAttr.Value, out bool removeTargets)) { if (removeTargets) { compatibility.FilesToRemove.AddRange(compatibility.RequiredFiles); } } else { throw new FormatException(Settings.GetLanguageString(3, "ModIdentityCantParseValue").Replace("%ATTRIBUTE%", "removeTargets").Replace("%VALUE%", removeTargetAttr.Value).Replace("%TYPE%", "bool")); //"'compatFile' 'removeTargets': '" + removeTargetAttr.Value + "' is not a boolean"); } } } else if (nodeName == "component" || nodeName == "componentgroup") { var component = ParseModComponent(identity, subNode); component.Parent = identity; if (nodeName == "componentgroup") { component.IsGroup = true; } identity.SubComponents.Add(component); } else { throw new FormatException(Settings.GetLanguageString(3, "ModIdentityUnrecognizedTag").Replace("%TAGNAME%", subNode.Name.LocalName));//"Unknown element '" + subNode.Name.LocalName + "'"); } } return(identity); }
/*public static bool IsValidUnique(string inputUnique) * { * bool returnValue = true; * * foreach (char c in System.IO.Path.GetInvalidPathChars()) * { * if (inputUnique.Contains(c)) * { * returnValue = false; * break; * } * } * return returnValue; * } * * public static bool IsValidUnique(string inputUnique, out string validUnique) * { * string value = inputUnique; * * bool returnValue = true; * * foreach (char c in System.IO.Path.GetInvalidPathChars()) * { * if (value.Contains(c)) * { * returnValue = false; * value = value.Replace(c.ToString(), string.Empty); * //break; * } * } * validUnique = value; * * return returnValue; * }*/ public ModIdentity(ManagedMod mod, string uniqueTag) : base(null, uniqueTag) { ParentMod = mod; }
public ModConfiguration(ManagedMod parent) { Parent = parent; }