mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
fix: don't save manifests every time a plugin loads, note reason for save if save fails
This commit is contained in:
parent
1443c751f5
commit
22a764ed82
3 changed files with 36 additions and 11 deletions
|
|
@ -865,7 +865,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
||||||
// Document the url the plugin was installed from
|
// Document the url the plugin was installed from
|
||||||
manifest.InstalledFromUrl = repoManifest.SourceRepo.IsThirdParty ? repoManifest.SourceRepo.PluginMasterUrl : LocalPluginManifest.FlagMainRepo;
|
manifest.InstalledFromUrl = repoManifest.SourceRepo.IsThirdParty ? repoManifest.SourceRepo.PluginMasterUrl : LocalPluginManifest.FlagMainRepo;
|
||||||
|
|
||||||
manifest.Save(manifestFile);
|
manifest.Save(manifestFile, "installation");
|
||||||
|
|
||||||
Log.Information($"Installed plugin {manifest.Name} (testing={useTesting})");
|
Log.Information($"Installed plugin {manifest.Name} (testing={useTesting})");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,13 +125,15 @@ internal class LocalPlugin : IDisposable
|
||||||
|
|
||||||
// Save the manifest to disk so there won't be any problems later.
|
// Save the manifest to disk so there won't be any problems later.
|
||||||
// We'll update the name property after it can be retrieved from the instance.
|
// We'll update the name property after it can be retrieved from the instance.
|
||||||
this.Manifest.Save(this.manifestFile);
|
this.Manifest.Save(this.manifestFile, "manifest was null");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Manifest = manifest;
|
this.Manifest = manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var needsSaveDueToLegacyFiles = false;
|
||||||
|
|
||||||
// This converts from the ".disabled" file feature to the manifest instead.
|
// This converts from the ".disabled" file feature to the manifest instead.
|
||||||
this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile);
|
this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile);
|
||||||
if (this.disabledFile.Exists)
|
if (this.disabledFile.Exists)
|
||||||
|
|
@ -140,6 +142,8 @@ internal class LocalPlugin : IDisposable
|
||||||
this.Manifest.Disabled = true;
|
this.Manifest.Disabled = true;
|
||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
this.disabledFile.Delete();
|
this.disabledFile.Delete();
|
||||||
|
|
||||||
|
needsSaveDueToLegacyFiles = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This converts from the ".testing" file feature to the manifest instead.
|
// This converts from the ".testing" file feature to the manifest instead.
|
||||||
|
|
@ -148,13 +152,16 @@ internal class LocalPlugin : IDisposable
|
||||||
{
|
{
|
||||||
this.Manifest.Testing = true;
|
this.Manifest.Testing = true;
|
||||||
this.testingFile.Delete();
|
this.testingFile.Delete();
|
||||||
|
|
||||||
|
needsSaveDueToLegacyFiles = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluginManager = Service<PluginManager>.Get();
|
var pluginManager = Service<PluginManager>.Get();
|
||||||
this.IsBanned = pluginManager.IsManifestBanned(this.Manifest) && !this.IsDev;
|
this.IsBanned = pluginManager.IsManifestBanned(this.Manifest) && !this.IsDev;
|
||||||
this.BanReason = pluginManager.GetBanReason(this.Manifest);
|
this.BanReason = pluginManager.GetBanReason(this.Manifest);
|
||||||
|
|
||||||
this.SaveManifest();
|
if (needsSaveDueToLegacyFiles)
|
||||||
|
this.SaveManifest("legacy");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -322,8 +329,11 @@ internal class LocalPlugin : IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reload a plugin we don't want to delete it. Makes sense, right?
|
// If we reload a plugin we don't want to delete it. Makes sense, right?
|
||||||
this.Manifest.ScheduledForDeletion = false;
|
if (this.Manifest.ScheduledForDeletion)
|
||||||
this.SaveManifest();
|
{
|
||||||
|
this.Manifest.ScheduledForDeletion = false;
|
||||||
|
this.SaveManifest("Scheduled for deletion, but loading");
|
||||||
|
}
|
||||||
|
|
||||||
switch (this.State)
|
switch (this.State)
|
||||||
{
|
{
|
||||||
|
|
@ -470,10 +480,10 @@ internal class LocalPlugin : IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
// In-case the manifest name was a placeholder. Can occur when no manifest was included.
|
// In-case the manifest name was a placeholder. Can occur when no manifest was included.
|
||||||
if (this.Manifest.Name.IsNullOrEmpty())
|
if (this.Manifest.Name.IsNullOrEmpty() && !this.IsDev)
|
||||||
{
|
{
|
||||||
this.Manifest.Name = this.instance.Name;
|
this.Manifest.Name = this.instance.Name;
|
||||||
this.Manifest.Save(this.manifestFile);
|
this.Manifest.Save(this.manifestFile, "manifest name null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.State = PluginState.Loaded;
|
this.State = PluginState.Loaded;
|
||||||
|
|
@ -618,7 +628,7 @@ internal class LocalPlugin : IDisposable
|
||||||
public void ScheduleDeletion(bool status = true)
|
public void ScheduleDeletion(bool status = true)
|
||||||
{
|
{
|
||||||
this.Manifest.ScheduledForDeletion = status;
|
this.Manifest.ScheduledForDeletion = status;
|
||||||
this.SaveManifest();
|
this.SaveManifest("scheduling for deletion");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -633,7 +643,7 @@ internal class LocalPlugin : IDisposable
|
||||||
this.Manifest = LocalPluginManifest.Load(manifest) ?? throw new Exception("Could not reload manifest.");
|
this.Manifest = LocalPluginManifest.Load(manifest) ?? throw new Exception("Could not reload manifest.");
|
||||||
// this.Manifest.Disabled = isDisabled;
|
// this.Manifest.Disabled = isDisabled;
|
||||||
|
|
||||||
this.SaveManifest();
|
this.SaveManifest("dev reload");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -665,5 +675,5 @@ internal class LocalPlugin : IDisposable
|
||||||
config.SharedAssemblies.Add(typeof(Lumina.Excel.ExcelSheetImpl).Assembly.GetName());
|
config.SharedAssemblies.Add(typeof(Lumina.Excel.ExcelSheetImpl).Assembly.GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveManifest() => this.Manifest.Save(this.manifestFile);
|
private void SaveManifest(string reason) => this.Manifest.Save(this.manifestFile, reason);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
|
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.Plugin.Internal.Types;
|
namespace Dalamud.Plugin.Internal.Types;
|
||||||
|
|
||||||
|
|
@ -69,7 +70,21 @@ internal record LocalPluginManifest : PluginManifest
|
||||||
/// Save a plugin manifest to file.
|
/// Save a plugin manifest to file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="manifestFile">Path to save at.</param>
|
/// <param name="manifestFile">Path to save at.</param>
|
||||||
public void Save(FileInfo manifestFile) => Util.WriteAllTextSafe(manifestFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented));
|
/// <param name="reason">The reason the manifest was saved.</param>
|
||||||
|
public void Save(FileInfo manifestFile, string reason)
|
||||||
|
{
|
||||||
|
Log.Verbose("Saving manifest for '{PluginName}' because '{Reason}'", this.InternalName, reason);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Util.WriteAllTextSafe(manifestFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Log.Error("Could not write out manifest for '{PluginName}' because '{Reason}'", this.InternalName, reason);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads a plugin manifest from file.
|
/// Loads a plugin manifest from file.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue