Create newly added mods in import folder instead of moving them.

This commit is contained in:
Ottermandias 2024-07-21 00:48:48 +02:00
parent 5b1c0cf0e3
commit c3b7ddad28
3 changed files with 20 additions and 34 deletions

@ -1 +1 @@
Subproject commit 89b3b9513f9b4989045517a452ef971e24377203
Subproject commit dc17161b1d9c47ffd6bcc17e91f4832cf7762993

View file

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

View file

@ -196,10 +196,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
}
while (_modImportManager.AddUnpackedMod(out var mod))
{
MoveModToDefaultDirectory(mod);
SelectByValue(mod);
}
}
protected override void DrawLeafName(FileSystem<Mod>.Leaf leaf, in ModState state, bool selected)
@ -379,34 +376,6 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
_collectionManager.Editor.SetMultipleModStates(_collectionManager.Active.Current, mods, enabled);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="mod"></param>
private void MoveModToDefaultDirectory(Mod mod)
{
if (_config.DefaultImportFolder.Length == 0)
return;
try
{
var leaf = FileSystem.Root.GetChildren(ISortMode<Mod>.Lexicographical)
.FirstOrDefault(f => f is FileSystem<Mod>.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()), () =>