mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Add KILL ALL button
This commit is contained in:
@@ -23,6 +23,12 @@
|
|||||||
<Button Content="LOCATE" HorizontalAlignment="Left" Margin="0,8,0,0"
|
<Button Content="LOCATE" HorizontalAlignment="Left" Margin="0,8,0,0"
|
||||||
Visibility="{Binding FolderPickerVisibility, Mode=OneTime}"
|
Visibility="{Binding FolderPickerVisibility, Mode=OneTime}"
|
||||||
Click="LocateZuneButton_Click"/>
|
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>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -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;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using ZuneModdingHelper.Messages;
|
||||||
using ZuneModdingHelper.Services;
|
using ZuneModdingHelper.Services;
|
||||||
|
|
||||||
namespace ZuneModdingHelper.Pages
|
namespace ZuneModdingHelper.Pages
|
||||||
@@ -43,6 +48,44 @@ namespace ZuneModdingHelper.Pages
|
|||||||
ViewModel.Settings.ZuneInstallDir = dialog.FileName;
|
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
|
internal class SettingsViewModel
|
||||||
|
|||||||
Reference in New Issue
Block a user