Merge pull request #2416 from Haselnussbomber/fix-testing-api-level

Fix for testing plugins with older stable releases
This commit is contained in:
goat 2025-11-04 20:36:49 +01:00 committed by GitHub
commit 32e04458c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 48 additions and 57 deletions

View file

@ -278,26 +278,6 @@ internal class PluginManager : IInternalDisposableService
return !manifest.IsHide;
}
/// <summary>
/// Check if a manifest even has an available testing version.
/// </summary>
/// <param name="manifest">The manifest to test.</param>
/// <returns>Whether a testing version is available.</returns>
public static bool HasTestingVersion(IPluginManifest manifest)
{
var av = manifest.AssemblyVersion;
var tv = manifest.TestingAssemblyVersion;
var hasTv = tv != null;
if (hasTv)
{
return tv > av &&
manifest.TestingDalamudApiLevel == DalamudApiLevel;
}
return false;
}
/// <summary>
/// Get a disposable that will lock plugin lists while it is not disposed.
/// You must NEVER use this in async code.
@ -371,6 +351,20 @@ internal class PluginManager : IInternalDisposableService
return this.configuration.PluginTestingOptIns!.Any(x => x.InternalName == manifest.InternalName);
}
/// <summary>
/// For a given manifest, determine if the testing version can be used over the normal version.
/// The higher of the two versions is calculated after checking other settings.
/// </summary>
/// <param name="manifest">Manifest to check.</param>
/// <returns>A value indicating whether testing can be used.</returns>
public bool CanUseTesting(IPluginManifest manifest)
{
if (!this.configuration.DoPluginTest)
return false;
return manifest.IsTestingExclusive || manifest.IsAvailableForTesting;
}
/// <summary>
/// For a given manifest, determine if the testing version should be used over the normal version.
/// The higher of the two versions is calculated after checking other settings.
@ -379,16 +373,7 @@ internal class PluginManager : IInternalDisposableService
/// <returns>A value indicating whether testing should be used.</returns>
public bool UseTesting(IPluginManifest manifest)
{
if (!this.configuration.DoPluginTest)
return false;
if (!this.HasTestingOptIn(manifest))
return false;
if (manifest.IsTestingExclusive)
return true;
return HasTestingVersion(manifest);
return this.CanUseTesting(manifest) && this.HasTestingOptIn(manifest);
}
/// <inheritdoc/>
@ -1208,9 +1193,18 @@ internal class PluginManager : IInternalDisposableService
return false;
// API level - we keep the API before this in the installer to show as "outdated"
var effectiveApiLevel = this.UseTesting(manifest) && manifest.TestingDalamudApiLevel != null ? manifest.TestingDalamudApiLevel.Value : manifest.DalamudApiLevel;
if (effectiveApiLevel < DalamudApiLevel - 1 && !this.LoadAllApiLevels)
return false;
if (!this.LoadAllApiLevels)
{
var effectiveDalamudApiLevel =
this.CanUseTesting(manifest) &&
manifest.TestingDalamudApiLevel.HasValue &&
manifest.TestingDalamudApiLevel.Value > manifest.DalamudApiLevel
? manifest.TestingDalamudApiLevel.Value
: manifest.DalamudApiLevel;
if (effectiveDalamudApiLevel < PluginManager.DalamudApiLevel - 1)
return false;
}
// Banned
if (this.IsManifestBanned(manifest))

View file

@ -301,7 +301,7 @@ internal class LocalPlugin : IAsyncDisposable
throw new PluginPreconditionFailedException($"Unable to load {this.Name}, game is newer than applicable version {this.manifest.ApplicableVersion}");
// We want to allow loading dev plugins with a lower API level than the current Dalamud API level, for ease of development
if (this.manifest.EffectiveApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels && !this.IsDev)
if (!pluginManager.LoadAllApiLevels && !this.IsDev && this.manifest.EffectiveApiLevel < PluginManager.DalamudApiLevel)
throw new PluginPreconditionFailedException($"Unable to load {this.Name}, incompatible API level {this.manifest.EffectiveApiLevel}");
// We might want to throw here?

View file

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
namespace Dalamud.Plugin.Internal.Types.Manifest;
@ -118,4 +118,9 @@ public interface IPluginManifest
/// Gets an URL for the plugin's icon.
/// </summary>
public string? IconUrl { get; }
/// <summary>
/// Gets a value indicating whether this plugin is eligible for testing.
/// </summary>
public bool IsAvailableForTesting { get; }
}

View file

@ -21,9 +21,4 @@ internal record RemotePluginManifest : PluginManifest
/// Gets or sets the changelog to be shown when obtaining the testing version of the plugin.
/// </summary>
public string? TestingChangelog { get; set; }
/// <summary>
/// Gets a value indicating whether this plugin is eligible for testing.
/// </summary>
public bool IsAvailableForTesting => this.TestingAssemblyVersion != null && this.TestingAssemblyVersion > this.AssemblyVersion;
}

View file

@ -160,4 +160,11 @@ internal record PluginManifest : IPluginManifest
/// <inheritdoc/>
[JsonProperty("_Dip17Channel")]
public string? Dip17Channel { get; init; }
/// <inheritdoc/>
[JsonIgnore]
public bool IsAvailableForTesting
=> this.TestingAssemblyVersion != null &&
this.TestingAssemblyVersion > this.AssemblyVersion &&
this.TestingDalamudApiLevel == PluginManager.DalamudApiLevel;
}