From 69ce929c5e02e1611a5119285b3ddbd8afad9e65 Mon Sep 17 00:00:00 2001 From: Sebastina Date: Fri, 7 Apr 2023 09:39:19 -0500 Subject: [PATCH] Update ModFileSystemSelector.cs add functions to allow penumbra to respond to requests to unpack mods. --- Penumbra/UI/ModsTab/ModFileSystemSelector.cs | 44 ++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index 1d072d89..25ac6275 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; @@ -12,6 +13,7 @@ using OtterGui.Classes; using OtterGui.Filesystem; using OtterGui.FileSystem.Selector; using OtterGui.Raii; +using Penumbra.Api; using Penumbra.Api.Enums; using Penumbra.Collections; using Penumbra.Collections.Manager; @@ -36,6 +38,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector _modUnpackQueue = new Queue(); private TexToolsImporter? _import; public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty; @@ -82,7 +85,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector new FileInfo(file)), AddNewMod, _config, _modEditor, _modManager); ImGui.OpenPopup(_infoPopupId); }, 0, modPath, _config.AlwaysOpenDefaultImport); } + private void ExternalImportListener() + { + if (_modUnpackQueue.Count > 0) + { + // Attempt to avoid triggering if other mods are already unpacking + if (!_modsCurrentlyUnpacking) + { + string modPackagePath = _modUnpackQueue.Dequeue(); + if (File.Exists(modPackagePath)) + { + _modsCurrentlyUnpacking = true; + var modPath = !_config.AlwaysOpenDefaultImport ? null + : _config.DefaultModImportPath.Length > 0 ? _config.DefaultModImportPath + : _config.ModDirectory.Length > 0 ? _config.ModDirectory : null; + + _import = new TexToolsImporter(Penumbra.ModManager.BasePath, 1, new List() { new FileInfo(modPackagePath) }, AddNewMod, + _config, _modEditor, _modManager); + ImGui.OpenPopup(_infoPopupId); + } + } + } + } + + /// + /// Unpacks the specified standalone package + /// + /// The package to unpack + public void ImportStandaloneModPackage(string modPackagePath) + { + _modUnpackQueue.Enqueue(modPackagePath); + } + /// Draw the progress information for import. private void DrawInfoPopup() { @@ -310,6 +346,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector