Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Encourage developers to use DLLs for devPlugins #1958

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 8 additions & 0 deletions Dalamud/Interface/Internal/Windows/Settings/SettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public virtual void Draw()
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)
Expand Down
26 changes: 17 additions & 9 deletions Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,23 @@ public override void Draw()
}

// 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -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()
{
Expand Down Expand Up @@ -68,7 +70,23 @@ public override void Draw()
}
}

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 Location");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this label to Select DLL or similar.

if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Folder, locationSelect))
{
this.fileDialogManager.OpenFileDialog(
locationSelect,
".dll",
(result, path) =>
{
if (result)
{
this.devPluginTempLocation = path;
this.AddDevPlugin();
}
});
}

ImGuiHelpers.ScaledDummy(5);

Expand Down Expand Up @@ -167,26 +185,7 @@ public override void Draw()
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);
Expand All @@ -197,6 +196,39 @@ public override void Draw()
}
}

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";
}
6 changes: 1 addition & 5 deletions Dalamud/Plugin/Internal/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,7 @@ public void ScanDevPlugins()

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))
Comment on lines -789 to -793
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, let's keep the recursive loading mode but just block setting folders in UI.

Removing this behavior should be an api11 todo so we have time to announce it.

if (File.Exists(setting.Path))
{
devDllFiles.Add(new FileInfo(setting.Path));
}
Expand Down
Loading