Fix crash on Delete Mod Button with no mod selected or already deleted mod.

This commit is contained in:
Ottermandias 2021-02-05 11:25:57 +01:00
parent fc2a18e5e7
commit 374b652f0d
2 changed files with 19 additions and 5 deletions

View file

@ -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();
}

View file

@ -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:" );