Skip to content

Commit

Permalink
Create newly added mods in import folder instead of moving them.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Jul 20, 2024
1 parent 5b1c0cf commit c3b7dda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion OtterGui
21 changes: 19 additions & 2 deletions Penumbra/Mods/Manager/ModFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Dalamud.Interface.ImGuiNotification;
using OtterGui.Classes;
using OtterGui.Filesystem;
using OtterGui.Services;
using Penumbra.Communication;
Expand All @@ -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);
Expand Down Expand Up @@ -91,7 +95,20 @@ private void OnModPathChange(ModPathChangeType type, Mod mod, DirectoryInfo? old
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))
Expand Down
31 changes: 0 additions & 31 deletions Penumbra/UI/ModsTab/ModFileSystemSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ protected override void DrawPopups()
}

while (_modImportManager.AddUnpackedMod(out var mod))
{
MoveModToDefaultDirectory(mod);
SelectByValue(mod);
}
}

protected override void DrawLeafName(FileSystem<Mod>.Leaf leaf, in ModState state, bool selected)
Expand Down Expand Up @@ -379,34 +376,6 @@ private void SetDescendants(ModFileSystem.Folder folder, bool enabled, bool inhe
_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()), () =>
Expand Down

0 comments on commit c3b7dda

Please sign in to comment.