From 57cc2f36f9aeb084774089bfe20467f1f242289d Mon Sep 17 00:00:00 2001 From: Julian Date: Tue, 12 Nov 2024 11:27:23 -0500 Subject: [PATCH] feat: Encourage developers to use DLLs for devPlugins (#1958) * Add file dialog to add a dev plugin * Require dev plugins to be paths to the DLL * Only allow .dlls in the dev plugin setting entry * Update dev plugin location hint * update wording --------- Co-authored-by: KazWolfe --- .../Windows/Settings/SettingsEntry.cs | 7 ++ .../Internal/Windows/Settings/SettingsTab.cs | 8 ++ .../Windows/Settings/SettingsWindow.cs | 26 ++++--- .../Widgets/DevPluginsSettingsEntry.cs | 76 +++++++++++++------ Dalamud/Plugin/Internal/PluginManager.cs | 6 +- 5 files changed, 87 insertions(+), 36 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/Settings/SettingsEntry.cs b/Dalamud/Interface/Internal/Windows/Settings/SettingsEntry.cs index a72cae024..46013b72c 100644 --- a/Dalamud/Interface/Internal/Windows/Settings/SettingsEntry.cs +++ b/Dalamud/Interface/Internal/Windows/Settings/SettingsEntry.cs @@ -40,6 +40,13 @@ public abstract class SettingsEntry /// public abstract void Draw(); + /// + /// Called after the draw function and when the style overrides are removed. + /// + public virtual void PostDraw() + { + } + /// /// Function to be called when the tab is opened. /// diff --git a/Dalamud/Interface/Internal/Windows/Settings/SettingsTab.cs b/Dalamud/Interface/Internal/Windows/Settings/SettingsTab.cs index d06fe0fb6..bd4a702f5 100644 --- a/Dalamud/Interface/Internal/Windows/Settings/SettingsTab.cs +++ b/Dalamud/Interface/Internal/Windows/Settings/SettingsTab.cs @@ -44,6 +44,14 @@ public abstract class SettingsTab : IDisposable ImGuiHelpers.ScaledDummy(15); } + public virtual void PostDraw() + { + foreach (var settingsEntry in this.Entries) + { + settingsEntry.PostDraw(); + } + } + public virtual void Load() { foreach (var settingsEntry in this.Entries) diff --git a/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs index 5e3857f42..c678dff10 100644 --- a/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs @@ -154,15 +154,23 @@ internal class SettingsWindow : Window } // Don't add padding for the about tab(credits) - using var padding = ImRaii.PushStyle(ImGuiStyleVar.WindowPadding, new Vector2(2, 2), - settingsTab is not SettingsTabAbout); - using var borderColor = ImRaii.PushColor(ImGuiCol.Border, ImGui.GetColorU32(ImGuiCol.ChildBg)); - using var tabChild = ImRaii.Child( - $"###settings_scrolling_{settingsTab.Title}", - new Vector2(-1, -1), - true); - if (tabChild) - settingsTab.Draw(); + { + using var padding = ImRaii.PushStyle( + ImGuiStyleVar.WindowPadding, + new Vector2(2, 2), + settingsTab is not SettingsTabAbout); + using var borderColor = ImRaii.PushColor( + ImGuiCol.Border, + ImGui.GetColorU32(ImGuiCol.ChildBg)); + using var tabChild = ImRaii.Child( + $"###settings_scrolling_{settingsTab.Title}", + new Vector2(-1, -1), + true); + if (tabChild) + settingsTab.Draw(); + } + + settingsTab.PostDraw(); } else if (settingsTab.IsOpen) { diff --git a/Dalamud/Interface/Internal/Windows/Settings/Widgets/DevPluginsSettingsEntry.cs b/Dalamud/Interface/Internal/Windows/Settings/Widgets/DevPluginsSettingsEntry.cs index cfb1ff39f..fe4462ce2 100644 --- a/Dalamud/Interface/Internal/Windows/Settings/Widgets/DevPluginsSettingsEntry.cs +++ b/Dalamud/Interface/Internal/Windows/Settings/Widgets/DevPluginsSettingsEntry.cs @@ -10,6 +10,7 @@ using Dalamud.Configuration; using Dalamud.Configuration.Internal; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; +using Dalamud.Interface.ImGuiFileDialog; using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using Dalamud.Plugin.Internal; @@ -25,6 +26,7 @@ public class DevPluginsSettingsEntry : SettingsEntry private bool devPluginLocationsChanged; private string devPluginTempLocation = string.Empty; private string devPluginLocationAddError = string.Empty; + private FileDialogManager fileDialogManager = new(); public DevPluginsSettingsEntry() { @@ -68,7 +70,23 @@ public class DevPluginsSettingsEntry : SettingsEntry } } - ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsDevPluginLocationsHint", "Add dev plugin load locations.\nThese can be either the directory or DLL path.")); + ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsDevPluginLocationsHint", "Add dev plugin load locations.\nThis must be a path to the plugin DLL.")); + + var locationSelect = Loc.Localize("DalamudDevPluginLocationSelect", "Select Dev Plugin DLL"); + if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Folder, locationSelect)) + { + this.fileDialogManager.OpenFileDialog( + locationSelect, + ".dll", + (result, path) => + { + if (result) + { + this.devPluginTempLocation = path; + this.AddDevPlugin(); + } + }); + } ImGuiHelpers.ScaledDummy(5); @@ -167,26 +185,7 @@ public class DevPluginsSettingsEntry : SettingsEntry ImGui.NextColumn(); if (!string.IsNullOrEmpty(this.devPluginTempLocation) && ImGuiComponents.IconButton(FontAwesomeIcon.Plus)) { - if (this.devPluginLocations.Any(r => string.Equals(r.Path, this.devPluginTempLocation, StringComparison.InvariantCultureIgnoreCase))) - { - this.devPluginLocationAddError = Loc.Localize("DalamudDevPluginLocationExists", "Location already exists."); - Task.Delay(5000).ContinueWith(t => this.devPluginLocationAddError = string.Empty); - } - else if (!ValidDevPluginPath(this.devPluginTempLocation)) - { - this.devPluginLocationAddError = Loc.Localize("DalamudDevPluginInvalid", "The entered value is not a valid path to a potential Dev Plugin.\nDid you mean to enter it as a custom plugin repository in the fields below instead?"); - Task.Delay(5000).ContinueWith(t => this.devPluginLocationAddError = string.Empty); - } - else - { - this.devPluginLocations.Add(new DevPluginLocationSettings - { - Path = this.devPluginTempLocation.Replace("\"", string.Empty), - IsEnabled = true, - }); - this.devPluginLocationsChanged = true; - this.devPluginTempLocation = string.Empty; - } + this.AddDevPlugin(); } ImGui.Columns(1); @@ -197,6 +196,39 @@ public class DevPluginsSettingsEntry : SettingsEntry } } + private void AddDevPlugin() + { + if (this.devPluginLocations.Any( + r => string.Equals(r.Path, this.devPluginTempLocation, StringComparison.InvariantCultureIgnoreCase))) + { + this.devPluginLocationAddError = Loc.Localize("DalamudDevPluginLocationExists", "Location already exists."); + Task.Delay(5000).ContinueWith(t => this.devPluginLocationAddError = string.Empty); + } + else if (!ValidDevPluginPath(this.devPluginTempLocation)) + { + this.devPluginLocationAddError = Loc.Localize( + "DalamudDevPluginInvalid", + "The entered value is not a valid path to a potential Dev Plugin.\nDid you mean to enter it as a custom plugin repository in the fields below instead?"); + Task.Delay(5000).ContinueWith(t => this.devPluginLocationAddError = string.Empty); + } + else + { + this.devPluginLocations.Add( + new DevPluginLocationSettings + { + Path = this.devPluginTempLocation.Replace("\"", string.Empty), + IsEnabled = true, + }); + this.devPluginLocationsChanged = true; + this.devPluginTempLocation = string.Empty; + } + } + + public override void PostDraw() + { + this.fileDialogManager.Draw(); + } + private static bool ValidDevPluginPath(string path) - => Path.IsPathRooted(path) && (Path.GetExtension(path) == ".dll" || !Path.Exists(path) || Directory.Exists(path)); + => Path.IsPathRooted(path) && Path.GetExtension(path) == ".dll"; } diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 6ad81a806..ddb59c027 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -772,11 +772,7 @@ internal class PluginManager : IInternalDisposableService Log.Verbose("Scanning dev plugins at {Path}", setting.Path); - if (Directory.Exists(setting.Path)) - { - devDllFiles.AddRange(new DirectoryInfo(setting.Path).GetFiles("*.dll", SearchOption.AllDirectories)); - } - else if (File.Exists(setting.Path)) + if (File.Exists(setting.Path)) { devDllFiles.Add(new FileInfo(setting.Path)); }