Skip to content

Commit a441c9d

Browse files
committed
v1.1
1 parent b8c53ad commit a441c9d

25 files changed

Lines changed: 153 additions & 17 deletions
104 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

.vs/CpuTrayApp/v17/.suo

79 KB
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"Version": 1,
3+
"WorkspaceRootPath": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\",
4+
"Documents": [
5+
{
6+
"AbsoluteMoniker": "D:0:0:{B003172C-9577-4AC7-A022-9225432A3072}|CpuTrayApp\\CpuTrayApp.csproj|c:\\users\\admin\\documents\\github\\cputrayapp\\cputrayapp\\tray.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
7+
"RelativeMoniker": "D:0:0:{B003172C-9577-4AC7-A022-9225432A3072}|CpuTrayApp\\CpuTrayApp.csproj|solutionrelative:cputrayapp\\tray.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
8+
},
9+
{
10+
"AbsoluteMoniker": "D:0:0:{00000000-0000-0000-0000-000000000000}|\u003CSolution\u003E|CpuTrayApp||{04B8AB82-A572-4FEF-95CE-5222444B6B64}|"
11+
}
12+
],
13+
"DocumentGroupContainers": [
14+
{
15+
"Orientation": 0,
16+
"VerticalTabListWidth": 256,
17+
"DocumentGroups": [
18+
{
19+
"DockedWidth": 200,
20+
"SelectedChildIndex": 1,
21+
"Children": [
22+
{
23+
"$type": "Document",
24+
"DocumentIndex": 1,
25+
"Title": "CpuTrayApp",
26+
"DocumentMoniker": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\CpuTrayApp.csproj",
27+
"RelativeDocumentMoniker": "CpuTrayApp\\CpuTrayApp.csproj",
28+
"ToolTip": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\CpuTrayApp.csproj",
29+
"RelativeToolTip": "CpuTrayApp\\CpuTrayApp.csproj",
30+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001001|",
31+
"WhenOpened": "2025-10-06T13:12:51.348Z"
32+
},
33+
{
34+
"$type": "Document",
35+
"DocumentIndex": 0,
36+
"Title": "Tray.cs",
37+
"DocumentMoniker": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\Tray.cs",
38+
"RelativeDocumentMoniker": "CpuTrayApp\\Tray.cs",
39+
"ToolTip": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\Tray.cs",
40+
"RelativeToolTip": "CpuTrayApp\\Tray.cs",
41+
"ViewState": "AgIAAAMAAAAAAAAAAAAAAPkAAAARAAAAAAAAAA==",
42+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
43+
"WhenOpened": "2025-10-06T13:04:10.261Z",
44+
"EditorCaption": ""
45+
}
46+
]
47+
}
48+
]
49+
}
50+
]
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"Version": 1,
3+
"WorkspaceRootPath": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\",
4+
"Documents": [
5+
{
6+
"AbsoluteMoniker": "D:0:0:{B003172C-9577-4AC7-A022-9225432A3072}|CpuTrayApp\\CpuTrayApp.csproj|c:\\users\\admin\\documents\\github\\cputrayapp\\cputrayapp\\tray.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
7+
"RelativeMoniker": "D:0:0:{B003172C-9577-4AC7-A022-9225432A3072}|CpuTrayApp\\CpuTrayApp.csproj|solutionrelative:cputrayapp\\tray.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
8+
},
9+
{
10+
"AbsoluteMoniker": "D:0:0:{00000000-0000-0000-0000-000000000000}|\u003CSolution\u003E|CpuTrayApp||{04B8AB82-A572-4FEF-95CE-5222444B6B64}|"
11+
}
12+
],
13+
"DocumentGroupContainers": [
14+
{
15+
"Orientation": 0,
16+
"VerticalTabListWidth": 256,
17+
"DocumentGroups": [
18+
{
19+
"DockedWidth": 200,
20+
"SelectedChildIndex": 1,
21+
"Children": [
22+
{
23+
"$type": "Document",
24+
"DocumentIndex": 1,
25+
"Title": "CpuTrayApp",
26+
"DocumentMoniker": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\CpuTrayApp.csproj",
27+
"RelativeDocumentMoniker": "CpuTrayApp\\CpuTrayApp.csproj",
28+
"ToolTip": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\CpuTrayApp.csproj",
29+
"RelativeToolTip": "CpuTrayApp\\CpuTrayApp.csproj",
30+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001001|",
31+
"WhenOpened": "2025-10-06T13:12:51.348Z"
32+
},
33+
{
34+
"$type": "Document",
35+
"DocumentIndex": 0,
36+
"Title": "Tray.cs",
37+
"DocumentMoniker": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\Tray.cs",
38+
"RelativeDocumentMoniker": "CpuTrayApp\\Tray.cs",
39+
"ToolTip": "C:\\Users\\admin\\Documents\\GitHub\\CpuTrayApp\\CpuTrayApp\\Tray.cs",
40+
"RelativeToolTip": "CpuTrayApp\\Tray.cs",
41+
"ViewState": "AgIAAAMAAAAAAAAAAAAAAPkAAAARAAAAAAAAAA==",
42+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
43+
"WhenOpened": "2025-10-06T13:04:10.261Z",
44+
"EditorCaption": ""
45+
}
46+
]
47+
}
48+
]
49+
}
50+
]
51+
}

