Repository navigation
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
171 lines (153 loc) · 6.93 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
171 lines (153 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Diagnostics;
using System.Windows;
using ProcMaster.Models;
using ProcMaster.ViewModels;
namespace ProcMaster
{
/// <summary>
/// Interaction logic for MainWindow.xaml. Hosts the Process Explorer split UI,
/// toolbar actions (Kill, Kill Tree, Suspend, Resume, Priority), and lower-pane tabs.
/// </summary>
public partial class MainWindow : Window
{
private readonly MainViewModel _vm;
/// <summary>
/// Initializes the MainWindow and instantiates the <see cref="MainViewModel"/>.
/// </summary>
public MainWindow()
{
InitializeComponent();
try
{
string iconPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "app_icon.png");
if (System.IO.File.Exists(iconPath))
{
Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri(iconPath, UriKind.Absolute));
}
}
catch { }
_vm = new MainViewModel();
DataContext = _vm;
}
/// <summary>
/// Handles TreeView selection change to trigger detailed lower pane inspection.
/// </summary>
private void OnTreeViewSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (e.NewValue is ProcessItem item)
{
_vm.SelectedProcess = item;
}
}
/// <summary>Prompts confirmation and terminates the selected process.</summary>
private void OnKillProcess_Click(object sender, RoutedEventArgs e)
{
if (_vm.SelectedProcess != null)
{
var res = MessageBox.Show($"Are you sure you want to terminate '{_vm.SelectedProcess.ProcessName}' (PID: {_vm.SelectedProcess.ProcessId})?",
"Terminate Process", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (res == MessageBoxResult.Yes)
{
_vm.KillSelected();
}
}
}
/// <summary>Prompts confirmation and terminates the selected process and all child processes.</summary>
private void OnKillTree_Click(object sender, RoutedEventArgs e)
{
if (_vm.SelectedProcess != null)
{
var res = MessageBox.Show($"Are you sure you want to terminate the process tree for '{_vm.SelectedProcess.ProcessName}' (PID: {_vm.SelectedProcess.ProcessId})?",
"Kill Process Tree", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (res == MessageBoxResult.Yes)
{
_vm.KillTreeSelected();
}
}
}
/// <summary>Suspends execution of the selected process.</summary>
private void OnSuspend_Click(object sender, RoutedEventArgs e)
{
_vm.SuspendSelected();
}
/// <summary>Resumes execution of the suspended process.</summary>
private void OnResume_Click(object sender, RoutedEventArgs e)
{
_vm.ResumeSelected();
}
private void OnPriorityRealtime_Click(object sender, RoutedEventArgs e) => _vm.SetPriority(ProcessPriorityClass.RealTime);
private void OnPriorityHigh_Click(object sender, RoutedEventArgs e) => _vm.SetPriority(ProcessPriorityClass.High);
private void OnPriorityAboveNormal_Click(object sender, RoutedEventArgs e) => _vm.SetPriority(ProcessPriorityClass.AboveNormal);
private void OnPriorityNormal_Click(object sender, RoutedEventArgs e) => _vm.SetPriority(ProcessPriorityClass.Normal);
private void OnPriorityBelowNormal_Click(object sender, RoutedEventArgs e) => _vm.SetPriority(ProcessPriorityClass.BelowNormal);
private void OnPriorityIdle_Click(object sender, RoutedEventArgs e) => _vm.SetPriority(ProcessPriorityClass.Idle);
/// <summary>Forces an immediate refresh of process metrics.</summary>
private async void OnRefresh_Click(object sender, RoutedEventArgs e)
{
await _vm.RefreshAsync();
}
/// <summary>
/// Prompts warning and closes an open kernel object handle in the selected process.
/// </summary>
private void OnCloseHandle_Click(object sender, RoutedEventArgs e)
{
if (HandlesGrid.SelectedItem is HandleItem handle)
{
var res = MessageBox.Show($"Closing handle {handle.HandleValue} ({handle.Type}: {handle.Name}) can cause the host process or system to crash. Do you want to proceed?",
"Close Handle Warning", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
if (res == MessageBoxResult.Yes)
{
_vm.CloseHandle(handle);
}
}
}
private void OnRunNewTask_Click(object sender, RoutedEventArgs e)
{
try
{
Process.Start(new ProcessStartInfo("explorer.exe") { UseShellExecute = true });
}
catch { }
}
private void OnSpeedHigh_Click(object sender, RoutedEventArgs e) => _vm.SetRefreshInterval(0.5);
private void OnSpeedNormal_Click(object sender, RoutedEventArgs e) => _vm.SetRefreshInterval(1.0);
private void OnSpeedLow_Click(object sender, RoutedEventArgs e) => _vm.SetRefreshInterval(2.0);
private void OnSpeedPaused_Click(object sender, RoutedEventArgs e) => _vm.SetRefreshInterval(0);
private void OnRestartAdmin_Click(object sender, RoutedEventArgs e)
{
try
{
var exePath = Environment.ProcessPath ?? Environment.GetCommandLineArgs()[0];
var psi = new ProcessStartInfo(exePath)
{
UseShellExecute = true,
Verb = "runas"
};
Process.Start(psi);
Application.Current.Shutdown();
}
catch (Exception ex)
{
MessageBox.Show($"Could not elevate: {ex.Message}", "Elevation Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void OnGitHub_Click(object sender, RoutedEventArgs e)
{
try
{
Process.Start(new ProcessStartInfo("https://github.com/techselect/ProcMaster") { UseShellExecute = true });
}
catch { }
}
private void OnAbout_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("ProcMaster v1.0.0\n\nAdvanced Windows Process Explorer & Task Manager Hybrid.\nBuilt in C# (.NET 10) & WPF.\nDedicated to the public domain under The Unlicense.",
"About ProcMaster", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void OnExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
}
}