From 642e8bf6d34a800608e2c462b3413763de33d316 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Mon, 10 Apr 2023 19:17:00 +0200
Subject: [PATCH 01/28] Profiles (#1178)
---
.../Internal/DalamudConfiguration.cs | 16 +
.../Internal/PluginCategoryManager.cs | 10 +-
.../PluginInstaller/PluginInstallerWindow.cs | 211 ++++++---
.../PluginInstaller/ProfileManagerWidget.cs | 399 ++++++++++++++++++
.../Settings/Tabs/SettingsTabExperimental.cs | 8 +
.../Windows/StyleEditor/StyleEditorWindow.cs | 16 +-
Dalamud/Plugin/Internal/PluginManager.cs | 30 +-
Dalamud/Plugin/Internal/Profiles/Profile.cs | 214 ++++++++++
.../Profiles/ProfileCommandHandler.cs | 164 +++++++
.../Internal/Profiles/ProfileManager.cs | 356 ++++++++++++++++
.../Plugin/Internal/Profiles/ProfileModel.cs | 40 ++
.../Internal/Profiles/ProfileModelV1.cs | 27 ++
.../Internal/Profiles/ProfilePluginEntry.cs | 14 +
Dalamud/Plugin/Internal/Types/LocalPlugin.cs | 37 +-
.../Internal/Types/LocalPluginManifest.cs | 1 +
.../Plugin/Internal/Types/PluginManifest.cs | 6 +
Dalamud/Plugin/PluginLoadReason.cs | 2 +
Dalamud/Utility/Util.cs | 15 +
18 files changed, 1492 insertions(+), 74 deletions(-)
create mode 100644 Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
create mode 100644 Dalamud/Plugin/Internal/Profiles/Profile.cs
create mode 100644 Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
create mode 100644 Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
create mode 100644 Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
create mode 100644 Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
create mode 100644 Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
index f6cf88d90..89396bd66 100644
--- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs
+++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
@@ -6,6 +6,7 @@ using System.Linq;
using Dalamud.Game.Text;
using Dalamud.Interface.Style;
+using Dalamud.Plugin.Internal.Profiles;
using Dalamud.Utility;
using Newtonsoft.Json;
using Serilog;
@@ -266,6 +267,21 @@ internal sealed class DalamudConfiguration : IServiceType
///
public string ChosenStyle { get; set; } = "Dalamud Standard";
+ ///
+ /// Gets or sets a list of saved plugin profiles.
+ ///
+ public List? SavedProfiles { get; set; }
+
+ ///
+ /// Gets or sets the default plugin profile.
+ ///
+ public ProfileModel? DefaultProfile { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether or not profiles are enabled.
+ ///
+ public bool ProfilesEnabled { get; set; } = false;
+
///
/// Gets or sets a value indicating whether or not Dalamud RMT filtering should be disabled.
///
diff --git a/Dalamud/Interface/Internal/PluginCategoryManager.cs b/Dalamud/Interface/Internal/PluginCategoryManager.cs
index 06e306c50..2af5d2354 100644
--- a/Dalamud/Interface/Internal/PluginCategoryManager.cs
+++ b/Dalamud/Interface/Internal/PluginCategoryManager.cs
@@ -28,6 +28,7 @@ internal class PluginCategoryManager
new(11, "special.devIconTester", () => Locs.Category_IconTester),
new(12, "special.dalamud", () => Locs.Category_Dalamud),
new(13, "special.plugins", () => Locs.Category_Plugins),
+ new(14, "special.profiles", () => Locs.Category_PluginProfiles, CategoryInfo.AppearCondition.ProfilesEnabled),
new(FirstTagBasedCategoryId + 0, "other", () => Locs.Category_Other),
new(FirstTagBasedCategoryId + 1, "jobs", () => Locs.Category_Jobs),
new(FirstTagBasedCategoryId + 2, "ui", () => Locs.Category_UI),
@@ -43,7 +44,7 @@ internal class PluginCategoryManager
private GroupInfo[] groupList =
{
new(GroupKind.DevTools, () => Locs.Group_DevTools, 10, 11),
- new(GroupKind.Installed, () => Locs.Group_Installed, 0, 1),
+ new(GroupKind.Installed, () => Locs.Group_Installed, 0, 1, 14),
new(GroupKind.Available, () => Locs.Group_Available, 0),
new(GroupKind.Changelog, () => Locs.Group_Changelog, 0, 12, 13),
@@ -352,6 +353,11 @@ internal class PluginCategoryManager
/// Check if plugin testing is enabled.
///
DoPluginTest,
+
+ ///
+ /// Check if plugin profiles are enabled.
+ ///
+ ProfilesEnabled,
}
///
@@ -429,6 +435,8 @@ internal class PluginCategoryManager
public static string Category_DevInstalled => Loc.Localize("InstallerInstalledDevPlugins", "Installed Dev Plugins");
public static string Category_IconTester => "Image/Icon Tester";
+
+ public static string Category_PluginProfiles => Loc.Localize("InstallerCategoryPluginProfiles", "Plugin Profiles");
public static string Category_Other => Loc.Localize("InstallerCategoryOther", "Other");
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index f6dad53bd..73ef523e9 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -21,6 +21,7 @@ using Dalamud.Logging.Internal;
using Dalamud.Plugin;
using Dalamud.Plugin.Internal;
using Dalamud.Plugin.Internal.Exceptions;
+using Dalamud.Plugin.Internal.Profiles;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Support;
using Dalamud.Utility;
@@ -48,6 +49,8 @@ internal class PluginInstallerWindow : Window, IDisposable
private readonly object listLock = new();
+ private readonly ProfileManagerWidget profileManagerWidget;
+
private DalamudChangelogManager? dalamudChangelogManager;
private Task? dalamudChangelogRefreshTask;
private CancellationTokenSource? dalamudChangelogRefreshTaskCts;
@@ -149,6 +152,8 @@ internal class PluginInstallerWindow : Window, IDisposable
});
this.timeLoaded = DateTime.Now;
+
+ this.profileManagerWidget = new(this);
}
private enum OperationStatus
@@ -167,6 +172,7 @@ internal class PluginInstallerWindow : Window, IDisposable
UpdatingAll,
Installing,
Manager,
+ ProfilesLoading,
}
private enum PluginSortKind
@@ -213,6 +219,8 @@ internal class PluginInstallerWindow : Window, IDisposable
this.updatePluginCount = 0;
this.updatedPlugins = null;
}
+
+ this.profileManagerWidget.Reset();
}
///
@@ -285,17 +293,56 @@ internal class PluginInstallerWindow : Window, IDisposable
this.searchText = text;
}
+ ///
+ /// Start a plugin install and handle errors visually.
+ ///
+ /// The manifest to install.
+ /// Install the testing version.
+ public void StartInstall(RemotePluginManifest manifest, bool useTesting)
+ {
+ var pluginManager = Service.Get();
+ var notifications = Service.Get();
+
+ this.installStatus = OperationStatus.InProgress;
+ this.loadingIndicatorKind = LoadingIndicatorKind.Installing;
+
+ Task.Run(() => pluginManager.InstallPluginAsync(manifest, useTesting || manifest.IsTestingExclusive, PluginLoadReason.Installer))
+ .ContinueWith(task =>
+ {
+ // There is no need to set as Complete for an individual plugin installation
+ this.installStatus = OperationStatus.Idle;
+ if (this.DisplayErrorContinuation(task, Locs.ErrorModal_InstallFail(manifest.Name)))
+ {
+ // Fine as long as we aren't in an error state
+ if (task.Result.State is PluginState.Loaded or PluginState.Unloaded)
+ {
+ notifications.AddNotification(Locs.Notifications_PluginInstalled(manifest.Name), Locs.Notifications_PluginInstalledTitle, NotificationType.Success);
+ }
+ else
+ {
+ notifications.AddNotification(Locs.Notifications_PluginNotInstalled(manifest.Name), Locs.Notifications_PluginNotInstalledTitle, NotificationType.Error);
+ this.ShowErrorModal(Locs.ErrorModal_InstallFail(manifest.Name));
+ }
+ }
+ });
+ }
+
private void DrawProgressOverlay()
{
var pluginManager = Service.Get();
+ var profileManager = Service.Get();
var isWaitingManager = !pluginManager.PluginsReady ||
!pluginManager.ReposReady;
+ var isWaitingProfiles = profileManager.IsBusy;
+
var isLoading = this.AnyOperationInProgress ||
- isWaitingManager;
+ isWaitingManager || isWaitingProfiles;
if (isWaitingManager)
this.loadingIndicatorKind = LoadingIndicatorKind.Manager;
+ else if (isWaitingProfiles)
+ this.loadingIndicatorKind = LoadingIndicatorKind.ProfilesLoading;
if (!isLoading)
return;
@@ -379,6 +426,9 @@ internal class PluginInstallerWindow : Window, IDisposable
}
}
+ break;
+ case LoadingIndicatorKind.ProfilesLoading:
+ ImGuiHelpers.CenteredText("Profiles are being applied...");
break;
default:
throw new ArgumentOutOfRangeException();
@@ -387,9 +437,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (DateTime.Now - this.timeLoaded > TimeSpan.FromSeconds(90) && !pluginManager.PluginsReady)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
- ImGuiHelpers.CenteredText("This is embarrassing, but...");
- ImGuiHelpers.CenteredText("one of your plugins may be blocking the installer.");
- ImGuiHelpers.CenteredText("You should tell us about this, please keep this window open.");
+ ImGuiHelpers.CenteredText("One of your plugins may be blocking the installer.");
ImGui.PopStyleColor();
}
@@ -1111,6 +1159,10 @@ internal class PluginInstallerWindow : Window, IDisposable
if (!Service.Get().DoPluginTest)
continue;
break;
+ case PluginCategoryManager.CategoryInfo.AppearCondition.ProfilesEnabled:
+ if (!Service.Get().ProfilesEnabled)
+ continue;
+ break;
default:
throw new ArgumentOutOfRangeException();
}
@@ -1216,6 +1268,10 @@ internal class PluginInstallerWindow : Window, IDisposable
case 1:
this.DrawInstalledPluginList(true);
break;
+
+ case 2:
+ this.profileManagerWidget.Draw();
+ break;
}
break;
@@ -1555,7 +1611,7 @@ internal class PluginInstallerWindow : Window, IDisposable
ImGui.SetCursorPos(startCursor);
- var pluginDisabled = plugin is { IsDisabled: true };
+ var pluginDisabled = plugin is { IsWantedByAnyProfile: false };
var iconSize = ImGuiHelpers.ScaledVector2(64, 64);
var cursorBeforeImage = ImGui.GetCursorPos();
@@ -1853,27 +1909,7 @@ internal class PluginInstallerWindow : Window, IDisposable
var buttonText = Locs.PluginButton_InstallVersion(versionString);
if (ImGui.Button($"{buttonText}##{buttonText}{index}"))
{
- this.installStatus = OperationStatus.InProgress;
- this.loadingIndicatorKind = LoadingIndicatorKind.Installing;
-
- Task.Run(() => pluginManager.InstallPluginAsync(manifest, useTesting || manifest.IsTestingExclusive, PluginLoadReason.Installer))
- .ContinueWith(task =>
- {
- // There is no need to set as Complete for an individual plugin installation
- this.installStatus = OperationStatus.Idle;
- if (this.DisplayErrorContinuation(task, Locs.ErrorModal_InstallFail(manifest.Name)))
- {
- if (task.Result.State == PluginState.Loaded)
- {
- notifications.AddNotification(Locs.Notifications_PluginInstalled(manifest.Name), Locs.Notifications_PluginInstalledTitle, NotificationType.Success);
- }
- else
- {
- notifications.AddNotification(Locs.Notifications_PluginNotInstalled(manifest.Name), Locs.Notifications_PluginNotInstalledTitle, NotificationType.Error);
- this.ShowErrorModal(Locs.ErrorModal_InstallFail(manifest.Name));
- }
- }
- });
+ this.StartInstall(manifest, useTesting);
}
}
@@ -1980,7 +2016,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
// Disabled
- if (plugin.IsDisabled || !plugin.CheckPolicy())
+ if (!plugin.IsWantedByAnyProfile || !plugin.CheckPolicy())
{
label += Locs.PluginTitleMod_Disabled;
trouble = true;
@@ -2262,6 +2298,11 @@ internal class PluginInstallerWindow : Window, IDisposable
{
var notifications = Service.Get();
var pluginManager = Service.Get();
+ var profileManager = Service.Get();
+ var config = Service.Get();
+
+ var applicableForProfiles = plugin.Manifest.SupportsProfiles;
+ var isDefaultPlugin = profileManager.IsInDefaultProfile(plugin.Manifest.InternalName);
// Disable everything if the updater is running or another plugin is operating
var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress;
@@ -2276,15 +2317,70 @@ internal class PluginInstallerWindow : Window, IDisposable
// Disable everything if the plugin failed to load
disabled = disabled || plugin.State == PluginState.LoadError || plugin.State == PluginState.DependencyResolutionFailed;
- // Disable everything if we're working
+ // Disable everything if we're loading plugins
disabled = disabled || plugin.State == PluginState.Loading || plugin.State == PluginState.Unloading;
+ // Disable everything if we're applying profiles
+ disabled = disabled || profileManager.IsBusy;
+
var toggleId = plugin.Manifest.InternalName;
var isLoadedAndUnloadable = plugin.State == PluginState.Loaded ||
plugin.State == PluginState.DependencyResolutionFailed;
StyleModelV1.DalamudStandard.Push();
+ var profileChooserPopupName = $"###pluginProfileChooser{plugin.Manifest.InternalName}";
+ if (ImGui.BeginPopup(profileChooserPopupName))
+ {
+ var didAny = false;
+
+ foreach (var profile in profileManager.Profiles.Where(x => !x.IsDefaultProfile))
+ {
+ var inProfile = profile.WantsPlugin(plugin.Manifest.InternalName) != null;
+ if (ImGui.Checkbox($"###profilePick{profile.Guid}{plugin.Manifest.InternalName}", ref inProfile))
+ {
+ if (inProfile)
+ {
+ Task.Run(() => profile.AddOrUpdate(plugin.Manifest.InternalName, true))
+ .ContinueWith(this.DisplayErrorContinuation, "Couldn't add plugin to this profile.");
+ }
+ else
+ {
+ Task.Run(() => profile.Remove(plugin.Manifest.InternalName))
+ .ContinueWith(this.DisplayErrorContinuation, "Couldn't remove plugin from this profile.");
+ }
+ }
+
+ ImGui.SameLine();
+
+ ImGui.TextUnformatted(profile.Name);
+
+ didAny = true;
+ }
+
+ if (!didAny)
+ ImGui.TextColored(ImGuiColors.DalamudGrey, "No profiles! Go add some!");
+
+ ImGui.Separator();
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.Times))
+ {
+ profileManager.DefaultProfile.AddOrUpdate(plugin.Manifest.InternalName, plugin.IsLoaded, false);
+ foreach (var profile in profileManager.Profiles.Where(x => !x.IsDefaultProfile && x.Plugins.Any(y => y.InternalName == plugin.Manifest.InternalName)))
+ {
+ profile.Remove(plugin.Manifest.InternalName, false);
+ }
+
+ // TODO error handling
+ Task.Run(() => profileManager.ApplyAllWantStates());
+ }
+
+ ImGui.SameLine();
+ ImGui.Text("Remove from all profiles");
+
+ ImGui.EndPopup();
+ }
+
if (plugin.State == PluginState.UnloadError && !plugin.IsDev)
{
ImGuiComponents.DisabledButton(FontAwesomeIcon.Frown);
@@ -2292,14 +2388,18 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGui.IsItemHovered())
ImGui.SetTooltip(Locs.PluginButtonToolTip_UnloadFailed);
}
- else if (disabled)
+ else if (disabled || !isDefaultPlugin)
{
ImGuiComponents.DisabledToggleButton(toggleId, isLoadedAndUnloadable);
+
+ if (!isDefaultPlugin && ImGui.IsItemHovered())
+ ImGui.SetTooltip(Locs.PluginButtonToolTip_NeedsToBeInDefault);
}
else
{
if (ImGuiComponents.ToggleButton(toggleId, ref isLoadedAndUnloadable))
{
+ // TODO: We can technically let profile manager take care of unloading/loading the plugin, but we should figure out error handling first.
if (!isLoadedAndUnloadable)
{
this.enableDisableStatus = OperationStatus.InProgress;
@@ -2322,15 +2422,9 @@ internal class PluginInstallerWindow : Window, IDisposable
return;
}
- var disableTask = Task.Run(() => plugin.Disable())
- .ContinueWith(this.DisplayErrorContinuation, Locs.ErrorModal_DisableFail(plugin.Name));
-
- disableTask.Wait();
+ profileManager.DefaultProfile.AddOrUpdate(plugin.Manifest.InternalName, false, false);
this.enableDisableStatus = OperationStatus.Complete;
- if (!disableTask.Result)
- return;
-
notifications.AddNotification(Locs.Notifications_PluginDisabled(plugin.Manifest.Name), Locs.Notifications_PluginDisabledTitle, NotificationType.Success);
});
}
@@ -2346,17 +2440,7 @@ internal class PluginInstallerWindow : Window, IDisposable
plugin.ReloadManifest();
}
- var enableTask = Task.Run(plugin.Enable)
- .ContinueWith(
- this.DisplayErrorContinuation,
- Locs.ErrorModal_EnableFail(plugin.Name));
-
- enableTask.Wait();
- if (!enableTask.Result)
- {
- this.enableDisableStatus = OperationStatus.Complete;
- return;
- }
+ profileManager.DefaultProfile.AddOrUpdate(plugin.Manifest.InternalName, true, false);
var loadTask = Task.Run(() => plugin.LoadAsync(PluginLoadReason.Installer))
.ContinueWith(
@@ -2409,6 +2493,29 @@ internal class PluginInstallerWindow : Window, IDisposable
// Only if the plugin isn't broken.
this.DrawOpenPluginSettingsButton(plugin);
}
+
+ if (applicableForProfiles && config.ProfilesEnabled)
+ {
+ ImGui.SameLine();
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.Toolbox))
+ {
+ ImGui.OpenPopup(profileChooserPopupName);
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip(Locs.PluginButtonToolTip_PickProfiles);
+ }
+ else if (!applicableForProfiles && config.ProfilesEnabled)
+ {
+ ImGui.SameLine();
+
+ ImGui.BeginDisabled();
+ ImGuiComponents.IconButton(FontAwesomeIcon.Toolbox);
+ ImGui.EndDisabled();
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip(Locs.PluginButtonToolTip_ProfilesNotSupported);
+ }
}
private async Task UpdateSinglePlugin(AvailablePluginUpdate update)
@@ -2827,7 +2934,7 @@ internal class PluginInstallerWindow : Window, IDisposable
/// The previous task.
/// An error message to be displayed.
/// A value indicating whether to continue with the next task.
- private bool DisplayErrorContinuation(Task task, object state)
+ public bool DisplayErrorContinuation(Task task, object state)
{
if (task.IsFaulted)
{
@@ -2911,7 +3018,7 @@ internal class PluginInstallerWindow : Window, IDisposable
#region Header
- public static string Header_Hint => Loc.Localize("InstallerHint", "This window allows you to install and remove in-game plugins.\nThey are made by third-party developers.");
+ public static string Header_Hint => Loc.Localize("InstallerHint", "This window allows you to install and remove Dalamud plugins.\nThey are made by the community.");
public static string Header_SearchPlaceholder => Loc.Localize("InstallerSearch", "Search");
@@ -3068,6 +3175,10 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButtonToolTip_OpenConfiguration => Loc.Localize("InstallerOpenConfig", "Open Configuration");
+ public static string PluginButtonToolTip_PickProfiles => Loc.Localize("InstallerPickProfiles", "Pick profiles for this plugin");
+
+ public static string PluginButtonToolTip_ProfilesNotSupported => Loc.Localize("InstallerProfilesNotSupported", "This plugin does not support profiles");
+
public static string PluginButtonToolTip_StartOnBoot => Loc.Localize("InstallerStartOnBoot", "Start on boot");
public static string PluginButtonToolTip_AutomaticReloading => Loc.Localize("InstallerAutomaticReloading", "Automatic reloading");
@@ -3088,6 +3199,8 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButtonToolTip_UnloadFailed => Loc.Localize("InstallerUnloadFailedTooltip", "Plugin unload failed, please restart your game and try again.");
+ public static string PluginButtonToolTip_NeedsToBeInDefault => Loc.Localize("InstallerUnloadNeedsToBeInDefault", "This plugin is in one or more profiles. If you want to enable or disable it, please do so by enabling or disabling one of the profiles it is in.\nIf you want to manage it manually, remove it from all profiles.");
+
#endregion
#region Notifications
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
new file mode 100644
index 000000000..fcb941d95
--- /dev/null
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -0,0 +1,399 @@
+using System;
+using System.Linq;
+using System.Numerics;
+using System.Threading.Tasks;
+
+using Dalamud.Interface.Colors;
+using Dalamud.Interface.Components;
+using Dalamud.Interface.Internal.Notifications;
+using Dalamud.Interface.Raii;
+using Dalamud.Plugin.Internal;
+using Dalamud.Plugin.Internal.Profiles;
+using ImGuiNET;
+using Serilog;
+
+namespace Dalamud.Interface.Internal.Windows.PluginInstaller;
+
+internal class ProfileManagerWidget
+{
+ private readonly PluginInstallerWindow installer;
+ private Mode mode = Mode.Overview;
+ private Guid? editingProfileGuid;
+
+ private string? pickerSelectedPluginInternalName = null;
+ private string profileNameEdit = string.Empty;
+
+ public ProfileManagerWidget(PluginInstallerWindow installer)
+ {
+ this.installer = installer;
+ }
+
+ public void Draw()
+ {
+ switch (this.mode)
+ {
+ case Mode.Overview:
+ this.DrawOverview();
+ break;
+
+ case Mode.EditSingleProfile:
+ this.DrawEdit();
+ break;
+ }
+ }
+
+ public void Reset()
+ {
+ this.mode = Mode.Overview;
+ this.editingProfileGuid = null;
+ this.pickerSelectedPluginInternalName = null;
+ }
+
+ private void DrawOverview()
+ {
+ var didAny = false;
+ var profman = Service.Get();
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
+ profman.AddNewProfile();
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Add a new profile");
+
+ ImGui.SameLine();
+ ImGuiHelpers.ScaledDummy(5);
+ ImGui.SameLine();
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.FileImport))
+ {
+ try
+ {
+ profman.ImportProfile(ImGui.GetClipboardText());
+ }
+ catch (Exception ex)
+ {
+ Log.Error(ex, "Could not import profile");
+ }
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Import a shared profile from your clipboard");
+
+ ImGui.Separator();
+ ImGuiHelpers.ScaledDummy(5);
+
+ var windowSize = ImGui.GetWindowSize();
+
+ if (ImGui.BeginChild("###profileChooserScrolling"))
+ {
+ Guid? toCloneGuid = null;
+
+ foreach (var profile in profman.Profiles)
+ {
+ if (profile.IsDefaultProfile)
+ continue;
+
+ var isEnabled = profile.IsEnabled;
+ if (ImGuiComponents.ToggleButton($"###toggleButton{profile.Guid}", ref isEnabled))
+ {
+ Task.Run(() => profile.SetState(isEnabled))
+ .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change profile state.");
+ }
+
+ ImGui.SameLine();
+ ImGuiHelpers.ScaledDummy(3);
+ ImGui.SameLine();
+
+ ImGui.Text(profile.Name);
+
+ ImGui.SameLine();
+ ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30));
+
+ if (ImGuiComponents.IconButton($"###editButton{profile.Guid}", FontAwesomeIcon.PencilAlt))
+ {
+ this.mode = Mode.EditSingleProfile;
+ this.editingProfileGuid = profile.Guid;
+ this.profileNameEdit = profile.Name;
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Edit this profile");
+
+ ImGui.SameLine();
+ ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 2) - 5);
+
+ if (ImGuiComponents.IconButton($"###cloneButton{profile.Guid}", FontAwesomeIcon.Copy))
+ toCloneGuid = profile.Guid;
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Clone this profile");
+
+ ImGui.SameLine();
+ ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 3) - 5);
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport))
+ {
+ ImGui.SetClipboardText(profile.Model.Serialize());
+ Service.Get().AddNotification("Copied to clipboard!", type: NotificationType.Success);
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Copy profile to clipboard for sharing");
+
+ didAny = true;
+
+ ImGuiHelpers.ScaledDummy(2);
+ }
+
+ if (toCloneGuid != null)
+ {
+ profman.CloneProfile(profman.Profiles.First(x => x.Guid == toCloneGuid));
+ }
+
+ if (!didAny)
+ {
+ ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudGrey);
+ ImGuiHelpers.CenteredText("No profiles! Add one!");
+ ImGui.PopStyleColor();
+ }
+
+ ImGui.EndChild();
+ }
+ }
+
+ private void DrawEdit()
+ {
+ if (this.editingProfileGuid == null)
+ {
+ Log.Error("Editing profile guid was null");
+ this.Reset();
+ return;
+ }
+
+ var profman = Service.Get();
+ var pm = Service.Get();
+ var pic = Service.Get();
+ var profile = profman.Profiles.FirstOrDefault(x => x.Guid == this.editingProfileGuid);
+
+ if (profile == null)
+ {
+ Log.Error("Could not find profile {Guid} for edit", this.editingProfileGuid);
+ this.Reset();
+ return;
+ }
+
+ const string addPluginToProfilePopup = "###addPluginToProfile";
+ if (ImGui.BeginPopup(addPluginToProfilePopup))
+ {
+ var selected =
+ pm.InstalledPlugins.FirstOrDefault(
+ x => x.Manifest.InternalName == this.pickerSelectedPluginInternalName);
+
+ if (ImGui.BeginCombo("###pluginPicker", selected == null ? "Pick one" : selected.Manifest.Name))
+ {
+ foreach (var plugin in pm.InstalledPlugins.Where(x => x.Manifest.SupportsProfiles))
+ {
+ if (ImGui.Selectable($"{plugin.Manifest.Name}###selector{plugin.Manifest.InternalName}"))
+ {
+ this.pickerSelectedPluginInternalName = plugin.Manifest.InternalName;
+ }
+ }
+
+ ImGui.EndCombo();
+ }
+
+ using (ImRaii.Disabled(this.pickerSelectedPluginInternalName == null))
+ {
+ if (ImGui.Button("Do it") && selected != null)
+ {
+ Task.Run(() => profile.AddOrUpdate(selected.Manifest.InternalName, selected.IsLoaded));
+ }
+ }
+
+ ImGui.EndPopup();
+ }
+
+ var didAny = false;
+
+ // ======== Top bar ========
+ var windowSize = ImGui.GetWindowSize();
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.ArrowLeft))
+ this.Reset();
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Back to overview");
+
+ ImGui.SameLine();
+ ImGuiHelpers.ScaledDummy(5);
+ ImGui.SameLine();
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport))
+ {
+ ImGui.SetClipboardText(profile.Model.Serialize());
+ Service.Get().AddNotification("Copied to clipboard!", type: NotificationType.Success);
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Copy profile to clipboard for sharing");
+
+ ImGui.SameLine();
+ ImGuiHelpers.ScaledDummy(5);
+ ImGui.SameLine();
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash))
+ {
+ Task.Run(() => profman.DeleteProfile(profile))
+ .ContinueWith(t =>
+ {
+ this.Reset();
+ this.installer.DisplayErrorContinuation(t, "Could not refresh profiles.");
+ });
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Delete this profile");
+
+ ImGui.SameLine();
+ ImGuiHelpers.ScaledDummy(5);
+ ImGui.SameLine();
+
+ ImGui.SetNextItemWidth(windowSize.X / 3);
+ if (ImGui.InputText("###profileNameInput", ref this.profileNameEdit, 255))
+ {
+ profile.Name = this.profileNameEdit;
+ }
+
+ ImGui.SameLine();
+ ImGui.SetCursorPosX(windowSize.X - (ImGui.GetFrameHeight() * 1.55f * ImGuiHelpers.GlobalScale));
+
+ var isEnabled = profile.IsEnabled;
+ if (ImGuiComponents.ToggleButton($"###toggleButton{profile.Guid}", ref isEnabled))
+ {
+ Task.Run(() => profile.SetState(isEnabled))
+ .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change profile state.");
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Enable/Disable this profile");
+
+ ImGui.Separator();
+
+ ImGuiHelpers.ScaledDummy(5);
+
+ var enableAtBoot = profile.AlwaysEnableAtBoot;
+ if (ImGui.Checkbox("Always enable when game starts", ref enableAtBoot))
+ {
+ profile.AlwaysEnableAtBoot = enableAtBoot;
+ }
+
+ ImGuiHelpers.ScaledDummy(5);
+
+ ImGui.Separator();
+ var wantPluginAddPopup = false;
+
+ if (ImGui.BeginChild("###profileEditorPluginList"))
+ {
+ var pluginLineHeight = 32 * ImGuiHelpers.GlobalScale;
+
+ foreach (var plugin in profile.Plugins)
+ {
+ didAny = true;
+ var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.InternalName == plugin.InternalName);
+
+ if (pmPlugin != null)
+ {
+ pic.TryGetIcon(pmPlugin, pmPlugin.Manifest, pmPlugin.Manifest.IsThirdParty, out var icon);
+ icon ??= pic.DefaultIcon;
+
+ ImGui.Image(icon.ImGuiHandle, new Vector2(pluginLineHeight));
+ ImGui.SameLine();
+
+ var text = $"{pmPlugin.Name}";
+ var textHeight = ImGui.CalcTextSize(text);
+ var before = ImGui.GetCursorPos();
+
+ ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (textHeight.Y / 2));
+ ImGui.TextUnformatted(text);
+
+ ImGui.SetCursorPos(before);
+ }
+ else
+ {
+ ImGui.Image(pic.DefaultIcon.ImGuiHandle, new Vector2(pluginLineHeight));
+ ImGui.SameLine();
+
+ var text = $"{plugin.InternalName} (Not Installed)";
+ var textHeight = ImGui.CalcTextSize(text);
+ var before = ImGui.GetCursorPos();
+
+ ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (textHeight.Y / 2));
+ ImGui.TextUnformatted(text);
+
+ var available =
+ pm.AvailablePlugins.FirstOrDefault(
+ x => x.InternalName == plugin.InternalName && !x.SourceRepo.IsThirdParty);
+ if (available != null)
+ {
+ ImGui.SameLine();
+ ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 32 * 2));
+ ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (ImGui.GetFrameHeight() / 2));
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.Download))
+ {
+ this.installer.StartInstall(available, false);
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Install this plugin");
+ }
+
+ ImGui.SetCursorPos(before);
+ }
+
+ ImGui.SameLine();
+ 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))
+ {
+ Task.Run(() => profile.AddOrUpdate(plugin.InternalName, enabled))
+ .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change plugin state.");
+ }
+ }
+
+ if (!didAny)
+ {
+ ImGui.TextColored(ImGuiColors.DalamudGrey, "Profile has no plugins!");
+ }
+
+ ImGuiHelpers.ScaledDummy(10);
+
+ var addPluginsText = "Add a plugin!";
+ ImGuiHelpers.CenterCursorFor((int)(ImGui.CalcTextSize(addPluginsText).X + 30 + (ImGuiHelpers.GlobalScale * 5)));
+
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
+ wantPluginAddPopup = true;
+
+ ImGui.SameLine();
+ ImGuiHelpers.ScaledDummy(5);
+ ImGui.SameLine();
+
+ ImGui.TextUnformatted(addPluginsText);
+
+ ImGuiHelpers.ScaledDummy(10);
+
+ ImGui.EndChild();
+ }
+
+ if (wantPluginAddPopup)
+ ImGui.OpenPopup(addPluginToProfilePopup);
+ }
+
+ private enum Mode
+ {
+ Overview,
+ EditSingleProfile,
+ }
+}
diff --git a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs
index ec22ef8d7..6d5c03137 100644
--- a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs
+++ b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs
@@ -46,6 +46,14 @@ public class SettingsTabExperimental : SettingsTab
new GapSettingsEntry(5, true),
new ThirdRepoSettingsEntry(),
+
+ new GapSettingsEntry(5, true),
+
+ new SettingsEntry(
+ Loc.Localize("DalamudSettingsEnableProfiles", "Enable plugin profiles"),
+ Loc.Localize("DalamudSettingsEnableProfilesHint", "EXPERIMENTAL: Enables plugin profiles."),
+ c => c.ProfilesEnabled,
+ (v, c) => c.ProfilesEnabled = v),
};
public override string Title => Loc.Localize("DalamudSettingsExperimental", "Experimental");
diff --git a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs
index 8fe978ef1..419361b3b 100644
--- a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs
@@ -11,6 +11,7 @@ using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Style;
using Dalamud.Interface.Windowing;
+using Dalamud.Utility;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using Serilog;
@@ -97,7 +98,7 @@ public class StyleEditorWindow : Window
this.SaveStyle();
var newStyle = StyleModelV1.DalamudStandard;
- newStyle.Name = GetRandomName();
+ newStyle.Name = Util.GetRandomName();
config.SavedStyles.Add(newStyle);
this.currentSel = config.SavedStyles.Count - 1;
@@ -167,11 +168,11 @@ public class StyleEditorWindow : Window
{
var newStyle = StyleModel.Deserialize(styleJson);
- newStyle.Name ??= GetRandomName();
+ newStyle.Name ??= Util.GetRandomName();
if (config.SavedStyles.Any(x => x.Name == newStyle.Name))
{
- newStyle.Name = $"{newStyle.Name} ({GetRandomName()} Mix)";
+ newStyle.Name = $"{newStyle.Name} ({Util.GetRandomName()} Mix)";
}
config.SavedStyles.Add(newStyle);
@@ -375,15 +376,6 @@ public class StyleEditorWindow : Window
}
}
- private static string GetRandomName()
- {
- var data = Service.Get();
- var names = data.GetExcelSheet(ClientLanguage.English);
- var rng = new Random();
-
- return names.ElementAt(rng.Next(0, names.Count() - 1)).Singular.RawString;
- }
-
private void SaveStyle()
{
if (this.currentSel < 2)
diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs
index 311172c97..a647c1d03 100644
--- a/Dalamud/Plugin/Internal/PluginManager.cs
+++ b/Dalamud/Plugin/Internal/PluginManager.cs
@@ -23,6 +23,7 @@ using Dalamud.Interface.Internal;
using Dalamud.IoC.Internal;
using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal.Exceptions;
+using Dalamud.Plugin.Internal.Profiles;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility;
using Dalamud.Utility.Timing;
@@ -77,6 +78,9 @@ Thanks and have fun!";
[ServiceManager.ServiceDependency]
private readonly DalamudStartInfo startInfo = Service.Get();
+ [ServiceManager.ServiceDependency]
+ private readonly ProfileManager profileManager = Service.Get();
+
[ServiceManager.ServiceConstructor]
private PluginManager()
{
@@ -421,7 +425,7 @@ Thanks and have fun!";
try
{
- pluginDefs.Add(versionsDefs.OrderByDescending(x => x.Manifest!.EffectiveVersion).First());
+ pluginDefs.Add(versionsDefs.MaxBy(x => x.Manifest!.EffectiveVersion));
}
catch (Exception ex)
{
@@ -839,7 +843,7 @@ Thanks and have fun!";
/// If this plugin is being loaded at boot.
/// Don't load the plugin, just don't do it.
/// The loaded plugin.
- public async Task LoadPluginAsync(FileInfo dllFile, LocalPluginManifest? manifest, PluginLoadReason reason, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
+ private async Task LoadPluginAsync(FileInfo dllFile, LocalPluginManifest? manifest, PluginLoadReason reason, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
{
var name = manifest?.Name ?? dllFile.Name;
var loadPlugin = !doNotLoad;
@@ -859,8 +863,9 @@ Thanks and have fun!";
loadPlugin &= !isBoot || devPlugin.StartOnBoot;
// If we're not loading it, make sure it's disabled
- if (!loadPlugin && !devPlugin.IsDisabled)
- devPlugin.Disable();
+ // NOTE: Should be taken care of below by the profile code
+ // if (!loadPlugin && !devPlugin.IsDisabled)
+ // devPlugin.Disable();
plugin = devPlugin;
}
@@ -870,17 +875,24 @@ Thanks and have fun!";
plugin = new LocalPlugin(dllFile, manifest);
}
+#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 = this.profileManager.GetWantState(plugin.Manifest.InternalName, defaultState);
+
if (loadPlugin)
{
try
{
- if (!plugin.IsDisabled && !plugin.IsOrphaned)
+ if (wantToLoad && !plugin.IsOrphaned)
{
await plugin.LoadAsync(reason);
}
else
{
- Log.Verbose($"{name} not loaded, disabled:{plugin.IsDisabled} orphaned:{plugin.IsOrphaned}");
+ Log.Verbose($"{name} not loaded, wantToLoad:{wantToLoad} orphaned:{plugin.IsOrphaned}");
}
}
catch (InvalidPluginException)
@@ -1073,7 +1085,7 @@ Thanks and have fun!";
if (plugin.InstalledPlugin.IsDev)
continue;
- if (plugin.InstalledPlugin.Manifest.Disabled && ignoreDisabled)
+ if (!plugin.InstalledPlugin.IsWantedByAnyProfile && ignoreDisabled)
continue;
if (plugin.InstalledPlugin.Manifest.ScheduledForDeletion)
@@ -1132,6 +1144,7 @@ Thanks and have fun!";
if (plugin.IsDev)
{
+ // TODO: Does this ever work? Why? We should never update devplugins
try
{
plugin.DllFile.Delete();
@@ -1151,8 +1164,11 @@ Thanks and have fun!";
{
try
{
+ // TODO: Why were we ever doing this? We should never be loading the old version in the first place
+ /*
if (!plugin.IsDisabled)
plugin.Disable();
+ */
lock (this.pluginListLock)
{
diff --git a/Dalamud/Plugin/Internal/Profiles/Profile.cs b/Dalamud/Plugin/Internal/Profiles/Profile.cs
new file mode 100644
index 000000000..bae3e6f95
--- /dev/null
+++ b/Dalamud/Plugin/Internal/Profiles/Profile.cs
@@ -0,0 +1,214 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+
+using Dalamud.Configuration.Internal;
+using Dalamud.Logging.Internal;
+using Dalamud.Utility;
+
+namespace Dalamud.Plugin.Internal.Profiles;
+
+///
+/// Class representing a single runtime profile.
+///
+internal class Profile
+{
+ private static readonly ModuleLog Log = new("PROFILE");
+
+ private readonly ProfileManager manager;
+ private readonly ProfileModelV1 modelV1;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The manager this profile belongs to.
+ /// The model this profile is tied to.
+ /// Whether or not this profile is the default profile.
+ /// Whether or not this profile was initialized during bootup.
+ public Profile(ProfileManager manager, ProfileModel model, bool isDefaultProfile, bool isBoot)
+ {
+ this.manager = manager;
+ this.IsDefaultProfile = isDefaultProfile;
+ this.modelV1 = model as ProfileModelV1 ??
+ throw new ArgumentException("Model was null or unhandled version");
+
+ // We don't actually enable plugins here, PM will do it on bootup
+ if (isDefaultProfile)
+ {
+ // Default profile cannot be disabled
+ this.IsEnabled = this.modelV1.IsEnabled = true;
+ this.Name = this.modelV1.Name = "DEFAULT";
+ }
+ else if (this.modelV1.AlwaysEnableOnBoot && isBoot)
+ {
+ this.IsEnabled = true;
+ Log.Verbose("{Guid} set enabled because bootup", this.modelV1.Guid);
+ }
+ else if (this.modelV1.IsEnabled)
+ {
+ this.IsEnabled = true;
+ Log.Verbose("{Guid} set enabled because remember", this.modelV1.Guid);
+ }
+ else
+ {
+ Log.Verbose("{Guid} not enabled", this.modelV1.Guid);
+ }
+ }
+
+ ///
+ /// Gets or sets this profile's name.
+ ///
+ public string Name
+ {
+ get => this.modelV1.Name;
+ set
+ {
+ this.modelV1.Name = value;
+ Service.Get().QueueSave();
+ }
+ }
+
+ ///
+ /// Gets or sets a value indicating whether this profile shall always be enabled at boot.
+ ///
+ public bool AlwaysEnableAtBoot
+ {
+ get => this.modelV1.AlwaysEnableOnBoot;
+ set
+ {
+ this.modelV1.AlwaysEnableOnBoot = value;
+ Service.Get().QueueSave();
+ }
+ }
+
+ ///
+ /// Gets this profile's guid.
+ ///
+ public Guid Guid => this.modelV1.Guid;
+
+ ///
+ /// Gets a value indicating whether or not this profile is currently enabled.
+ ///
+ public bool IsEnabled { get; private set; }
+
+ ///
+ /// Gets a value indicating whether or not this profile is the default profile.
+ ///
+ public bool IsDefaultProfile { get; }
+
+ ///
+ /// Gets all plugins declared in this profile.
+ ///
+ public IEnumerable Plugins =>
+ this.modelV1.Plugins.Select(x => new ProfilePluginEntry(x.InternalName, x.IsEnabled));
+
+ ///
+ /// Gets this profile's underlying model.
+ ///
+ public ProfileModel Model => this.modelV1;
+
+ ///
+ /// Set this profile's state. This cannot be called for the default profile.
+ /// This will block until all states have been applied.
+ ///
+ /// Whether or not the profile is enabled.
+ /// Whether or not the current state should immediately be applied.
+ /// Thrown when an untoggleable profile is toggled.
+ public void SetState(bool enabled, bool apply = true)
+ {
+ if (this.IsDefaultProfile)
+ throw new InvalidOperationException("Cannot set state of default profile");
+
+ Debug.Assert(this.IsEnabled != enabled, "Trying to set state of a profile to the same state");
+ this.IsEnabled = this.modelV1.IsEnabled = enabled;
+ Log.Verbose("Set state {State} for {Guid}", enabled, this.modelV1.Guid);
+
+ Service.Get().QueueSave();
+
+ if (apply)
+ this.manager.ApplyAllWantStates();
+ }
+
+ ///
+ /// Check if this profile contains a specific plugin, and if it is enabled.
+ ///
+ /// The internal name of the plugin.
+ /// 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.
+ public bool? WantsPlugin(string internalName)
+ {
+ var entry = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName);
+ return entry?.IsEnabled;
+ }
+
+ ///
+ /// 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.
+ ///
+ /// The internal name of the plugin.
+ /// Whether or not the plugin should be enabled.
+ /// Whether or not the current state should immediately be applied.
+ public void AddOrUpdate(string internalName, bool state, bool apply = true)
+ {
+ Debug.Assert(!internalName.IsNullOrEmpty(), "!internalName.IsNullOrEmpty()");
+
+ var existing = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName);
+ if (existing != null)
+ {
+ existing.IsEnabled = state;
+ }
+ else
+ {
+ this.modelV1.Plugins.Add(new ProfileModelV1.ProfileModelV1Plugin
+ {
+ InternalName = internalName,
+ 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)
+ {
+ this.manager.DefaultProfile.Remove(internalName, false);
+ }
+
+ Service.Get().QueueSave();
+
+ if (apply)
+ this.manager.ApplyAllWantStates();
+ }
+
+ ///
+ /// Remove a plugin from this profile.
+ /// This will block until all states have been applied.
+ ///
+ /// The internal name of the plugin.
+ /// Whether or not the current state should immediately be applied.
+ public void Remove(string internalName, bool apply = true)
+ {
+ var entry = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName);
+ if (entry == null)
+ throw new ArgumentException($"No plugin \"{internalName}\" in profile \"{this.Guid}\"");
+
+ 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(internalName))
+ {
+ if (!this.IsDefaultProfile)
+ {
+ this.manager.DefaultProfile.AddOrUpdate(internalName, entry.IsEnabled, false);
+ }
+ else
+ {
+ throw new Exception("Removed plugin from default profile, but wasn't in any other profile");
+ }
+ }
+
+ Service.Get().QueueSave();
+
+ if (apply)
+ this.manager.ApplyAllWantStates();
+ }
+}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
new file mode 100644
index 000000000..995f91f5f
--- /dev/null
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
@@ -0,0 +1,164 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+using CheapLoc;
+using Dalamud.Game;
+using Dalamud.Game.Command;
+using Dalamud.Game.Gui;
+using Dalamud.Utility;
+using Serilog;
+
+namespace Dalamud.Plugin.Internal.Profiles;
+
+[ServiceManager.EarlyLoadedService]
+internal class ProfileCommandHandler : IServiceType, IDisposable
+{
+ private readonly CommandManager cmd;
+ private readonly ProfileManager profileManager;
+ private readonly ChatGui chat;
+ private readonly Framework framework;
+
+ private Queue<(string, ProfileOp)> queue = new();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ [ServiceManager.ServiceConstructor]
+ public ProfileCommandHandler(CommandManager cmd, ProfileManager profileManager, ChatGui chat, Framework framework)
+ {
+ this.cmd = cmd;
+ this.profileManager = profileManager;
+ this.chat = chat;
+ this.framework = framework;
+
+ this.cmd.AddHandler("/xlenableprofile", new CommandInfo(this.OnEnableProfile)
+ {
+ HelpMessage = "",
+ ShowInHelp = true,
+ });
+
+ this.cmd.AddHandler("/xldisableprofile", new CommandInfo(this.OnDisableProfile)
+ {
+ HelpMessage = "",
+ ShowInHelp = true,
+ });
+
+ this.cmd.AddHandler("/xltoggleprofile", new CommandInfo(this.OnToggleProfile)
+ {
+ HelpMessage = "",
+ ShowInHelp = true,
+ });
+
+ this.framework.Update += this.FrameworkOnUpdate;
+ }
+
+ private void FrameworkOnUpdate(Framework framework1)
+ {
+ if (this.profileManager.IsBusy)
+ return;
+
+ if (this.queue.TryDequeue(out var op))
+ {
+ var profile = this.profileManager.Profiles.FirstOrDefault(x => x.Name == op.Item1);
+ if (profile == null || profile.IsDefaultProfile)
+ return;
+
+ switch (op.Item2)
+ {
+ case ProfileOp.Enable:
+ if (!profile.IsEnabled)
+ profile.SetState(true, false);
+ break;
+ case ProfileOp.Disable:
+ if (profile.IsEnabled)
+ profile.SetState(false, false);
+ break;
+ case ProfileOp.Toggle:
+ profile.SetState(!profile.IsEnabled, false);
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+
+ if (profile.IsEnabled)
+ {
+ this.chat.Print(Loc.Localize("ProfileCommandsEnabling", "Enabling profile \"{0}\"...").Format(profile.Name));
+ }
+ else
+ {
+ this.chat.Print(Loc.Localize("ProfileCommandsDisabling", "Disabling profile \"{0}\"...").Format(profile.Name));
+ }
+
+ Task.Run(() => this.profileManager.ApplyAllWantStates()).ContinueWith(t =>
+ {
+ if (!t.IsCompletedSuccessfully && t.Exception != null)
+ {
+ Log.Error(t.Exception, "Could not apply profiles through commands");
+ this.chat.PrintError(Loc.Localize("ProfileCommandsApplyFailed", "Failed to apply all of your profiles. Please check the console for errors."));
+ }
+ else
+ {
+ this.chat.Print(Loc.Localize("ProfileCommandsApplySuccess", "Profiles applied."));
+ }
+ });
+ }
+ }
+
+ public void Dispose()
+ {
+ this.cmd.RemoveHandler("/xlenableprofile");
+ this.cmd.RemoveHandler("/xldisableprofile");
+ this.cmd.RemoveHandler("/xltoggleprofile");
+
+ this.framework.Update += this.FrameworkOnUpdate;
+ }
+
+ private void OnEnableProfile(string command, string arguments)
+ {
+ var name = this.ValidateName(arguments);
+ if (name == null)
+ return;
+
+ this.queue.Enqueue((name, ProfileOp.Enable));
+ }
+
+ private void OnDisableProfile(string command, string arguments)
+ {
+ var name = this.ValidateName(arguments);
+ if (name == null)
+ return;
+
+ this.queue.Enqueue((name, ProfileOp.Disable));
+ }
+
+ private void OnToggleProfile(string command, string arguments)
+ {
+ var name = this.ValidateName(arguments);
+ if (name == null)
+ return;
+
+ this.queue.Enqueue((name, ProfileOp.Toggle));
+ }
+
+ private string? ValidateName(string arguments)
+ {
+ var name = arguments.Replace("\"", string.Empty);
+ if (this.profileManager.Profiles.All(x => x.Name != name))
+ {
+ this.chat.PrintError($"No profile like \"{name}\".");
+ return null;
+ }
+
+ return name;
+ }
+
+ private enum ProfileOp
+ {
+ Enable,
+ Disable,
+ Toggle,
+ }
+}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
new file mode 100644
index 000000000..7a8772d74
--- /dev/null
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -0,0 +1,356 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+using CheapLoc;
+using Dalamud.Configuration.Internal;
+using Dalamud.Logging.Internal;
+using Dalamud.Utility;
+
+namespace Dalamud.Plugin.Internal.Profiles;
+
+///
+/// Class responsible for managing plugin profiles.
+///
+[ServiceManager.BlockingEarlyLoadedService]
+internal class ProfileManager : IServiceType
+{
+ private static readonly ModuleLog Log = new("PROFMAN");
+ private readonly DalamudConfiguration config;
+
+ private readonly List profiles = new();
+
+ private volatile bool isBusy = false;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Dalamud config.
+ [ServiceManager.ServiceConstructor]
+ public ProfileManager(DalamudConfiguration config)
+ {
+ this.config = config;
+
+ this.LoadProfilesFromConfigInitially();
+ }
+
+ ///
+ /// Gets the default profile.
+ ///
+ public Profile DefaultProfile => this.profiles.First(x => x.IsDefaultProfile);
+
+ ///
+ /// Gets all profiles, including the default profile.
+ ///
+ public IEnumerable Profiles => this.profiles;
+
+ ///
+ /// Gets a value indicating whether or not the profile manager is busy enabling/disabling plugins.
+ ///
+ public bool IsBusy => this.isBusy;
+
+ ///
+ /// Check if any enabled profile wants a specific plugin enabled.
+ ///
+ /// The internal name of the plugin.
+ /// The state the plugin shall be in, if it needs to be added.
+ /// Whether or not the plugin should be added to the default preset, if it's not present in any preset.
+ /// Whether or not the plugin shall be enabled.
+ public bool GetWantState(string internalName, bool defaultState, bool addIfNotDeclared = true)
+ {
+ var want = false;
+ var wasInAnyProfile = false;
+
+ foreach (var profile in this.profiles)
+ {
+ var state = profile.WantsPlugin(internalName);
+ Log.Verbose("Checking {Name} in {Profile}: {State}", internalName, profile.Guid, state == null ? "null" : state);
+
+ if (state.HasValue)
+ {
+ want = want || (profile.IsEnabled && state.Value);
+ wasInAnyProfile = true;
+ }
+ }
+
+ if (!wasInAnyProfile && addIfNotDeclared)
+ {
+ Log.Warning("{Name} was not in any profile, adding to default with {Default}", internalName, defaultState);
+ this.DefaultProfile.AddOrUpdate(internalName, defaultState, false);
+ return defaultState;
+ }
+
+ return want;
+ }
+
+ ///
+ /// Check whether a plugin is declared in any profile.
+ ///
+ /// The internal name of the plugin.
+ /// Whether or not the plugin is in any profile.
+ public bool IsInAnyProfile(string internalName)
+ => this.profiles.Any(x => x.WantsPlugin(internalName) != null);
+
+ ///
+ /// 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.
+ ///
+ /// The internal name of the plugin.
+ /// Whether or not the plugin is in the default profile.
+ public bool IsInDefaultProfile(string internalName)
+ => this.DefaultProfile.WantsPlugin(internalName) != null;
+
+ ///
+ /// Add a new profile.
+ ///
+ /// The added profile.
+ public Profile AddNewProfile()
+ {
+ var model = new ProfileModelV1
+ {
+ Guid = Guid.NewGuid(),
+ Name = this.GenerateUniqueProfileName(Loc.Localize("PluginProfilesNewProfile", "New Profile")),
+ IsEnabled = false,
+ };
+
+ this.config.SavedProfiles!.Add(model);
+ this.config.QueueSave();
+
+ var profile = new Profile(this, model, false, false);
+ this.profiles.Add(profile);
+
+ return profile;
+ }
+
+ ///
+ /// Clone a specified profile.
+ ///
+ /// The profile to clone.
+ /// The newly cloned profile.
+ public Profile CloneProfile(Profile toClone)
+ {
+ var newProfile = this.ImportProfile(toClone.Model.Serialize());
+ if (newProfile == null)
+ throw new Exception("New profile was null while cloning");
+
+ return newProfile;
+ }
+
+ ///
+ /// Import a profile with a sharing string.
+ ///
+ /// The sharing string to import.
+ /// The imported profile, or null, if the string was invalid.
+ public Profile? ImportProfile(string data)
+ {
+ var newModel = ProfileModel.Deserialize(data);
+ if (newModel == null)
+ return null;
+
+ newModel.Guid = Guid.NewGuid();
+ newModel.Name = this.GenerateUniqueProfileName(newModel.Name.IsNullOrEmpty() ? "Unknown Profile" : newModel.Name);
+ if (newModel is ProfileModelV1 modelV1)
+ modelV1.IsEnabled = false;
+
+ this.config.SavedProfiles!.Add(newModel);
+ this.config.QueueSave();
+
+ var profile = new Profile(this, newModel, false, false);
+ this.profiles.Add(profile);
+
+ return profile;
+ }
+
+ ///
+ /// Go through all profiles and plugins, and enable/disable plugins they want active.
+ /// This will block until all plugins have been loaded/reloaded!
+ ///
+ public void ApplyAllWantStates()
+ {
+ this.isBusy = true;
+ Log.Information("Getting want states...");
+
+ var wantActive = this.profiles
+ .Where(x => x.IsEnabled)
+ .SelectMany(profile => profile.Plugins.Where(plugin => plugin.IsEnabled)
+ .Select(plugin => plugin.InternalName))
+ .Distinct().ToList();
+
+ foreach (var internalName in wantActive)
+ {
+ Log.Information("\t=> Want {Name}", internalName);
+ }
+
+ Log.Information("Applying want states...");
+
+ var pm = Service.Get();
+ var tasks = new List();
+
+ foreach (var installedPlugin in pm.InstalledPlugins)
+ {
+ if (installedPlugin.IsDev)
+ continue;
+
+ var wantThis = wantActive.Contains(installedPlugin.Manifest.InternalName);
+ switch (wantThis)
+ {
+ case true when !installedPlugin.IsLoaded:
+ if (installedPlugin.ApplicableForLoad)
+ {
+ Log.Information("\t=> Enabling {Name}", installedPlugin.Manifest.InternalName);
+ tasks.Add(installedPlugin.LoadAsync(PluginLoadReason.Installer));
+ }
+ else
+ {
+ Log.Warning("\t=> {Name} wanted active, but not applicable", installedPlugin.Manifest.InternalName);
+ }
+
+ break;
+ case false when installedPlugin.IsLoaded:
+ Log.Information("\t=> Disabling {Name}", installedPlugin.Manifest.InternalName);
+ tasks.Add(installedPlugin.UnloadAsync());
+ break;
+ }
+ }
+
+ // This is probably not ideal... Might need to rethink the error handling strategy for this.
+ try
+ {
+ Task.WaitAll(tasks.ToArray());
+ }
+ catch (Exception e)
+ {
+ Log.Error(e, "Couldn't apply state for one or more plugins");
+ }
+
+ Log.Information("Applied!");
+ this.isBusy = false;
+ }
+
+ ///
+ /// Delete a profile and re-apply all profiles.
+ ///
+ /// The profile to delete.
+ public void DeleteProfile(Profile profile)
+ {
+ Debug.Assert(this.config.SavedProfiles!.Remove(profile.Model), "this.config.SavedProfiles!.Remove(profile.Model)");
+ Debug.Assert(this.profiles.Remove(profile), "this.profiles.Remove(profile)");
+
+ this.ApplyAllWantStates();
+ this.config.QueueSave();
+ }
+
+ private string GenerateUniqueProfileName(string startingWith)
+ {
+ if (this.profiles.All(x => x.Name != startingWith))
+ return startingWith;
+
+ startingWith = Regex.Replace(startingWith, @" \(.* Mix\)", string.Empty);
+
+ while (true)
+ {
+ var newName = $"{startingWith} ({CultureInfo.InvariantCulture.TextInfo.ToTitleCase(Util.GetRandomName())} Mix)";
+
+ if (this.profiles.All(x => x.Name != newName))
+ return newName;
+ }
+ }
+
+ private void LoadProfilesFromConfigInitially()
+ {
+ var needMigration = false;
+ if (this.config.DefaultProfile == null)
+ {
+ this.config.DefaultProfile = new ProfileModelV1();
+ needMigration = true;
+ }
+
+ this.profiles.Add(new Profile(this, this.config.DefaultProfile, true, true));
+
+ if (needMigration)
+ {
+ // Don't think we need this here with the migration logic in GetWantState
+ //this.MigratePluginsIntoDefaultProfile();
+ }
+
+ this.config.SavedProfiles ??= new List();
+ foreach (var profileModel in this.config.SavedProfiles)
+ {
+ this.profiles.Add(new Profile(this, profileModel, false, true));
+ }
+
+ this.config.QueueSave();
+ }
+
+ // This duplicates some of the original handling in PM; don't care though
+ /*
+ private void MigratePluginsIntoDefaultProfile()
+ {
+ var pluginDirectory = new DirectoryInfo(Service.Get().PluginDirectory!);
+ var pluginDefs = new List();
+
+ Log.Information($"Now migrating plugins at {pluginDirectory} into profiles");
+
+ // Nothing to migrate
+ if (!pluginDirectory.Exists)
+ {
+ Log.Information("\t=> Plugin directory didn't exist, nothing to migrate");
+ return;
+ }
+
+ // Add installed plugins. These are expected to be in a specific format so we can look for exactly that.
+ foreach (var pluginDir in pluginDirectory.GetDirectories())
+ {
+ var versionsDefs = new List();
+ foreach (var versionDir in pluginDir.GetDirectories())
+ {
+ try
+ {
+ var dllFile = new FileInfo(Path.Combine(versionDir.FullName, $"{pluginDir.Name}.dll"));
+ var manifestFile = LocalPluginManifest.GetManifestFile(dllFile);
+
+ if (!manifestFile.Exists)
+ continue;
+
+ var manifest = LocalPluginManifest.Load(manifestFile);
+ versionsDefs.Add(new PluginDef(dllFile, manifest, false));
+ }
+ catch (Exception ex)
+ {
+ Log.Error(ex, "Could not load manifest for installed at {Directory}", versionDir.FullName);
+ }
+ }
+
+ try
+ {
+ pluginDefs.Add(versionsDefs.MaxBy(x => x.Manifest!.EffectiveVersion));
+ }
+ catch (Exception ex)
+ {
+ Log.Error(ex, "Couldn't choose best version for plugin: {Name}", pluginDir.Name);
+ }
+ }
+
+ var defaultProfile = this.DefaultProfile;
+ foreach (var pluginDef in pluginDefs)
+ {
+ if (pluginDef.Manifest == null)
+ {
+ Log.Information($"\t=> Skipping DLL at {pluginDef.DllFile.FullName}, no valid manifest");
+ continue;
+ }
+
+ // OK for migration code
+#pragma warning disable CS0618
+ defaultProfile.AddOrUpdate(pluginDef.Manifest.InternalName, !pluginDef.Manifest.Disabled, false);
+ Log.Information(
+ $"\t=> Added {pluginDef.Manifest.InternalName} to default profile with {!pluginDef.Manifest.Disabled}");
+#pragma warning restore CS0618
+ }
+ }
+ */
+}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
new file mode 100644
index 000000000..06075a07e
--- /dev/null
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
@@ -0,0 +1,40 @@
+using System;
+
+using Dalamud.Utility;
+using Newtonsoft.Json;
+
+namespace Dalamud.Plugin.Internal.Profiles;
+
+public abstract class ProfileModel
+{
+ [JsonProperty("id")]
+ public Guid Guid { get; set; } = Guid.Empty;
+
+ [JsonProperty("n")]
+ public string Name { get; set; } = "New Profile";
+
+ public static ProfileModel? Deserialize(string model)
+ {
+ var json = Util.DecompressString(Convert.FromBase64String(model.Substring(3)));
+
+ if (model.StartsWith(ProfileModelV1.SerializedPrefix))
+ return JsonConvert.DeserializeObject(json);
+
+ throw new ArgumentException("Was not a compressed style model.");
+ }
+
+ public string Serialize()
+ {
+ string prefix;
+ switch (this)
+ {
+ case ProfileModelV1:
+ prefix = ProfileModelV1.SerializedPrefix;
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+
+ return prefix + Convert.ToBase64String(Util.CompressString(JsonConvert.SerializeObject(this)));
+ }
+}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs b/Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
new file mode 100644
index 000000000..cae585c30
--- /dev/null
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Dalamud.Plugin.Internal.Profiles;
+
+public class ProfileModelV1 : ProfileModel
+{
+ public static string SerializedPrefix => "DP1";
+
+ [JsonProperty("b")]
+ public bool AlwaysEnableOnBoot { get; set; } = false;
+
+ [JsonProperty("e")]
+ public bool IsEnabled { get; set; } = false;
+
+ [JsonProperty("c")]
+ public uint Color { get; set; }
+
+ public List Plugins { get; set; } = new();
+
+ public class ProfileModelV1Plugin
+ {
+ public string InternalName { get; set; }
+
+ public bool IsEnabled { get; set; }
+ }
+}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs b/Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
new file mode 100644
index 000000000..21856e572
--- /dev/null
+++ b/Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
@@ -0,0 +1,14 @@
+namespace Dalamud.Plugin.Internal.Profiles;
+
+internal class ProfilePluginEntry
+{
+ public ProfilePluginEntry(string internalName, bool state)
+ {
+ this.InternalName = internalName;
+ this.IsEnabled = state;
+ }
+
+ public string InternalName { get; }
+
+ public bool IsEnabled { get; }
+}
diff --git a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
index 2c77ff528..db5556662 100644
--- a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
+++ b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
@@ -14,6 +14,7 @@ using Dalamud.IoC.Internal;
using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal.Exceptions;
using Dalamud.Plugin.Internal.Loader;
+using Dalamud.Plugin.Internal.Profiles;
using Dalamud.Utility;
namespace Dalamud.Plugin.Internal.Types;
@@ -199,10 +200,20 @@ internal class LocalPlugin : IDisposable
///
public bool IsLoaded => this.State == PluginState.Loaded;
+ /*
///
/// Gets a value indicating whether the plugin is disabled.
///
+ [Obsolete("This is no longer accurate, use the profile manager instead.", true)]
public bool IsDisabled => this.Manifest.Disabled;
+ */
+
+ ///
+ /// Gets a value indicating whether this plugin is wanted active by any profile.
+ /// INCLUDES the default profile.
+ ///
+ public bool IsWantedByAnyProfile =>
+ Service.Get().GetWantState(this.Manifest.InternalName, false, false);
///
/// Gets a value indicating whether this plugin's API level is out of date.
@@ -238,6 +249,12 @@ internal class LocalPlugin : IDisposable
///
public bool IsDev => this is LocalDevPlugin;
+ ///
+ /// Gets a value indicating whether this plugin should be allowed to load.
+ ///
+ public bool ApplicableForLoad => !this.IsBanned && !this.IsDecommissioned && !this.IsOrphaned && !this.IsOutdated
+ && !(!this.IsDev && this.State == PluginState.UnloadError) && this.CheckPolicy();
+
///
public void Dispose()
{
@@ -275,7 +292,6 @@ internal class LocalPlugin : IDisposable
/// A task.
public async Task LoadAsync(PluginLoadReason reason, bool reloading = false)
{
- var configuration = await Service.GetAsync();
var framework = await Service.GetAsync();
var ioc = await Service.GetAsync();
var pluginManager = await Service.GetAsync();
@@ -297,6 +313,10 @@ internal class LocalPlugin : IDisposable
this.ReloadManifest();
}
+ // If we reload a plugin we don't want to delete it. Makes sense, right?
+ this.Manifest.ScheduledForDeletion = false;
+ this.SaveManifest();
+
switch (this.State)
{
case PluginState.Loaded:
@@ -329,8 +349,9 @@ internal class LocalPlugin : IDisposable
if (this.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels)
throw new InvalidPluginOperationException($"Unable to load {this.Name}, incompatible API level");
- if (this.Manifest.Disabled)
- throw new InvalidPluginOperationException($"Unable to load {this.Name}, disabled");
+ // TODO: should we throw here?
+ if (!this.IsWantedByAnyProfile)
+ Log.Warning("{Name} is loading, but isn't wanted by any profile", this.Name);
if (this.IsOrphaned)
throw new InvalidPluginOperationException($"Plugin {this.Name} had no associated repo.");
@@ -547,9 +568,11 @@ internal class LocalPlugin : IDisposable
await this.LoadAsync(PluginLoadReason.Reload, true);
}
+ /*
///
/// Revert a disable. Must be unloaded first, does not load.
///
+ [Obsolete("Profile API", true)]
public void Enable()
{
// Allowed: Unloaded, UnloadError
@@ -580,6 +603,7 @@ internal class LocalPlugin : IDisposable
this.Manifest.ScheduledForDeletion = false;
this.SaveManifest();
}
+ */
///
/// Check if anything forbids this plugin from loading.
@@ -602,9 +626,11 @@ internal class LocalPlugin : IDisposable
return true;
}
+ /*
///
/// Disable this plugin, must be unloaded first.
///
+ [Obsolete("Profile API", true)]
public void Disable()
{
// Allowed: Unloaded, UnloadError
@@ -631,6 +657,7 @@ internal class LocalPlugin : IDisposable
this.Manifest.Disabled = true;
this.SaveManifest();
}
+ */
///
/// Schedule the deletion of this plugin on next cleanup.
@@ -650,9 +677,9 @@ internal class LocalPlugin : IDisposable
var manifest = LocalPluginManifest.GetManifestFile(this.DllFile);
if (manifest.Exists)
{
- var isDisabled = this.IsDisabled; // saving the internal state because it could have been deleted
+ //var isDisabled = this.IsDisabled; // saving the internal state because it could have been deleted
this.Manifest = LocalPluginManifest.Load(manifest);
- this.Manifest.Disabled = isDisabled;
+ //this.Manifest.Disabled = isDisabled;
this.SaveManifest();
}
diff --git a/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs b/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs
index 52cc55b23..8a21328c5 100644
--- a/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs
+++ b/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs
@@ -28,6 +28,7 @@ internal record LocalPluginManifest : PluginManifest
/// Gets or sets a value indicating whether the plugin is disabled and should not be loaded.
/// This value supersedes the ".disabled" file functionality and should not be included in the plugin master.
///
+ [Obsolete("This is merely used for migrations now. Use the profile manager to check if a plugin shall be enabled.")]
public bool Disabled { get; set; }
///
diff --git a/Dalamud/Plugin/Internal/Types/PluginManifest.cs b/Dalamud/Plugin/Internal/Types/PluginManifest.cs
index 66b17ed73..71051e666 100644
--- a/Dalamud/Plugin/Internal/Types/PluginManifest.cs
+++ b/Dalamud/Plugin/Internal/Types/PluginManifest.cs
@@ -162,6 +162,12 @@ internal record PluginManifest
[JsonProperty]
public bool CanUnloadAsync { get; init; }
+ ///
+ /// Gets a value indicating whether the plugin supports profiles.
+ ///
+ [JsonProperty]
+ public bool SupportsProfiles { get; init; } = true;
+
///
/// Gets a list of screenshot image URLs to show in the plugin installer.
///
diff --git a/Dalamud/Plugin/PluginLoadReason.cs b/Dalamud/Plugin/PluginLoadReason.cs
index ade95ae67..d4c1a3b26 100644
--- a/Dalamud/Plugin/PluginLoadReason.cs
+++ b/Dalamud/Plugin/PluginLoadReason.cs
@@ -30,3 +30,5 @@ public enum PluginLoadReason
///
Boot,
}
+
+// TODO(api9): This should be a mask, so that we can combine Installer | ProfileLoaded
diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs
index 7837e1bab..e04be3334 100644
--- a/Dalamud/Utility/Util.cs
+++ b/Dalamud/Utility/Util.cs
@@ -11,12 +11,14 @@ using System.Runtime.CompilerServices;
using System.Text;
using Dalamud.Configuration.Internal;
+using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Logging.Internal;
using ImGuiNET;
+using Lumina.Excel.GeneratedSheets;
using Microsoft.Win32;
using Serilog;
@@ -605,6 +607,19 @@ public static class Util
File.Move(tmpPath, path, true);
}
+ ///
+ /// Gets a random, inoffensive, human-friendly string.
+ ///
+ /// A random human-friendly name.
+ internal static string GetRandomName()
+ {
+ var data = Service.Get();
+ var names = data.GetExcelSheet(ClientLanguage.English)!;
+ var rng = new Random();
+
+ return names.ElementAt(rng.Next(0, names.Count() - 1)).Singular.RawString;
+ }
+
private static unsafe void ShowValue(ulong addr, IEnumerable path, Type type, object value)
{
if (type.IsPointer)
From e93e1cc806ec6e09e9dcda75aa0d4bf65283f0e9 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 20:08:10 +0200
Subject: [PATCH 02/28] add delete button to plugins in profiles
---
.../PluginInstaller/ProfileManagerWidget.cs | 27 ++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index fcb941d95..c9fe5ba84 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -131,7 +131,7 @@ internal class ProfileManagerWidget
ImGui.SameLine();
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 3) - 5);
- if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport))
+ if (ImGuiComponents.IconButton($"###exportButton{profile.Guid}", FontAwesomeIcon.FileExport))
{
ImGui.SetClipboardText(profile.Model.Serialize());
Service.Get().AddNotification("Copied to clipboard!", type: NotificationType.Success);
@@ -295,11 +295,13 @@ internal class ProfileManagerWidget
if (ImGui.BeginChild("###profileEditorPluginList"))
{
var pluginLineHeight = 32 * ImGuiHelpers.GlobalScale;
+ string? wantRemovePluginInternalName = null;
foreach (var plugin in profile.Plugins)
{
didAny = true;
var pmPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.InternalName == plugin.InternalName);
+ var btnOffset = 2;
if (pmPlugin != null)
{
@@ -336,10 +338,11 @@ internal class ProfileManagerWidget
if (available != null)
{
ImGui.SameLine();
- ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 32 * 2));
+ ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 2) - 2);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (ImGui.GetFrameHeight() / 2));
+ btnOffset = 3;
- if (ImGuiComponents.IconButton(FontAwesomeIcon.Download))
+ if (ImGuiComponents.IconButton($"###installMissingPlugin{available.InternalName}", FontAwesomeIcon.Download))
{
this.installer.StartInstall(available, false);
}
@@ -361,6 +364,24 @@ internal class ProfileManagerWidget
Task.Run(() => profile.AddOrUpdate(plugin.InternalName, enabled))
.ContinueWith(this.installer.DisplayErrorContinuation, "Could not change plugin state.");
}
+
+ ImGui.SameLine();
+ 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))
+ {
+ wantRemovePluginInternalName = plugin.InternalName;
+ }
+
+ if (ImGui.IsItemHovered())
+ ImGui.SetTooltip("Remove plugin from this profile");
+ }
+
+ if (wantRemovePluginInternalName != null)
+ {
+ Task.Run(() => profile.Remove(wantRemovePluginInternalName))
+ .ContinueWith(this.installer.DisplayErrorContinuation, "Could not remove plugin.");
}
if (!didAny)
From 2ed215b74b3f8be71f69981655dc0328d2123bd7 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 20:14:06 +0200
Subject: [PATCH 03/28] make sure no plugins are lost when deleting a profile
---
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index 7a8772d74..11214ba08 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -237,6 +237,12 @@ internal class ProfileManager : IServiceType
/// The profile to delete.
public void DeleteProfile(Profile profile)
{
+ // 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)
+ {
+ profile.Remove(plugin.InternalName, false);
+ }
+
Debug.Assert(this.config.SavedProfiles!.Remove(profile.Model), "this.config.SavedProfiles!.Remove(profile.Model)");
Debug.Assert(this.profiles.Remove(profile), "this.profiles.Remove(profile)");
From 7fe004c8758889eeecb82ca65812c9b05cbb6fcd Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 20:25:46 +0200
Subject: [PATCH 04/28] remove plugins from deleting profile synchronously
---
.../Windows/PluginInstaller/ProfileManagerWidget.cs | 4 +++-
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs | 8 +++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index c9fe5ba84..ab25c4c88 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -243,7 +243,9 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash))
{
- Task.Run(() => profman.DeleteProfile(profile))
+ // DeleteProfile() is sync, it doesn't apply and we are modifying the plugins collection. Will throw below when iterating
+ profman.DeleteProfile(profile);
+ Task.Run(() => profman.ApplyAllWantStates())
.ContinueWith(t =>
{
this.Reset();
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index 11214ba08..71835a9d6 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -232,13 +232,16 @@ internal class ProfileManager : IServiceType
}
///
- /// Delete a profile and re-apply all profiles.
+ /// Delete a profile.
///
+ ///
+ /// You should definitely apply states after this. It doesn't do it for you.
+ ///
/// The profile to delete.
public void DeleteProfile(Profile profile)
{
// 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)
+ foreach (var plugin in profile.Plugins.ToArray())
{
profile.Remove(plugin.InternalName, false);
}
@@ -246,7 +249,6 @@ internal class ProfileManager : IServiceType
Debug.Assert(this.config.SavedProfiles!.Remove(profile.Model), "this.config.SavedProfiles!.Remove(profile.Model)");
Debug.Assert(this.profiles.Remove(profile), "this.profiles.Remove(profile)");
- this.ApplyAllWantStates();
this.config.QueueSave();
}
From 8d7ae903a4644780235c2fdc5d7124cb3d4e4b50 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 20:28:06 +0200
Subject: [PATCH 05/28] actually delete profiles in release build
---
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index 71835a9d6..62ade19b2 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -246,8 +246,11 @@ internal class ProfileManager : IServiceType
profile.Remove(plugin.InternalName, false);
}
- Debug.Assert(this.config.SavedProfiles!.Remove(profile.Model), "this.config.SavedProfiles!.Remove(profile.Model)");
- Debug.Assert(this.profiles.Remove(profile), "this.profiles.Remove(profile)");
+ if (!this.config.SavedProfiles!.Remove(profile.Model))
+ throw new Exception("Couldn't remove profile from models");
+
+ if (!this.profiles.Remove(profile))
+ throw new Exception("Couldn't remove runtime profile");
this.config.QueueSave();
}
From 29ba86021c21c1ed50d02ce62864d172cb33d2a5 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 20:45:29 +0200
Subject: [PATCH 06/28] remove spammy log
---
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs | 2 --
1 file changed, 2 deletions(-)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index 62ade19b2..e5455cd44 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -68,8 +68,6 @@ internal class ProfileManager : IServiceType
foreach (var profile in this.profiles)
{
var state = profile.WantsPlugin(internalName);
- Log.Verbose("Checking {Name} in {Profile}: {State}", internalName, profile.Guid, state == null ? "null" : state);
-
if (state.HasValue)
{
want = want || (profile.IsEnabled && state.Value);
From 869ce9568d21e9673cf2d75cdd6c8eba0706ea27 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 21:03:15 +0200
Subject: [PATCH 07/28] make dev plugins work, maybe
---
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs | 3 ---
1 file changed, 3 deletions(-)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index e5455cd44..f189424a3 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -190,9 +190,6 @@ internal class ProfileManager : IServiceType
foreach (var installedPlugin in pm.InstalledPlugins)
{
- if (installedPlugin.IsDev)
- continue;
-
var wantThis = wantActive.Contains(installedPlugin.Manifest.InternalName);
switch (wantThis)
{
From 4328826c8682d8296d5607edde2c82e94e1d9f3e Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 21:07:21 +0200
Subject: [PATCH 08/28] never ever update dev plugins
---
.../PluginInstaller/PluginInstallerWindow.cs | 2 +-
Dalamud/Plugin/Internal/PluginManager.cs | 42 ++++++-------------
2 files changed, 14 insertions(+), 30 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index 73ef523e9..4c9074043 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -2176,7 +2176,7 @@ internal class PluginInstallerWindow : Window, IDisposable
this.DrawSendFeedbackButton(plugin.Manifest, plugin.IsTesting);
}
- if (availablePluginUpdate != default)
+ if (availablePluginUpdate != default && ! plugin.IsDev)
this.DrawUpdateSinglePluginButton(availablePluginUpdate);
ImGui.SameLine();
diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs
index a647c1d03..15d975d0b 100644
--- a/Dalamud/Plugin/Internal/PluginManager.cs
+++ b/Dalamud/Plugin/Internal/PluginManager.cs
@@ -1144,44 +1144,28 @@ Thanks and have fun!";
if (plugin.IsDev)
{
- // TODO: Does this ever work? Why? We should never update devplugins
- try
- {
- plugin.DllFile.Delete();
- lock (this.pluginListLock)
- {
- this.InstalledPlugins = this.InstalledPlugins.Remove(plugin);
- }
- }
- catch (Exception ex)
- {
- Log.Error(ex, "Error during delete (update)");
- updateStatus.WasUpdated = false;
- return updateStatus;
- }
+ throw new Exception("We should never update a dev plugin");
}
- else
+
+ try
{
- try
- {
- // TODO: Why were we ever doing this? We should never be loading the old version in the first place
- /*
+ // TODO: Why were we ever doing this? We should never be loading the old version in the first place
+ /*
if (!plugin.IsDisabled)
plugin.Disable();
*/
- lock (this.pluginListLock)
- {
- this.InstalledPlugins = this.InstalledPlugins.Remove(plugin);
- }
- }
- catch (Exception ex)
+ lock (this.pluginListLock)
{
- Log.Error(ex, "Error during disable (update)");
- updateStatus.WasUpdated = false;
- return updateStatus;
+ this.InstalledPlugins = this.InstalledPlugins.Remove(plugin);
}
}
+ catch (Exception ex)
+ {
+ Log.Error(ex, "Error during disable (update)");
+ updateStatus.WasUpdated = false;
+ return updateStatus;
+ }
// We need to handle removed DTR nodes here, as otherwise, plugins will not be able to re-add their bar entries after updates.
var dtr = Service.Get();
From b0906af1ba8b89c32dbe8a8c95bba31b3f8e6268 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 21:18:23 +0200
Subject: [PATCH 09/28] prevent some collection is modified errors
---
.../Windows/PluginInstaller/ProfileManagerWidget.cs | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index ab25c4c88..ebabe4436 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -206,7 +206,10 @@ internal class ProfileManagerWidget
{
if (ImGui.Button("Do it") && selected != null)
{
- Task.Run(() => profile.AddOrUpdate(selected.Manifest.InternalName, selected.IsLoaded));
+ // TODO: handle error
+ profile.AddOrUpdate(selected.Manifest.InternalName, selected.IsLoaded, false);
+ Task.Run(() => profman.ApplyAllWantStates())
+ .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change plugin state.");
}
}
@@ -382,7 +385,9 @@ internal class ProfileManagerWidget
if (wantRemovePluginInternalName != null)
{
- Task.Run(() => profile.Remove(wantRemovePluginInternalName))
+ // TODO: handle error
+ profile.Remove(wantRemovePluginInternalName, false);
+ Task.Run(() => profman.ApplyAllWantStates())
.ContinueWith(this.installer.DisplayErrorContinuation, "Could not remove plugin.");
}
From 91ada49fa7df78f2a82db07ac462050422bc617a Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 21:20:36 +0200
Subject: [PATCH 10/28] always add plugins as enabled in profile editor
---
.../Internal/Windows/PluginInstaller/ProfileManagerWidget.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index ebabe4436..005e38040 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -204,10 +204,10 @@ internal class ProfileManagerWidget
using (ImRaii.Disabled(this.pickerSelectedPluginInternalName == null))
{
- if (ImGui.Button("Do it") && selected != null)
+ if (ImGui.Button("Add plugin") && selected != null)
{
// TODO: handle error
- profile.AddOrUpdate(selected.Manifest.InternalName, selected.IsLoaded, false);
+ profile.AddOrUpdate(selected.Manifest.InternalName, true, false);
Task.Run(() => profman.ApplyAllWantStates())
.ContinueWith(this.installer.DisplayErrorContinuation, "Could not change plugin state.");
}
From 4b2f649215c0a59c6dac709d246270c692b4775e Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 22:53:35 +0200
Subject: [PATCH 11/28] feedback for profile imports
---
.../Internal/Windows/PluginInstaller/ProfileManagerWidget.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index 005e38040..0545b1656 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -69,10 +69,12 @@ internal class ProfileManagerWidget
try
{
profman.ImportProfile(ImGui.GetClipboardText());
+ Service.Get().AddNotification("Profile successfully imported!", type: NotificationType.Success);
}
catch (Exception ex)
{
Log.Error(ex, "Could not import profile");
+ Service.Get().AddNotification("Could not import profile.", type: NotificationType.Error);
}
}
From ea01e629364bab95fc2cb30844538102163130b8 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 22:54:19 +0200
Subject: [PATCH 12/28] reset widget before deleting profile
---
.../Internal/Windows/PluginInstaller/ProfileManagerWidget.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index 0545b1656..6a60f6960 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -248,12 +248,13 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash))
{
+ this.Reset();
+
// DeleteProfile() is sync, it doesn't apply and we are modifying the plugins collection. Will throw below when iterating
profman.DeleteProfile(profile);
Task.Run(() => profman.ApplyAllWantStates())
.ContinueWith(t =>
{
- this.Reset();
this.installer.DisplayErrorContinuation(t, "Could not refresh profiles.");
});
}
From ffb0a0c41db1c57c076a89ab652cacd81e757344 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 22:59:44 +0200
Subject: [PATCH 13/28] disable search and sort when in profile editor
---
.../PluginInstaller/PluginInstallerWindow.cs | 83 ++++++++++---------
1 file changed, 42 insertions(+), 41 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index 4c9074043..e873b1047 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -15,6 +15,7 @@ using Dalamud.Game.Command;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Internal.Notifications;
+using Dalamud.Interface.Raii;
using Dalamud.Interface.Style;
using Dalamud.Interface.Windowing;
using Dalamud.Logging.Internal;
@@ -219,7 +220,7 @@ internal class PluginInstallerWindow : Window, IDisposable
this.updatePluginCount = 0;
this.updatedPlugins = null;
}
-
+
this.profileManagerWidget.Reset();
}
@@ -482,54 +483,54 @@ internal class PluginInstallerWindow : Window, IDisposable
ImGui.SetCursorPosX(windowSize.X - sortSelectWidth - (style.ItemSpacing.X * 2) - searchInputWidth - searchClearButtonWidth);
- var searchTextChanged = false;
- ImGui.SetNextItemWidth(searchInputWidth);
- searchTextChanged |= ImGui.InputTextWithHint(
- "###XlPluginInstaller_Search",
- Locs.Header_SearchPlaceholder,
- ref this.searchText,
- 100);
-
- ImGui.SameLine();
- ImGui.SetCursorPosY(downShift);
-
- ImGui.SetNextItemWidth(searchClearButtonWidth);
- if (ImGuiComponents.IconButton(FontAwesomeIcon.Times))
+ // Disable search if profile editor
+ using (ImRaii.Disabled(this.categoryManager.CurrentCategoryIdx == 14))
{
- this.searchText = string.Empty;
- searchTextChanged = true;
- }
+ var searchTextChanged = false;
+ ImGui.SetNextItemWidth(searchInputWidth);
+ searchTextChanged |= ImGui.InputTextWithHint(
+ "###XlPluginInstaller_Search",
+ Locs.Header_SearchPlaceholder,
+ ref this.searchText,
+ 100);
- if (searchTextChanged)
- this.UpdateCategoriesOnSearchChange();
+ ImGui.SameLine();
+ ImGui.SetCursorPosY(downShift);
- // Changelog group
- var isSortDisabled = this.categoryManager.CurrentGroupIdx == 3;
- if (isSortDisabled)
- ImGui.BeginDisabled();
-
- ImGui.SameLine();
- ImGui.SetCursorPosY(downShift);
- ImGui.SetNextItemWidth(selectableWidth);
- if (ImGui.BeginCombo(sortByText, this.filterText, ImGuiComboFlags.NoArrowButton))
- {
- foreach (var selectable in sortSelectables)
+ ImGui.SetNextItemWidth(searchClearButtonWidth);
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.Times))
{
- if (ImGui.Selectable(selectable.Localization))
- {
- this.sortKind = selectable.SortKind;
- this.filterText = selectable.Localization;
-
- lock (this.listLock)
- this.ResortPlugins();
- }
+ this.searchText = string.Empty;
+ searchTextChanged = true;
}
- ImGui.EndCombo();
+ if (searchTextChanged)
+ this.UpdateCategoriesOnSearchChange();
}
- if (isSortDisabled)
- ImGui.EndDisabled();
+ // Disable sort if changelogs or profile editor
+ using (ImRaii.Disabled(this.categoryManager.CurrentGroupIdx == 3 || this.categoryManager.CurrentCategoryIdx == 14))
+ {
+ ImGui.SameLine();
+ ImGui.SetCursorPosY(downShift);
+ ImGui.SetNextItemWidth(selectableWidth);
+ if (ImGui.BeginCombo(sortByText, this.filterText, ImGuiComboFlags.NoArrowButton))
+ {
+ foreach (var selectable in sortSelectables)
+ {
+ if (ImGui.Selectable(selectable.Localization))
+ {
+ this.sortKind = selectable.SortKind;
+ this.filterText = selectable.Localization;
+
+ lock (this.listLock)
+ this.ResortPlugins();
+ }
+ }
+
+ ImGui.EndCombo();
+ }
+ }
}
private void DrawFooter()
From 92f638d1148ccdb6cc3068c11374a1fe92cc438e Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 10 Apr 2023 23:11:37 +0200
Subject: [PATCH 14/28] remove unprocessed profile commands when another one is
queued
---
.../Profiles/ProfileCommandHandler.cs | 48 ++++++++++++-------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
index 995f91f5f..994069335 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
@@ -12,6 +12,9 @@ using Serilog;
namespace Dalamud.Plugin.Internal.Profiles;
+///
+/// Service responsible for profile-related chat commands.
+///
[ServiceManager.EarlyLoadedService]
internal class ProfileCommandHandler : IServiceType, IDisposable
{
@@ -20,12 +23,15 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
private readonly ChatGui chat;
private readonly Framework framework;
- private Queue<(string, ProfileOp)> queue = new();
+ private List<(string, ProfileOp)> queue = new();
///
/// Initializes a new instance of the class.
///
- ///
+ /// Command handler.
+ /// Profile manager.
+ /// Chat handler.
+ /// Framework.
[ServiceManager.ServiceConstructor]
public ProfileCommandHandler(CommandManager cmd, ProfileManager profileManager, ChatGui chat, Framework framework)
{
@@ -36,32 +42,45 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
this.cmd.AddHandler("/xlenableprofile", new CommandInfo(this.OnEnableProfile)
{
- HelpMessage = "",
+ HelpMessage = Loc.Localize("ProfileCommandsEnableHint", "Enable a profile. Usage: /xlenableprofile \"Profile Name\""),
ShowInHelp = true,
});
this.cmd.AddHandler("/xldisableprofile", new CommandInfo(this.OnDisableProfile)
{
- HelpMessage = "",
+ HelpMessage = Loc.Localize("ProfileCommandsDisableHint", "Disable a profile. Usage: /xldisableprofile \"Profile Name\""),
ShowInHelp = true,
});
this.cmd.AddHandler("/xltoggleprofile", new CommandInfo(this.OnToggleProfile)
{
- HelpMessage = "",
+ HelpMessage = Loc.Localize("ProfileCommandsToggleHint", "Toggle a profile. Usage: /xltoggleprofile \"Profile Name\""),
ShowInHelp = true,
});
this.framework.Update += this.FrameworkOnUpdate;
}
+ ///
+ public void Dispose()
+ {
+ this.cmd.RemoveHandler("/xlenableprofile");
+ this.cmd.RemoveHandler("/xldisableprofile");
+ this.cmd.RemoveHandler("/xltoggleprofile");
+
+ this.framework.Update += this.FrameworkOnUpdate;
+ }
+
private void FrameworkOnUpdate(Framework framework1)
{
if (this.profileManager.IsBusy)
return;
- if (this.queue.TryDequeue(out var op))
+ if (this.queue.Count > 0)
{
+ var op = this.queue[0];
+ this.queue.RemoveAt(0);
+
var profile = this.profileManager.Profiles.FirstOrDefault(x => x.Name == op.Item1);
if (profile == null || profile.IsDefaultProfile)
return;
@@ -107,22 +126,14 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
}
}
- public void Dispose()
- {
- this.cmd.RemoveHandler("/xlenableprofile");
- this.cmd.RemoveHandler("/xldisableprofile");
- this.cmd.RemoveHandler("/xltoggleprofile");
-
- this.framework.Update += this.FrameworkOnUpdate;
- }
-
private void OnEnableProfile(string command, string arguments)
{
var name = this.ValidateName(arguments);
if (name == null)
return;
- this.queue.Enqueue((name, ProfileOp.Enable));
+ this.queue = this.queue.Where(x => x.Item1 != name).ToList();
+ this.queue.Add((name, ProfileOp.Enable));
}
private void OnDisableProfile(string command, string arguments)
@@ -131,7 +142,8 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
if (name == null)
return;
- this.queue.Enqueue((name, ProfileOp.Disable));
+ this.queue = this.queue.Where(x => x.Item1 != name).ToList();
+ this.queue.Add((name, ProfileOp.Disable));
}
private void OnToggleProfile(string command, string arguments)
@@ -140,7 +152,7 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
if (name == null)
return;
- this.queue.Enqueue((name, ProfileOp.Toggle));
+ this.queue.Add((name, ProfileOp.Toggle));
}
private string? ValidateName(string arguments)
From 7028f5072bd09f09830810046404088f4e8fdb74 Mon Sep 17 00:00:00 2001
From: goat
Date: Tue, 11 Apr 2023 00:49:12 +0200
Subject: [PATCH 15/28] cool new plugin picker
---
.../PluginInstaller/ProfileManagerWidget.cs | 55 ++++++++++---------
1 file changed, 30 insertions(+), 25 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index 6a60f6960..42dda032d 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -9,6 +9,7 @@ using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.Raii;
using Dalamud.Plugin.Internal;
using Dalamud.Plugin.Internal.Profiles;
+using Dalamud.Utility;
using ImGuiNET;
using Serilog;
@@ -20,7 +21,7 @@ internal class ProfileManagerWidget
private Mode mode = Mode.Overview;
private Guid? editingProfileGuid;
- private string? pickerSelectedPluginInternalName = null;
+ private string pickerSearch = string.Empty;
private string profileNameEdit = string.Empty;
public ProfileManagerWidget(PluginInstallerWindow installer)
@@ -46,7 +47,7 @@ internal class ProfileManagerWidget
{
this.mode = Mode.Overview;
this.editingProfileGuid = null;
- this.pickerSelectedPluginInternalName = null;
+ this.pickerSearch = string.Empty;
}
private void DrawOverview()
@@ -185,37 +186,38 @@ internal class ProfileManagerWidget
}
const string addPluginToProfilePopup = "###addPluginToProfile";
- if (ImGui.BeginPopup(addPluginToProfilePopup))
+ using (var popup = ImRaii.Popup(addPluginToProfilePopup))
{
- var selected =
- pm.InstalledPlugins.FirstOrDefault(
- x => x.Manifest.InternalName == this.pickerSelectedPluginInternalName);
-
- if (ImGui.BeginCombo("###pluginPicker", selected == null ? "Pick one" : selected.Manifest.Name))
+ if (popup.Success)
{
- foreach (var plugin in pm.InstalledPlugins.Where(x => x.Manifest.SupportsProfiles))
+ var width = ImGuiHelpers.GlobalScale * 300;
+
+ using var disabled = ImRaii.Disabled(profman.IsBusy);
+
+ ImGui.SetNextItemWidth(width);
+ ImGui.InputTextWithHint("###pluginPickerSearch", "Search...", ref this.pickerSearch, 255);
+
+ if (ImGui.BeginListBox("###pluginPicker", new Vector2(width, width - 80)))
{
- if (ImGui.Selectable($"{plugin.Manifest.Name}###selector{plugin.Manifest.InternalName}"))
+ // 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 &&
+ (this.pickerSearch.IsNullOrWhitespace() || x.Manifest.Name.ToLowerInvariant().Contains(this.pickerSearch.ToLowerInvariant()))))
{
- this.pickerSelectedPluginInternalName = plugin.Manifest.InternalName;
+ using var disabled2 =
+ ImRaii.Disabled(profile.Plugins.Any(y => y.InternalName == plugin.Manifest.InternalName));
+
+ if (ImGui.Selectable($"{plugin.Manifest.Name}###selector{plugin.Manifest.InternalName}"))
+ {
+ // TODO this sucks
+ profile.AddOrUpdate(plugin.Manifest.InternalName, true, false);
+ Task.Run(() => profman.ApplyAllWantStates())
+ .ContinueWith(this.installer.DisplayErrorContinuation, "Could not apply profiles.");
+ }
}
- }
- ImGui.EndCombo();
- }
-
- using (ImRaii.Disabled(this.pickerSelectedPluginInternalName == null))
- {
- if (ImGui.Button("Add plugin") && selected != null)
- {
- // TODO: handle error
- profile.AddOrUpdate(selected.Manifest.InternalName, true, false);
- Task.Run(() => profman.ApplyAllWantStates())
- .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change plugin state.");
+ ImGui.EndListBox();
}
}
-
- ImGui.EndPopup();
}
var didAny = false;
@@ -419,7 +421,10 @@ internal class ProfileManagerWidget
}
if (wantPluginAddPopup)
+ {
+ this.pickerSearch = string.Empty;
ImGui.OpenPopup(addPluginToProfilePopup);
+ }
}
private enum Mode
From 3f112376ebd3e772f3792ee059a9e98259c51418 Mon Sep 17 00:00:00 2001
From: goat
Date: Tue, 11 Apr 2023 21:45:26 +0200
Subject: [PATCH 16/28] make "start on boot" work as expected for dev plugins
---
.../PluginInstaller/PluginInstallerWindow.cs | 30 +++++++++++--------
Dalamud/Plugin/Internal/PluginManager.cs | 15 +++++++---
2 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index 560c1e61a..b2dfe445e 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -2581,26 +2581,32 @@ internal class PluginInstallerWindow : Window, IDisposable
if (localPlugin is LocalDevPlugin plugin)
{
+ var isInDefaultProfile =
+ Service.Get().IsInDefaultProfile(localPlugin.Manifest.InternalName);
+
// https://colorswall.com/palette/2868/
var greenColor = new Vector4(0x5C, 0xB8, 0x5C, 0xFF) / 0xFF;
var redColor = new Vector4(0xD9, 0x53, 0x4F, 0xFF) / 0xFF;
// Load on boot
- ImGui.PushStyleColor(ImGuiCol.Button, plugin.StartOnBoot ? greenColor : redColor);
- ImGui.PushStyleColor(ImGuiCol.ButtonHovered, plugin.StartOnBoot ? greenColor : redColor);
-
- ImGui.SameLine();
- if (ImGuiComponents.IconButton(FontAwesomeIcon.PowerOff))
+ using (ImRaii.Disabled(!isInDefaultProfile))
{
- plugin.StartOnBoot ^= true;
- configuration.QueueSave();
- }
+ ImGui.PushStyleColor(ImGuiCol.Button, plugin.StartOnBoot ? greenColor : redColor);
+ ImGui.PushStyleColor(ImGuiCol.ButtonHovered, plugin.StartOnBoot ? greenColor : redColor);
- ImGui.PopStyleColor(2);
+ ImGui.SameLine();
+ if (ImGuiComponents.IconButton(FontAwesomeIcon.PowerOff))
+ {
+ plugin.StartOnBoot ^= true;
+ configuration.QueueSave();
+ }
- if (ImGui.IsItemHovered())
- {
- ImGui.SetTooltip(Locs.PluginButtonToolTip_StartOnBoot);
+ ImGui.PopStyleColor(2);
+
+ if (ImGui.IsItemHovered())
+ {
+ ImGui.SetTooltip(isInDefaultProfile ? Locs.PluginButtonToolTip_StartOnBoot : Locs.PluginButtonToolTip_NeedsToBeInDefault);
+ }
}
// Automatic reload
diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs
index c382ce3d8..781732776 100644
--- a/Dalamud/Plugin/Internal/PluginManager.cs
+++ b/Dalamud/Plugin/Internal/PluginManager.cs
@@ -862,10 +862,17 @@ Thanks and have fun!";
var devPlugin = new LocalDevPlugin(dllFile, manifest);
loadPlugin &= !isBoot || devPlugin.StartOnBoot;
- // If we're not loading it, make sure it's disabled
- // NOTE: Should be taken care of below by the profile code
- // if (!loadPlugin && !devPlugin.IsDisabled)
- // devPlugin.Disable();
+ var probablyInternalNameForThisPurpose = manifest?.InternalName ?? dllFile.Name;
+ var wantsInDefaultProfile =
+ this.profileManager.DefaultProfile.WantsPlugin(probablyInternalNameForThisPurpose);
+ if (wantsInDefaultProfile == false && devPlugin.StartOnBoot)
+ {
+ this.profileManager.DefaultProfile.AddOrUpdate(probablyInternalNameForThisPurpose, true, false);
+ }
+ else if (wantsInDefaultProfile == true && !devPlugin.StartOnBoot)
+ {
+ this.profileManager.DefaultProfile.AddOrUpdate(probablyInternalNameForThisPurpose, false, false);
+ }
plugin = devPlugin;
}
From 75bf13597891756308d918654351f905a2149ed8 Mon Sep 17 00:00:00 2001
From: goat
Date: Tue, 11 Apr 2023 22:02:30 +0200
Subject: [PATCH 17/28] clean up commented out code
---
.../Internal/Profiles/ProfileManager.cs | 82 +------------------
Dalamud/Plugin/Internal/Types/LocalPlugin.cs | 80 +-----------------
2 files changed, 2 insertions(+), 160 deletions(-)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index f189424a3..b7073ac99 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -268,21 +268,9 @@ internal class ProfileManager : IServiceType
private void LoadProfilesFromConfigInitially()
{
- var needMigration = false;
- if (this.config.DefaultProfile == null)
- {
- this.config.DefaultProfile = new ProfileModelV1();
- needMigration = true;
- }
-
+ this.config.DefaultProfile ??= new ProfileModelV1();
this.profiles.Add(new Profile(this, this.config.DefaultProfile, true, true));
- if (needMigration)
- {
- // Don't think we need this here with the migration logic in GetWantState
- //this.MigratePluginsIntoDefaultProfile();
- }
-
this.config.SavedProfiles ??= new List();
foreach (var profileModel in this.config.SavedProfiles)
{
@@ -291,72 +279,4 @@ internal class ProfileManager : IServiceType
this.config.QueueSave();
}
-
- // This duplicates some of the original handling in PM; don't care though
- /*
- private void MigratePluginsIntoDefaultProfile()
- {
- var pluginDirectory = new DirectoryInfo(Service.Get().PluginDirectory!);
- var pluginDefs = new List();
-
- Log.Information($"Now migrating plugins at {pluginDirectory} into profiles");
-
- // Nothing to migrate
- if (!pluginDirectory.Exists)
- {
- Log.Information("\t=> Plugin directory didn't exist, nothing to migrate");
- return;
- }
-
- // Add installed plugins. These are expected to be in a specific format so we can look for exactly that.
- foreach (var pluginDir in pluginDirectory.GetDirectories())
- {
- var versionsDefs = new List();
- foreach (var versionDir in pluginDir.GetDirectories())
- {
- try
- {
- var dllFile = new FileInfo(Path.Combine(versionDir.FullName, $"{pluginDir.Name}.dll"));
- var manifestFile = LocalPluginManifest.GetManifestFile(dllFile);
-
- if (!manifestFile.Exists)
- continue;
-
- var manifest = LocalPluginManifest.Load(manifestFile);
- versionsDefs.Add(new PluginDef(dllFile, manifest, false));
- }
- catch (Exception ex)
- {
- Log.Error(ex, "Could not load manifest for installed at {Directory}", versionDir.FullName);
- }
- }
-
- try
- {
- pluginDefs.Add(versionsDefs.MaxBy(x => x.Manifest!.EffectiveVersion));
- }
- catch (Exception ex)
- {
- Log.Error(ex, "Couldn't choose best version for plugin: {Name}", pluginDir.Name);
- }
- }
-
- var defaultProfile = this.DefaultProfile;
- foreach (var pluginDef in pluginDefs)
- {
- if (pluginDef.Manifest == null)
- {
- Log.Information($"\t=> Skipping DLL at {pluginDef.DllFile.FullName}, no valid manifest");
- continue;
- }
-
- // OK for migration code
-#pragma warning disable CS0618
- defaultProfile.AddOrUpdate(pluginDef.Manifest.InternalName, !pluginDef.Manifest.Disabled, false);
- Log.Information(
- $"\t=> Added {pluginDef.Manifest.InternalName} to default profile with {!pluginDef.Manifest.Disabled}");
-#pragma warning restore CS0618
- }
- }
- */
}
diff --git a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
index db5556662..2ef0269a3 100644
--- a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
+++ b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
@@ -200,14 +200,6 @@ internal class LocalPlugin : IDisposable
///
public bool IsLoaded => this.State == PluginState.Loaded;
- /*
- ///
- /// Gets a value indicating whether the plugin is disabled.
- ///
- [Obsolete("This is no longer accurate, use the profile manager instead.", true)]
- public bool IsDisabled => this.Manifest.Disabled;
- */
-
///
/// Gets a value indicating whether this plugin is wanted active by any profile.
/// INCLUDES the default profile.
@@ -349,7 +341,7 @@ internal class LocalPlugin : IDisposable
if (this.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels)
throw new InvalidPluginOperationException($"Unable to load {this.Name}, incompatible API level");
- // TODO: should we throw here?
+ // We might want to throw here?
if (!this.IsWantedByAnyProfile)
Log.Warning("{Name} is loading, but isn't wanted by any profile", this.Name);
@@ -568,43 +560,6 @@ internal class LocalPlugin : IDisposable
await this.LoadAsync(PluginLoadReason.Reload, true);
}
- /*
- ///
- /// Revert a disable. Must be unloaded first, does not load.
- ///
- [Obsolete("Profile API", true)]
- public void Enable()
- {
- // Allowed: Unloaded, UnloadError
- switch (this.State)
- {
- case PluginState.Loading:
- case PluginState.Unloading:
- case PluginState.Loaded:
- case PluginState.LoadError:
- throw new InvalidPluginOperationException($"Unable to enable {this.Name}, still loaded");
- case PluginState.Unloaded:
- break;
- case PluginState.UnloadError:
- break;
- case PluginState.DependencyResolutionFailed:
- throw new InvalidPluginOperationException($"Unable to enable {this.Name}, dependency resolution failed");
- default:
- throw new ArgumentOutOfRangeException(this.State.ToString());
- }
-
- // NOTE(goat): This is inconsequential, and we do have situations where a plugin can end up enabled but not loaded:
- // Orphaned plugins can have their repo added back, but may not have been loaded at boot and may still be enabled.
- // We don't want to disable orphaned plugins when they are orphaned so this is how it's going to be.
- // if (!this.Manifest.Disabled)
- // throw new InvalidPluginOperationException($"Unable to enable {this.Name}, not disabled");
-
- this.Manifest.Disabled = false;
- this.Manifest.ScheduledForDeletion = false;
- this.SaveManifest();
- }
- */
-
///
/// Check if anything forbids this plugin from loading.
///
@@ -626,39 +581,6 @@ internal class LocalPlugin : IDisposable
return true;
}
- /*
- ///
- /// Disable this plugin, must be unloaded first.
- ///
- [Obsolete("Profile API", true)]
- public void Disable()
- {
- // Allowed: Unloaded, UnloadError
- switch (this.State)
- {
- case PluginState.Loading:
- case PluginState.Unloading:
- case PluginState.Loaded:
- case PluginState.LoadError:
- throw new InvalidPluginOperationException($"Unable to disable {this.Name}, still loaded");
- case PluginState.Unloaded:
- break;
- case PluginState.UnloadError:
- break;
- case PluginState.DependencyResolutionFailed:
- return; // This is a no-op.
- default:
- throw new ArgumentOutOfRangeException(this.State.ToString());
- }
-
- if (this.Manifest.Disabled)
- throw new InvalidPluginOperationException($"Unable to disable {this.Name}, already disabled");
-
- this.Manifest.Disabled = true;
- this.SaveManifest();
- }
- */
-
///
/// Schedule the deletion of this plugin on next cleanup.
///
From cbfd4bbd2a09248913b0847ca8d70bd9e296e188 Mon Sep 17 00:00:00 2001
From: goat
Date: Wed, 12 Apr 2023 21:28:03 +0200
Subject: [PATCH 18/28] fix: skip a stack frame in the VEH callback handler
---
Dalamud/EntryPoint.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs
index 8fa9e70a0..d3c28011f 100644
--- a/Dalamud/EntryPoint.cs
+++ b/Dalamud/EntryPoint.cs
@@ -68,7 +68,7 @@ public sealed class EntryPoint
{
try
{
- return Marshal.StringToHGlobalUni(Environment.StackTrace);
+ return Marshal.StringToHGlobalUni(new StackTrace(1).ToString());
}
catch (Exception e)
{
From eb06636290122cadc3c824e6b5ddb85bb284357a Mon Sep 17 00:00:00 2001
From: goat
Date: Wed, 12 Apr 2023 21:43:12 +0200
Subject: [PATCH 19/28] enable profiles by default
---
Dalamud/Configuration/Internal/DalamudConfiguration.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
index 89396bd66..c870fa09d 100644
--- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs
+++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
@@ -280,7 +280,7 @@ internal sealed class DalamudConfiguration : IServiceType
///
/// Gets or sets a value indicating whether or not profiles are enabled.
///
- public bool ProfilesEnabled { get; set; } = false;
+ public bool ProfilesEnabled { get; set; } = true;
///
/// Gets or sets a value indicating whether or not Dalamud RMT filtering should be disabled.
From 5ad3ec123d0700d3065e4c902b107b832fe0ae95 Mon Sep 17 00:00:00 2001
From: goat
Date: Tue, 18 Apr 2023 20:37:05 +0200
Subject: [PATCH 20/28] localize profiles strings
---
.../Internal/PluginCategoryManager.cs | 4 +-
.../PluginInstaller/PluginInstallerWindow.cs | 31 +++--
.../PluginInstaller/ProfileManagerWidget.cs | 112 +++++++++++++-----
3 files changed, 110 insertions(+), 37 deletions(-)
diff --git a/Dalamud/Interface/Internal/PluginCategoryManager.cs b/Dalamud/Interface/Internal/PluginCategoryManager.cs
index 2af5d2354..9515a55b5 100644
--- a/Dalamud/Interface/Internal/PluginCategoryManager.cs
+++ b/Dalamud/Interface/Internal/PluginCategoryManager.cs
@@ -435,8 +435,8 @@ internal class PluginCategoryManager
public static string Category_DevInstalled => Loc.Localize("InstallerInstalledDevPlugins", "Installed Dev Plugins");
public static string Category_IconTester => "Image/Icon Tester";
-
- public static string Category_PluginProfiles => Loc.Localize("InstallerCategoryPluginProfiles", "Plugin Profiles");
+
+ public static string Category_PluginProfiles => Loc.Localize("InstallerCategoryPluginProfiles", "Plugin Collections");
public static string Category_Other => Loc.Localize("InstallerCategoryOther", "Other");
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index b2dfe445e..a50be905f 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -428,7 +428,7 @@ internal class PluginInstallerWindow : Window, IDisposable
break;
case LoadingIndicatorKind.ProfilesLoading:
- ImGuiHelpers.CenteredText("Profiles are being applied...");
+ ImGuiHelpers.CenteredText("Collections are being applied...");
break;
default:
throw new ArgumentOutOfRangeException();
@@ -2321,12 +2321,12 @@ internal class PluginInstallerWindow : Window, IDisposable
if (inProfile)
{
Task.Run(() => profile.AddOrUpdate(plugin.Manifest.InternalName, true))
- .ContinueWith(this.DisplayErrorContinuation, "Couldn't add plugin to this profile.");
+ .ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotAdd);
}
else
{
Task.Run(() => profile.Remove(plugin.Manifest.InternalName))
- .ContinueWith(this.DisplayErrorContinuation, "Couldn't remove plugin from this profile.");
+ .ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotRemove);
}
}
@@ -2338,7 +2338,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
if (!didAny)
- ImGui.TextColored(ImGuiColors.DalamudGrey, "No profiles! Go add some!");
+ ImGui.TextColored(ImGuiColors.DalamudGrey, Locs.Profiles_None);
ImGui.Separator();
@@ -2355,7 +2355,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
ImGui.SameLine();
- ImGui.Text("Remove from all profiles");
+ ImGui.Text(Locs.Profiles_RemoveFromAll);
ImGui.EndPopup();
}
@@ -3160,9 +3160,9 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButtonToolTip_OpenConfiguration => Loc.Localize("InstallerOpenConfig", "Open Configuration");
- public static string PluginButtonToolTip_PickProfiles => Loc.Localize("InstallerPickProfiles", "Pick profiles for this plugin");
+ public static string PluginButtonToolTip_PickProfiles => Loc.Localize("InstallerPickProfiles", "Pick collections for this plugin");
- public static string PluginButtonToolTip_ProfilesNotSupported => Loc.Localize("InstallerProfilesNotSupported", "This plugin does not support profiles");
+ public static string PluginButtonToolTip_ProfilesNotSupported => Loc.Localize("InstallerProfilesNotSupported", "This plugin does not support collections");
public static string PluginButtonToolTip_StartOnBoot => Loc.Localize("InstallerStartOnBoot", "Start on boot");
@@ -3184,7 +3184,7 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButtonToolTip_UnloadFailed => Loc.Localize("InstallerUnloadFailedTooltip", "Plugin unload failed, please restart your game and try again.");
- public static string PluginButtonToolTip_NeedsToBeInDefault => Loc.Localize("InstallerUnloadNeedsToBeInDefault", "This plugin is in one or more profiles. If you want to enable or disable it, please do so by enabling or disabling one of the profiles it is in.\nIf you want to manage it manually, remove it from all profiles.");
+ public static string PluginButtonToolTip_NeedsToBeInDefault => Loc.Localize("InstallerUnloadNeedsToBeInDefault", "This plugin is in one or more collections. If you want to enable or disable it, please do so by enabling or disabling the collections it is in.\nIf you want to manage it manually, remove it from all collections.");
#endregion
@@ -3345,5 +3345,20 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string SafeModeDisclaimer => Loc.Localize("SafeModeDisclaimer", "You enabled safe mode, no plugins will be loaded.\nYou may delete plugins from the \"Installed plugins\" tab.\nSimply restart your game to disable safe mode.");
#endregion
+
+ #region Profiles
+
+ public static string Profiles_CouldNotAdd =>
+ Loc.Localize("InstallerProfilesCouldNotAdd", "Couldn't add plugin to this collection.");
+
+ public static string Profiles_CouldNotRemove =>
+ Loc.Localize("InstallerProfilesCouldNotRemove", "Couldn't remove plugin from this collection.");
+
+ public static string Profiles_None => Loc.Localize("InstallerProfilesNone", "No collections! Go add some in \"Plugin Collections\"!");
+
+ public static string Profiles_RemoveFromAll =>
+ Loc.Localize("InstallerProfilesRemoveFromAll", "Remove from all collections");
+
+ #endregion
}
}
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index 42dda032d..1448074f3 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -3,6 +3,7 @@ using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
+using CheapLoc;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Internal.Notifications;
@@ -59,7 +60,7 @@ internal class ProfileManagerWidget
profman.AddNewProfile();
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Add a new profile");
+ ImGui.SetTooltip(Locs.AddProfile);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5);
@@ -70,17 +71,17 @@ internal class ProfileManagerWidget
try
{
profman.ImportProfile(ImGui.GetClipboardText());
- Service.Get().AddNotification("Profile successfully imported!", type: NotificationType.Success);
+ Service.Get().AddNotification(Locs.NotificationImportSuccess, type: NotificationType.Success);
}
catch (Exception ex)
{
Log.Error(ex, "Could not import profile");
- Service.Get().AddNotification("Could not import profile.", type: NotificationType.Error);
+ Service.Get().AddNotification(Locs.NotificationImportError, type: NotificationType.Error);
}
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Import a shared profile from your clipboard");
+ ImGui.SetTooltip(Locs.ImportProfileHint);
ImGui.Separator();
ImGuiHelpers.ScaledDummy(5);
@@ -100,7 +101,7 @@ internal class ProfileManagerWidget
if (ImGuiComponents.ToggleButton($"###toggleButton{profile.Guid}", ref isEnabled))
{
Task.Run(() => profile.SetState(isEnabled))
- .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change profile state.");
+ .ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
}
ImGui.SameLine();
@@ -120,7 +121,7 @@ internal class ProfileManagerWidget
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Edit this profile");
+ ImGui.SetTooltip(Locs.EditProfileHint);
ImGui.SameLine();
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 2) - 5);
@@ -129,7 +130,7 @@ internal class ProfileManagerWidget
toCloneGuid = profile.Guid;
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Clone this profile");
+ ImGui.SetTooltip(Locs.CloneProfileHint);
ImGui.SameLine();
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 3) - 5);
@@ -137,11 +138,11 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton($"###exportButton{profile.Guid}", FontAwesomeIcon.FileExport))
{
ImGui.SetClipboardText(profile.Model.Serialize());
- Service.Get().AddNotification("Copied to clipboard!", type: NotificationType.Success);
+ Service.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Copy profile to clipboard for sharing");
+ ImGui.SetTooltip(Locs.CopyToClipboardHint);
didAny = true;
@@ -156,7 +157,7 @@ internal class ProfileManagerWidget
if (!didAny)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudGrey);
- ImGuiHelpers.CenteredText("No profiles! Add one!");
+ ImGuiHelpers.CenteredText(Locs.AddProfileHint);
ImGui.PopStyleColor();
}
@@ -195,7 +196,7 @@ internal class ProfileManagerWidget
using var disabled = ImRaii.Disabled(profman.IsBusy);
ImGui.SetNextItemWidth(width);
- ImGui.InputTextWithHint("###pluginPickerSearch", "Search...", ref this.pickerSearch, 255);
+ ImGui.InputTextWithHint("###pluginPickerSearch", Locs.SearchHint, ref this.pickerSearch, 255);
if (ImGui.BeginListBox("###pluginPicker", new Vector2(width, width - 80)))
{
@@ -211,7 +212,7 @@ internal class ProfileManagerWidget
// TODO this sucks
profile.AddOrUpdate(plugin.Manifest.InternalName, true, false);
Task.Run(() => profman.ApplyAllWantStates())
- .ContinueWith(this.installer.DisplayErrorContinuation, "Could not apply profiles.");
+ .ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
}
}
@@ -229,7 +230,7 @@ internal class ProfileManagerWidget
this.Reset();
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Back to overview");
+ ImGui.SetTooltip(Locs.BackToOverview);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5);
@@ -238,11 +239,11 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport))
{
ImGui.SetClipboardText(profile.Model.Serialize());
- Service.Get().AddNotification("Copied to clipboard!", type: NotificationType.Success);
+ Service.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Copy profile to clipboard for sharing");
+ ImGui.SetTooltip(Locs.CopyToClipboardHint);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5);
@@ -257,12 +258,12 @@ internal class ProfileManagerWidget
Task.Run(() => profman.ApplyAllWantStates())
.ContinueWith(t =>
{
- this.installer.DisplayErrorContinuation(t, "Could not refresh profiles.");
+ this.installer.DisplayErrorContinuation(t, Locs.ErrorCouldNotChangeState);
});
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Delete this profile");
+ ImGui.SetTooltip(Locs.DeleteProfileHint);
ImGui.SameLine();
ImGuiHelpers.ScaledDummy(5);
@@ -281,18 +282,18 @@ internal class ProfileManagerWidget
if (ImGuiComponents.ToggleButton($"###toggleButton{profile.Guid}", ref isEnabled))
{
Task.Run(() => profile.SetState(isEnabled))
- .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change profile state.");
+ .ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Enable/Disable this profile");
+ ImGui.SetTooltip(Locs.TooltipEnableDisable);
ImGui.Separator();
ImGuiHelpers.ScaledDummy(5);
var enableAtBoot = profile.AlwaysEnableAtBoot;
- if (ImGui.Checkbox("Always enable when game starts", ref enableAtBoot))
+ if (ImGui.Checkbox(Locs.AlwaysEnableAtBoot, ref enableAtBoot))
{
profile.AlwaysEnableAtBoot = enableAtBoot;
}
@@ -335,7 +336,7 @@ internal class ProfileManagerWidget
ImGui.Image(pic.DefaultIcon.ImGuiHandle, new Vector2(pluginLineHeight));
ImGui.SameLine();
- var text = $"{plugin.InternalName} (Not Installed)";
+ var text = Locs.NotInstalled(plugin.InternalName);
var textHeight = ImGui.CalcTextSize(text);
var before = ImGui.GetCursorPos();
@@ -358,7 +359,7 @@ internal class ProfileManagerWidget
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Install this plugin");
+ ImGui.SetTooltip(Locs.InstallPlugin);
}
ImGui.SetCursorPos(before);
@@ -372,7 +373,7 @@ internal class ProfileManagerWidget
if (ImGui.Checkbox($"###{this.editingProfileGuid}-{plugin.InternalName}", ref enabled))
{
Task.Run(() => profile.AddOrUpdate(plugin.InternalName, enabled))
- .ContinueWith(this.installer.DisplayErrorContinuation, "Could not change plugin state.");
+ .ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
}
ImGui.SameLine();
@@ -385,7 +386,7 @@ internal class ProfileManagerWidget
}
if (ImGui.IsItemHovered())
- ImGui.SetTooltip("Remove plugin from this profile");
+ ImGui.SetTooltip(Locs.RemovePlugin);
}
if (wantRemovePluginInternalName != null)
@@ -393,17 +394,17 @@ internal class ProfileManagerWidget
// TODO: handle error
profile.Remove(wantRemovePluginInternalName, false);
Task.Run(() => profman.ApplyAllWantStates())
- .ContinueWith(this.installer.DisplayErrorContinuation, "Could not remove plugin.");
+ .ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotRemove);
}
if (!didAny)
{
- ImGui.TextColored(ImGuiColors.DalamudGrey, "Profile has no plugins!");
+ ImGui.TextColored(ImGuiColors.DalamudGrey, Locs.NoPluginsInProfile);
}
ImGuiHelpers.ScaledDummy(10);
- var addPluginsText = "Add a plugin!";
+ var addPluginsText = Locs.AddPlugin;
ImGuiHelpers.CenterCursorFor((int)(ImGui.CalcTextSize(addPluginsText).X + 30 + (ImGuiHelpers.GlobalScale * 5)));
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
@@ -432,4 +433,61 @@ internal class ProfileManagerWidget
Overview,
EditSingleProfile,
}
+
+ private static class Locs
+ {
+ public static string TooltipEnableDisable =>
+ Loc.Localize("ProfileManagerEnableDisableHint", "Enable/Disable this profile");
+
+ public static string InstallPlugin => Loc.Localize("ProfileManagerInstall", "Install this plugin");
+
+ public static string RemovePlugin =>
+ Loc.Localize("ProfileManagerRemoveFromProfile", "Remove plugin from this profile");
+
+ public static string AddPlugin => Loc.Localize("ProfileManagerAddPlugin", "Add a plugin!");
+
+ public static string NoPluginsInProfile =>
+ Loc.Localize("ProfileManagerNoPluginsInProfile", "Profile has no plugins!");
+
+ public static string AlwaysEnableAtBoot =>
+ Loc.Localize("ProfileManagerAlwaysEnableAtBoot", "Always enable when game starts");
+
+ public static string DeleteProfileHint => Loc.Localize("ProfileManagerDeleteProfile", "Delete this profile");
+
+ public static string CopyToClipboardHint =>
+ Loc.Localize("ProfileManagerCopyToClipboard", "Copy profile to clipboard for sharing");
+
+ public static string CopyToClipboardNotification =>
+ Loc.Localize("ProfileManagerCopyToClipboardHint", "Copied to clipboard!");
+
+ public static string BackToOverview => Loc.Localize("ProfileManagerBackToOverview", "Back to overview");
+
+ public static string SearchHint => Loc.Localize("ProfileManagerSearchHint", "Search...");
+
+ public static string AddProfileHint => Loc.Localize("ProfileManagerAddProfileHint", "No profiles! Add one!");
+
+ public static string CloneProfileHint => Loc.Localize("ProfileManagerCloneProfile", "Clone this profile");
+
+ public static string EditProfileHint => Loc.Localize("ProfileManagerEditProfile", "Edit this profile");
+
+ public static string ImportProfileHint =>
+ Loc.Localize("ProfileManagerImportProfile", "Import a shared profile from your clipboard");
+
+ public static string AddProfile => Loc.Localize("ProfileManagerAddProfile", "Add a new profile");
+
+ public static string NotificationImportSuccess =>
+ Loc.Localize("ProfileManagerNotificationImportSuccess", "Profile successfully imported!");
+
+ public static string NotificationImportError =>
+ Loc.Localize("ProfileManagerNotificationImportError", "Could not import profile.");
+
+ public static string ErrorCouldNotRemove =>
+ Loc.Localize("ProfileManagerCouldNotRemove", "Could not remove plugin.");
+
+ public static string ErrorCouldNotChangeState =>
+ Loc.Localize("ProfileManagerCouldNotChangeState", "Could not change plugin state.");
+
+ public static string NotInstalled(string name) =>
+ Loc.Localize("ProfileManagerNotInstalled", "{0} (Not Installed)").Format(name);
+ }
}
From f375b8fe5b0f8591ff5b4f707253a47b19be7f38 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 24 Apr 2023 21:15:24 +0200
Subject: [PATCH 21/28] increase GameStart max tries to 1200(1min)
---
Dalamud.Injector/GameStart.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dalamud.Injector/GameStart.cs b/Dalamud.Injector/GameStart.cs
index 44102d952..95e963a9a 100644
--- a/Dalamud.Injector/GameStart.cs
+++ b/Dalamud.Injector/GameStart.cs
@@ -127,7 +127,7 @@ namespace Dalamud.Injector
try
{
var tries = 0;
- const int maxTries = 420;
+ const int maxTries = 1200;
const int timeout = 50;
do
From 0a829d304eea9c5a734839fec88520188fc38235 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 12 Jun 2023 20:17:30 +0200
Subject: [PATCH 22/28] fix warnings
---
.../PluginInstaller/PluginInstallerWindow.cs | 82 +++---
.../PluginInstaller/ProfileManagerWidget.cs | 25 +-
Dalamud/Plugin/Internal/PluginManager.cs | 262 +++++++++---------
.../Profiles/ProfileCommandHandler.cs | 14 +-
.../Internal/Profiles/ProfileManager.cs | 2 +-
.../Plugin/Internal/Profiles/ProfileModel.cs | 20 ++
.../Internal/Profiles/ProfileModelV1.cs | 30 +-
.../Internal/Profiles/ProfilePluginEntry.cs | 14 +
Dalamud/Plugin/Internal/Types/LocalPlugin.cs | 6 +-
9 files changed, 266 insertions(+), 189 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index 3b3804baa..d28401e73 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -327,6 +327,46 @@ internal class PluginInstallerWindow : Window, IDisposable
});
}
+ ///
+ /// A continuation task that displays any errors received into the error modal.
+ ///
+ /// The previous task.
+ /// An error message to be displayed.
+ /// A value indicating whether to continue with the next task.
+ public bool DisplayErrorContinuation(Task task, object state)
+ {
+ if (task.IsFaulted)
+ {
+ var errorModalMessage = state as string;
+
+ foreach (var ex in task.Exception.InnerExceptions)
+ {
+ if (ex is PluginException)
+ {
+ Log.Error(ex, "Plugin installer threw an error");
+#if DEBUG
+ if (!string.IsNullOrEmpty(ex.Message))
+ errorModalMessage += $"\n\n{ex.Message}";
+#endif
+ }
+ else
+ {
+ Log.Error(ex, "Plugin installer threw an unexpected error");
+#if DEBUG
+ if (!string.IsNullOrEmpty(ex.Message))
+ errorModalMessage += $"\n\n{ex.Message}";
+#endif
+ }
+ }
+
+ this.ShowErrorModal(errorModalMessage);
+
+ return false;
+ }
+
+ return true;
+ }
+
private void DrawProgressOverlay()
{
var pluginManager = Service.Get();
@@ -2155,7 +2195,7 @@ internal class PluginInstallerWindow : Window, IDisposable
this.DrawSendFeedbackButton(plugin.Manifest, plugin.IsTesting);
}
- if (availablePluginUpdate != default && ! plugin.IsDev)
+ if (availablePluginUpdate != default && !plugin.IsDev)
this.DrawUpdateSinglePluginButton(availablePluginUpdate);
ImGui.SameLine();
@@ -2914,46 +2954,6 @@ internal class PluginInstallerWindow : Window, IDisposable
private bool WasPluginSeen(string internalName) =>
Service.Get().SeenPluginInternalName.Contains(internalName);
- ///
- /// A continuation task that displays any errors received into the error modal.
- ///
- /// The previous task.
- /// An error message to be displayed.
- /// A value indicating whether to continue with the next task.
- public bool DisplayErrorContinuation(Task task, object state)
- {
- if (task.IsFaulted)
- {
- var errorModalMessage = state as string;
-
- foreach (var ex in task.Exception.InnerExceptions)
- {
- if (ex is PluginException)
- {
- Log.Error(ex, "Plugin installer threw an error");
-#if DEBUG
- if (!string.IsNullOrEmpty(ex.Message))
- errorModalMessage += $"\n\n{ex.Message}";
-#endif
- }
- else
- {
- Log.Error(ex, "Plugin installer threw an unexpected error");
-#if DEBUG
- if (!string.IsNullOrEmpty(ex.Message))
- errorModalMessage += $"\n\n{ex.Message}";
-#endif
- }
- }
-
- this.ShowErrorModal(errorModalMessage);
-
- return false;
- }
-
- return true;
- }
-
private Task ShowErrorModal(string message)
{
this.errorModalMessage = message;
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index 1448074f3..60f605f8e 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -16,6 +16,9 @@ using Serilog;
namespace Dalamud.Interface.Internal.Windows.PluginInstaller;
+///
+/// ImGui widget used to manage profiles.
+///
internal class ProfileManagerWidget
{
private readonly PluginInstallerWindow installer;
@@ -25,11 +28,24 @@ internal class ProfileManagerWidget
private string pickerSearch = string.Empty;
private string profileNameEdit = string.Empty;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The plugin installer.
public ProfileManagerWidget(PluginInstallerWindow installer)
{
this.installer = installer;
}
+ private enum Mode
+ {
+ Overview,
+ EditSingleProfile,
+ }
+
+ ///
+ /// Draw this widget's contents.
+ ///
public void Draw()
{
switch (this.mode)
@@ -44,6 +60,9 @@ internal class ProfileManagerWidget
}
}
+ ///
+ /// Reset the widget.
+ ///
public void Reset()
{
this.mode = Mode.Overview;
@@ -428,12 +447,6 @@ internal class ProfileManagerWidget
}
}
- private enum Mode
- {
- Overview,
- EditSingleProfile,
- }
-
private static class Locs
{
public static string TooltipEnableDisable =>
diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs
index a0283ca67..162b6c90b 100644
--- a/Dalamud/Plugin/Internal/PluginManager.cs
+++ b/Dalamud/Plugin/Internal/PluginManager.cs
@@ -816,137 +816,6 @@ internal partial class PluginManager : IDisposable, IServiceType
return plugin;
}
- ///
- /// Load a plugin.
- ///
- /// The associated with the main assembly of this plugin.
- /// The already loaded definition, if available.
- /// The reason this plugin was loaded.
- /// If this plugin should support development features.
- /// If this plugin is being loaded at boot.
- /// Don't load the plugin, just don't do it.
- /// The loaded plugin.
- private async Task LoadPluginAsync(FileInfo dllFile, LocalPluginManifest? manifest, PluginLoadReason reason, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
- {
- var name = manifest?.Name ?? dllFile.Name;
- var loadPlugin = !doNotLoad;
-
- LocalPlugin plugin;
-
- if (manifest != null && manifest.InternalName == null)
- {
- Log.Error("{FileName}: Your manifest has no internal name set! Can't load this.", dllFile.FullName);
- throw new Exception("No internal name");
- }
-
- if (isDev)
- {
- Log.Information($"Loading dev plugin {name}");
- var devPlugin = new LocalDevPlugin(dllFile, manifest);
- loadPlugin &= !isBoot || devPlugin.StartOnBoot;
-
- var probablyInternalNameForThisPurpose = manifest?.InternalName ?? dllFile.Name;
- var wantsInDefaultProfile =
- this.profileManager.DefaultProfile.WantsPlugin(probablyInternalNameForThisPurpose);
- if (wantsInDefaultProfile == false && devPlugin.StartOnBoot)
- {
- this.profileManager.DefaultProfile.AddOrUpdate(probablyInternalNameForThisPurpose, true, false);
- }
- else if (wantsInDefaultProfile == true && !devPlugin.StartOnBoot)
- {
- this.profileManager.DefaultProfile.AddOrUpdate(probablyInternalNameForThisPurpose, false, false);
- }
-
- plugin = devPlugin;
- }
- else
- {
- Log.Information($"Loading plugin {name}");
- plugin = new LocalPlugin(dllFile, manifest);
- }
-
-#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 = this.profileManager.GetWantState(plugin.Manifest.InternalName, defaultState);
-
- if (loadPlugin)
- {
- try
- {
- if (wantToLoad && !plugin.IsOrphaned)
- {
- await plugin.LoadAsync(reason);
- }
- else
- {
- Log.Verbose($"{name} not loaded, wantToLoad:{wantToLoad} orphaned:{plugin.IsOrphaned}");
- }
- }
- catch (InvalidPluginException)
- {
- PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
- throw;
- }
- catch (BannedPluginException)
- {
- // Out of date plugins get added so they can be updated.
- Log.Information($"Plugin was banned, adding anyways: {dllFile.Name}");
- }
- catch (Exception ex)
- {
- if (plugin.IsDev)
- {
- // Dev plugins always get added to the list so they can be fiddled with in the UI
- Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}");
-
- // NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
- // plugin.Disable(); // Disable here, otherwise you can't enable+load later
- }
- else if (plugin.IsOutdated)
- {
- // Out of date plugins get added, so they can be updated.
- Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}");
- }
- else if (plugin.IsOrphaned)
- {
- // Orphaned plugins get added, so that users aren't confused.
- Log.Information(ex, $"Plugin was orphaned, adding anyways: {dllFile.Name}");
- }
- else if (isBoot)
- {
- // During boot load, plugins always get added to the list so they can be fiddled with in the UI
- Log.Information(ex, $"Regular plugin failed to load, adding anyways: {dllFile.Name}");
-
- // NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
- // plugin.Disable(); // Disable here, otherwise you can't enable+load later
- }
- else if (!plugin.CheckPolicy())
- {
- // During boot load, plugins always get added to the list so they can be fiddled with in the UI
- Log.Information(ex, $"Plugin not loaded due to policy, adding anyways: {dllFile.Name}");
-
- // NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
- // plugin.Disable(); // Disable here, otherwise you can't enable+load later
- }
- else
- {
- PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
- throw;
- }
- }
- }
-
- lock (this.pluginListLock)
- {
- this.InstalledPlugins = this.InstalledPlugins.Add(plugin);
- }
-
- return plugin;
- }
-
///
/// Remove a plugin.
///
@@ -1330,6 +1199,137 @@ internal partial class PluginManager : IDisposable, IServiceType
/// The calling plugin, or null.
public LocalPlugin? FindCallingPlugin() => this.FindCallingPlugin(new StackTrace());
+ ///
+ /// Load a plugin.
+ ///
+ /// The associated with the main assembly of this plugin.
+ /// The already loaded definition, if available.
+ /// The reason this plugin was loaded.
+ /// If this plugin should support development features.
+ /// If this plugin is being loaded at boot.
+ /// Don't load the plugin, just don't do it.
+ /// The loaded plugin.
+ private async Task LoadPluginAsync(FileInfo dllFile, LocalPluginManifest? manifest, PluginLoadReason reason, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
+ {
+ var name = manifest?.Name ?? dllFile.Name;
+ var loadPlugin = !doNotLoad;
+
+ LocalPlugin plugin;
+
+ if (manifest != null && manifest.InternalName == null)
+ {
+ Log.Error("{FileName}: Your manifest has no internal name set! Can't load this.", dllFile.FullName);
+ throw new Exception("No internal name");
+ }
+
+ if (isDev)
+ {
+ Log.Information($"Loading dev plugin {name}");
+ var devPlugin = new LocalDevPlugin(dllFile, manifest);
+ loadPlugin &= !isBoot || devPlugin.StartOnBoot;
+
+ var probablyInternalNameForThisPurpose = manifest?.InternalName ?? dllFile.Name;
+ var wantsInDefaultProfile =
+ this.profileManager.DefaultProfile.WantsPlugin(probablyInternalNameForThisPurpose);
+ if (wantsInDefaultProfile == false && devPlugin.StartOnBoot)
+ {
+ this.profileManager.DefaultProfile.AddOrUpdate(probablyInternalNameForThisPurpose, true, false);
+ }
+ else if (wantsInDefaultProfile == true && !devPlugin.StartOnBoot)
+ {
+ this.profileManager.DefaultProfile.AddOrUpdate(probablyInternalNameForThisPurpose, false, false);
+ }
+
+ plugin = devPlugin;
+ }
+ else
+ {
+ Log.Information($"Loading plugin {name}");
+ plugin = new LocalPlugin(dllFile, manifest);
+ }
+
+#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 = this.profileManager.GetWantState(plugin.Manifest.InternalName, defaultState);
+
+ if (loadPlugin)
+ {
+ try
+ {
+ if (wantToLoad && !plugin.IsOrphaned)
+ {
+ await plugin.LoadAsync(reason);
+ }
+ else
+ {
+ Log.Verbose($"{name} not loaded, wantToLoad:{wantToLoad} orphaned:{plugin.IsOrphaned}");
+ }
+ }
+ catch (InvalidPluginException)
+ {
+ PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
+ throw;
+ }
+ catch (BannedPluginException)
+ {
+ // Out of date plugins get added so they can be updated.
+ Log.Information($"Plugin was banned, adding anyways: {dllFile.Name}");
+ }
+ catch (Exception ex)
+ {
+ if (plugin.IsDev)
+ {
+ // Dev plugins always get added to the list so they can be fiddled with in the UI
+ Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}");
+
+ // NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
+ // plugin.Disable(); // Disable here, otherwise you can't enable+load later
+ }
+ else if (plugin.IsOutdated)
+ {
+ // Out of date plugins get added, so they can be updated.
+ Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}");
+ }
+ else if (plugin.IsOrphaned)
+ {
+ // Orphaned plugins get added, so that users aren't confused.
+ Log.Information(ex, $"Plugin was orphaned, adding anyways: {dllFile.Name}");
+ }
+ else if (isBoot)
+ {
+ // During boot load, plugins always get added to the list so they can be fiddled with in the UI
+ Log.Information(ex, $"Regular plugin failed to load, adding anyways: {dllFile.Name}");
+
+ // NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
+ // plugin.Disable(); // Disable here, otherwise you can't enable+load later
+ }
+ else if (!plugin.CheckPolicy())
+ {
+ // During boot load, plugins always get added to the list so they can be fiddled with in the UI
+ Log.Information(ex, $"Plugin not loaded due to policy, adding anyways: {dllFile.Name}");
+
+ // NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
+ // plugin.Disable(); // Disable here, otherwise you can't enable+load later
+ }
+ else
+ {
+ PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
+ throw;
+ }
+ }
+ }
+
+ lock (this.pluginListLock)
+ {
+ this.InstalledPlugins = this.InstalledPlugins.Add(plugin);
+ }
+
+ return plugin;
+ }
+
private void DetectAvailablePluginUpdates()
{
var updatablePlugins = new List();
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
index 994069335..aa72200a1 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
@@ -61,6 +61,13 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
this.framework.Update += this.FrameworkOnUpdate;
}
+ private enum ProfileOp
+ {
+ Enable,
+ Disable,
+ Toggle,
+ }
+
///
public void Dispose()
{
@@ -166,11 +173,4 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
return name;
}
-
- private enum ProfileOp
- {
- Enable,
- Disable,
- Toggle,
- }
}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index b7073ac99..f7eac6d21 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -165,7 +165,7 @@ internal class ProfileManager : IServiceType
///
/// Go through all profiles and plugins, and enable/disable plugins they want active.
- /// This will block until all plugins have been loaded/reloaded!
+ /// This will block until all plugins have been loaded/reloaded.
///
public void ApplyAllWantStates()
{
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
index 06075a07e..c73e80450 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
@@ -5,14 +5,29 @@ using Newtonsoft.Json;
namespace Dalamud.Plugin.Internal.Profiles;
+///
+/// Class representing a profile.
+///
public abstract class ProfileModel
{
+ ///
+ /// Gets or sets the ID of the profile.
+ ///
[JsonProperty("id")]
public Guid Guid { get; set; } = Guid.Empty;
+ ///
+ /// Gets or sets the name of the profile.
+ ///
[JsonProperty("n")]
public string Name { get; set; } = "New Profile";
+ ///
+ /// Deserialize a profile into a model.
+ ///
+ /// The string to decompress.
+ /// The parsed model.
+ /// Thrown when the parsed string is not a valid profile.
public static ProfileModel? Deserialize(string model)
{
var json = Util.DecompressString(Convert.FromBase64String(model.Substring(3)));
@@ -23,6 +38,11 @@ public abstract class ProfileModel
throw new ArgumentException("Was not a compressed style model.");
}
+ ///
+ /// Serialize this model into a string usable for sharing.
+ ///
+ /// The serialized representation of the model.
+ /// Thrown when an unsupported model is serialized.
public string Serialize()
{
string prefix;
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs b/Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
index cae585c30..2a851d234 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
@@ -1,27 +1,55 @@
using System.Collections.Generic;
+
using Newtonsoft.Json;
namespace Dalamud.Plugin.Internal.Profiles;
+///
+/// Version 1 of the profile model.
+///
public class ProfileModelV1 : ProfileModel
{
+ ///
+ /// Gets the prefix of this version.
+ ///
public static string SerializedPrefix => "DP1";
+ ///
+ /// Gets or sets a value indicating whether or not this profile should always be enabled at boot.
+ ///
[JsonProperty("b")]
public bool AlwaysEnableOnBoot { get; set; } = false;
+ ///
+ /// Gets or sets a value indicating whether or not this profile is currently enabled.
+ ///
[JsonProperty("e")]
public bool IsEnabled { get; set; } = false;
+ ///
+ /// Gets or sets a value indicating this profile's color.
+ ///
[JsonProperty("c")]
public uint Color { get; set; }
+ ///
+ /// Gets or sets the list of plugins in this profile.
+ ///
public List Plugins { get; set; } = new();
+ ///
+ /// Class representing a single plugin in a profile.
+ ///
public class ProfileModelV1Plugin
{
- public string InternalName { get; set; }
+ ///
+ /// Gets or sets the internal name of the plugin.
+ ///
+ public string? InternalName { get; set; }
+ ///
+ /// Gets or sets a value indicating whether or not this entry is enabled.
+ ///
public bool IsEnabled { get; set; }
}
}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs b/Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
index 21856e572..0a6f5140b 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
@@ -1,14 +1,28 @@
namespace Dalamud.Plugin.Internal.Profiles;
+///
+/// Class representing a single plugin in a profile.
+///
internal class ProfilePluginEntry
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The internal name of the plugin.
+ /// A value indicating whether or not this entry is enabled.
public ProfilePluginEntry(string internalName, bool state)
{
this.InternalName = internalName;
this.IsEnabled = state;
}
+ ///
+ /// Gets the internal name of the plugin.
+ ///
public string InternalName { get; }
+ ///
+ /// Gets a value indicating whether or not this entry is enabled.
+ ///
public bool IsEnabled { get; }
}
diff --git a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
index 7811939b4..062fc94f1 100644
--- a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
+++ b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs
@@ -136,7 +136,9 @@ internal class LocalPlugin : IDisposable
this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile);
if (this.disabledFile.Exists)
{
+#pragma warning disable CS0618
this.Manifest.Disabled = true;
+#pragma warning restore CS0618
this.disabledFile.Delete();
}
@@ -627,9 +629,9 @@ internal class LocalPlugin : IDisposable
var manifest = LocalPluginManifest.GetManifestFile(this.DllFile);
if (manifest.Exists)
{
- //var isDisabled = this.IsDisabled; // saving the internal state because it could have been deleted
+ // var isDisabled = this.IsDisabled; // saving the internal state because it could have been deleted
this.Manifest = LocalPluginManifest.Load(manifest);
- //this.Manifest.Disabled = isDisabled;
+ // this.Manifest.Disabled = isDisabled;
this.SaveManifest();
}
From a913192765d567337a0e9e2a71f38dec16763be4 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 12 Jun 2023 20:21:28 +0200
Subject: [PATCH 23/28] profile => collection
---
.../PluginInstaller/ProfileManagerWidget.cs | 24 +++++++++----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index 60f605f8e..4f92cebb8 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -450,25 +450,25 @@ internal class ProfileManagerWidget
private static class Locs
{
public static string TooltipEnableDisable =>
- Loc.Localize("ProfileManagerEnableDisableHint", "Enable/Disable this profile");
+ Loc.Localize("ProfileManagerEnableDisableHint", "Enable/Disable this collection");
public static string InstallPlugin => Loc.Localize("ProfileManagerInstall", "Install this plugin");
public static string RemovePlugin =>
- Loc.Localize("ProfileManagerRemoveFromProfile", "Remove plugin from this profile");
+ Loc.Localize("ProfileManagerRemoveFromProfile", "Remove plugin from this collection");
public static string AddPlugin => Loc.Localize("ProfileManagerAddPlugin", "Add a plugin!");
public static string NoPluginsInProfile =>
- Loc.Localize("ProfileManagerNoPluginsInProfile", "Profile has no plugins!");
+ Loc.Localize("ProfileManagerNoPluginsInProfile", "Collection has no plugins!");
public static string AlwaysEnableAtBoot =>
Loc.Localize("ProfileManagerAlwaysEnableAtBoot", "Always enable when game starts");
- public static string DeleteProfileHint => Loc.Localize("ProfileManagerDeleteProfile", "Delete this profile");
+ public static string DeleteProfileHint => Loc.Localize("ProfileManagerDeleteProfile", "Delete this collection");
public static string CopyToClipboardHint =>
- Loc.Localize("ProfileManagerCopyToClipboard", "Copy profile to clipboard for sharing");
+ Loc.Localize("ProfileManagerCopyToClipboard", "Copy collection to clipboard for sharing");
public static string CopyToClipboardNotification =>
Loc.Localize("ProfileManagerCopyToClipboardHint", "Copied to clipboard!");
@@ -477,22 +477,22 @@ internal class ProfileManagerWidget
public static string SearchHint => Loc.Localize("ProfileManagerSearchHint", "Search...");
- public static string AddProfileHint => Loc.Localize("ProfileManagerAddProfileHint", "No profiles! Add one!");
+ public static string AddProfileHint => Loc.Localize("ProfileManagerAddProfileHint", "No collections! Add one!");
- public static string CloneProfileHint => Loc.Localize("ProfileManagerCloneProfile", "Clone this profile");
+ public static string CloneProfileHint => Loc.Localize("ProfileManagerCloneProfile", "Clone this collection");
- public static string EditProfileHint => Loc.Localize("ProfileManagerEditProfile", "Edit this profile");
+ public static string EditProfileHint => Loc.Localize("ProfileManagerEditProfile", "Edit this collection");
public static string ImportProfileHint =>
- Loc.Localize("ProfileManagerImportProfile", "Import a shared profile from your clipboard");
+ Loc.Localize("ProfileManagerImportProfile", "Import a shared collection from your clipboard");
- public static string AddProfile => Loc.Localize("ProfileManagerAddProfile", "Add a new profile");
+ public static string AddProfile => Loc.Localize("ProfileManagerAddProfile", "Add a new collection");
public static string NotificationImportSuccess =>
- Loc.Localize("ProfileManagerNotificationImportSuccess", "Profile successfully imported!");
+ Loc.Localize("ProfileManagerNotificationImportSuccess", "Collection successfully imported!");
public static string NotificationImportError =>
- Loc.Localize("ProfileManagerNotificationImportError", "Could not import profile.");
+ Loc.Localize("ProfileManagerNotificationImportError", "Could not import collection.");
public static string ErrorCouldNotRemove =>
Loc.Localize("ProfileManagerCouldNotRemove", "Could not remove plugin.");
From 26ee5371a55833341fc8f1774de80678a5e37403 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 12 Jun 2023 20:26:13 +0200
Subject: [PATCH 24/28] use correct cat + group idx to hide search bar
---
.../Windows/PluginInstaller/PluginInstallerWindow.cs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index d28401e73..fb7714098 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -522,8 +522,11 @@ internal class PluginInstallerWindow : Window, IDisposable
ImGui.SetCursorPosX(windowSize.X - sortSelectWidth - (style.ItemSpacing.X * 2) - searchInputWidth - searchClearButtonWidth);
+ var isProfileManager =
+ this.categoryManager.CurrentGroupIdx == 1 && this.categoryManager.CurrentCategoryIdx == 2;
+
// Disable search if profile editor
- using (ImRaii.Disabled(this.categoryManager.CurrentCategoryIdx == 14))
+ using (ImRaii.Disabled(isProfileManager))
{
var searchTextChanged = false;
ImGui.SetNextItemWidth(searchInputWidth);
@@ -548,7 +551,7 @@ internal class PluginInstallerWindow : Window, IDisposable
}
// Disable sort if changelogs or profile editor
- using (ImRaii.Disabled(this.categoryManager.CurrentGroupIdx == 3 || this.categoryManager.CurrentCategoryIdx == 14))
+ using (ImRaii.Disabled(this.categoryManager.CurrentGroupIdx == 3 || isProfileManager))
{
ImGui.SameLine();
ImGui.SetCursorPosY(downShift);
From bcdbe06e3f80adbeec25c11bb3e39cab1b3a3295 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 12 Jun 2023 20:31:34 +0200
Subject: [PATCH 25/28] disable profiles by default
---
Dalamud/Configuration/Internal/DalamudConfiguration.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
index 0d29b8cb7..cb33e7070 100644
--- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs
+++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
@@ -285,7 +285,7 @@ internal sealed class DalamudConfiguration : IServiceType
///
/// Gets or sets a value indicating whether or not profiles are enabled.
///
- public bool ProfilesEnabled { get; set; } = true;
+ public bool ProfilesEnabled { get; set; } = false;
///
/// Gets or sets a value indicating whether or not Dalamud RMT filtering should be disabled.
From 66026bbc3e48df971bd5a472f1fef4f89bf37d8a Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 12 Jun 2023 20:33:22 +0200
Subject: [PATCH 26/28] one more profile => collection
---
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index f7eac6d21..1b2c16088 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -111,7 +111,7 @@ internal class ProfileManager : IServiceType
var model = new ProfileModelV1
{
Guid = Guid.NewGuid(),
- Name = this.GenerateUniqueProfileName(Loc.Localize("PluginProfilesNewProfile", "New Profile")),
+ Name = this.GenerateUniqueProfileName(Loc.Localize("PluginProfilesNewProfile", "New Collection")),
IsEnabled = false,
};
From 3d057c4e35714d1d6dea41a03030759ad27025d2 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 12 Jun 2023 20:34:16 +0200
Subject: [PATCH 27/28] one one more profile => collection
---
Dalamud/Plugin/Internal/Profiles/ProfileModel.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
index c73e80450..80c47db78 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
@@ -20,7 +20,7 @@ public abstract class ProfileModel
/// Gets or sets the name of the profile.
///
[JsonProperty("n")]
- public string Name { get; set; } = "New Profile";
+ public string Name { get; set; } = "New Collection";
///
/// Deserialize a profile into a model.
From 6dd7188f6cdcdf82c85efaf08c455f7018d31180 Mon Sep 17 00:00:00 2001
From: goat
Date: Mon, 12 Jun 2023 20:44:28 +0200
Subject: [PATCH 28/28] even more profile => collection
---
.../Settings/Tabs/SettingsTabExperimental.cs | 4 ++--
.../Profiles/ProfileCommandHandler.cs | 22 +++++++++----------
.../Internal/Profiles/ProfileManager.cs | 2 +-
.../Plugin/Internal/Profiles/ProfileModel.cs | 2 +-
4 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs
index 6d5c03137..62981f4a2 100644
--- a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs
+++ b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabExperimental.cs
@@ -50,8 +50,8 @@ public class SettingsTabExperimental : SettingsTab
new GapSettingsEntry(5, true),
new SettingsEntry(
- Loc.Localize("DalamudSettingsEnableProfiles", "Enable plugin profiles"),
- Loc.Localize("DalamudSettingsEnableProfilesHint", "EXPERIMENTAL: Enables plugin profiles."),
+ Loc.Localize("DalamudSettingsEnableProfiles", "Enable plugin collections"),
+ Loc.Localize("DalamudSettingsEnableProfilesHint", "Enables plugin collections, which lets you create toggleable lists of plugins."),
c => c.ProfilesEnabled,
(v, c) => c.ProfilesEnabled = v),
};
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
index aa72200a1..81e63e0bc 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
@@ -42,19 +42,19 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
this.cmd.AddHandler("/xlenableprofile", new CommandInfo(this.OnEnableProfile)
{
- HelpMessage = Loc.Localize("ProfileCommandsEnableHint", "Enable a profile. Usage: /xlenableprofile \"Profile Name\""),
+ HelpMessage = Loc.Localize("ProfileCommandsEnableHint", "Enable a collection. Usage: /xlenablecollection \"Collection Name\""),
ShowInHelp = true,
});
this.cmd.AddHandler("/xldisableprofile", new CommandInfo(this.OnDisableProfile)
{
- HelpMessage = Loc.Localize("ProfileCommandsDisableHint", "Disable a profile. Usage: /xldisableprofile \"Profile Name\""),
+ HelpMessage = Loc.Localize("ProfileCommandsDisableHint", "Disable a collection. Usage: /xldisablecollection \"Collection Name\""),
ShowInHelp = true,
});
this.cmd.AddHandler("/xltoggleprofile", new CommandInfo(this.OnToggleProfile)
{
- HelpMessage = Loc.Localize("ProfileCommandsToggleHint", "Toggle a profile. Usage: /xltoggleprofile \"Profile Name\""),
+ HelpMessage = Loc.Localize("ProfileCommandsToggleHint", "Toggle a collection. Usage: /xltogglecollection \"Collection Name\""),
ShowInHelp = true,
});
@@ -71,9 +71,9 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
///
public void Dispose()
{
- this.cmd.RemoveHandler("/xlenableprofile");
- this.cmd.RemoveHandler("/xldisableprofile");
- this.cmd.RemoveHandler("/xltoggleprofile");
+ this.cmd.RemoveHandler("/xlenablecollection");
+ this.cmd.RemoveHandler("/xldisablecollection");
+ this.cmd.RemoveHandler("/xltogglecollection");
this.framework.Update += this.FrameworkOnUpdate;
}
@@ -111,11 +111,11 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
if (profile.IsEnabled)
{
- this.chat.Print(Loc.Localize("ProfileCommandsEnabling", "Enabling profile \"{0}\"...").Format(profile.Name));
+ this.chat.Print(Loc.Localize("ProfileCommandsEnabling", "Enabling collection \"{0}\"...").Format(profile.Name));
}
else
{
- this.chat.Print(Loc.Localize("ProfileCommandsDisabling", "Disabling profile \"{0}\"...").Format(profile.Name));
+ this.chat.Print(Loc.Localize("ProfileCommandsDisabling", "Disabling collection \"{0}\"...").Format(profile.Name));
}
Task.Run(() => this.profileManager.ApplyAllWantStates()).ContinueWith(t =>
@@ -123,11 +123,11 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
if (!t.IsCompletedSuccessfully && t.Exception != null)
{
Log.Error(t.Exception, "Could not apply profiles through commands");
- this.chat.PrintError(Loc.Localize("ProfileCommandsApplyFailed", "Failed to apply all of your profiles. Please check the console for errors."));
+ this.chat.PrintError(Loc.Localize("ProfileCommandsApplyFailed", "Failed to apply your collections. Please check the console for errors."));
}
else
{
- this.chat.Print(Loc.Localize("ProfileCommandsApplySuccess", "Profiles applied."));
+ this.chat.Print(Loc.Localize("ProfileCommandsApplySuccess", "Collections applied."));
}
});
}
@@ -167,7 +167,7 @@ internal class ProfileCommandHandler : IServiceType, IDisposable
var name = arguments.Replace("\"", string.Empty);
if (this.profileManager.Profiles.All(x => x.Name != name))
{
- this.chat.PrintError($"No profile like \"{name}\".");
+ this.chat.PrintError($"No collection like \"{name}\".");
return null;
}
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index 1b2c16088..d91db1283 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -150,7 +150,7 @@ internal class ProfileManager : IServiceType
return null;
newModel.Guid = Guid.NewGuid();
- newModel.Name = this.GenerateUniqueProfileName(newModel.Name.IsNullOrEmpty() ? "Unknown Profile" : newModel.Name);
+ newModel.Name = this.GenerateUniqueProfileName(newModel.Name.IsNullOrEmpty() ? "Unknown Collection" : newModel.Name);
if (newModel is ProfileModelV1 modelV1)
modelV1.IsEnabled = false;
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
index 80c47db78..bf2a9c2c9 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
@@ -35,7 +35,7 @@ public abstract class ProfileModel
if (model.StartsWith(ProfileModelV1.SerializedPrefix))
return JsonConvert.DeserializeObject(json);
- throw new ArgumentException("Was not a compressed style model.");
+ throw new ArgumentException("Was not a compressed profile.");
}
///