From c3b7ddad2810e4687aec33b4da7f721de3b4625f Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 21 Jul 2024 00:48:48 +0200 Subject: [PATCH] Create newly added mods in import folder instead of moving them. --- OtterGui | 2 +- Penumbra/Mods/Manager/ModFileSystem.cs | 21 +++++++++++-- Penumbra/UI/ModsTab/ModFileSystemSelector.cs | 31 -------------------- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/OtterGui b/OtterGui index 89b3b951..dc17161b 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit 89b3b9513f9b4989045517a452ef971e24377203 +Subproject commit dc17161b1d9c47ffd6bcc17e91f4832cf7762993 diff --git a/Penumbra/Mods/Manager/ModFileSystem.cs b/Penumbra/Mods/Manager/ModFileSystem.cs index e32fec0c..693db944 100644 --- a/Penumbra/Mods/Manager/ModFileSystem.cs +++ b/Penumbra/Mods/Manager/ModFileSystem.cs @@ -1,3 +1,5 @@ +using Dalamud.Interface.ImGuiNotification; +using OtterGui.Classes; using OtterGui.Filesystem; using OtterGui.Services; using Penumbra.Communication; @@ -10,13 +12,15 @@ public sealed class ModFileSystem : FileSystem, IDisposable, ISavable, ISer private readonly ModManager _modManager; private readonly CommunicatorService _communicator; private readonly SaveService _saveService; + private readonly Configuration _config; // Create a new ModFileSystem from the currently loaded mods and the current sort order file. - public ModFileSystem(ModManager modManager, CommunicatorService communicator, SaveService saveService) + public ModFileSystem(ModManager modManager, CommunicatorService communicator, SaveService saveService, Configuration config) { _modManager = modManager; _communicator = communicator; _saveService = saveService; + _config = config; Reload(); Changed += OnChange; _communicator.ModDiscoveryFinished.Subscribe(Reload, ModDiscoveryFinished.Priority.ModFileSystem); @@ -91,7 +95,20 @@ public sealed class ModFileSystem : FileSystem, IDisposable, ISavable, ISer switch (type) { case ModPathChangeType.Added: - CreateDuplicateLeaf(Root, mod.Name.Text, mod); + var parent = Root; + if (_config.DefaultImportFolder.Length != 0) + try + { + parent = FindOrCreateAllFolders(_config.DefaultImportFolder); + } + catch (Exception e) + { + Penumbra.Messager.NotificationMessage(e, + $"Could not move newly imported mod {mod.Name} to default import folder {_config.DefaultImportFolder}.", + NotificationType.Warning); + } + + CreateDuplicateLeaf(parent, mod.Name.Text, mod); break; case ModPathChangeType.Deleted: if (FindLeaf(mod, out var leaf)) diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index 88d6afa2..55405313 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -196,10 +196,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector.Leaf leaf, in ModState state, bool selected) @@ -379,34 +376,6 @@ public sealed class ModFileSystemSelector : FileSystemSelector - /// If a default import folder is setup, try to move the given mod in there. - /// If the folder does not exist, create it if possible. - /// - /// - private void MoveModToDefaultDirectory(Mod mod) - { - if (_config.DefaultImportFolder.Length == 0) - return; - - try - { - var leaf = FileSystem.Root.GetChildren(ISortMode.Lexicographical) - .FirstOrDefault(f => f is FileSystem.Leaf l && l.Value == mod); - if (leaf == null) - throw new Exception("Mod was not found at root."); - - var folder = FileSystem.FindOrCreateAllFolders(_config.DefaultImportFolder); - FileSystem.Move(leaf, folder); - } - catch (Exception e) - { - _messager.NotificationMessage(e, - $"Could not move newly imported mod {mod.Name} to default import folder {_config.DefaultImportFolder}.", - NotificationType.Warning); - } - } - private void DrawHelpPopup() { ImGuiUtil.HelpPopup("ExtendedHelp", new Vector2(1000 * UiHelpers.Scale, 38.5f * ImGui.GetTextLineHeightWithSpacing()), () =>