mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
commit
7eb05ddae2
19 changed files with 1835 additions and 372 deletions
|
|
@ -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;
|
||||
|
|
@ -271,6 +272,21 @@ internal sealed class DalamudConfiguration : IServiceType
|
|||
/// </summary>
|
||||
public string ChosenStyle { get; set; } = "Dalamud Standard";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of saved plugin profiles.
|
||||
/// </summary>
|
||||
public List<ProfileModel>? SavedProfiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default plugin profile.
|
||||
/// </summary>
|
||||
public ProfileModel? DefaultProfile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not profiles are enabled.
|
||||
/// </summary>
|
||||
public bool ProfilesEnabled { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not Dalamud RMT filtering should be disabled.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public sealed class EntryPoint
|
|||
{
|
||||
try
|
||||
{
|
||||
return Marshal.StringToHGlobalUni(Environment.StackTrace);
|
||||
return Marshal.StringToHGlobalUni(new StackTrace(1).ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
/// </summary>
|
||||
DoPluginTest,
|
||||
|
||||
/// <summary>
|
||||
/// Check if plugin profiles are enabled.
|
||||
/// </summary>
|
||||
ProfilesEnabled,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -430,6 +436,8 @@ internal class PluginCategoryManager
|
|||
|
||||
public static string Category_IconTester => "Image/Icon Tester";
|
||||
|
||||
public static string Category_PluginProfiles => Loc.Localize("InstallerCategoryPluginProfiles", "Plugin Collections");
|
||||
|
||||
public static string Category_Other => Loc.Localize("InstallerCategoryOther", "Other");
|
||||
|
||||
public static string Category_Jobs => Loc.Localize("InstallerCategoryJobs", "Jobs");
|
||||
|
|
|
|||
|
|
@ -15,12 +15,14 @@ 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;
|
||||
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 +50,8 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
|
||||
private readonly object listLock = new();
|
||||
|
||||
private readonly ProfileManagerWidget profileManagerWidget;
|
||||
|
||||
private DalamudChangelogManager? dalamudChangelogManager;
|
||||
private Task? dalamudChangelogRefreshTask;
|
||||
private CancellationTokenSource? dalamudChangelogRefreshTaskCts;
|
||||
|
|
@ -148,6 +152,8 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
});
|
||||
|
||||
this.timeLoaded = DateTime.Now;
|
||||
|
||||
this.profileManagerWidget = new(this);
|
||||
}
|
||||
|
||||
private enum OperationStatus
|
||||
|
|
@ -166,6 +172,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
UpdatingAll,
|
||||
Installing,
|
||||
Manager,
|
||||
ProfilesLoading,
|
||||
}
|
||||
|
||||
private enum PluginSortKind
|
||||
|
|
@ -212,6 +219,8 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
this.updatePluginCount = 0;
|
||||
this.updatedPlugins = null;
|
||||
}
|
||||
|
||||
this.profileManagerWidget.Reset();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -284,17 +293,96 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
this.searchText = text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a plugin install and handle errors visually.
|
||||
/// </summary>
|
||||
/// <param name="manifest">The manifest to install.</param>
|
||||
/// <param name="useTesting">Install the testing version.</param>
|
||||
public void StartInstall(RemotePluginManifest manifest, bool useTesting)
|
||||
{
|
||||
var pluginManager = Service<PluginManager>.Get();
|
||||
var notifications = Service<NotificationManager>.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));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A continuation task that displays any errors received into the error modal.
|
||||
/// </summary>
|
||||
/// <param name="task">The previous task.</param>
|
||||
/// <param name="state">An error message to be displayed.</param>
|
||||
/// <returns>A value indicating whether to continue with the next task.</returns>
|
||||
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<PluginManager>.Get();
|
||||
var profileManager = Service<ProfileManager>.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;
|
||||
|
|
@ -378,6 +466,9 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case LoadingIndicatorKind.ProfilesLoading:
|
||||
ImGuiHelpers.CenteredText("Collections are being applied...");
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
|
@ -386,9 +477,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();
|
||||
}
|
||||
|
||||
|
|
@ -433,54 +522,57 @@ 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))
|
||||
var isProfileManager =
|
||||
this.categoryManager.CurrentGroupIdx == 1 && this.categoryManager.CurrentCategoryIdx == 2;
|
||||
|
||||
// Disable search if profile editor
|
||||
using (ImRaii.Disabled(isProfileManager))
|
||||
{
|
||||
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 || isProfileManager))
|
||||
{
|
||||
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()
|
||||
|
|
@ -1089,6 +1181,10 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
if (!Service<DalamudConfiguration>.Get().DoPluginTest)
|
||||
continue;
|
||||
break;
|
||||
case PluginCategoryManager.CategoryInfo.AppearCondition.ProfilesEnabled:
|
||||
if (!Service<DalamudConfiguration>.Get().ProfilesEnabled)
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
|
@ -1194,6 +1290,10 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
case 1:
|
||||
this.DrawInstalledPluginList(true);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this.profileManagerWidget.Draw();
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -1533,7 +1633,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();
|
||||
|
|
@ -1831,27 +1931,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1958,7 +2038,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
}
|
||||
|
||||
// Disabled
|
||||
if (plugin.IsDisabled || !plugin.CheckPolicy())
|
||||
if (!plugin.IsWantedByAnyProfile || !plugin.CheckPolicy())
|
||||
{
|
||||
label += Locs.PluginTitleMod_Disabled;
|
||||
trouble = true;
|
||||
|
|
@ -2118,7 +2198,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();
|
||||
|
|
@ -2240,6 +2320,11 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
{
|
||||
var notifications = Service<NotificationManager>.Get();
|
||||
var pluginManager = Service<PluginManager>.Get();
|
||||
var profileManager = Service<ProfileManager>.Get();
|
||||
var config = Service<DalamudConfiguration>.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;
|
||||
|
|
@ -2255,15 +2340,70 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
// Now handled by the first case below
|
||||
// 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, Locs.Profiles_CouldNotAdd);
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run(() => profile.Remove(plugin.Manifest.InternalName))
|
||||
.ContinueWith(this.DisplayErrorContinuation, Locs.Profiles_CouldNotRemove);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
ImGui.TextUnformatted(profile.Name);
|
||||
|
||||
didAny = true;
|
||||
}
|
||||
|
||||
if (!didAny)
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey, Locs.Profiles_None);
|
||||
|
||||
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(Locs.Profiles_RemoveFromAll);
|
||||
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
if (plugin.State is PluginState.UnloadError or PluginState.LoadError or PluginState.DependencyResolutionFailed && !plugin.IsDev)
|
||||
{
|
||||
ImGuiComponents.DisabledButton(FontAwesomeIcon.Frown);
|
||||
|
|
@ -2271,14 +2411,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;
|
||||
|
|
@ -2301,15 +2445,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);
|
||||
});
|
||||
}
|
||||
|
|
@ -2325,17 +2463,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(
|
||||
|
|
@ -2388,6 +2516,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<bool> UpdateSinglePlugin(AvailablePluginUpdate update)
|
||||
|
|
@ -2474,26 +2625,32 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
|
||||
if (localPlugin is LocalDevPlugin plugin)
|
||||
{
|
||||
var isInDefaultProfile =
|
||||
Service<ProfileManager>.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
|
||||
|
|
@ -2800,46 +2957,6 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
private bool WasPluginSeen(string internalName) =>
|
||||
Service<DalamudConfiguration>.Get().SeenPluginInternalName.Contains(internalName);
|
||||
|
||||
/// <summary>
|
||||
/// A continuation task that displays any errors received into the error modal.
|
||||
/// </summary>
|
||||
/// <param name="task">The previous task.</param>
|
||||
/// <param name="state">An error message to be displayed.</param>
|
||||
/// <returns>A value indicating whether to continue with the next task.</returns>
|
||||
private 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;
|
||||
|
|
@ -2890,7 +3007,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");
|
||||
|
||||
|
|
@ -3047,6 +3164,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 collections for this plugin");
|
||||
|
||||
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");
|
||||
|
||||
public static string PluginButtonToolTip_AutomaticReloading => Loc.Localize("InstallerAutomaticReloading", "Automatic reloading");
|
||||
|
|
@ -3067,6 +3188,8 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
|
||||
public static string PluginButtonToolTip_UnloadFailed => Loc.Localize("InstallerLoadUnloadFailedTooltip", "Plugin load/unload failed, please restart your game and try again.");
|
||||
|
||||
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
|
||||
|
||||
#region Notifications
|
||||
|
|
@ -3226,5 +3349,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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,506 @@
|
|||
using System;
|
||||
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;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Plugin.Internal.Profiles;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.PluginInstaller;
|
||||
|
||||
/// <summary>
|
||||
/// ImGui widget used to manage profiles.
|
||||
/// </summary>
|
||||
internal class ProfileManagerWidget
|
||||
{
|
||||
private readonly PluginInstallerWindow installer;
|
||||
private Mode mode = Mode.Overview;
|
||||
private Guid? editingProfileGuid;
|
||||
|
||||
private string pickerSearch = string.Empty;
|
||||
private string profileNameEdit = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProfileManagerWidget"/> class.
|
||||
/// </summary>
|
||||
/// <param name="installer">The plugin installer.</param>
|
||||
public ProfileManagerWidget(PluginInstallerWindow installer)
|
||||
{
|
||||
this.installer = installer;
|
||||
}
|
||||
|
||||
private enum Mode
|
||||
{
|
||||
Overview,
|
||||
EditSingleProfile,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw this widget's contents.
|
||||
/// </summary>
|
||||
public void Draw()
|
||||
{
|
||||
switch (this.mode)
|
||||
{
|
||||
case Mode.Overview:
|
||||
this.DrawOverview();
|
||||
break;
|
||||
|
||||
case Mode.EditSingleProfile:
|
||||
this.DrawEdit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the widget.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
this.mode = Mode.Overview;
|
||||
this.editingProfileGuid = null;
|
||||
this.pickerSearch = string.Empty;
|
||||
}
|
||||
|
||||
private void DrawOverview()
|
||||
{
|
||||
var didAny = false;
|
||||
var profman = Service<ProfileManager>.Get();
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
|
||||
profman.AddNewProfile();
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.AddProfile);
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.FileImport))
|
||||
{
|
||||
try
|
||||
{
|
||||
profman.ImportProfile(ImGui.GetClipboardText());
|
||||
Service<NotificationManager>.Get().AddNotification(Locs.NotificationImportSuccess, type: NotificationType.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Could not import profile");
|
||||
Service<NotificationManager>.Get().AddNotification(Locs.NotificationImportError, type: NotificationType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.ImportProfileHint);
|
||||
|
||||
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, Locs.ErrorCouldNotChangeState);
|
||||
}
|
||||
|
||||
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(Locs.EditProfileHint);
|
||||
|
||||
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(Locs.CloneProfileHint);
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.SetCursorPosX(windowSize.X - (ImGuiHelpers.GlobalScale * 30 * 3) - 5);
|
||||
|
||||
if (ImGuiComponents.IconButton($"###exportButton{profile.Guid}", FontAwesomeIcon.FileExport))
|
||||
{
|
||||
ImGui.SetClipboardText(profile.Model.Serialize());
|
||||
Service<NotificationManager>.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.CopyToClipboardHint);
|
||||
|
||||
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(Locs.AddProfileHint);
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
ImGui.EndChild();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawEdit()
|
||||
{
|
||||
if (this.editingProfileGuid == null)
|
||||
{
|
||||
Log.Error("Editing profile guid was null");
|
||||
this.Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
var profman = Service<ProfileManager>.Get();
|
||||
var pm = Service<PluginManager>.Get();
|
||||
var pic = Service<PluginImageCache>.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";
|
||||
using (var popup = ImRaii.Popup(addPluginToProfilePopup))
|
||||
{
|
||||
if (popup.Success)
|
||||
{
|
||||
var width = ImGuiHelpers.GlobalScale * 300;
|
||||
|
||||
using var disabled = ImRaii.Disabled(profman.IsBusy);
|
||||
|
||||
ImGui.SetNextItemWidth(width);
|
||||
ImGui.InputTextWithHint("###pluginPickerSearch", Locs.SearchHint, ref this.pickerSearch, 255);
|
||||
|
||||
if (ImGui.BeginListBox("###pluginPicker", new Vector2(width, width - 80)))
|
||||
{
|
||||
// TODO: Plugin searching should be abstracted... installer and this should use the same search
|
||||
foreach (var plugin in pm.InstalledPlugins.Where(x => x.Manifest.SupportsProfiles &&
|
||||
(this.pickerSearch.IsNullOrWhitespace() || x.Manifest.Name.ToLowerInvariant().Contains(this.pickerSearch.ToLowerInvariant()))))
|
||||
{
|
||||
using var disabled2 =
|
||||
ImRaii.Disabled(profile.Plugins.Any(y => y.InternalName == plugin.Manifest.InternalName));
|
||||
|
||||
if (ImGui.Selectable($"{plugin.Manifest.Name}###selector{plugin.Manifest.InternalName}"))
|
||||
{
|
||||
// TODO this sucks
|
||||
profile.AddOrUpdate(plugin.Manifest.InternalName, true, false);
|
||||
Task.Run(() => profman.ApplyAllWantStates())
|
||||
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotChangeState);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndListBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var didAny = false;
|
||||
|
||||
// ======== Top bar ========
|
||||
var windowSize = ImGui.GetWindowSize();
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.ArrowLeft))
|
||||
this.Reset();
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.BackToOverview);
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport))
|
||||
{
|
||||
ImGui.SetClipboardText(profile.Model.Serialize());
|
||||
Service<NotificationManager>.Get().AddNotification(Locs.CopyToClipboardNotification, type: NotificationType.Success);
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.CopyToClipboardHint);
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
ImGui.SameLine();
|
||||
|
||||
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.installer.DisplayErrorContinuation(t, Locs.ErrorCouldNotChangeState);
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.DeleteProfileHint);
|
||||
|
||||
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, Locs.ErrorCouldNotChangeState);
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.TooltipEnableDisable);
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
var enableAtBoot = profile.AlwaysEnableAtBoot;
|
||||
if (ImGui.Checkbox(Locs.AlwaysEnableAtBoot, ref enableAtBoot))
|
||||
{
|
||||
profile.AlwaysEnableAtBoot = enableAtBoot;
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
ImGui.Separator();
|
||||
var wantPluginAddPopup = false;
|
||||
|
||||
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)
|
||||
{
|
||||
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 = Locs.NotInstalled(plugin.InternalName);
|
||||
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 * 30 * 2) - 2);
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (pluginLineHeight / 2) - (ImGui.GetFrameHeight() / 2));
|
||||
btnOffset = 3;
|
||||
|
||||
if (ImGuiComponents.IconButton($"###installMissingPlugin{available.InternalName}", FontAwesomeIcon.Download))
|
||||
{
|
||||
this.installer.StartInstall(available, false);
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(Locs.InstallPlugin);
|
||||
}
|
||||
|
||||
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, Locs.ErrorCouldNotChangeState);
|
||||
}
|
||||
|
||||
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(Locs.RemovePlugin);
|
||||
}
|
||||
|
||||
if (wantRemovePluginInternalName != null)
|
||||
{
|
||||
// TODO: handle error
|
||||
profile.Remove(wantRemovePluginInternalName, false);
|
||||
Task.Run(() => profman.ApplyAllWantStates())
|
||||
.ContinueWith(this.installer.DisplayErrorContinuation, Locs.ErrorCouldNotRemove);
|
||||
}
|
||||
|
||||
if (!didAny)
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey, Locs.NoPluginsInProfile);
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(10);
|
||||
|
||||
var addPluginsText = Locs.AddPlugin;
|
||||
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)
|
||||
{
|
||||
this.pickerSearch = string.Empty;
|
||||
ImGui.OpenPopup(addPluginToProfilePopup);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Locs
|
||||
{
|
||||
public static string TooltipEnableDisable =>
|
||||
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 collection");
|
||||
|
||||
public static string AddPlugin => Loc.Localize("ProfileManagerAddPlugin", "Add a plugin!");
|
||||
|
||||
public static string NoPluginsInProfile =>
|
||||
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 collection");
|
||||
|
||||
public static string CopyToClipboardHint =>
|
||||
Loc.Localize("ProfileManagerCopyToClipboard", "Copy collection 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 collections! Add one!");
|
||||
|
||||
public static string CloneProfileHint => Loc.Localize("ProfileManagerCloneProfile", "Clone this collection");
|
||||
|
||||
public static string EditProfileHint => Loc.Localize("ProfileManagerEditProfile", "Edit this collection");
|
||||
|
||||
public static string ImportProfileHint =>
|
||||
Loc.Localize("ProfileManagerImportProfile", "Import a shared collection from your clipboard");
|
||||
|
||||
public static string AddProfile => Loc.Localize("ProfileManagerAddProfile", "Add a new collection");
|
||||
|
||||
public static string NotificationImportSuccess =>
|
||||
Loc.Localize("ProfileManagerNotificationImportSuccess", "Collection successfully imported!");
|
||||
|
||||
public static string NotificationImportError =>
|
||||
Loc.Localize("ProfileManagerNotificationImportError", "Could not import collection.");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,14 @@ public class SettingsTabExperimental : SettingsTab
|
|||
new GapSettingsEntry(5, true),
|
||||
|
||||
new ThirdRepoSettingsEntry(),
|
||||
|
||||
new GapSettingsEntry(5, true),
|
||||
|
||||
new SettingsEntry<bool>(
|
||||
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),
|
||||
};
|
||||
|
||||
public override string Title => Loc.Localize("DalamudSettingsExperimental", "Experimental");
|
||||
|
|
|
|||
|
|
@ -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<DataManager>.Get();
|
||||
var names = data.GetExcelSheet<BNpcName>(ClientLanguage.English);
|
||||
var rng = new Random();
|
||||
|
||||
return names.ElementAt(rng.Next(0, names.Count() - 1)).Singular.RawString;
|
||||
}
|
||||
|
||||
private void SaveStyle()
|
||||
{
|
||||
if (this.currentSel < 2)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ using Dalamud.IoC.Internal;
|
|||
using Dalamud.Logging.Internal;
|
||||
using Dalamud.Networking.Http;
|
||||
using Dalamud.Plugin.Internal.Exceptions;
|
||||
using Dalamud.Plugin.Internal.Profiles;
|
||||
using Dalamud.Plugin.Internal.Types;
|
||||
using Dalamud.Utility;
|
||||
using Dalamud.Utility.Timing;
|
||||
|
|
@ -71,6 +72,9 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
[ServiceManager.ServiceDependency]
|
||||
private readonly DalamudStartInfo startInfo = Service<DalamudStartInfo>.Get();
|
||||
|
||||
[ServiceManager.ServiceDependency]
|
||||
private readonly ProfileManager profileManager = Service<ProfileManager>.Get();
|
||||
|
||||
[ServiceManager.ServiceDependency]
|
||||
private readonly HappyHttpClient happyHttpClient = Service<HappyHttpClient>.Get();
|
||||
|
||||
|
|
@ -407,7 +411,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
|
||||
try
|
||||
{
|
||||
pluginDefs.Add(versionsDefs.OrderByDescending(x => x.Manifest!.EffectiveVersion).First());
|
||||
pluginDefs.Add(versionsDefs.MaxBy(x => x.Manifest!.EffectiveVersion));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -812,122 +816,6 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
return plugin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a plugin.
|
||||
/// </summary>
|
||||
/// <param name="dllFile">The <see cref="FileInfo"/> associated with the main assembly of this plugin.</param>
|
||||
/// <param name="manifest">The already loaded definition, if available.</param>
|
||||
/// <param name="reason">The reason this plugin was loaded.</param>
|
||||
/// <param name="isDev">If this plugin should support development features.</param>
|
||||
/// <param name="isBoot">If this plugin is being loaded at boot.</param>
|
||||
/// <param name="doNotLoad">Don't load the plugin, just don't do it.</param>
|
||||
/// <returns>The loaded plugin.</returns>
|
||||
public async Task<LocalPlugin> 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;
|
||||
|
||||
// If we're not loading it, make sure it's disabled
|
||||
if (!loadPlugin && !devPlugin.IsDisabled)
|
||||
devPlugin.Disable();
|
||||
|
||||
plugin = devPlugin;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information($"Loading plugin {name}");
|
||||
plugin = new LocalPlugin(dllFile, manifest);
|
||||
}
|
||||
|
||||
if (loadPlugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!plugin.IsDisabled && !plugin.IsOrphaned)
|
||||
{
|
||||
await plugin.LoadAsync(reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Verbose($"{name} not loaded, disabled:{plugin.IsDisabled} 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a plugin.
|
||||
/// </summary>
|
||||
|
|
@ -1057,7 +945,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
if (plugin.InstalledPlugin.IsDev)
|
||||
continue;
|
||||
|
||||
if (plugin.InstalledPlugin.Manifest.Disabled && ignoreDisabled)
|
||||
if (!plugin.InstalledPlugin.IsWantedByAnyProfile && ignoreDisabled)
|
||||
continue;
|
||||
|
||||
if (plugin.InstalledPlugin.Manifest.ScheduledForDeletion)
|
||||
|
|
@ -1119,40 +1007,28 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
|
||||
if (plugin.IsDev)
|
||||
{
|
||||
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
|
||||
/*
|
||||
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<DtrBar>.Get();
|
||||
|
|
@ -1323,6 +1199,137 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
/// <returns>The calling plugin, or null.</returns>
|
||||
public LocalPlugin? FindCallingPlugin() => this.FindCallingPlugin(new StackTrace());
|
||||
|
||||
/// <summary>
|
||||
/// Load a plugin.
|
||||
/// </summary>
|
||||
/// <param name="dllFile">The <see cref="FileInfo"/> associated with the main assembly of this plugin.</param>
|
||||
/// <param name="manifest">The already loaded definition, if available.</param>
|
||||
/// <param name="reason">The reason this plugin was loaded.</param>
|
||||
/// <param name="isDev">If this plugin should support development features.</param>
|
||||
/// <param name="isBoot">If this plugin is being loaded at boot.</param>
|
||||
/// <param name="doNotLoad">Don't load the plugin, just don't do it.</param>
|
||||
/// <returns>The loaded plugin.</returns>
|
||||
private async Task<LocalPlugin> 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<AvailablePluginUpdate>();
|
||||
|
|
|
|||
214
Dalamud/Plugin/Internal/Profiles/Profile.cs
Normal file
214
Dalamud/Plugin/Internal/Profiles/Profile.cs
Normal file
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a single runtime profile.
|
||||
/// </summary>
|
||||
internal class Profile
|
||||
{
|
||||
private static readonly ModuleLog Log = new("PROFILE");
|
||||
|
||||
private readonly ProfileManager manager;
|
||||
private readonly ProfileModelV1 modelV1;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Profile"/> class.
|
||||
/// </summary>
|
||||
/// <param name="manager">The manager this profile belongs to.</param>
|
||||
/// <param name="model">The model this profile is tied to.</param>
|
||||
/// <param name="isDefaultProfile">Whether or not this profile is the default profile.</param>
|
||||
/// <param name="isBoot">Whether or not this profile was initialized during bootup.</param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets this profile's name.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => this.modelV1.Name;
|
||||
set
|
||||
{
|
||||
this.modelV1.Name = value;
|
||||
Service<DalamudConfiguration>.Get().QueueSave();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this profile shall always be enabled at boot.
|
||||
/// </summary>
|
||||
public bool AlwaysEnableAtBoot
|
||||
{
|
||||
get => this.modelV1.AlwaysEnableOnBoot;
|
||||
set
|
||||
{
|
||||
this.modelV1.AlwaysEnableOnBoot = value;
|
||||
Service<DalamudConfiguration>.Get().QueueSave();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets this profile's guid.
|
||||
/// </summary>
|
||||
public Guid Guid => this.modelV1.Guid;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not this profile is currently enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not this profile is the default profile.
|
||||
/// </summary>
|
||||
public bool IsDefaultProfile { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets all plugins declared in this profile.
|
||||
/// </summary>
|
||||
public IEnumerable<ProfilePluginEntry> Plugins =>
|
||||
this.modelV1.Plugins.Select(x => new ProfilePluginEntry(x.InternalName, x.IsEnabled));
|
||||
|
||||
/// <summary>
|
||||
/// Gets this profile's underlying model.
|
||||
/// </summary>
|
||||
public ProfileModel Model => this.modelV1;
|
||||
|
||||
/// <summary>
|
||||
/// Set this profile's state. This cannot be called for the default profile.
|
||||
/// This will block until all states have been applied.
|
||||
/// </summary>
|
||||
/// <param name="enabled">Whether or not the profile is enabled.</param>
|
||||
/// <param name="apply">Whether or not the current state should immediately be applied.</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when an untoggleable profile is toggled.</exception>
|
||||
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<DalamudConfiguration>.Get().QueueSave();
|
||||
|
||||
if (apply)
|
||||
this.manager.ApplyAllWantStates();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if this profile contains a specific plugin, and if it is enabled.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <returns>Null if this profile does not declare the plugin, true if the profile declares the plugin and wants it enabled, false if the profile declares the plugin and does not want it enabled.</returns>
|
||||
public bool? WantsPlugin(string internalName)
|
||||
{
|
||||
var entry = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName);
|
||||
return entry?.IsEnabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a plugin to this profile with the desired state, or change the state of a plugin in this profile.
|
||||
/// This will block until all states have been applied.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="state">Whether or not the plugin should be enabled.</param>
|
||||
/// <param name="apply">Whether or not the current state should immediately be applied.</param>
|
||||
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<DalamudConfiguration>.Get().QueueSave();
|
||||
|
||||
if (apply)
|
||||
this.manager.ApplyAllWantStates();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a plugin from this profile.
|
||||
/// This will block until all states have been applied.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="apply">Whether or not the current state should immediately be applied.</param>
|
||||
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<DalamudConfiguration>.Get().QueueSave();
|
||||
|
||||
if (apply)
|
||||
this.manager.ApplyAllWantStates();
|
||||
}
|
||||
}
|
||||
176
Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
Normal file
176
Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Service responsible for profile-related chat commands.
|
||||
/// </summary>
|
||||
[ServiceManager.EarlyLoadedService]
|
||||
internal class ProfileCommandHandler : IServiceType, IDisposable
|
||||
{
|
||||
private readonly CommandManager cmd;
|
||||
private readonly ProfileManager profileManager;
|
||||
private readonly ChatGui chat;
|
||||
private readonly Framework framework;
|
||||
|
||||
private List<(string, ProfileOp)> queue = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProfileCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="cmd">Command handler.</param>
|
||||
/// <param name="profileManager">Profile manager.</param>
|
||||
/// <param name="chat">Chat handler.</param>
|
||||
/// <param name="framework">Framework.</param>
|
||||
[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 = 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 collection. Usage: /xldisablecollection \"Collection Name\""),
|
||||
ShowInHelp = true,
|
||||
});
|
||||
|
||||
this.cmd.AddHandler("/xltoggleprofile", new CommandInfo(this.OnToggleProfile)
|
||||
{
|
||||
HelpMessage = Loc.Localize("ProfileCommandsToggleHint", "Toggle a collection. Usage: /xltogglecollection \"Collection Name\""),
|
||||
ShowInHelp = true,
|
||||
});
|
||||
|
||||
this.framework.Update += this.FrameworkOnUpdate;
|
||||
}
|
||||
|
||||
private enum ProfileOp
|
||||
{
|
||||
Enable,
|
||||
Disable,
|
||||
Toggle,
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.cmd.RemoveHandler("/xlenablecollection");
|
||||
this.cmd.RemoveHandler("/xldisablecollection");
|
||||
this.cmd.RemoveHandler("/xltogglecollection");
|
||||
|
||||
this.framework.Update += this.FrameworkOnUpdate;
|
||||
}
|
||||
|
||||
private void FrameworkOnUpdate(Framework framework1)
|
||||
{
|
||||
if (this.profileManager.IsBusy)
|
||||
return;
|
||||
|
||||
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;
|
||||
|
||||
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 collection \"{0}\"...").Format(profile.Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.chat.Print(Loc.Localize("ProfileCommandsDisabling", "Disabling collection \"{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 your collections. Please check the console for errors."));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.chat.Print(Loc.Localize("ProfileCommandsApplySuccess", "Collections applied."));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnableProfile(string command, string arguments)
|
||||
{
|
||||
var name = this.ValidateName(arguments);
|
||||
if (name == null)
|
||||
return;
|
||||
|
||||
this.queue = this.queue.Where(x => x.Item1 != name).ToList();
|
||||
this.queue.Add((name, ProfileOp.Enable));
|
||||
}
|
||||
|
||||
private void OnDisableProfile(string command, string arguments)
|
||||
{
|
||||
var name = this.ValidateName(arguments);
|
||||
if (name == null)
|
||||
return;
|
||||
|
||||
this.queue = this.queue.Where(x => x.Item1 != name).ToList();
|
||||
this.queue.Add((name, ProfileOp.Disable));
|
||||
}
|
||||
|
||||
private void OnToggleProfile(string command, string arguments)
|
||||
{
|
||||
var name = this.ValidateName(arguments);
|
||||
if (name == null)
|
||||
return;
|
||||
|
||||
this.queue.Add((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 collection like \"{name}\".");
|
||||
return null;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
282
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
Normal file
282
Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Class responsible for managing plugin profiles.
|
||||
/// </summary>
|
||||
[ServiceManager.BlockingEarlyLoadedService]
|
||||
internal class ProfileManager : IServiceType
|
||||
{
|
||||
private static readonly ModuleLog Log = new("PROFMAN");
|
||||
private readonly DalamudConfiguration config;
|
||||
|
||||
private readonly List<Profile> profiles = new();
|
||||
|
||||
private volatile bool isBusy = false;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProfileManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="config">Dalamud config.</param>
|
||||
[ServiceManager.ServiceConstructor]
|
||||
public ProfileManager(DalamudConfiguration config)
|
||||
{
|
||||
this.config = config;
|
||||
|
||||
this.LoadProfilesFromConfigInitially();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default profile.
|
||||
/// </summary>
|
||||
public Profile DefaultProfile => this.profiles.First(x => x.IsDefaultProfile);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all profiles, including the default profile.
|
||||
/// </summary>
|
||||
public IEnumerable<Profile> Profiles => this.profiles;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not the profile manager is busy enabling/disabling plugins.
|
||||
/// </summary>
|
||||
public bool IsBusy => this.isBusy;
|
||||
|
||||
/// <summary>
|
||||
/// Check if any enabled profile wants a specific plugin enabled.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="defaultState">The state the plugin shall be in, if it needs to be added.</param>
|
||||
/// <param name="addIfNotDeclared">Whether or not the plugin should be added to the default preset, if it's not present in any preset.</param>
|
||||
/// <returns>Whether or not the plugin shall be enabled.</returns>
|
||||
public 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);
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a plugin is declared in any profile.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <returns>Whether or not the plugin is in any profile.</returns>
|
||||
public bool IsInAnyProfile(string internalName)
|
||||
=> this.profiles.Any(x => x.WantsPlugin(internalName) != null);
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a plugin is only in the default profile.
|
||||
/// A plugin can never be in the default profile if it is in any other profile.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <returns>Whether or not the plugin is in the default profile.</returns>
|
||||
public bool IsInDefaultProfile(string internalName)
|
||||
=> this.DefaultProfile.WantsPlugin(internalName) != null;
|
||||
|
||||
/// <summary>
|
||||
/// Add a new profile.
|
||||
/// </summary>
|
||||
/// <returns>The added profile.</returns>
|
||||
public Profile AddNewProfile()
|
||||
{
|
||||
var model = new ProfileModelV1
|
||||
{
|
||||
Guid = Guid.NewGuid(),
|
||||
Name = this.GenerateUniqueProfileName(Loc.Localize("PluginProfilesNewProfile", "New Collection")),
|
||||
IsEnabled = false,
|
||||
};
|
||||
|
||||
this.config.SavedProfiles!.Add(model);
|
||||
this.config.QueueSave();
|
||||
|
||||
var profile = new Profile(this, model, false, false);
|
||||
this.profiles.Add(profile);
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone a specified profile.
|
||||
/// </summary>
|
||||
/// <param name="toClone">The profile to clone.</param>
|
||||
/// <returns>The newly cloned profile.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Import a profile with a sharing string.
|
||||
/// </summary>
|
||||
/// <param name="data">The sharing string to import.</param>
|
||||
/// <returns>The imported profile, or null, if the string was invalid.</returns>
|
||||
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 Collection" : 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Go through all profiles and plugins, and enable/disable plugins they want active.
|
||||
/// This will block until all plugins have been loaded/reloaded.
|
||||
/// </summary>
|
||||
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<PluginManager>.Get();
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var installedPlugin in pm.InstalledPlugins)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a profile.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// You should definitely apply states after this. It doesn't do it for you.
|
||||
/// </remarks>
|
||||
/// <param name="profile">The profile to delete.</param>
|
||||
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.ToArray())
|
||||
{
|
||||
profile.Remove(plugin.InternalName, false);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
this.config.DefaultProfile ??= new ProfileModelV1();
|
||||
this.profiles.Add(new Profile(this, this.config.DefaultProfile, true, true));
|
||||
|
||||
this.config.SavedProfiles ??= new List<ProfileModel>();
|
||||
foreach (var profileModel in this.config.SavedProfiles)
|
||||
{
|
||||
this.profiles.Add(new Profile(this, profileModel, false, true));
|
||||
}
|
||||
|
||||
this.config.QueueSave();
|
||||
}
|
||||
}
|
||||
60
Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
Normal file
60
Dalamud/Plugin/Internal/Profiles/ProfileModel.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
|
||||
using Dalamud.Utility;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Plugin.Internal.Profiles;
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a profile.
|
||||
/// </summary>
|
||||
public abstract class ProfileModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the profile.
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public Guid Guid { get; set; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the profile.
|
||||
/// </summary>
|
||||
[JsonProperty("n")]
|
||||
public string Name { get; set; } = "New Collection";
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a profile into a model.
|
||||
/// </summary>
|
||||
/// <param name="model">The string to decompress.</param>
|
||||
/// <returns>The parsed model.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when the parsed string is not a valid profile.</exception>
|
||||
public static ProfileModel? Deserialize(string model)
|
||||
{
|
||||
var json = Util.DecompressString(Convert.FromBase64String(model.Substring(3)));
|
||||
|
||||
if (model.StartsWith(ProfileModelV1.SerializedPrefix))
|
||||
return JsonConvert.DeserializeObject<ProfileModelV1>(json);
|
||||
|
||||
throw new ArgumentException("Was not a compressed profile.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize this model into a string usable for sharing.
|
||||
/// </summary>
|
||||
/// <returns>The serialized representation of the model.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when an unsupported model is serialized.</exception>
|
||||
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)));
|
||||
}
|
||||
}
|
||||
55
Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
Normal file
55
Dalamud/Plugin/Internal/Profiles/ProfileModelV1.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Plugin.Internal.Profiles;
|
||||
|
||||
/// <summary>
|
||||
/// Version 1 of the profile model.
|
||||
/// </summary>
|
||||
public class ProfileModelV1 : ProfileModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the prefix of this version.
|
||||
/// </summary>
|
||||
public static string SerializedPrefix => "DP1";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not this profile should always be enabled at boot.
|
||||
/// </summary>
|
||||
[JsonProperty("b")]
|
||||
public bool AlwaysEnableOnBoot { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not this profile is currently enabled.
|
||||
/// </summary>
|
||||
[JsonProperty("e")]
|
||||
public bool IsEnabled { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating this profile's color.
|
||||
/// </summary>
|
||||
[JsonProperty("c")]
|
||||
public uint Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of plugins in this profile.
|
||||
/// </summary>
|
||||
public List<ProfileModelV1Plugin> Plugins { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a single plugin in a profile.
|
||||
/// </summary>
|
||||
public class ProfileModelV1Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the internal name of the plugin.
|
||||
/// </summary>
|
||||
public string? InternalName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not this entry is enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
28
Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
Normal file
28
Dalamud/Plugin/Internal/Profiles/ProfilePluginEntry.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
namespace Dalamud.Plugin.Internal.Profiles;
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a single plugin in a profile.
|
||||
/// </summary>
|
||||
internal class ProfilePluginEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProfilePluginEntry"/> class.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="state">A value indicating whether or not this entry is enabled.</param>
|
||||
public ProfilePluginEntry(string internalName, bool state)
|
||||
{
|
||||
this.InternalName = internalName;
|
||||
this.IsEnabled = state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the internal name of the plugin.
|
||||
/// </summary>
|
||||
public string InternalName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not this entry is enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; }
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ using Dalamud.Logging;
|
|||
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;
|
||||
|
|
@ -135,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();
|
||||
}
|
||||
|
||||
|
|
@ -206,9 +209,11 @@ internal class LocalPlugin : IDisposable
|
|||
public bool IsLoaded => this.State == PluginState.Loaded;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the plugin is disabled.
|
||||
/// Gets a value indicating whether this plugin is wanted active by any profile.
|
||||
/// INCLUDES the default profile.
|
||||
/// </summary>
|
||||
public bool IsDisabled => this.Manifest.Disabled;
|
||||
public bool IsWantedByAnyProfile =>
|
||||
Service<ProfileManager>.Get().GetWantState(this.Manifest.InternalName, false, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this plugin's API level is out of date.
|
||||
|
|
@ -244,6 +249,12 @@ internal class LocalPlugin : IDisposable
|
|||
/// </summary>
|
||||
public bool IsDev => this is LocalDevPlugin;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this plugin should be allowed to load.
|
||||
/// </summary>
|
||||
public bool ApplicableForLoad => !this.IsBanned && !this.IsDecommissioned && !this.IsOrphaned && !this.IsOutdated
|
||||
&& !(!this.IsDev && this.State == PluginState.UnloadError) && this.CheckPolicy();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the service scope for this plugin.
|
||||
/// </summary>
|
||||
|
|
@ -289,7 +300,6 @@ internal class LocalPlugin : IDisposable
|
|||
/// <returns>A task.</returns>
|
||||
public async Task LoadAsync(PluginLoadReason reason, bool reloading = false)
|
||||
{
|
||||
var configuration = await Service<DalamudConfiguration>.GetAsync();
|
||||
var framework = await Service<Framework>.GetAsync();
|
||||
var ioc = await Service<ServiceContainer>.GetAsync();
|
||||
var pluginManager = await Service<PluginManager>.GetAsync();
|
||||
|
|
@ -311,6 +321,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:
|
||||
|
|
@ -348,8 +362,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");
|
||||
// We might want to 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.");
|
||||
|
|
@ -575,42 +590,6 @@ internal class LocalPlugin : IDisposable
|
|||
await this.LoadAsync(PluginLoadReason.Reload, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Revert a disable. Must be unloaded first, does not load.
|
||||
/// </summary>
|
||||
public void Enable()
|
||||
{
|
||||
// Allowed: Unloaded, UnloadError
|
||||
switch (this.State)
|
||||
{
|
||||
case PluginState.Loading:
|
||||
case PluginState.Unloading:
|
||||
case PluginState.Loaded:
|
||||
case PluginState.LoadError:
|
||||
if (!this.IsDev)
|
||||
throw new InvalidPluginOperationException($"Unable to enable {this.Name}, still loaded");
|
||||
break;
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if anything forbids this plugin from loading.
|
||||
/// </summary>
|
||||
|
|
@ -632,36 +611,6 @@ internal class LocalPlugin : IDisposable
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable this plugin, must be unloaded first.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Schedule the deletion of this plugin on next cleanup.
|
||||
/// </summary>
|
||||
|
|
@ -680,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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -162,6 +162,12 @@ internal record PluginManifest
|
|||
[JsonProperty]
|
||||
public bool CanUnloadAsync { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the plugin supports profiles.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public bool SupportsProfiles { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of screenshot image URLs to show in the plugin installer.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -30,3 +30,5 @@ public enum PluginLoadReason
|
|||
/// </summary>
|
||||
Boot,
|
||||
}
|
||||
|
||||
// TODO(api9): This should be a mask, so that we can combine Installer | ProfileLoaded
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ 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;
|
||||
|
|
@ -18,6 +19,7 @@ using Dalamud.Interface.Colors;
|
|||
using Dalamud.Logging.Internal;
|
||||
using Dalamud.Networking.Http;
|
||||
using ImGuiNET;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using Microsoft.Win32;
|
||||
using Serilog;
|
||||
|
||||
|
|
@ -657,6 +659,19 @@ public static class Util
|
|||
File.Move(tmpPath, path, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a random, inoffensive, human-friendly string.
|
||||
/// </summary>
|
||||
/// <returns>A random human-friendly name.</returns>
|
||||
internal static string GetRandomName()
|
||||
{
|
||||
var data = Service<DataManager>.Get();
|
||||
var names = data.GetExcelSheet<BNpcName>(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<string> path, Type type, object value)
|
||||
{
|
||||
if (type.IsPointer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue