-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.c
42 lines (30 loc) · 896 Bytes
/
config.c
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
#include "config.h"
void defaultConfig(CONFIG *config) {
config->FREQ_ACCURATE = 0;
config->SHOW_ADVANCED = 0;
}
int loadConfig(CONFIG *config) {
defaultConfig(config);
int fd = sceIoOpen(CONFIG_PATH, SCE_O_RDONLY, 0777);
char chunk[1025];
int chunk_size = 0;
if ((chunk_size=sceIoRead(fd, chunk, 1024)) < 2) return -1;
char *token = strtok(chunk, "=");
while (token && token[0] != '\n') {
char key[30];
sscanf(token, "%s", key);
token = strtok(NULL, "\n");
int value = atoi(token);
token = strtok(NULL, "=");
if (strcmp(key, "freq_accurate") == 0) {
config->FREQ_ACCURATE = value;
continue;
}
if (strcmp(key, "show_advanced") == 0) {
config->SHOW_ADVANCED = value;
continue;
}
}
sceIoClose(fd);
return 0;
}