From 374b652f0d816925e5f356ce47e3565fb4df556b Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 5 Feb 2021 11:25:57 +0100 Subject: [PATCH] Fix crash on Delete Mod Button with no mod selected or already deleted mod. --- Penumbra/Mods/ModManager.cs | 15 +++++++++++++-- Penumbra/UI/TabInstalledSelector.cs | 9 ++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Penumbra/Mods/ModManager.cs b/Penumbra/Mods/ModManager.cs index 17be24d8..28e48b45 100644 --- a/Penumbra/Mods/ModManager.cs +++ b/Penumbra/Mods/ModManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Dalamud.Plugin; using Penumbra.Models; namespace Penumbra.Mods @@ -245,8 +246,18 @@ namespace Penumbra.Mods } public void DeleteMod( ResourceMod mod ) - { - Directory.Delete( mod.ModBasePath.FullName, true ); + { + if (mod?.ModBasePath?.Exists ?? false) + { + try + { + Directory.Delete(mod.ModBasePath.FullName, true); + } + catch( Exception e ) + { + PluginLog.Error($"Could not delete the mod {mod.ModBasePath.Name}:\n{e}"); + } + } DiscoverMods(); } diff --git a/Penumbra/UI/TabInstalledSelector.cs b/Penumbra/UI/TabInstalledSelector.cs index 3ea959da..21797949 100644 --- a/Penumbra/UI/TabInstalledSelector.cs +++ b/Penumbra/UI/TabInstalledSelector.cs @@ -119,8 +119,10 @@ namespace Penumbra.UI void DrawDeleteModal() { - if( _deleteIndex != null ) - ImGui.OpenPopup( DialogDeleteMod ); + if( _deleteIndex == null ) + return; + + ImGui.OpenPopup( DialogDeleteMod ); var ret = ImGui.BeginPopupModal( DialogDeleteMod ); if( !ret ) @@ -129,7 +131,8 @@ namespace Penumbra.UI if( _mod?.Mod == null ) { ImGui.CloseCurrentPopup(); - ImGui.EndPopup(); + ImGui.EndPopup(); + return; } ImGui.Text( "Are you sure you want to delete the following mod:" );