From f938531e21b42a8da8abbedbfd4c0ea3f76baea8 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 27 May 2023 13:56:43 +0200 Subject: [PATCH] Some small fixes/improvements. --- Penumbra.GameData/Data/DataSharer.cs | 1 - Penumbra/Collections/Cache/CollectionCache.cs | 1 - .../Collections/Cache/CollectionCacheManager.cs | 14 +++----------- Penumbra/CommandHandler.cs | 2 ++ Penumbra/Interop/Services/CharacterUtility.cs | 5 ++++- Penumbra/Penumbra.cs | 6 ++++-- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Penumbra.GameData/Data/DataSharer.cs b/Penumbra.GameData/Data/DataSharer.cs index ce5fc0c3..3608a4a0 100644 --- a/Penumbra.GameData/Data/DataSharer.cs +++ b/Penumbra.GameData/Data/DataSharer.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using Dalamud; using Dalamud.Logging; diff --git a/Penumbra/Collections/Cache/CollectionCache.cs b/Penumbra/Collections/Cache/CollectionCache.cs index e753c8c8..298e683c 100644 --- a/Penumbra/Collections/Cache/CollectionCache.cs +++ b/Penumbra/Collections/Cache/CollectionCache.cs @@ -3,7 +3,6 @@ using OtterGui.Classes; using Penumbra.Meta.Manipulations; using Penumbra.Mods; using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/Penumbra/Collections/Cache/CollectionCacheManager.cs b/Penumbra/Collections/Cache/CollectionCacheManager.cs index d7408e9b..a14c6ac2 100644 --- a/Penumbra/Collections/Cache/CollectionCacheManager.cs +++ b/Penumbra/Collections/Cache/CollectionCacheManager.cs @@ -325,17 +325,12 @@ public class CollectionCacheManager : IDisposable /// public void CreateNecessaryCaches() { - var tasks = _active.SpecialAssignments.Select(p => p.Value) + Parallel.ForEach(_active.SpecialAssignments.Select(p => p.Value) .Concat(_active.Individuals.Select(p => p.Collection)) .Prepend(_active.Current) .Prepend(_active.Default) .Prepend(_active.Interface) - .Where(CreateCache) - .Select(c => Task.Run(() => CalculateEffectiveFileListInternal(c))) - .ToArray(); - - Penumbra.Log.Debug($"Creating {tasks.Length} necessary caches."); - Task.WaitAll(tasks); + .Where(CreateCache), CalculateEffectiveFileListInternal); } private void OnModDiscoveryStarted() @@ -349,10 +344,7 @@ public class CollectionCacheManager : IDisposable } private void OnModDiscoveryFinished() - { - var tasks = Active.Select(c => Task.Run(() => CalculateEffectiveFileListInternal(c))).ToArray(); - Task.WaitAll(tasks); - } + => Parallel.ForEach(Active, CalculateEffectiveFileListInternal); /// /// Update forced files only on framework. diff --git a/Penumbra/CommandHandler.cs b/Penumbra/CommandHandler.cs index 9555f772..2e38448b 100644 --- a/Penumbra/CommandHandler.cs +++ b/Penumbra/CommandHandler.cs @@ -51,11 +51,13 @@ public class CommandHandler : IDisposable _collectionEditor = collectionEditor; framework.RunOnFrameworkThread(() => { + _commandManager.RemoveHandler(CommandName); _commandManager.AddHandler(CommandName, new CommandInfo(OnCommand) { HelpMessage = "Without arguments, toggles the main window. Use /penumbra help to get further command help.", ShowInHelp = true, }); + Penumbra.Log.Information($"Registered {CommandName} with Dalamud."); }); } diff --git a/Penumbra/Interop/Services/CharacterUtility.cs b/Penumbra/Interop/Services/CharacterUtility.cs index 3ac83e50..ef706f6d 100644 --- a/Penumbra/Interop/Services/CharacterUtility.cs +++ b/Penumbra/Interop/Services/CharacterUtility.cs @@ -140,7 +140,10 @@ public unsafe partial class CharacterUtility : IDisposable /// Return all relevant resources to the default resource. public void ResetAll() - { + { + if (!Ready) + return; + foreach (var list in _lists) list.Dispose(); diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index c70d688a..4876d530 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using System.Text; @@ -86,8 +87,9 @@ public class Penumbra : IDalamudPlugin if (_characterUtility.Ready) _residentResources.Reload(); } - catch - { + catch(Exception ex) + { + Log.Error($"Error constructing Penumbra, Disposing again:\n{ex}"); Dispose(); throw; }