This repository was archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerscheme.h
More file actions
113 lines (94 loc) · 2 KB
/
powerscheme.h
File metadata and controls
113 lines (94 loc) · 2 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
#ifndef __powerscheme_h__
#define __powerscheme_h__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <shellapi.h>
typedef struct powerscheme {
char alias[10];
char guid[37];
int activation;
}powerscheme;
typedef struct cfgchain {
powerscheme scheme;
struct cfgchain* next;
}cfgchain;
class PowerScheme {
private:
cfgchain* cfg = getcfg();
cfgchain* getcfg();
public:
void changecfg(int choice);
int getActiveCfg();
//void getCfgNames();
};
cfgchain* PowerScheme::getcfg() {
FILE* fp;
char t;
int i = 0, j = 0;
cfgchain* cfg = (cfgchain*)malloc(sizeof(cfgchain));
cfgchain* temp = cfg;
fp = _popen("powercfg /l", "r");
while (1) {
/*---»ñÈ¡GUID---*/
while (getc(fp) != ':');
getc(fp);
fgets(temp->scheme.guid, sizeof(temp->scheme.guid), fp);
/*---»ñÈ¡Ãû³Æ---*/
getc(fp); getc(fp); getc(fp);
i = 0;
while ((t = getc(fp)) != ')')
{
temp->scheme.alias[i] = t;
i++;
}
temp->scheme.alias[i] = '\0';
/*---»ñÈ¡¼¤»î״̬---*/
getc(fp);
if ((t = getc(fp)) == '*') {
temp->scheme.activation = 1;
t = getc(fp);
t = getc(fp);
}
else temp->scheme.activation = 0;
/*---Á´±í²Ù×÷---*/
if (feof(fp)) break;
cfgchain* p = (cfgchain*)malloc(sizeof(cfgchain));
p->next = NULL;
temp->next = p;
temp = p;
}
_pclose(fp);
return cfg;
}
void PowerScheme::changecfg(int choice) {
char command[50];
while (choice - 1) {
cfg = cfg->next;
choice--;
}
strcpy_s(command, "powercfg /s ");
strcat_s(command, cfg->scheme.guid);
system(command);
/*
int cchWideChar = MultiByteToWideChar(CP_ACP, 0, command, -1, NULL, 0);
wchar_t* lpParameters = new wchar_t[cchWideChar];
MultiByteToWideChar(CP_ACP, 0, command, -1, lpParameters, cchWideChar);
ShellExecute(NULL, NULL, L"powercfg", lpParameters, NULL, SW_HIDE);
*/
cfg = getcfg();
}
inline int PowerScheme::getActiveCfg() {
cfgchain* head = cfg;
int i = 1;
while (head) {
if (head->scheme.activation)
return i;
else {
i++;
head = head->next;
}
}
exit(-1);
}
#endif // !__powerscheme_h__