From 983f7de9d5a9a5100ba958433524ed8c35f02bd6 Mon Sep 17 00:00:00 2001 From: Sewer56 Date: Tue, 26 Nov 2024 13:51:43 +0000 Subject: [PATCH 1/4] Added: Missing 'ValidateDependencies' param in ValidateModuleEx call --- src/Bannerlord.ModuleManager/ModuleUtilities.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bannerlord.ModuleManager/ModuleUtilities.cs b/src/Bannerlord.ModuleManager/ModuleUtilities.cs index 2cb5e16..fa8f3e1 100644 --- a/src/Bannerlord.ModuleManager/ModuleUtilities.cs +++ b/src/Bannerlord.ModuleManager/ModuleUtilities.cs @@ -1,4 +1,4 @@ -#region License +#region License // MIT License // // Copyright (c) Bannerlord's Unofficial Tools & Resources @@ -273,7 +273,7 @@ public static IEnumerable ValidateModuleEx( bool validateDependencies = true) { var visited = new HashSet(); - foreach (var issue in ValidateModuleEx(modules, targetModule, visited, isSelected, isValid)) + foreach (var issue in ValidateModuleEx(modules, targetModule, visited, isSelected, isValid, validateDependencies)) { yield return issue; } From 4cbef0857f8021545a5ac457512e645a40a985d9 Mon Sep 17 00:00:00 2001 From: Sewer56 Date: Tue, 26 Nov 2024 13:59:34 +0000 Subject: [PATCH 2/4] Added: Separate error for missing BLSE --- .../Issues/ModuleIssueV2.cs | 46 ++++++++++++++++++- .../ModuleIssueType.cs | 2 + .../ModuleUtilities.cs | 16 ++++++- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs b/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs index 87904c1..1b57751 100644 --- a/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs +++ b/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs @@ -101,7 +101,7 @@ ApplicationVersionRange SourceVersion #else public # endif - sealed record ModuleMissingUnversionedDependencyIssue( + record ModuleMissingUnversionedDependencyIssue( ModuleInfoExtended Module, DependentModuleMetadata Dependency ) : ModuleIssueV2(Module) @@ -115,6 +115,50 @@ DependentModuleMetadata Dependency ApplicationVersionRange.Empty); } +/// +/// Represents an issue where the `Bannerlord Software Extender` (BLSE) is missing. +/// +/// The module with the missing dependency +/// The missing dependency module +/// +/// This issue occurs when a mod requires the `Bannerlord Software Extender` (BLSE) +/// but it is not installed. +/// +/// Example scenario: +/// ```xml +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// ``` +/// If `BLSE` is not installed at all, this issue will be raised if `SimpleTournaments` is enabled. +/// +#if !BANNERLORDBUTRMODULEMANAGER_PUBLIC +internal +#else +public +# endif + sealed record ModuleMissingBLSEDependencyIssue( + ModuleInfoExtended Module, + DependentModuleMetadata Dependency + ) : ModuleMissingUnversionedDependencyIssue(Module, Dependency) +{ + public override string ToString() => $"Missing Bannerlord Software Extender"; + public override LegacyModuleIssue ToLegacy() => new( + Module, + Dependency.Id, + ModuleIssueType.MissingBLSE, + ToString(), + ApplicationVersionRange.Empty); +} + /// /// Represents an issue where a required dependency module is missing AND an exact version was specified /// diff --git a/src/Bannerlord.ModuleManager.Models/ModuleIssueType.cs b/src/Bannerlord.ModuleManager.Models/ModuleIssueType.cs index 5048785..6c07173 100644 --- a/src/Bannerlord.ModuleManager.Models/ModuleIssueType.cs +++ b/src/Bannerlord.ModuleManager.Models/ModuleIssueType.cs @@ -56,6 +56,8 @@ enum ModuleIssueType MissingModuleName, DependencyIsNull, DependencyMissingModuleId, + + MissingBLSE, } #nullable restore diff --git a/src/Bannerlord.ModuleManager/ModuleUtilities.cs b/src/Bannerlord.ModuleManager/ModuleUtilities.cs index fa8f3e1..4e9093c 100644 --- a/src/Bannerlord.ModuleManager/ModuleUtilities.cs +++ b/src/Bannerlord.ModuleManager/ModuleUtilities.cs @@ -1,4 +1,4 @@ -#region License +#region License // MIT License // // Copyright (c) Bannerlord's Unofficial Tools & Resources @@ -427,6 +427,13 @@ private static IEnumerable ValidateModuleDependenciesEx( if (!modules.Any(x => string.Equals(x.Id, metadata.Id, StringComparison.Ordinal))) { + // For BLSE, there is a special case, + if (metadata.Id is "BLSE.LoadingInterceptor" or "BLSE.AssemblyResolver") + { + yield return new ModuleMissingBLSEDependencyIssue(targetModule, metadata); + yield break; + } + if (metadata.Version != ApplicationVersion.Empty) yield return new ModuleMissingExactVersionDependencyIssue(targetModule, metadata); else if (metadata.VersionRange != ApplicationVersionRange.Empty) @@ -600,6 +607,13 @@ public static IEnumerable ValidateLoadOrderEx( if (metadataIdx == -1) { + // For BLSE, there is a special case, + if (metadata.Id is "BLSE.LoadingInterceptor" or "BLSE.AssemblyResolver") + { + yield return new ModuleMissingBLSEDependencyIssue(targetModule, metadata); + yield break; + } + // If the dependency lacks an Id, it's not valid if (!string.IsNullOrWhiteSpace(metadata.Id) && !metadata.IsOptional) { From b861335832bf9eb8fcfc417bd286816cc03ad380 Mon Sep 17 00:00:00 2001 From: Sewer56 Date: Tue, 26 Nov 2024 14:31:17 +0000 Subject: [PATCH 3/4] Added: Cleanup new diagnostic cases. --- src/Bannerlord.ModuleManager/ModuleUtilities.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Bannerlord.ModuleManager/ModuleUtilities.cs b/src/Bannerlord.ModuleManager/ModuleUtilities.cs index 4e9093c..1f59598 100644 --- a/src/Bannerlord.ModuleManager/ModuleUtilities.cs +++ b/src/Bannerlord.ModuleManager/ModuleUtilities.cs @@ -429,12 +429,8 @@ private static IEnumerable ValidateModuleDependenciesEx( { // For BLSE, there is a special case, if (metadata.Id is "BLSE.LoadingInterceptor" or "BLSE.AssemblyResolver") - { yield return new ModuleMissingBLSEDependencyIssue(targetModule, metadata); - yield break; - } - - if (metadata.Version != ApplicationVersion.Empty) + else if (metadata.Version != ApplicationVersion.Empty) yield return new ModuleMissingExactVersionDependencyIssue(targetModule, metadata); else if (metadata.VersionRange != ApplicationVersionRange.Empty) yield return new ModuleMissingVersionRangeDependencyIssue(targetModule, metadata); @@ -609,13 +605,10 @@ public static IEnumerable ValidateLoadOrderEx( { // For BLSE, there is a special case, if (metadata.Id is "BLSE.LoadingInterceptor" or "BLSE.AssemblyResolver") - { yield return new ModuleMissingBLSEDependencyIssue(targetModule, metadata); - yield break; - } // If the dependency lacks an Id, it's not valid - if (!string.IsNullOrWhiteSpace(metadata.Id) && !metadata.IsOptional) + else if (!string.IsNullOrWhiteSpace(metadata.Id) && !metadata.IsOptional) { if (metadata.Version != ApplicationVersion.Empty) yield return new ModuleMissingExactVersionDependencyIssue(targetModule, metadata); From 9614b5c8d11736861593c335085de43ba6db4213 Mon Sep 17 00:00:00 2001 From: Sewer56 Date: Tue, 26 Nov 2024 15:47:18 +0000 Subject: [PATCH 4/4] Update: Let's not subclass this, as it will match on switch branches when branching on type --- src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs b/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs index 1b57751..1a1baa1 100644 --- a/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs +++ b/src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs @@ -101,7 +101,7 @@ ApplicationVersionRange SourceVersion #else public # endif - record ModuleMissingUnversionedDependencyIssue( + sealed record ModuleMissingUnversionedDependencyIssue( ModuleInfoExtended Module, DependentModuleMetadata Dependency ) : ModuleIssueV2(Module) @@ -148,7 +148,7 @@ DependentModuleMetadata Dependency sealed record ModuleMissingBLSEDependencyIssue( ModuleInfoExtended Module, DependentModuleMetadata Dependency - ) : ModuleMissingUnversionedDependencyIssue(Module, Dependency) + ) : ModuleIssueV2(Module) { public override string ToString() => $"Missing Bannerlord Software Extender"; public override LegacyModuleIssue ToLegacy() => new(