-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathProcessHandler.cs
More file actions
62 lines (53 loc) · 1.99 KB
/
ProcessHandler.cs
File metadata and controls
62 lines (53 loc) · 1.99 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
// keeps reference of launched unity processes, so that can close them even if project list is refreshed
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Threading;
namespace UnityLauncherPro.Helpers
{
public static class ProcessHandler
{
static Dictionary<string, Process> processes = new Dictionary<string, Process>();
public static void Add(Project proj, Process proc)
{
if (proc == null) return;
var key = proj.Path;
if (processes.ContainsKey(key))
{
// already in the list, maybe trying to launch same project twice? only overwrite if previous process has closed
if (processes[key] == null) processes[key] = proc;
}
else
{
processes.Add(key, proc);
}
// subscribe to process exit here, so that can update proj details row (if it was changed in Unity)
proc.Exited += (object o, EventArgs ea) =>
{
// call method in mainwindow, to easy access for sourcedata and grid
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate ()
{
MainWindow wnd = (MainWindow)Application.Current.MainWindow;
wnd.ProcessExitedCallBack(proj);
});
// remove closed process item
Remove(key);
};
}
public static Process Get(string key)
{
if (processes.ContainsKey(key)) return processes[key];
return null;
}
public static bool IsRunning(string key)
{
return processes.ContainsKey(key) && (processes[key] != null);
}
public static void Remove(string key)
{
if (processes.ContainsKey(key)) processes.Remove(key);
}
}
}