diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 2865d4f4d..6f1ffdb04 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -556,7 +556,12 @@ internal partial class PluginManager : IDisposable, IServiceType public async Task ReloadPluginMastersAsync(bool notify = true) { Log.Information("Now reloading all PluginMasters..."); - await Task.WhenAll(this.Repos.Select(repo => repo.ReloadPluginMasterAsync())); + + Debug.Assert(!this.Repos.First().IsThirdParty, "First repository should be main repository"); + await this.Repos.First().ReloadPluginMasterAsync(); // Load official repo first + + await Task.WhenAll(this.Repos.Skip(1).Select(repo => repo.ReloadPluginMasterAsync())); + Log.Information("PluginMasters reloaded, now refiltering..."); this.RefilterPluginMasters(notify); @@ -730,6 +735,13 @@ internal partial class PluginManager : IDisposable, IServiceType // Reload as a local manifest, add some attributes, and save again. var manifest = LocalPluginManifest.Load(manifestFile); + if (manifest.InternalName != repoManifest.InternalName) + { + Directory.Delete(outputDir.FullName, true); + throw new Exception( + $"Distributed internal name does not match repo internal name: {manifest.InternalName} - {repoManifest.InternalName}"); + } + if (useTesting) { manifest.Testing = true; diff --git a/Dalamud/Plugin/Internal/Types/PluginRepository.cs b/Dalamud/Plugin/Internal/Types/PluginRepository.cs index 5c7659d90..e0373ff33 100644 --- a/Dalamud/Plugin/Internal/Types/PluginRepository.cs +++ b/Dalamud/Plugin/Internal/Types/PluginRepository.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; @@ -108,6 +110,35 @@ internal class PluginRepository manifest.SourceRepo = this; } + var pm = Service.Get(); + var official = pm.Repos.First(); + Debug.Assert(!official.IsThirdParty, "First repository should be official repository"); + + if (official.State == PluginRepositoryState.Success && this.IsThirdParty) + { + pluginMaster = pluginMaster.Where(thisRepoEntry => + { + if (official.PluginMaster!.Any(officialRepoEntry => + string.Equals(thisRepoEntry.InternalName, officialRepoEntry.InternalName, StringComparison.InvariantCultureIgnoreCase))) + { + Log.Warning( + "The repository {RepoName} tried to replace the plugin {PluginName}, which is already installed through the official repo - this is no longer allowed for security reasons. " + + "Please reach out if you have an use case for this.", + this.PluginMasterUrl, + thisRepoEntry.InternalName); + return false; + } + + return true; + }).ToList(); + } + else if (this.IsThirdParty) + { + Log.Warning("Official repository not loaded - couldn't check for overrides!"); + this.State = PluginRepositoryState.Fail; + return; + } + this.PluginMaster = pluginMaster.AsReadOnly(); Log.Information($"Successfully fetched repo: {this.PluginMasterUrl}");