-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSettingsManager.cs
71 lines (63 loc) · 2.58 KB
/
SettingsManager.cs
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
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
namespace TrayApp
{
public class SettingsManager
{
private static bool NeedUpgrade = true;
// TODO: Add a "Clear Settings" button and set NeedUpgrade to false before calling this again
public static void LoadSettings()
{
if (NeedUpgrade)
{
MainApplication.Properties.Settings.Default.Upgrade();
MainApplication.Properties.Settings.Default.Save();
}
StringCollection known_processes_from_settings = MainApplication.Properties.Settings.Default.KnownGPUProcesses;
StringCollection processes_list = new StringCollection();
//NotificationManager.PushNotificationToOS("Loading processes list...");
foreach (string url_iter in known_processes_from_settings)
{
bool success = Helper.ValidateExecutableName(url_iter);
if (success)
{
success = !processes_list.Contains(url_iter);
}
if (success)
{
processes_list.Add(url_iter);
}
}
// Must be saved after the foreach loop to prevent overwriting the working data
SettingsManager.WriteNewProcessesList(processes_list);
List<string> processes_list_real = Helper.Convert(processes_list);
string first = processes_list_real.First();
string last = processes_list_real.Last();
string processes_list_string = "";
foreach (string process in processes_list_real)
{
if (process == first)
{
processes_list_string = process;
}
else if (process != last)
{
processes_list_string += ", " + process;
}
else
{
processes_list_string += " and " + process;
}
}
NotificationManager.PushNotificationToOS("Processes that will be killed: " + processes_list_string);
}
public static void WriteNewProcessesList(StringCollection coll)
{
MainApplication.Properties.Settings.Default.KnownGPUProcesses.Clear();
MainApplication.Properties.Settings.Default.KnownGPUProcesses = coll;
MainApplication.Properties.Settings.Default.Save();
MainApplication.Properties.Settings.Default.Reload();
}
}
}