Update ModFileSystemSelector.cs add functions to allow penumbra to respond to requests to unpack mods.

This commit is contained in:
Sebastina 2023-04-07 09:39:19 -05:00
parent 0ed1a81c29
commit 69ce929c5e

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
@ -12,6 +13,7 @@ using OtterGui.Classes;
using OtterGui.Filesystem; using OtterGui.Filesystem;
using OtterGui.FileSystem.Selector; using OtterGui.FileSystem.Selector;
using OtterGui.Raii; using OtterGui.Raii;
using Penumbra.Api;
using Penumbra.Api.Enums; using Penumbra.Api.Enums;
using Penumbra.Collections; using Penumbra.Collections;
using Penumbra.Collections.Manager; using Penumbra.Collections.Manager;
@ -36,6 +38,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector<Mod, ModF
private readonly CollectionManager _collectionManager; private readonly CollectionManager _collectionManager;
private readonly TutorialService _tutorial; private readonly TutorialService _tutorial;
private readonly ModEditor _modEditor; private readonly ModEditor _modEditor;
private Queue<string> _modUnpackQueue = new Queue<string>();
private TexToolsImporter? _import; private TexToolsImporter? _import;
public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty; public ModSettings SelectedSettings { get; private set; } = ModSettings.Empty;
@ -82,7 +85,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector<Mod, ModF
SelectionChanged += OnSelectionChange; SelectionChanged += OnSelectionChange;
_communicator.CollectionChange.Subscribe(OnCollectionChange); _communicator.CollectionChange.Subscribe(OnCollectionChange);
_collectionManager.Active.Current.ModSettingChanged += OnSettingChange; _collectionManager.Active.Current.ModSettingChanged += OnSettingChange;
_collectionManager.Active.Current.InheritanceChanged += OnInheritanceChange; _collectionManager.Active.Current.InheritanceChanged += OnInheritanceChange;
_communicator.ModDataChanged.Subscribe(OnModDataChange); _communicator.ModDataChanged.Subscribe(OnModDataChange);
_communicator.ModDiscoveryStarted.Subscribe(StoreCurrentSelection); _communicator.ModDiscoveryStarted.Subscribe(StoreCurrentSelection);
@ -96,7 +99,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector<Mod, ModF
_communicator.ModDiscoveryStarted.Unsubscribe(StoreCurrentSelection); _communicator.ModDiscoveryStarted.Unsubscribe(StoreCurrentSelection);
_communicator.ModDiscoveryFinished.Unsubscribe(RestoreLastSelection); _communicator.ModDiscoveryFinished.Unsubscribe(RestoreLastSelection);
_communicator.ModDataChanged.Unsubscribe(OnModDataChange); _communicator.ModDataChanged.Unsubscribe(OnModDataChange);
_collectionManager.Active.Current.ModSettingChanged -= OnSettingChange; _collectionManager.Active.Current.ModSettingChanged -= OnSettingChange;
_collectionManager.Active.Current.InheritanceChanged -= OnInheritanceChange; _collectionManager.Active.Current.InheritanceChanged -= OnInheritanceChange;
_communicator.CollectionChange.Unsubscribe(OnCollectionChange); _communicator.CollectionChange.Unsubscribe(OnCollectionChange);
_import?.Dispose(); _import?.Dispose();
@ -231,6 +234,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector<Mod, ModF
private void AddImportModButton(Vector2 size) private void AddImportModButton(Vector2 size)
{ {
_infoPopupId = ImGui.GetID("Import Status"); _infoPopupId = ImGui.GetID("Import Status");
ExternalImportListener();
var button = ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.FileImport.ToIconString(), size, var button = ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.FileImport.ToIconString(), size,
"Import one or multiple mods from Tex Tools Mod Pack Files or Penumbra Mod Pack Files.", !Penumbra.ModManager.Valid, true); "Import one or multiple mods from Tex Tools Mod Pack Files or Penumbra Mod Pack Files.", !Penumbra.ModManager.Valid, true);
_tutorial.OpenTutorial(BasicTutorialSteps.ModImport); _tutorial.OpenTutorial(BasicTutorialSteps.ModImport);
@ -246,13 +250,45 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector<Mod, ModF
{ {
if (!s) if (!s)
return; return;
_modsCurrentlyUnpacking = true;
_import = new TexToolsImporter(_modManager.BasePath, f.Count, f.Select(file => new FileInfo(file)), _import = new TexToolsImporter(_modManager.BasePath, f.Count, f.Select(file => new FileInfo(file)),
AddNewMod, _config, _modEditor, _modManager); AddNewMod, _config, _modEditor, _modManager);
ImGui.OpenPopup(_infoPopupId); ImGui.OpenPopup(_infoPopupId);
}, 0, modPath, _config.AlwaysOpenDefaultImport); }, 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<FileInfo>() { new FileInfo(modPackagePath) }, AddNewMod,
_config, _modEditor, _modManager);
ImGui.OpenPopup(_infoPopupId);
}
}
}
}
/// <summary>
/// Unpacks the specified standalone package
/// </summary>
/// <param name="modPackagePath">The package to unpack</param>
public void ImportStandaloneModPackage(string modPackagePath)
{
_modUnpackQueue.Enqueue(modPackagePath);
}
/// <summary> Draw the progress information for import. </summary> /// <summary> Draw the progress information for import. </summary>
private void DrawInfoPopup() private void DrawInfoPopup()
{ {
@ -310,6 +346,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector<Mod, ModF
{ {
_modsToAdd.Enqueue(dir); _modsToAdd.Enqueue(dir);
} }
_modsCurrentlyUnpacking = false;
} }
private void DeleteModButton(Vector2 size) private void DeleteModButton(Vector2 size)
@ -535,6 +572,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector<Mod, ModF
private LowerString _modFilter = LowerString.Empty; private LowerString _modFilter = LowerString.Empty;
private int _filterType = -1; private int _filterType = -1;
private ModFilter _stateFilter = ModFilterExtensions.UnfilteredStateMods; private ModFilter _stateFilter = ModFilterExtensions.UnfilteredStateMods;
private bool _modsCurrentlyUnpacking;
private void SetFilterTooltip() private void SetFilterTooltip()
{ {