From 4b2084a2dbf8f4cd1a9c895212b2dfb9e55035af Mon Sep 17 00:00:00 2001 From: Jakob Harder <12190313+jakobharder@users.noreply.github.com> Date: Sun, 30 Apr 2023 14:01:41 +0200 Subject: [PATCH] include sub mod ids in dependency validation --- ModManager_Classes/Models/Mod.cs | 23 +++++++++++++++++++ .../Validation/ModCompatibilityValidator.cs | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ModManager_Classes/Models/Mod.cs b/ModManager_Classes/Models/Mod.cs index 2811bea..e6acaee 100644 --- a/ModManager_Classes/Models/Mod.cs +++ b/ModManager_Classes/Models/Mod.cs @@ -142,6 +142,25 @@ public Mod (string folderName, Modinfo? modinfo, string basePath) // TODO move to separate async? var info = new DirectoryInfo(FullModPath); SizeInMB = (float)Math.Round((decimal)info.EnumerateFiles("*", SearchOption.AllDirectories).Sum(x => x.Length) / 1024 / 1024, 1); + + string[] modinfos = Directory.GetFiles(Path.Combine(basePath, folderName), "modinfo.json", SearchOption.AllDirectories); + if (modinfos.Length > 1) + { + SubMods = new List(); + foreach (var submodinfo in modinfos) + { + if (submodinfo == Path.Combine(basePath, folderName, "modinfo.json")) + { + continue; + } + + Mod? submod = TryFromFolder(Path.GetDirectoryName(submodinfo) ?? ""); + if (submod is not null) + { + SubMods.Add(submod); + } + } + } } public void InitImageAsFilepath(String ImagePath) @@ -310,6 +329,10 @@ public bool IsUpdateOf(Mod? target) } #endregion + #region Sub mods + public List? SubMods { get; private set; } + #endregion + public ModStatus GetStatus() { return (Attributes.GetByType(AttributeType.ModStatus) as ModStatusAttribute)?.Status ?? ModStatus.Default; diff --git a/ModManager_Classes/Validation/ModCompatibilityValidator.cs b/ModManager_Classes/Validation/ModCompatibilityValidator.cs index 8345bce..dd117aa 100644 --- a/ModManager_Classes/Validation/ModCompatibilityValidator.cs +++ b/ModManager_Classes/Validation/ModCompatibilityValidator.cs @@ -43,7 +43,9 @@ private static IEnumerable GetUnresolvedDependencies(Modinfo modinfo, IR foreach (var dep in modinfo.ModDependencies) { - if (!collection.Any(x => x.Modinfo.ModID is not null && x.Modinfo.ModID.Equals(dep) && x.IsActiveAndValid)) + if (!collection.Any(x => x.Modinfo.ModID is not null + && (x.Modinfo.ModID.Equals(dep) || x.SubMods?.Find(submod => submod.ModID.Equals(dep)) is not null) + && x.IsActiveAndValid)) yield return dep; } }