Add KILL ALL button

This commit is contained in:
Yoshi Askharoun
2024-05-17 22:59:24 -05:00
parent f2b9169ae2
commit 6a9239eea9
2 changed files with 50 additions and 1 deletions
@@ -23,6 +23,12 @@
<Button Content="LOCATE" HorizontalAlignment="Left" Margin="0,8,0,0"
Visibility="{Binding FolderPickerVisibility, Mode=OneTime}"
Click="LocateZuneButton_Click"/>
<TextBlock Text="Force close all Zune processes that may prevent mods from being applied. May cause data loss." Margin="0,12,0,0"
Style="{StaticResource ZuneBodyTextBlockStyle}" />
<Button Content="KILL ALL" HorizontalAlignment="Left" Margin="0,8,0,0"
Visibility="{Binding FolderPickerVisibility, Mode=OneTime}"
Click="KillZuneButton_Click"/>
</StackPanel>
</ScrollViewer>
</UserControl>
+44 -1
View File
@@ -1,6 +1,11 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.WindowsAPICodePack.Dialogs;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using ZuneModdingHelper.Messages;
using ZuneModdingHelper.Services;
namespace ZuneModdingHelper.Pages
@@ -43,6 +48,44 @@ namespace ZuneModdingHelper.Pages
ViewModel.Settings.ZuneInstallDir = dialog.FileName;
}
}
private void KillZuneButton_Click(object sender, RoutedEventArgs e)
{
var curProc = Process.GetCurrentProcess();
var zuneProcs = Process.GetProcesses()
.Where(p =>
p.ProcessName.Contains("zune", System.StringComparison.OrdinalIgnoreCase)
&& p.Id != curProc.Id
);
StringBuilder sb = new("The following processes were killed:\r\n");
bool anyKilled = false;
foreach (var proc in zuneProcs)
{
var id = proc.Id;
var name = proc.ProcessName;
var path = OwlCore.Flow.Catch(() => proc.MainModule.FileName);
try
{
proc.Kill(true);
sb.AppendFormat(" • ({0}) {1}", id, name);
if (path is not null)
sb.AppendFormat(" @ {0}", path);
sb.AppendLine();
anyKilled = true;
}
catch { }
}
WeakReferenceMessenger.Default.Send(new ShowDialogMessage(new()
{
Description = anyKilled ? sb.ToString() : "No processes were killed.",
}));
}
}
internal class SettingsViewModel