mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Merge pull request #1614 from goaaats/wpid_profiles
Use WorkingPluginId as identifier for plugins, take 2
This commit is contained in:
commit
f338c470e2
12 changed files with 516 additions and 187 deletions
|
|
@ -63,41 +63,48 @@ public enum DalamudAsset
|
|||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "troubleIcon.png")]
|
||||
TroubleIcon = 1006,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.TextureFromPng"/>: The plugin trouble icon overlay.
|
||||
/// </summary>
|
||||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "devPluginIcon.png")]
|
||||
DevPluginIcon = 1007,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.TextureFromPng"/>: The plugin update icon overlay.
|
||||
/// </summary>
|
||||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "updateIcon.png")]
|
||||
UpdateIcon = 1007,
|
||||
UpdateIcon = 1008,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.TextureFromPng"/>: The plugin installed icon overlay.
|
||||
/// </summary>
|
||||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "installedIcon.png")]
|
||||
InstalledIcon = 1008,
|
||||
InstalledIcon = 1009,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.TextureFromPng"/>: The third party plugin icon overlay.
|
||||
/// </summary>
|
||||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "thirdIcon.png")]
|
||||
ThirdIcon = 1009,
|
||||
ThirdIcon = 1010,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.TextureFromPng"/>: The installed third party plugin icon overlay.
|
||||
/// </summary>
|
||||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "thirdInstalledIcon.png")]
|
||||
ThirdInstalledIcon = 1010,
|
||||
ThirdInstalledIcon = 1011,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.TextureFromPng"/>: The API bump explainer icon.
|
||||
/// </summary>
|
||||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "changelogApiBump.png")]
|
||||
ChangelogApiBumpIcon = 1011,
|
||||
ChangelogApiBumpIcon = 1012,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.TextureFromPng"/>: The background shade for
|
||||
|
|
@ -105,7 +112,7 @@ public enum DalamudAsset
|
|||
/// </summary>
|
||||
[DalamudAsset(DalamudAssetPurpose.TextureFromPng)]
|
||||
[DalamudAssetPath("UIRes", "tsmShade.png")]
|
||||
TitleScreenMenuShade = 1012,
|
||||
TitleScreenMenuShade = 1013,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DalamudAssetPurpose.Font"/>: Noto Sans CJK JP Medium.
|
||||
|
|
|
|||
|
|
@ -98,6 +98,12 @@ internal class PluginImageCache : IDisposable, IServiceType
|
|||
/// </summary>
|
||||
public IDalamudTextureWrap TroubleIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.TroubleIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the devPlugin icon overlay.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap DevPluginIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.DevPluginIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin update icon overlay.
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
private int updatePluginCount = 0;
|
||||
private List<PluginUpdateStatus>? updatedPlugins;
|
||||
|
||||
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:Elements should appear in the correct order", Justification = "Makes sense like this")]
|
||||
private List<RemotePluginManifest> pluginListAvailable = new();
|
||||
private List<LocalPlugin> pluginListInstalled = new();
|
||||
private List<AvailablePluginUpdate> pluginListUpdatable = new();
|
||||
|
|
@ -1126,45 +1127,79 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
this.DrawChangelog(logEntry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private record PluginInstallerAvailablePluginProxy(RemotePluginManifest? RemoteManifest, LocalPlugin? LocalPlugin);
|
||||
|
||||
#pragma warning disable SA1201
|
||||
private void DrawAvailablePluginList()
|
||||
#pragma warning restore SA1201
|
||||
{
|
||||
var pluginList = this.pluginListAvailable;
|
||||
var availableManifests = this.pluginListAvailable;
|
||||
var installedPlugins = this.pluginListInstalled.ToList(); // Copy intended
|
||||
|
||||
if (pluginList.Count == 0)
|
||||
if (availableManifests.Count == 0)
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey, Locs.TabBody_SearchNoCompatible);
|
||||
return;
|
||||
}
|
||||
|
||||
var filteredManifests = pluginList
|
||||
var filteredAvailableManifests = availableManifests
|
||||
.Where(rm => !this.IsManifestFiltered(rm))
|
||||
.ToList();
|
||||
|
||||
if (filteredManifests.Count == 0)
|
||||
if (filteredAvailableManifests.Count == 0)
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey2, Locs.TabBody_SearchNoMatching);
|
||||
return;
|
||||
}
|
||||
|
||||
// get list to show and reset category dirty flag
|
||||
var categoryManifestsList = this.categoryManager.GetCurrentCategoryContent(filteredManifests);
|
||||
var proxies = new List<PluginInstallerAvailablePluginProxy>();
|
||||
|
||||
// Go through all AVAILABLE manifests, associate them with a NON-DEV local plugin, if one is available, and remove it from the pile
|
||||
foreach (var availableManifest in this.categoryManager.GetCurrentCategoryContent(filteredAvailableManifests).Cast<RemotePluginManifest>())
|
||||
{
|
||||
var plugin = this.pluginListInstalled.FirstOrDefault(plugin => plugin.Manifest.InternalName == availableManifest.InternalName && plugin.Manifest.RepoUrl == availableManifest.RepoUrl);
|
||||
|
||||
// We "consumed" this plugin from the pile and remove it.
|
||||
if (plugin != null && !plugin.IsDev)
|
||||
{
|
||||
installedPlugins.Remove(plugin);
|
||||
proxies.Add(new PluginInstallerAvailablePluginProxy(null, plugin));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
proxies.Add(new PluginInstallerAvailablePluginProxy(availableManifest, null));
|
||||
}
|
||||
|
||||
// Now, add all applicable local plugins that haven't been "used up", in most cases either dev or orphaned plugins.
|
||||
foreach (var installedPlugin in installedPlugins)
|
||||
{
|
||||
if (this.IsManifestFiltered(installedPlugin.Manifest))
|
||||
continue;
|
||||
|
||||
// TODO: We should also check categories here, for good measure
|
||||
|
||||
proxies.Add(new PluginInstallerAvailablePluginProxy(null, installedPlugin));
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
foreach (var manifest in categoryManifestsList)
|
||||
foreach (var proxy in proxies)
|
||||
{
|
||||
if (manifest is not RemotePluginManifest remoteManifest)
|
||||
continue;
|
||||
var (isInstalled, plugin) = this.IsManifestInstalled(remoteManifest);
|
||||
IPluginManifest applicableManifest = proxy.LocalPlugin != null ? proxy.LocalPlugin.Manifest : proxy.RemoteManifest;
|
||||
|
||||
ImGui.PushID($"{manifest.InternalName}{manifest.AssemblyVersion}");
|
||||
if (isInstalled)
|
||||
if (applicableManifest == null)
|
||||
throw new Exception("Could not determine manifest for available plugin");
|
||||
|
||||
ImGui.PushID($"{applicableManifest.InternalName}{applicableManifest.AssemblyVersion}");
|
||||
|
||||
if (proxy.LocalPlugin != null)
|
||||
{
|
||||
this.DrawInstalledPlugin(plugin, i++, true);
|
||||
this.DrawInstalledPlugin(proxy.LocalPlugin, i++, true);
|
||||
}
|
||||
else
|
||||
else if (proxy.RemoteManifest != null)
|
||||
{
|
||||
this.DrawAvailablePlugin(remoteManifest, i++);
|
||||
this.DrawAvailablePlugin(proxy.RemoteManifest, i++);
|
||||
}
|
||||
|
||||
ImGui.PopID();
|
||||
|
|
@ -1828,8 +1863,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
// Name
|
||||
ImGui.TextUnformatted(label);
|
||||
|
||||
// Verified Checkmark, don't show for dev plugins
|
||||
if (plugin is null or { IsDev: false })
|
||||
// Verified Checkmark or dev plugin wrench
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(" ");
|
||||
|
|
@ -1839,8 +1873,15 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
var unverifiedOutlineColor = KnownColor.Black.Vector();
|
||||
var verifiedIconColor = KnownColor.RoyalBlue.Vector() with { W = 0.75f };
|
||||
var unverifiedIconColor = KnownColor.Orange.Vector();
|
||||
|
||||
if (!isThirdParty)
|
||||
var devIconOutlineColor = KnownColor.White.Vector();
|
||||
var devIconColor = KnownColor.MediumOrchid.Vector();
|
||||
|
||||
if (plugin is LocalDevPlugin)
|
||||
{
|
||||
this.DrawFontawesomeIconOutlined(FontAwesomeIcon.Wrench, devIconOutlineColor, devIconColor);
|
||||
this.VerifiedCheckmarkFadeTooltip(label, "This is a dev plugin. You added it.");
|
||||
}
|
||||
else if (!isThirdParty)
|
||||
{
|
||||
this.DrawFontawesomeIconOutlined(FontAwesomeIcon.CheckCircle, verifiedOutlineColor, verifiedIconColor);
|
||||
this.VerifiedCheckmarkFadeTooltip(label, Locs.VerifiedCheckmark_VerifiedTooltip);
|
||||
|
|
@ -1873,16 +1914,32 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
if (plugin is { IsOutdated: true, IsBanned: false } || installableOutdated)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
ImGui.TextWrapped(Locs.PluginBody_Outdated);
|
||||
|
||||
var bodyText = Locs.PluginBody_Outdated + " ";
|
||||
if (updateAvailable)
|
||||
bodyText += Locs.PluginBody_Outdated_CanNowUpdate;
|
||||
else
|
||||
bodyText += Locs.PluginBody_Outdated_WaitForUpdate;
|
||||
|
||||
ImGui.TextWrapped(bodyText);
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
else if (plugin is { IsBanned: true })
|
||||
{
|
||||
// Banned warning
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
ImGuiHelpers.SafeTextWrapped(plugin.BanReason.IsNullOrEmpty()
|
||||
? Locs.PluginBody_Banned
|
||||
: Locs.PluginBody_BannedReason(plugin.BanReason));
|
||||
|
||||
var bodyText = plugin.BanReason.IsNullOrEmpty()
|
||||
? Locs.PluginBody_Banned
|
||||
: Locs.PluginBody_BannedReason(plugin.BanReason);
|
||||
bodyText += " ";
|
||||
|
||||
if (updateAvailable)
|
||||
bodyText += Locs.PluginBody_Outdated_CanNowUpdate;
|
||||
else
|
||||
bodyText += Locs.PluginBody_Outdated_WaitForUpdate;
|
||||
|
||||
ImGuiHelpers.SafeTextWrapped(bodyText);
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
|
@ -2238,6 +2295,11 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
}
|
||||
|
||||
var availablePluginUpdate = this.pluginListUpdatable.FirstOrDefault(up => up.InstalledPlugin == plugin);
|
||||
|
||||
// Dev plugins can never update
|
||||
if (plugin.IsDev)
|
||||
availablePluginUpdate = null;
|
||||
|
||||
// Update available
|
||||
if (availablePluginUpdate != default)
|
||||
{
|
||||
|
|
@ -2526,12 +2588,12 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
var profileManager = Service<ProfileManager>.Get();
|
||||
var config = Service<DalamudConfiguration>.Get();
|
||||
|
||||
var applicableForProfiles = plugin.Manifest.SupportsProfiles && !plugin.IsDev;
|
||||
var applicableForProfiles = plugin.Manifest.SupportsProfiles /*&& !plugin.IsDev*/;
|
||||
var profilesThatWantThisPlugin = profileManager.Profiles
|
||||
.Where(x => x.WantsPlugin(plugin.InternalName) != null)
|
||||
.Where(x => x.WantsPlugin(plugin.Manifest.WorkingPluginId) != null)
|
||||
.ToArray();
|
||||
var isInSingleProfile = profilesThatWantThisPlugin.Length == 1;
|
||||
var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.Manifest.InternalName);
|
||||
var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.Manifest.WorkingPluginId);
|
||||
|
||||
// Disable everything if the updater is running or another plugin is operating
|
||||
var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress;
|
||||
|
|
@ -2566,17 +2628,17 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
|
||||
foreach (var profile in profileManager.Profiles.Where(x => !x.IsDefaultProfile))
|
||||
{
|
||||
var inProfile = profile.WantsPlugin(plugin.Manifest.InternalName) != null;
|
||||
var inProfile = profile.WantsPlugin(plugin.Manifest.WorkingPluginId) != null;
|
||||
if (ImGui.Checkbox($"###profilePick{profile.Guid}{plugin.Manifest.InternalName}", ref inProfile))
|
||||
{
|
||||
if (inProfile)
|
||||
{
|
||||
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.InternalName, true))
|
||||
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true))
|
||||
.ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotAdd);
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run(() => profile.RemoveAsync(plugin.Manifest.InternalName))
|
||||
Task.Run(() => profile.RemoveAsync(plugin.Manifest.WorkingPluginId))
|
||||
.ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotRemove);
|
||||
}
|
||||
}
|
||||
|
|
@ -2596,11 +2658,11 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Times))
|
||||
{
|
||||
// TODO: Work this out
|
||||
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.InternalName, plugin.IsLoaded, false))
|
||||
Task.Run(() => profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, plugin.IsLoaded, false))
|
||||
.GetAwaiter().GetResult();
|
||||
foreach (var profile in profileManager.Profiles.Where(x => !x.IsDefaultProfile && x.Plugins.Any(y => y.InternalName == plugin.Manifest.InternalName)))
|
||||
{
|
||||
Task.Run(() => profile.RemoveAsync(plugin.Manifest.InternalName, false))
|
||||
Task.Run(() => profile.RemoveAsync(plugin.Manifest.WorkingPluginId, false))
|
||||
.GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
|
@ -2674,7 +2736,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
{
|
||||
await plugin.UnloadAsync();
|
||||
await applicableProfile.AddOrUpdateAsync(
|
||||
plugin.Manifest.InternalName, false, false);
|
||||
plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, false, false);
|
||||
|
||||
notifications.AddNotification(Locs.Notifications_PluginDisabled(plugin.Manifest.Name), Locs.Notifications_PluginDisabledTitle, NotificationType.Success);
|
||||
}).ContinueWith(t =>
|
||||
|
|
@ -2691,7 +2753,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
this.loadingIndicatorKind = LoadingIndicatorKind.EnablingSingle;
|
||||
this.enableDisableWorkingPluginId = plugin.Manifest.WorkingPluginId;
|
||||
|
||||
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.InternalName, true, false);
|
||||
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true, false);
|
||||
await plugin.LoadAsync(PluginLoadReason.Installer);
|
||||
|
||||
notifications.AddNotification(Locs.Notifications_PluginEnabled(plugin.Manifest.Name), Locs.Notifications_PluginEnabledTitle, NotificationType.Success);
|
||||
|
|
@ -2712,7 +2774,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
if (shouldUpdate)
|
||||
{
|
||||
// We need to update the profile right here, because PM will not enable the plugin otherwise
|
||||
await applicableProfile.AddOrUpdateAsync(plugin.InternalName, true, false);
|
||||
await applicableProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true, false);
|
||||
await this.UpdateSinglePlugin(availableUpdate);
|
||||
}
|
||||
else
|
||||
|
|
@ -2893,7 +2955,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
if (localPlugin is LocalDevPlugin plugin)
|
||||
{
|
||||
var isInDefaultProfile =
|
||||
Service<ProfileManager>.Get().IsInDefaultProfile(localPlugin.Manifest.InternalName);
|
||||
Service<ProfileManager>.Get().IsInDefaultProfile(localPlugin.Manifest.WorkingPluginId);
|
||||
|
||||
// https://colorswall.com/palette/2868/
|
||||
var greenColor = new Vector4(0x5C, 0xB8, 0x5C, 0xFF) / 0xFF;
|
||||
|
|
@ -3237,7 +3299,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
this.pluginListAvailable.Sort((p1, p2) => p1.Name.CompareTo(p2.Name));
|
||||
|
||||
var profman = Service<ProfileManager>.Get();
|
||||
this.pluginListInstalled.Sort((p1, p2) => profman.IsInDefaultProfile(p1.InternalName).CompareTo(profman.IsInDefaultProfile(p2.InternalName)));
|
||||
this.pluginListInstalled.Sort((p1, p2) => profman.IsInDefaultProfile(p1.Manifest.WorkingPluginId).CompareTo(profman.IsInDefaultProfile(p2.Manifest.WorkingPluginId)));
|
||||
break;
|
||||
default:
|
||||
throw new InvalidEnumArgumentException("Unknown plugin sort type.");
|
||||
|
|
@ -3484,7 +3546,11 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
|
||||
public static string PluginBody_Plugin3rdPartyRepo(string url) => Loc.Localize("InstallerPlugin3rdPartyRepo", "From custom plugin repository {0}").Format(url);
|
||||
|
||||
public static string PluginBody_Outdated => Loc.Localize("InstallerOutdatedPluginBody ", "This plugin is outdated and incompatible at the moment. Please wait for it to be updated by its author.");
|
||||
public static string PluginBody_Outdated => Loc.Localize("InstallerOutdatedPluginBody ", "This plugin is outdated and incompatible.");
|
||||
|
||||
public static string PluginBody_Outdated_WaitForUpdate => Loc.Localize("InstallerOutdatedWaitForUpdate", "Please wait for it to be updated by its author.");
|
||||
|
||||
public static string PluginBody_Outdated_CanNowUpdate => Loc.Localize("InstallerOutdatedCanNowUpdate", "An update is available for installation.");
|
||||
|
||||
public static string PluginBody_Orphaned => Loc.Localize("InstallerOrphanedPluginBody ", "This plugin's source repository is no longer available. You may need to reinstall it from its repository, or re-add the repository.");
|
||||
|
||||
|
|
@ -3494,7 +3560,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
|
||||
public static string PluginBody_LoadFailed => Loc.Localize("InstallerLoadFailedPluginBody ", "This plugin failed to load. Please contact the author for more information.");
|
||||
|
||||
public static string PluginBody_Banned => Loc.Localize("InstallerBannedPluginBody ", "This plugin was automatically disabled due to incompatibilities and is not available at the moment. Please wait for it to be updated by its author.");
|
||||
public static string PluginBody_Banned => Loc.Localize("InstallerBannedPluginBody ", "This plugin was automatically disabled due to incompatibilities and is not available.");
|
||||
|
||||
public static string PluginBody_Policy => Loc.Localize("InstallerPolicyPluginBody ", "Plugin loads for this type of plugin were manually disabled.");
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ using Dalamud.Interface.Utility;
|
|||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Plugin.Internal.Profiles;
|
||||
using Dalamud.Plugin.Internal.Types;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
|
|
@ -252,7 +253,7 @@ internal class ProfileManagerWidget
|
|||
|
||||
if (ImGuiComponents.IconButton($"###exportButton{profile.Guid}", FontAwesomeIcon.FileExport))
|
||||
{
|
||||
ImGui.SetClipboardText(profile.Model.Serialize());
|
||||
ImGui.SetClipboardText(profile.Model.SerializeForShare());
|
||||
Service<NotificationManager>.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
|
||||
}
|
||||
|
||||
|
|
@ -315,15 +316,15 @@ internal class ProfileManagerWidget
|
|||
if (ImGui.BeginListBox("###pluginPicker", new Vector2(width, width - 80)))
|
||||
{
|
||||
// TODO: Plugin searching should be abstracted... installer and this should use the same search
|
||||
foreach (var plugin in pm.InstalledPlugins.Where(x => x.Manifest.SupportsProfiles && !x.IsDev &&
|
||||
foreach (var plugin in pm.InstalledPlugins.Where(x => x.Manifest.SupportsProfiles &&
|
||||
(this.pickerSearch.IsNullOrWhitespace() || x.Manifest.Name.ToLowerInvariant().Contains(this.pickerSearch.ToLowerInvariant()))))
|
||||
{
|
||||
using var disabled2 =
|
||||
ImRaii.Disabled(profile.Plugins.Any(y => y.InternalName == plugin.Manifest.InternalName));
|
||||
|
||||
if (ImGui.Selectable($"{plugin.Manifest.Name}###selector{plugin.Manifest.InternalName}"))
|
||||
if (ImGui.Selectable($"{plugin.Manifest.Name}{(plugin is LocalDevPlugin ? "(dev plugin)" : string.Empty)}###selector{plugin.Manifest.InternalName}"))
|
||||
{
|
||||
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.InternalName, true, false))
|
||||
Task.Run(() => profile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true, false))
|
||||
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
|
||||
}
|
||||
}
|
||||
|
|
@ -350,7 +351,7 @@ internal class ProfileManagerWidget
|
|||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport))
|
||||
{
|
||||
ImGui.SetClipboardText(profile.Model.Serialize());
|
||||
ImGui.SetClipboardText(profile.Model.SerializeForShare());
|
||||
Service<NotificationManager>.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
|
||||
}
|
||||
|
||||
|
|
@ -423,24 +424,34 @@ internal class ProfileManagerWidget
|
|||
if (pluginListChild)
|
||||
{
|
||||
var pluginLineHeight = 32 * ImGuiHelpers.GlobalScale;
|
||||
string? wantRemovePluginInternalName = null;
|
||||
Guid? wantRemovePluginGuid = null;
|
||||
|
||||
using var syncScope = profile.GetSyncScope();
|
||||
foreach (var plugin in profile.Plugins.ToArray())
|
||||
foreach (var profileEntry in profile.Plugins.ToArray())
|
||||
{
|
||||
didAny = true;
|
||||
var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.InternalName == plugin.InternalName);
|
||||
var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.WorkingPluginId == profileEntry.WorkingPluginId);
|
||||
var btnOffset = 2;
|
||||
|
||||
if (pmPlugin != null)
|
||||
{
|
||||
var cursorBeforeIcon = ImGui.GetCursorPos();
|
||||
pic.TryGetIcon(pmPlugin, pmPlugin.Manifest, pmPlugin.IsThirdParty, out var icon);
|
||||
icon ??= pic.DefaultIcon;
|
||||
|
||||
ImGui.Image(icon.ImGuiHandle, new Vector2(pluginLineHeight));
|
||||
|
||||
if (pmPlugin.IsDev)
|
||||
{
|
||||
ImGui.SetCursorPos(cursorBeforeIcon);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.7f);
|
||||
ImGui.Image(pic.DevPluginIcon.ImGuiHandle, new Vector2(pluginLineHeight));
|
||||
ImGui.PopStyleVar();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
var text = $"{pmPlugin.Name}";
|
||||
var text = $"{pmPlugin.Name}{(pmPlugin.IsDev ? " (dev plugin" : string.Empty)}";
|
||||
var textHeight = ImGui.CalcTextSize(text);
|
||||
var before = ImGui.GetCursorPos();
|
||||
|
||||
|
|
@ -454,32 +465,53 @@ internal class ProfileManagerWidget
|
|||
ImGui.Image(pic.DefaultIcon.ImGuiHandle, new Vector2(pluginLineHeight));
|
||||
ImGui.SameLine();
|
||||
|
||||
var text = Locs.NotInstalled(plugin.InternalName);
|
||||
var text = Locs.NotInstalled(profileEntry.InternalName);
|
||||
var textHeight = ImGui.CalcTextSize(text);
|
||||
var before = ImGui.GetCursorPos();
|
||||
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (textHeight.Y / 2));
|
||||
ImGui.TextUnformatted(text);
|
||||
|
||||
var available =
|
||||
|
||||
var firstAvailableInstalled = pm.InstalledPlugins.FirstOrDefault(x => x.InternalName == profileEntry.InternalName);
|
||||
var installable =
|
||||
pm.AvailablePlugins.FirstOrDefault(
|
||||
x => x.InternalName == plugin.InternalName && !x.SourceRepo.IsThirdParty);
|
||||
if (available != null)
|
||||
x => x.InternalName == profileEntry.InternalName && !x.SourceRepo.IsThirdParty);
|
||||
|
||||
if (firstAvailableInstalled != null)
|
||||
{
|
||||
ImGui.Text($"Match to plugin '{firstAvailableInstalled.Name}'?");
|
||||
ImGui.SameLine();
|
||||
if (ImGuiComponents.IconButtonWithText(
|
||||
FontAwesomeIcon.Check,
|
||||
"Yes, use this one"))
|
||||
{
|
||||
profileEntry.WorkingPluginId = firstAvailableInstalled.Manifest.WorkingPluginId;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await profman.ApplyAllWantStatesAsync();
|
||||
})
|
||||
.ContinueWith(t =>
|
||||
{
|
||||
this.installer.DisplayErrorContinuation(t, Locs.ErrorCouldNotChangeState);
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (installable != null)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 2) - 2);
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (ImGui.GetFrameHeight() / 2));
|
||||
btnOffset = 3;
|
||||
|
||||
if (ImGuiComponents.IconButton($"###installMissingPlugin{available.InternalName}", FontAwesomeIcon.Download))
|
||||
if (ImGuiComponents.IconButton($"###installMissingPlugin{installable.InternalName}", FontAwesomeIcon.Download))
|
||||
{
|
||||
this.installer.StartInstall(available, false);
|
||||
this.installer.StartInstall(installable, false);
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.InstallPlugin);
|
||||
}
|
||||
|
||||
|
||||
ImGui.SetCursorPos(before);
|
||||
}
|
||||
|
||||
|
|
@ -487,10 +519,10 @@ internal class ProfileManagerWidget
|
|||
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30));
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (ImGui.GetFrameHeight() / 2));
|
||||
|
||||
var enabled = plugin.IsEnabled;
|
||||
if (ImGui.Checkbox($"###{this.editingProfileGuid}-{plugin.InternalName}", ref enabled))
|
||||
var enabled = profileEntry.IsEnabled;
|
||||
if (ImGui.Checkbox($"###{this.editingProfileGuid}-{profileEntry.InternalName}", ref enabled))
|
||||
{
|
||||
Task.Run(() => profile.AddOrUpdateAsync(plugin.InternalName, enabled))
|
||||
Task.Run(() => profile.AddOrUpdateAsync(profileEntry.WorkingPluginId, profileEntry.InternalName, enabled))
|
||||
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
|
||||
}
|
||||
|
||||
|
|
@ -498,19 +530,19 @@ internal class ProfileManagerWidget
|
|||
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * btnOffset) - 5);
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (ImGui.GetFrameHeight() / 2));
|
||||
|
||||
if (ImGuiComponents.IconButton($"###removePlugin{plugin.InternalName}", FontAwesomeIcon.Trash))
|
||||
if (ImGuiComponents.IconButton($"###removePlugin{profileEntry.InternalName}", FontAwesomeIcon.Trash))
|
||||
{
|
||||
wantRemovePluginInternalName = plugin.InternalName;
|
||||
wantRemovePluginGuid = profileEntry.WorkingPluginId;
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.RemovePlugin);
|
||||
}
|
||||
|
||||
if (wantRemovePluginInternalName != null)
|
||||
if (wantRemovePluginGuid != null)
|
||||
{
|
||||
// TODO: handle error
|
||||
Task.Run(() => profile.RemoveAsync(wantRemovePluginInternalName, false))
|
||||
Task.Run(() => profile.RemoveAsync(wantRemovePluginGuid.Value, false))
|
||||
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotRemove);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Verbose(string messageTemplate, params object[] values)
|
||||
public void Verbose(string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Verbose, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -43,7 +43,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Verbose(Exception exception, string messageTemplate, params object[] values)
|
||||
public void Verbose(Exception? exception, string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Verbose, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -52,7 +52,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Debug(string messageTemplate, params object[] values)
|
||||
public void Debug(string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Debug, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -62,7 +62,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Debug(Exception exception, string messageTemplate, params object[] values)
|
||||
public void Debug(Exception? exception, string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Debug, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -71,7 +71,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Information(string messageTemplate, params object[] values)
|
||||
public void Information(string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Information, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -81,7 +81,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Information(Exception exception, string messageTemplate, params object[] values)
|
||||
public void Information(Exception? exception, string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -90,7 +90,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Warning(string messageTemplate, params object[] values)
|
||||
public void Warning(string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Warning, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -100,7 +100,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Warning(Exception exception, string messageTemplate, params object[] values)
|
||||
public void Warning(Exception? exception, string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Warning, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -109,7 +109,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Error(string messageTemplate, params object[] values)
|
||||
public void Error(string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Error, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -119,7 +119,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Error(Exception? exception, string messageTemplate, params object[] values)
|
||||
public void Error(Exception? exception, string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Error, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -128,7 +128,7 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Fatal(string messageTemplate, params object[] values)
|
||||
public void Fatal(string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -138,12 +138,12 @@ public class ModuleLog
|
|||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public void Fatal(Exception exception, string messageTemplate, params object[] values)
|
||||
public void Fatal(Exception? exception, string messageTemplate, params object?[] values)
|
||||
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, exception, values);
|
||||
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
private void WriteLog(
|
||||
LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)
|
||||
LogEventLevel level, string messageTemplate, Exception? exception = null, params object?[] values)
|
||||
{
|
||||
// FIXME: Eventually, the `pluginName` tag should be removed from here and moved over to the actual log
|
||||
// formatter.
|
||||
|
|
|
|||
|
|
@ -664,6 +664,15 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
this.PluginsReady = true;
|
||||
this.NotifyinstalledPluginsListChanged();
|
||||
sigScanner.Save();
|
||||
|
||||
try
|
||||
{
|
||||
this.ParanoiaValidatePluginsAndProfiles();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Plugin and profile validation failed!");
|
||||
}
|
||||
},
|
||||
tokenSource.Token);
|
||||
}
|
||||
|
|
@ -1256,6 +1265,30 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if there are any inconsistencies with our plugins, their IDs, and our profiles.
|
||||
/// </summary>
|
||||
private void ParanoiaValidatePluginsAndProfiles()
|
||||
{
|
||||
var seenIds = new List<Guid>();
|
||||
|
||||
foreach (var installedPlugin in this.InstalledPlugins)
|
||||
{
|
||||
if (installedPlugin.Manifest.WorkingPluginId == Guid.Empty)
|
||||
throw new Exception($"{(installedPlugin is LocalDevPlugin ? "DevPlugin" : "Plugin")} '{installedPlugin.Manifest.InternalName}' has an empty WorkingPluginId.");
|
||||
|
||||
if (seenIds.Contains(installedPlugin.Manifest.WorkingPluginId))
|
||||
{
|
||||
throw new Exception(
|
||||
$"{(installedPlugin is LocalDevPlugin ? "DevPlugin" : "Plugin")} '{installedPlugin.Manifest.InternalName}' has a duplicate WorkingPluginId '{installedPlugin.Manifest.WorkingPluginId}'");
|
||||
}
|
||||
|
||||
seenIds.Add(installedPlugin.Manifest.WorkingPluginId);
|
||||
}
|
||||
|
||||
this.profileManager.ParanoiaValidateProfiles();
|
||||
}
|
||||
|
||||
private async Task<Stream> DownloadPluginAsync(RemotePluginManifest repoManifest, bool useTesting)
|
||||
{
|
||||
var downloadUrl = useTesting ? repoManifest.DownloadLinkTesting : repoManifest.DownloadLinkInstall;
|
||||
|
|
@ -1297,7 +1330,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
try
|
||||
{
|
||||
// We don't need to apply, it doesn't matter
|
||||
await this.profileManager.DefaultProfile.RemoveAsync(repoManifest.InternalName, false);
|
||||
await this.profileManager.DefaultProfile.RemoveByInternalNameAsync(repoManifest.InternalName, false);
|
||||
}
|
||||
catch (ProfileOperationException)
|
||||
{
|
||||
|
|
@ -1445,73 +1478,98 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
if (isDev)
|
||||
{
|
||||
Log.Information($"Loading dev plugin {name}");
|
||||
var devPlugin = new LocalDevPlugin(dllFile, manifest);
|
||||
loadPlugin &= !isBoot;
|
||||
|
||||
var probablyInternalNameForThisPurpose = manifest?.InternalName ?? dllFile.Name;
|
||||
|
||||
var wantsInDefaultProfile =
|
||||
this.profileManager.DefaultProfile.WantsPlugin(probablyInternalNameForThisPurpose);
|
||||
if (wantsInDefaultProfile == null)
|
||||
{
|
||||
// We don't know about this plugin, so we don't want to do anything here.
|
||||
// The code below will take care of it and add it with the default value.
|
||||
}
|
||||
else if (wantsInDefaultProfile == false && devPlugin.StartOnBoot)
|
||||
{
|
||||
// We didn't want this plugin, and StartOnBoot is on. That means we don't want it and it should stay off until manually enabled.
|
||||
Log.Verbose("DevPlugin {Name} disabled and StartOnBoot => disable", probablyInternalNameForThisPurpose);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(probablyInternalNameForThisPurpose, false, false);
|
||||
loadPlugin = false;
|
||||
}
|
||||
else if (wantsInDefaultProfile == true && devPlugin.StartOnBoot)
|
||||
{
|
||||
// We wanted this plugin, and StartOnBoot is on. That means we actually do want it.
|
||||
Log.Verbose("DevPlugin {Name} enabled and StartOnBoot => enable", probablyInternalNameForThisPurpose);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(probablyInternalNameForThisPurpose, true, false);
|
||||
loadPlugin = !doNotLoad;
|
||||
}
|
||||
else if (wantsInDefaultProfile == true && !devPlugin.StartOnBoot)
|
||||
{
|
||||
// We wanted this plugin, but StartOnBoot is off. This means we don't want it anymore.
|
||||
Log.Verbose("DevPlugin {Name} enabled and !StartOnBoot => disable", probablyInternalNameForThisPurpose);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(probablyInternalNameForThisPurpose, false, false);
|
||||
loadPlugin = false;
|
||||
}
|
||||
else if (wantsInDefaultProfile == false && !devPlugin.StartOnBoot)
|
||||
{
|
||||
// We didn't want this plugin, and StartOnBoot is off. We don't want it.
|
||||
Log.Verbose("DevPlugin {Name} disabled and !StartOnBoot => disable", probablyInternalNameForThisPurpose);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(probablyInternalNameForThisPurpose, false, false);
|
||||
loadPlugin = false;
|
||||
}
|
||||
|
||||
plugin = devPlugin;
|
||||
plugin = new LocalDevPlugin(dllFile, manifest);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information($"Loading plugin {name}");
|
||||
plugin = new LocalPlugin(dllFile, manifest);
|
||||
}
|
||||
|
||||
// Perform a migration from InternalName to GUIDs. The plugin should definitely have a GUID here.
|
||||
// This will also happen if you are installing a plugin with the installer, and that's intended!
|
||||
// It means that, if you have a profile which has unsatisfied plugins, installing a matching plugin will
|
||||
// enter it into the profiles it can match.
|
||||
if (plugin.Manifest.WorkingPluginId == Guid.Empty)
|
||||
throw new Exception("Plugin should have a WorkingPluginId at this point");
|
||||
this.profileManager.MigrateProfilesToGuidsForPlugin(plugin.Manifest.InternalName, plugin.Manifest.WorkingPluginId);
|
||||
|
||||
var wantedByAnyProfile = false;
|
||||
|
||||
// Now, if this is a devPlugin, figure out if we want to load it
|
||||
if (isDev)
|
||||
{
|
||||
var devPlugin = (LocalDevPlugin)plugin;
|
||||
loadPlugin &= !isBoot;
|
||||
|
||||
var wantsInDefaultProfile =
|
||||
this.profileManager.DefaultProfile.WantsPlugin(plugin.Manifest.WorkingPluginId);
|
||||
if (wantsInDefaultProfile == null)
|
||||
{
|
||||
// We don't know about this plugin, so we don't want to do anything here.
|
||||
// The code below will take care of it and add it with the default value.
|
||||
Log.Verbose("DevPlugin {Name} not wanted in default plugin", plugin.Manifest.InternalName);
|
||||
|
||||
// Check if any profile wants this plugin. We need to do this here, since we want to allow loading a dev plugin if a non-default profile wants it active.
|
||||
// Note that this will not add the plugin to the default profile. That's done below in any other case.
|
||||
wantedByAnyProfile = await this.profileManager.GetWantStateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, false, false);
|
||||
|
||||
// If it is wanted by any other profile, we do want to load it.
|
||||
if (wantedByAnyProfile)
|
||||
loadPlugin = true;
|
||||
}
|
||||
else if (wantsInDefaultProfile == false && devPlugin.StartOnBoot)
|
||||
{
|
||||
// We didn't want this plugin, and StartOnBoot is on. That means we don't want it and it should stay off until manually enabled.
|
||||
Log.Verbose("DevPlugin {Name} disabled and StartOnBoot => disable", plugin.Manifest.InternalName);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, false, false);
|
||||
loadPlugin = false;
|
||||
}
|
||||
else if (wantsInDefaultProfile == true && devPlugin.StartOnBoot)
|
||||
{
|
||||
// We wanted this plugin, and StartOnBoot is on. That means we actually do want it.
|
||||
Log.Verbose("DevPlugin {Name} enabled and StartOnBoot => enable", plugin.Manifest.InternalName);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, true, false);
|
||||
loadPlugin = !doNotLoad;
|
||||
}
|
||||
else if (wantsInDefaultProfile == true && !devPlugin.StartOnBoot)
|
||||
{
|
||||
// We wanted this plugin, but StartOnBoot is off. This means we don't want it anymore.
|
||||
Log.Verbose("DevPlugin {Name} enabled and !StartOnBoot => disable", plugin.Manifest.InternalName);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, false, false);
|
||||
loadPlugin = false;
|
||||
}
|
||||
else if (wantsInDefaultProfile == false && !devPlugin.StartOnBoot)
|
||||
{
|
||||
// We didn't want this plugin, and StartOnBoot is off. We don't want it.
|
||||
Log.Verbose("DevPlugin {Name} disabled and !StartOnBoot => disable", plugin.Manifest.InternalName);
|
||||
await this.profileManager.DefaultProfile.AddOrUpdateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, false, false);
|
||||
loadPlugin = false;
|
||||
}
|
||||
|
||||
plugin = devPlugin;
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618
|
||||
var defaultState = manifest?.Disabled != true && loadPlugin;
|
||||
#pragma warning restore CS0618
|
||||
|
||||
// Need to do this here, so plugins that don't load are still added to the default profile
|
||||
var wantToLoad = await this.profileManager.GetWantStateAsync(plugin.Manifest.InternalName, defaultState);
|
||||
|
||||
|
||||
// Plugins that aren't in any profile will be added to the default profile with this call.
|
||||
// We are skipping a double-lookup for dev plugins that are wanted by non-default profiles, as noted above.
|
||||
wantedByAnyProfile = wantedByAnyProfile || await this.profileManager.GetWantStateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, defaultState);
|
||||
Log.Information("{Name} defaultState: {State} wantedByAnyProfile: {WantedByAny} loadPlugin: {LoadPlugin}", plugin.Manifest.InternalName, defaultState, wantedByAnyProfile, loadPlugin);
|
||||
|
||||
if (loadPlugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (wantToLoad && !plugin.IsOrphaned)
|
||||
if (wantedByAnyProfile && !plugin.IsOrphaned)
|
||||
{
|
||||
await plugin.LoadAsync(reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Verbose($"{name} not loaded, wantToLoad:{wantToLoad} orphaned:{plugin.IsOrphaned}");
|
||||
Log.Verbose($"{name} not loaded, wantToLoad:{wantedByAnyProfile} orphaned:{plugin.IsOrphaned}");
|
||||
}
|
||||
}
|
||||
catch (InvalidPluginException)
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ internal class Profile
|
|||
/// Gets all plugins declared in this profile.
|
||||
/// </summary>
|
||||
public IEnumerable<ProfilePluginEntry> Plugins =>
|
||||
this.modelV1.Plugins.Select(x => new ProfilePluginEntry(x.InternalName, x.IsEnabled));
|
||||
this.modelV1.Plugins.Select(x => new ProfilePluginEntry(x.InternalName, x.WorkingPluginId, x.IsEnabled));
|
||||
|
||||
/// <summary>
|
||||
/// Gets this profile's underlying model.
|
||||
|
|
@ -142,13 +142,13 @@ internal class Profile
|
|||
/// <summary>
|
||||
/// Check if this profile contains a specific plugin, and if it is enabled.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="workingPluginId">The ID of the plugin.</param>
|
||||
/// <returns>Null if this profile does not declare the plugin, true if the profile declares the plugin and wants it enabled, false if the profile declares the plugin and does not want it enabled.</returns>
|
||||
public bool? WantsPlugin(string internalName)
|
||||
public bool? WantsPlugin(Guid workingPluginId)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
var entry = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName);
|
||||
var entry = this.modelV1.Plugins.FirstOrDefault(x => x.WorkingPluginId == workingPluginId);
|
||||
return entry?.IsEnabled;
|
||||
}
|
||||
}
|
||||
|
|
@ -157,17 +157,18 @@ internal class Profile
|
|||
/// Add a plugin to this profile with the desired state, or change the state of a plugin in this profile.
|
||||
/// This will block until all states have been applied.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="workingPluginId">The ID of the plugin.</param>
|
||||
/// <param name="internalName">The internal name of the plugin, if available.</param>
|
||||
/// <param name="state">Whether or not the plugin should be enabled.</param>
|
||||
/// <param name="apply">Whether or not the current state should immediately be applied.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
public async Task AddOrUpdateAsync(string internalName, bool state, bool apply = true)
|
||||
public async Task AddOrUpdateAsync(Guid workingPluginId, string? internalName, bool state, bool apply = true)
|
||||
{
|
||||
Debug.Assert(!internalName.IsNullOrEmpty(), "!internalName.IsNullOrEmpty()");
|
||||
|
||||
Debug.Assert(workingPluginId != Guid.Empty, "Trying to add plugin with empty guid");
|
||||
|
||||
lock (this)
|
||||
{
|
||||
var existing = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName);
|
||||
var existing = this.modelV1.Plugins.FirstOrDefault(x => x.WorkingPluginId == workingPluginId);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.IsEnabled = state;
|
||||
|
|
@ -177,15 +178,55 @@ internal class Profile
|
|||
this.modelV1.Plugins.Add(new ProfileModelV1.ProfileModelV1Plugin
|
||||
{
|
||||
InternalName = internalName,
|
||||
WorkingPluginId = workingPluginId,
|
||||
IsEnabled = state,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// We need to remove this plugin from the default profile, if it declares it.
|
||||
if (!this.IsDefaultProfile && this.manager.DefaultProfile.WantsPlugin(internalName) != null)
|
||||
if (!this.IsDefaultProfile && this.manager.DefaultProfile.WantsPlugin(workingPluginId) != null)
|
||||
{
|
||||
await this.manager.DefaultProfile.RemoveAsync(internalName, false);
|
||||
await this.manager.DefaultProfile.RemoveAsync(workingPluginId, false);
|
||||
}
|
||||
|
||||
Service<DalamudConfiguration>.Get().QueueSave();
|
||||
|
||||
if (apply)
|
||||
await this.manager.ApplyAllWantStatesAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a plugin from this profile.
|
||||
/// This will block until all states have been applied.
|
||||
/// </summary>
|
||||
/// <param name="workingPluginId">The ID of the plugin.</param>
|
||||
/// <param name="apply">Whether or not the current state should immediately be applied.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
public async Task RemoveAsync(Guid workingPluginId, bool apply = true)
|
||||
{
|
||||
ProfileModelV1.ProfileModelV1Plugin entry;
|
||||
lock (this)
|
||||
{
|
||||
entry = this.modelV1.Plugins.FirstOrDefault(x => x.WorkingPluginId == workingPluginId);
|
||||
if (entry == null)
|
||||
throw new PluginNotFoundException(workingPluginId);
|
||||
|
||||
if (!this.modelV1.Plugins.Remove(entry))
|
||||
throw new Exception("Couldn't remove plugin from model collection");
|
||||
}
|
||||
|
||||
// We need to add this plugin back to the default profile, if we were the last profile to have it.
|
||||
if (!this.manager.IsInAnyProfile(workingPluginId))
|
||||
{
|
||||
if (!this.IsDefaultProfile)
|
||||
{
|
||||
await this.manager.DefaultProfile.AddOrUpdateAsync(workingPluginId, entry.InternalName, this.IsEnabled && entry.IsEnabled, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PluginNotInDefaultProfileException(workingPluginId.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
Service<DalamudConfiguration>.Get().QueueSave();
|
||||
|
|
@ -201,36 +242,50 @@ internal class Profile
|
|||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="apply">Whether or not the current state should immediately be applied.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
public async Task RemoveAsync(string internalName, bool apply = true)
|
||||
public async Task RemoveByInternalNameAsync(string internalName, bool apply = true)
|
||||
{
|
||||
ProfileModelV1.ProfileModelV1Plugin entry;
|
||||
Guid? pluginToRemove = null;
|
||||
lock (this)
|
||||
{
|
||||
entry = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName);
|
||||
if (entry == null)
|
||||
throw new PluginNotFoundException(internalName);
|
||||
|
||||
if (!this.modelV1.Plugins.Remove(entry))
|
||||
throw new Exception("Couldn't remove plugin from model collection");
|
||||
foreach (var plugin in this.Plugins)
|
||||
{
|
||||
if (plugin.InternalName.Equals(internalName, StringComparison.Ordinal))
|
||||
{
|
||||
pluginToRemove = plugin.WorkingPluginId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We need to add this plugin back to the default profile, if we were the last profile to have it.
|
||||
if (!this.manager.IsInAnyProfile(internalName))
|
||||
await this.RemoveAsync(pluginToRemove ?? throw new PluginNotFoundException(internalName), apply);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function tries to migrate all plugins with this internalName which do not have
|
||||
/// a GUID to the specified GUID.
|
||||
/// This is best-effort and will probably work well for anyone that only uses regular plugins.
|
||||
/// </summary>
|
||||
/// <param name="internalName">InternalName of the plugin to migrate.</param>
|
||||
/// <param name="newGuid">Guid to use.</param>
|
||||
public void MigrateProfilesToGuidsForPlugin(string internalName, Guid newGuid)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (!this.IsDefaultProfile)
|
||||
foreach (var plugin in this.modelV1.Plugins)
|
||||
{
|
||||
await this.manager.DefaultProfile.AddOrUpdateAsync(internalName, this.IsEnabled && entry.IsEnabled, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PluginNotInDefaultProfileException(internalName);
|
||||
// TODO: What should happen if a profile has a GUID locked in, but the plugin
|
||||
// is not installed anymore? That probably means that the user uninstalled the plugin
|
||||
// and is now reinstalling it. We should still satisfy that and update the ID.
|
||||
|
||||
if (plugin.InternalName == internalName && plugin.WorkingPluginId == Guid.Empty)
|
||||
{
|
||||
plugin.WorkingPluginId = newGuid;
|
||||
Log.Information("Migrated profile {Profile} plugin {Name} to guid {Guid}", this, internalName, newGuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Service<DalamudConfiguration>.Get().QueueSave();
|
||||
|
||||
if (apply)
|
||||
await this.manager.ApplyAllWantStatesAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -280,4 +335,13 @@ internal sealed class PluginNotFoundException : ProfileOperationException
|
|||
: base($"The plugin '{internalName}' was not found in the profile")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginNotFoundException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="workingPluginId">The ID of the plugin causing the error.</param>
|
||||
public PluginNotFoundException(Guid workingPluginId)
|
||||
: base($"The plugin '{workingPluginId}' was not found in the profile")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,11 +69,12 @@ internal class ProfileManager : IServiceType
|
|||
/// <summary>
|
||||
/// Check if any enabled profile wants a specific plugin enabled.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="workingPluginId">The ID of the plugin.</param>
|
||||
/// <param name="internalName">The internal name of the plugin, if available.</param>
|
||||
/// <param name="defaultState">The state the plugin shall be in, if it needs to be added.</param>
|
||||
/// <param name="addIfNotDeclared">Whether or not the plugin should be added to the default preset, if it's not present in any preset.</param>
|
||||
/// <returns>Whether or not the plugin shall be enabled.</returns>
|
||||
public async Task<bool> GetWantStateAsync(string internalName, bool defaultState, bool addIfNotDeclared = true)
|
||||
public async Task<bool> GetWantStateAsync(Guid workingPluginId, string? internalName, bool defaultState, bool addIfNotDeclared = true)
|
||||
{
|
||||
var want = false;
|
||||
var wasInAnyProfile = false;
|
||||
|
|
@ -82,7 +83,7 @@ internal class ProfileManager : IServiceType
|
|||
{
|
||||
foreach (var profile in this.profiles)
|
||||
{
|
||||
var state = profile.WantsPlugin(internalName);
|
||||
var state = profile.WantsPlugin(workingPluginId);
|
||||
if (state.HasValue)
|
||||
{
|
||||
want = want || (profile.IsEnabled && state.Value);
|
||||
|
|
@ -93,8 +94,8 @@ internal class ProfileManager : IServiceType
|
|||
|
||||
if (!wasInAnyProfile && addIfNotDeclared)
|
||||
{
|
||||
Log.Warning("{Name} was not in any profile, adding to default with {Default}", internalName, defaultState);
|
||||
await this.DefaultProfile.AddOrUpdateAsync(internalName, defaultState, false);
|
||||
Log.Warning("'{Guid}'('{InternalName}') was not in any profile, adding to default with {Default}", workingPluginId, internalName, defaultState);
|
||||
await this.DefaultProfile.AddOrUpdateAsync(workingPluginId, internalName, defaultState, false);
|
||||
|
||||
return defaultState;
|
||||
}
|
||||
|
|
@ -105,22 +106,22 @@ internal class ProfileManager : IServiceType
|
|||
/// <summary>
|
||||
/// Check whether a plugin is declared in any profile.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="workingPluginId">The ID of the plugin.</param>
|
||||
/// <returns>Whether or not the plugin is in any profile.</returns>
|
||||
public bool IsInAnyProfile(string internalName)
|
||||
public bool IsInAnyProfile(Guid workingPluginId)
|
||||
{
|
||||
lock (this.profiles)
|
||||
return this.profiles.Any(x => x.WantsPlugin(internalName) != null);
|
||||
return this.profiles.Any(x => x.WantsPlugin(workingPluginId) != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a plugin is only in the default profile.
|
||||
/// A plugin can never be in the default profile if it is in any other profile.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="workingPluginId">The ID of the plugin.</param>
|
||||
/// <returns>Whether or not the plugin is in the default profile.</returns>
|
||||
public bool IsInDefaultProfile(string internalName)
|
||||
=> this.DefaultProfile.WantsPlugin(internalName) != null;
|
||||
public bool IsInDefaultProfile(Guid workingPluginId)
|
||||
=> this.DefaultProfile.WantsPlugin(workingPluginId) != null;
|
||||
|
||||
/// <summary>
|
||||
/// Add a new profile.
|
||||
|
|
@ -151,7 +152,7 @@ internal class ProfileManager : IServiceType
|
|||
/// <returns>The newly cloned profile.</returns>
|
||||
public Profile CloneProfile(Profile toClone)
|
||||
{
|
||||
var newProfile = this.ImportProfile(toClone.Model.Serialize());
|
||||
var newProfile = this.ImportProfile(toClone.Model.SerializeForShare());
|
||||
if (newProfile == null)
|
||||
throw new Exception("New profile was null while cloning");
|
||||
|
||||
|
|
@ -172,7 +173,27 @@ internal class ProfileManager : IServiceType
|
|||
newModel.Guid = Guid.NewGuid();
|
||||
newModel.Name = this.GenerateUniqueProfileName(newModel.Name.IsNullOrEmpty() ? "Unknown Collection" : newModel.Name);
|
||||
if (newModel is ProfileModelV1 modelV1)
|
||||
{
|
||||
// Disable it
|
||||
modelV1.IsEnabled = false;
|
||||
|
||||
// Try to find matching plugins for all plugins in the profile
|
||||
var pm = Service<PluginManager>.Get();
|
||||
foreach (var plugin in modelV1.Plugins)
|
||||
{
|
||||
var installedPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.InternalName == plugin.InternalName);
|
||||
if (installedPlugin != null)
|
||||
{
|
||||
Log.Information("Satisfying plugin {InternalName} for profile {Name} with {Guid}", plugin.InternalName, newModel.Name, installedPlugin.Manifest.WorkingPluginId);
|
||||
plugin.WorkingPluginId = installedPlugin.Manifest.WorkingPluginId;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warning("Couldn't find plugin {InternalName} for profile {Name}", plugin.InternalName, newModel.Name);
|
||||
plugin.WorkingPluginId = Guid.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.config.SavedProfiles!.Add(newModel);
|
||||
this.config.QueueSave();
|
||||
|
|
@ -196,19 +217,18 @@ internal class ProfileManager : IServiceType
|
|||
this.isBusy = true;
|
||||
Log.Information("Getting want states...");
|
||||
|
||||
List<string> wantActive;
|
||||
List<ProfilePluginEntry> wantActive;
|
||||
lock (this.profiles)
|
||||
{
|
||||
wantActive = this.profiles
|
||||
.Where(x => x.IsEnabled)
|
||||
.SelectMany(profile => profile.Plugins.Where(plugin => plugin.IsEnabled)
|
||||
.Select(plugin => plugin.InternalName))
|
||||
.SelectMany(profile => profile.Plugins.Where(plugin => plugin.IsEnabled))
|
||||
.Distinct().ToList();
|
||||
}
|
||||
|
||||
foreach (var internalName in wantActive)
|
||||
foreach (var profilePluginEntry in wantActive)
|
||||
{
|
||||
Log.Information("\t=> Want {Name}", internalName);
|
||||
Log.Information("\t=> Want {Name}({WorkingPluginId})", profilePluginEntry.InternalName, profilePluginEntry.WorkingPluginId);
|
||||
}
|
||||
|
||||
Log.Information("Applying want states...");
|
||||
|
|
@ -218,7 +238,7 @@ internal class ProfileManager : IServiceType
|
|||
var pm = Service<PluginManager>.Get();
|
||||
foreach (var installedPlugin in pm.InstalledPlugins)
|
||||
{
|
||||
var wantThis = wantActive.Contains(installedPlugin.Manifest.InternalName);
|
||||
var wantThis = wantActive.Any(x => x.WorkingPluginId == installedPlugin.Manifest.WorkingPluginId);
|
||||
switch (wantThis)
|
||||
{
|
||||
case true when !installedPlugin.IsLoaded:
|
||||
|
|
@ -267,7 +287,7 @@ internal class ProfileManager : IServiceType
|
|||
// We need to remove all plugins from the profile first, so that they are re-added to the default profile if needed
|
||||
foreach (var plugin in profile.Plugins.ToArray())
|
||||
{
|
||||
await profile.RemoveAsync(plugin.InternalName, false);
|
||||
await profile.RemoveAsync(plugin.WorkingPluginId, false);
|
||||
}
|
||||
|
||||
if (!this.config.SavedProfiles!.Remove(profile.Model))
|
||||
|
|
@ -279,6 +299,42 @@ internal class ProfileManager : IServiceType
|
|||
this.config.QueueSave();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function tries to migrate all plugins with this internalName which do not have
|
||||
/// a GUID to the specified GUID.
|
||||
/// This is best-effort and will probably work well for anyone that only uses regular plugins.
|
||||
/// </summary>
|
||||
/// <param name="internalName">InternalName of the plugin to migrate.</param>
|
||||
/// <param name="newGuid">Guid to use.</param>
|
||||
public void MigrateProfilesToGuidsForPlugin(string internalName, Guid newGuid)
|
||||
{
|
||||
lock (this.profiles)
|
||||
{
|
||||
foreach (var profile in this.profiles)
|
||||
profile.MigrateProfilesToGuidsForPlugin(internalName, newGuid);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate profiles for errors.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">Thrown when a profile is not sane.</exception>
|
||||
public void ParanoiaValidateProfiles()
|
||||
{
|
||||
foreach (var profile in this.profiles)
|
||||
{
|
||||
var seenIds = new List<Guid>();
|
||||
|
||||
foreach (var pluginEntry in profile.Plugins)
|
||||
{
|
||||
if (seenIds.Contains(pluginEntry.WorkingPluginId))
|
||||
throw new Exception($"Plugin '{pluginEntry.WorkingPluginId}'('{pluginEntry.InternalName}') is twice in profile '{profile.Guid}'('{profile.Name}')");
|
||||
|
||||
seenIds.Add(pluginEntry.WorkingPluginId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GenerateUniqueProfileName(string startingWith)
|
||||
{
|
||||
if (this.profiles.All(x => x.Name != startingWith))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
using Dalamud.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Dalamud.Plugin.Internal.Profiles;
|
||||
|
||||
|
|
@ -39,11 +41,11 @@ public abstract class ProfileModel
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize this model into a string usable for sharing.
|
||||
/// Serialize this model into a string usable for sharing, without including GUIDs.
|
||||
/// </summary>
|
||||
/// <returns>The serialized representation of the model.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when an unsupported model is serialized.</exception>
|
||||
public string Serialize()
|
||||
public string SerializeForShare()
|
||||
{
|
||||
string prefix;
|
||||
switch (this)
|
||||
|
|
@ -55,6 +57,32 @@ public abstract class ProfileModel
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return prefix + Convert.ToBase64String(Util.CompressString(JsonConvert.SerializeObject(this)));
|
||||
// HACK: Just filter the ID for now, we should split the sharing + saving model
|
||||
var serialized = JsonConvert.SerializeObject(this, new JsonSerializerSettings()
|
||||
{ ContractResolver = new IgnorePropertiesResolver(new[] { "WorkingPluginId" }) });
|
||||
|
||||
return prefix + Convert.ToBase64String(Util.CompressString(serialized));
|
||||
}
|
||||
|
||||
// Short helper class to ignore some properties from serialization
|
||||
private class IgnorePropertiesResolver : DefaultContractResolver
|
||||
{
|
||||
private readonly HashSet<string> ignoreProps;
|
||||
|
||||
public IgnorePropertiesResolver(IEnumerable<string> propNamesToIgnore)
|
||||
{
|
||||
this.ignoreProps = new HashSet<string>(propNamesToIgnore);
|
||||
}
|
||||
|
||||
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
|
||||
{
|
||||
var property = base.CreateProperty(member, memberSerialization);
|
||||
if (this.ignoreProps.Contains(property.PropertyName))
|
||||
{
|
||||
property.ShouldSerialize = _ => false;
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,11 @@ public class ProfileModelV1 : ProfileModel
|
|||
/// Gets or sets the internal name of the plugin.
|
||||
/// </summary>
|
||||
public string? InternalName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an ID uniquely identifying this specific instance of a plugin.
|
||||
/// </summary>
|
||||
public Guid WorkingPluginId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not this entry is enabled.
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ internal class ProfilePluginEntry
|
|||
/// Initializes a new instance of the <see cref="ProfilePluginEntry"/> class.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="workingPluginId">The ID of the plugin.</param>
|
||||
/// <param name="state">A value indicating whether or not this entry is enabled.</param>
|
||||
public ProfilePluginEntry(string internalName, bool state)
|
||||
public ProfilePluginEntry(string internalName, Guid workingPluginId, bool state)
|
||||
{
|
||||
this.InternalName = internalName;
|
||||
this.WorkingPluginId = workingPluginId;
|
||||
this.IsEnabled = state;
|
||||
}
|
||||
|
||||
|
|
@ -20,6 +22,11 @@ internal class ProfilePluginEntry
|
|||
/// Gets the internal name of the plugin.
|
||||
/// </summary>
|
||||
public string InternalName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an ID uniquely identifying this specific instance of a plugin.
|
||||
/// </summary>
|
||||
public Guid WorkingPluginId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not this entry is enabled.
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ internal class LocalPlugin : IDisposable
|
|||
/// INCLUDES the default profile.
|
||||
/// </summary>
|
||||
public bool IsWantedByAnyProfile =>
|
||||
Service<ProfileManager>.Get().GetWantStateAsync(this.manifest.InternalName, false, false).GetAwaiter().GetResult();
|
||||
Service<ProfileManager>.Get().GetWantStateAsync(this.manifest.WorkingPluginId, this.Manifest.InternalName, false, false).GetAwaiter().GetResult();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this plugin's API level is out of date.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue