Skip to content

Commit

Permalink
Merge pull request #371 from Sewer56/add-blse-diagnostic-special-casing
Browse files Browse the repository at this point in the history
Added: Special Casing for Finding BLSE Dependencies in ModuleManager
  • Loading branch information
Aragas authored Dec 16, 2024
2 parents 3cae400 + 9614b5c commit 3a8a313
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
44 changes: 44 additions & 0 deletions src/Bannerlord.ModuleManager.Models/Issues/ModuleIssueV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,50 @@ DependentModuleMetadata Dependency
ApplicationVersionRange.Empty);
}

/// <summary>
/// Represents an issue where the `Bannerlord Software Extender` (BLSE) is missing.
/// </summary>
/// <param name="Module">The module with the missing dependency</param>
/// <param name="Dependency">The missing dependency module</param>
/// <remarks>
/// This issue occurs when a mod requires the `Bannerlord Software Extender` (BLSE)
/// but it is not installed.
///
/// Example scenario:
/// ```xml
/// <Module>
/// <!-- 👇 Current mod is `SimpleTournaments` -->
/// <Id value="SimpleTournaments"/>
/// <DependedModules>
/// <!-- 👇 This dependency `BLSE.AssemblyResolver` is provided by BLSE -->
/// <DependedModule Id="BLSE.AssemblyResolver" />
///
/// <!-- 👇 This dependency `BLSE.LoadingInterceptor` is provided by BLSE -->
/// <DependedModule Id="BLSE.LoadingInterceptor" />
/// </DependedModules>
/// </Module>
/// ```
/// If `BLSE` is not installed at all, this issue will be raised if `SimpleTournaments` is enabled.
/// </remarks>
#if !BANNERLORDBUTRMODULEMANAGER_PUBLIC
internal
#else
public
# endif
sealed record ModuleMissingBLSEDependencyIssue(
ModuleInfoExtended Module,
DependentModuleMetadata Dependency
) : ModuleIssueV2(Module)
{
public override string ToString() => $"Missing Bannerlord Software Extender";
public override LegacyModuleIssue ToLegacy() => new(
Module,
Dependency.Id,
ModuleIssueType.MissingBLSE,
ToString(),
ApplicationVersionRange.Empty);
}

/// <summary>
/// Represents an issue where a required dependency module is missing AND an exact version was specified
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Bannerlord.ModuleManager.Models/ModuleIssueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ enum ModuleIssueType
MissingModuleName,
DependencyIsNull,
DependencyMissingModuleId,

MissingBLSE,
}

#nullable restore
Expand Down
13 changes: 10 additions & 3 deletions src/Bannerlord.ModuleManager/ModuleUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static IEnumerable<ModuleIssueV2> ValidateModuleEx(
bool validateDependencies = true)
{
var visited = new HashSet<ModuleInfoExtended>();
foreach (var issue in ValidateModuleEx(modules, targetModule, visited, isSelected, isValid))
foreach (var issue in ValidateModuleEx(modules, targetModule, visited, isSelected, isValid, validateDependencies))
{
yield return issue;
}
Expand Down Expand Up @@ -427,7 +427,10 @@ private static IEnumerable<ModuleIssueV2> ValidateModuleDependenciesEx(

if (!modules.Any(x => string.Equals(x.Id, metadata.Id, StringComparison.Ordinal)))
{
if (metadata.Version != ApplicationVersion.Empty)
// For BLSE, there is a special case,
if (metadata.Id is "BLSE.LoadingInterceptor" or "BLSE.AssemblyResolver")
yield return new ModuleMissingBLSEDependencyIssue(targetModule, metadata);
else if (metadata.Version != ApplicationVersion.Empty)
yield return new ModuleMissingExactVersionDependencyIssue(targetModule, metadata);
else if (metadata.VersionRange != ApplicationVersionRange.Empty)
yield return new ModuleMissingVersionRangeDependencyIssue(targetModule, metadata);
Expand Down Expand Up @@ -600,8 +603,12 @@ public static IEnumerable<ModuleIssueV2> 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);

// 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);
Expand Down

0 comments on commit 3a8a313

Please sign in to comment.