Skip to content

Commit

Permalink
fix: testing API level being ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
Aireil committed Oct 6, 2023
1 parent 392d9ac commit 4004f46
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,8 @@ private void DrawAvailablePlugin(RemotePluginManifest manifest, int index)
var useTesting = pluginManager.UseTesting(manifest);
var wasSeen = this.WasPluginSeen(manifest.InternalName);

var isOutdated = manifest.DalamudApiLevel < PluginManager.DalamudApiLevel;
var effectiveApiLevel = useTesting ? manifest.TestingDalamudApiLevel : manifest.DalamudApiLevel;
var isOutdated = effectiveApiLevel < PluginManager.DalamudApiLevel;

// Check for valid versions
if ((useTesting && manifest.TestingAssemblyVersion == null) || manifest.AssemblyVersion == null)
Expand Down Expand Up @@ -2220,7 +2221,8 @@ private void DrawInstalledPlugin(LocalPlugin plugin, int index, bool showInstall
var canFeedback = !isThirdParty &&
!plugin.IsDev &&
!plugin.IsOrphaned &&
plugin.Manifest.DalamudApiLevel == PluginManager.DalamudApiLevel &&
(plugin.Manifest.DalamudApiLevel == PluginManager.DalamudApiLevel
|| plugin.Manifest.TestingDalamudApiLevel == PluginManager.DalamudApiLevel) &&
acceptsFeedback &&
availablePluginUpdate == default;

Expand Down Expand Up @@ -3002,7 +3004,9 @@ private bool IsManifestFiltered(IPluginManifest manifest)
var searchString = this.searchText.ToLowerInvariant();
var matcher = new FuzzyMatcher(searchString, MatchMode.FuzzyParts);
var hasSearchString = !string.IsNullOrWhiteSpace(this.searchText);
var oldApi = manifest.DalamudApiLevel < PluginManager.DalamudApiLevel;
var oldApi = (manifest.TestingDalamudApiLevel == null
|| manifest.TestingDalamudApiLevel < PluginManager.DalamudApiLevel)
&& manifest.DalamudApiLevel < PluginManager.DalamudApiLevel;
var installed = this.IsManifestInstalled(manifest).IsInstalled;

if (oldApi && !hasSearchString && !installed)
Expand Down
16 changes: 13 additions & 3 deletions Dalamud/Plugin/Internal/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,9 @@ public bool IsManifestEligible(PluginManifest manifest)
}

// API level - we keep the API before this in the installer to show as "outdated"
if (manifest.DalamudApiLevel < DalamudApiLevel - 1 && !this.LoadAllApiLevels)
var pluginManager = Service<PluginManager>.Get();
var effectiveApiLevel = pluginManager.UseTesting(manifest) ? manifest.TestingDalamudApiLevel : manifest.DalamudApiLevel;
if (effectiveApiLevel < DalamudApiLevel - 1 && !this.LoadAllApiLevels)
{
Log.Verbose($"API Level: {manifest.InternalName} - {manifest.AssemblyVersion} - {manifest.TestingAssemblyVersion}");
return false;
Expand Down Expand Up @@ -1442,7 +1444,7 @@ private async Task<LocalPlugin> LoadPluginAsync(FileInfo dllFile, LocalPluginMan

if (plugin == null)
throw new Exception("Plugin was null when adding to list");

lock (this.pluginListLock)
{
this.installedPluginsList.Add(plugin);
Expand All @@ -1466,7 +1468,15 @@ private void DetectAvailablePluginUpdates()
var updates = this.AvailablePlugins
.Where(remoteManifest => plugin.Manifest.InternalName == remoteManifest.InternalName)
.Where(remoteManifest => plugin.Manifest.InstalledFromUrl == remoteManifest.SourceRepo.PluginMasterUrl || !remoteManifest.SourceRepo.IsThirdParty)
.Where(remoteManifest => remoteManifest.DalamudApiLevel == DalamudApiLevel)
.Where(remoteManifest =>
{
var useTesting = this.UseTesting(remoteManifest);
var candidateApiLevel = useTesting
? remoteManifest.TestingDalamudApiLevel
: remoteManifest.DalamudApiLevel;

return candidateApiLevel == DalamudApiLevel;
})
.Select(remoteManifest =>
{
var useTesting = this.UseTesting(remoteManifest);
Expand Down
4 changes: 2 additions & 2 deletions Dalamud/Plugin/Internal/Types/LocalPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public LocalPlugin(FileInfo dllFile, LocalPluginManifest manifest)
/// <summary>
/// Gets a value indicating whether this plugin's API level is out of date.
/// </summary>
public bool IsOutdated => this.manifest.DalamudApiLevel < PluginManager.DalamudApiLevel;
public bool IsOutdated => this.manifest.EffectiveApiLevel < PluginManager.DalamudApiLevel;

/// <summary>
/// Gets a value indicating whether the plugin is for testing use only.
Expand Down Expand Up @@ -324,7 +324,7 @@ public async Task LoadAsync(PluginLoadReason reason, bool reloading = false)
if (this.manifest.ApplicableVersion < dalamud.StartInfo.GameVersion)
throw new InvalidPluginOperationException($"Unable to load {this.Name}, no applicable version");

if (this.manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels)
if (this.manifest.EffectiveApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels)
throw new InvalidPluginOperationException($"Unable to load {this.Name}, incompatible API level");

// We might want to throw here?
Expand Down
10 changes: 8 additions & 2 deletions Dalamud/Plugin/Internal/Types/Manifest/IPluginManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ public interface IPluginManifest
public List<string>? Tags { get; }

/// <summary>
/// Gets the API level of this plugin. For the current API level, please see <see cref="PluginManager.DalamudApiLevel"/>
/// for the currently used API level.
/// Gets the API level of this plugin.
/// For the current API level, please see <see cref="PluginManager.DalamudApiLevel"/> for the currently used API level.
/// </summary>
public int DalamudApiLevel { get; }

/// <summary>
/// Gets the API level of the plugin's testing variant.
/// For the current API level, please see <see cref="PluginManager.DalamudApiLevel"/> for the currently used API level.
/// </summary>
public int? TestingDalamudApiLevel { get; }

/// <summary>
/// Gets the number of downloads this plugin has.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Dalamud/Plugin/Internal/Types/Manifest/LocalPluginManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ internal record LocalPluginManifest : PluginManifest, ILocalPluginManifest
/// </summary>
public Version EffectiveVersion => this.Testing && this.TestingAssemblyVersion != null ? this.TestingAssemblyVersion : this.AssemblyVersion;

/// <summary>
/// Gets the effective API level of this plugin.
/// </summary>
public int EffectiveApiLevel => this.Testing && this.TestingDalamudApiLevel != null ? this.TestingDalamudApiLevel.Value : this.DalamudApiLevel;

/// <summary>
/// Save a plugin manifest to file.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Dalamud/Plugin/Internal/Types/PluginManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ internal record PluginManifest : IPluginManifest
[JsonProperty]
public int DalamudApiLevel { get; init; } = PluginManager.DalamudApiLevel;

/// <inheritdoc/>
[JsonProperty]
public int? TestingDalamudApiLevel { get; init; }

/// <inheritdoc/>
[JsonProperty]
public long DownloadCount { get; init; }
Expand Down

0 comments on commit 4004f46

Please sign in to comment.