CpuTrayApp/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("1.0.0.0")]
32-
[assembly: AssemblyFileVersion("1.0.0.0")]
31+
[assembly: AssemblyVersion("1.1.0.0")]
32+
[assembly: AssemblyFileVersion("1.1.0.0")]

CpuTrayApp/Tray.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Linq;
55
using System.Management;
66
using System.Runtime.InteropServices;
7-
using System.Threading.Tasks;
7+
using System.Text.RegularExpressions;
88
using System.Windows.Forms;
99

1010
namespace CpuTrayApp
@@ -109,23 +109,28 @@ private void InitializeCpuMenu()
109109
trayMenu.Items.Add(cpuMenu);
110110
}
111111

112-
// Get all available power plans on the system
112+
// Get all available power plans on the system (language independent)
113113
private Dictionary<string, string> GetPowerPlans()
114114
{
115115
var plans = new Dictionary<string, string>();
116116
string output = RunPowerCfg("/L");
117117

118+
// Regex pour détecter un GUID
119+
Regex guidRegex = new Regex(@"([a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12})");
120+
118121
foreach (var line in output.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
119122
{
120-
if (line.Contains("GUID"))
123+
var match = guidRegex.Match(line);
124+
if (match.Success)
121125
{
122-
int start = line.IndexOf("GUID:") + 5;
123-
int end = line.IndexOf('(', start);
124-
string guid = line.Substring(start, end - start).Trim();
126+
string guid = match.Groups[1].Value;
127+
128+
// Le nom est la partie après le GUID dans la ligne, on va la récupérer
129+
int guidIndex = line.IndexOf(guid) + guid.Length;
130+
string name = line.Substring(guidIndex).Trim();
125131

126-
int nameStart = line.IndexOf('(', start) + 1;
127-
int nameEnd = line.IndexOf(')', nameStart);
128-
string name = line.Substring(nameStart, nameEnd - nameStart);
132+
// Nettoyer le nom en enlevant les éventuels symboles * ou parenthèses autour
133+
name = name.Trim(new char[] { '*', ' ', '(', ')' });
129134

130135
plans[guid] = name;
131136
}
@@ -144,17 +149,21 @@ private void UpdateActivePlanMenu()
144149
}
145150
}
146151

147-
// Fetch the GUID of the currently active power plan
152+
// Fetch the GUID of the currently active power plan (language independent)
148153
private string GetActivePlanGuid()
149154
{
150155
string output = RunPowerCfg("/L");
156+
Regex guidRegex = new Regex(@"([a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12})");
157+
151158
foreach (var line in output.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
152159
{
153-
if (line.Contains("*") && line.Contains("GUID"))
160+
if (line.Contains("*"))
154161
{
155-
int start = line.IndexOf("GUID:") + 5;
156-
int end = line.IndexOf('(', start);
157-
return line.Substring(start, end - start).Trim();
162+
var match = guidRegex.Match(line);
163+
if (match.Success)
164+
{
165+
return match.Groups[1].Value;
166+
}
158167
}
159168
}
160169
return null;
@@ -169,7 +178,8 @@ private int GetCurrentCpuLimit()
169178
string output = RunPowerCfg($"/query {activePlan} SUB_PROCESSOR {MaxProcessorStateGuid}");
170179
foreach (var line in output.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
171180
{
172-
if (line.Trim().StartsWith("Current AC Power Setting Index"))
181+
// Le texte ici peut être localisé, donc on recherche la ligne qui contient "Current AC Power Setting Index" en insensible à la casse
182+
if (line.Trim().ToLower().Contains("current ac power setting index"))
173183
{
174184
string value = line.Split(':')[1].Trim();
175185
if (value.StartsWith("0x"))
42 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
5+
</startup>
6+
</configuration>

0 commit comments

Comments
 (0)