-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginSettings.cs
More file actions
103 lines (96 loc) · 4.3 KB
/
Copy pathPluginSettings.cs
File metadata and controls
103 lines (96 loc) · 4.3 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
using System;
using System.IO;
using System.Text;
namespace CoreTempGPU
{
/// <summary>Persists plugin settings to a small INI-style file next to the plugin DLL.</summary>
public sealed class PluginSettings
{
private const string FileName = "CoreTempGPU.ini";
public const int PosUnset = int.MinValue;
/// <summary>Magnet-snap to working-area edges/corners on mouse release.</summary>
public bool SnapOnRelease = true;
public bool AlwaysOnTop = true;
public int IntervalMs = 1000;
public bool ShowPanel = true;
public bool TrayShowLoad = true;
public bool TrayShowVram = true;
public bool TrayShowTemp = true;
public bool TrayShowClock = false;
/// <summary>Saved strip location; PosUnset means use default bottom-right.</summary>
public int PosX = PosUnset;
public int PosY = PosUnset;
public string SettingsPath
{
get
{
try
{
string dir = Path.GetDirectoryName(typeof(PluginSettings).Assembly.Location);
if (string.IsNullOrEmpty(dir)) return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);
return Path.Combine(dir, FileName);
}
catch { return FileName; }
}
}
public void Load()
{
try
{
if (!File.Exists(SettingsPath)) return;
foreach (var raw in File.ReadAllLines(SettingsPath))
{
string line = raw.Trim();
if (line.Length == 0 || line.StartsWith("[")) continue;
int eq = line.IndexOf('=');
if (eq < 0) continue;
string key = line.Substring(0, eq).Trim();
string val = line.Substring(eq + 1).Trim();
bool b;
int i;
switch (key)
{
case "SnapOnRelease":
if (bool.TryParse(val, out b)) SnapOnRelease = b;
break;
case "PinToBottomRight":
case "DockToCoreTemp":
// Migrate legacy pin/dock → snap-on-release enabled.
if (bool.TryParse(val, out b) && b) SnapOnRelease = true;
break;
case "AlwaysOnTop": if (bool.TryParse(val, out b)) AlwaysOnTop = b; break;
case "IntervalMs": if (int.TryParse(val, out i)) IntervalMs = Math.Max(250, Math.Min(10000, i)); break;
case "ShowPanel": if (bool.TryParse(val, out b)) ShowPanel = b; break;
case "TrayShowLoad": if (bool.TryParse(val, out b)) TrayShowLoad = b; break;
case "TrayShowVram": if (bool.TryParse(val, out b)) TrayShowVram = b; break;
case "TrayShowTemp": if (bool.TryParse(val, out b)) TrayShowTemp = b; break;
case "TrayShowClock": if (bool.TryParse(val, out b)) TrayShowClock = b; break;
case "PosX": if (int.TryParse(val, out i)) PosX = i; break;
case "PosY": if (int.TryParse(val, out i)) PosY = i; break;
}
}
}
catch { }
}
public void Save()
{
try
{
var sb = new StringBuilder();
sb.AppendLine("[CoreTempGPU]");
sb.AppendLine("SnapOnRelease=" + SnapOnRelease);
sb.AppendLine("AlwaysOnTop=" + AlwaysOnTop);
sb.AppendLine("IntervalMs=" + IntervalMs);
sb.AppendLine("ShowPanel=" + ShowPanel);
sb.AppendLine("TrayShowLoad=" + TrayShowLoad);
sb.AppendLine("TrayShowVram=" + TrayShowVram);
sb.AppendLine("TrayShowTemp=" + TrayShowTemp);
sb.AppendLine("TrayShowClock=" + TrayShowClock);
if (PosX != PosUnset) sb.AppendLine("PosX=" + PosX);
if (PosY != PosUnset) sb.AppendLine("PosY=" + PosY);
File.WriteAllText(SettingsPath, sb.ToString());
}
catch { }
}
}
}