UI: Fix crash when using "delete all" button in mod manager.

This commit is contained in:
Evan Husted
2024-11-16 19:49:06 -06:00
committed by KeatonTheBot
parent 69ba77d6ee
commit 05058e1cf8
@@ -4,6 +4,7 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using DynamicData;
using Gommon;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.Models;
@@ -182,7 +183,7 @@ namespace Ryujinx.Ava.UI.ViewModels
JsonHelper.SerializeToFile(_modJsonPath, modData, _serializerContext.ModMetadata);
}
public void Delete(ModModel model)
public void Delete(ModModel model, bool removeFromList = true)
{
var isSubdir = true;
var pathToDelete = model.Path;
@@ -222,8 +223,11 @@ namespace Ryujinx.Ava.UI.ViewModels
Logger.Info?.Print(LogClass.Application, $"Deleting mod at \"{pathToDelete}\"");
Directory.Delete(pathToDelete, true);
Mods.Remove(model);
OnPropertyChanged(nameof(ModCount));
if (removeFromList)
{
Mods.Remove(model);
OnPropertyChanged(nameof(ModCount));
}
Sort();
}
@@ -313,11 +317,7 @@ namespace Ryujinx.Ava.UI.ViewModels
public void DeleteAll()
{
foreach (var mod in Mods)
{
Delete(mod);
}
Mods.ForEach(it => Delete(it, false));
Mods.Clear();
OnPropertyChanged(nameof(ModCount));
Sort();