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 <KazWolfe@users.noreply.github.com>
This commit is contained in:
Julian 2024-11-12 11:27:23 -05:00 committed by GitHub
parent 67e6bcac61
commit 57cc2f36f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 87 additions and 36 deletions

View file

@ -40,6 +40,13 @@ public abstract class SettingsEntry
/// </summary>
public abstract void Draw();
/// <summary>
/// Called after the draw function and when the style overrides are removed.
/// </summary>
public virtual void PostDraw()
{
}
/// <summary>
/// Function to be called when the tab is opened.
/// </summary>

View file

@ -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)

View file

@ -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)
{

View file

@ -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";
}

View file

@ -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));
}