-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.h
90 lines (74 loc) · 2.35 KB
/
settings.h
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
int isdigit(int c){
return (c >= '0' && c <= '9');
}
// extracts the last positive integral value of string s
// returns...
// on success, the int value scanned
// -1, if the string is null, empty, or not terminated by a number
int extractLastIntegral(const char* s) {
int value = -1;
if (s && *s) { // don't parse null and empty strings
const char *scanstr = s + strlen(s) - 1;
while (scanstr > s && isdigit(*(scanstr-1))) {
scanstr--;
}
sscanf(scanstr,"%d", &value);
}
return value;
}
void saveSettings(){
#ifndef POK_SIM
mkdir("/joe2/", 0777); // make sure folder exist
File f;
if(f.openRW("/joe2/settings.ini",1,0)){
char tempText[20]={0};
sprintf(tempText,"volume = %d\n",myVolume);
f.write(tempText, strlen(tempText));
sprintf(tempText,"border = %d\n",bg.screenTop);
f.write(tempText, strlen(tempText));
f.close();
}
#endif
}
void loadSettings(){
#ifndef POK_SIM
printf("trying to load settings\n");
char txtLine[64];
char tempChar;
int index = 0;
mkdir("/joe2/", 0777); // make sure folder exist
File f;
if(f.openRO("/joe2/settings.ini")){
printf("settings file opened\n");
while(f.read(&tempChar, 1)){
// printf("%c", tempChar);
if (tempChar == EOF) {
txtLine[index] = '\0';
break;
}
if (tempChar == '\n' || tempChar == '\r') {
txtLine[index] = '\0';
printf("New Line\n");
index=0;
if(strncmp(txtLine, "volume", strlen("volume"))==0){
myVolume = extractLastIntegral(txtLine);
printf("Volume = %d\n", myVolume);
}
if(strncmp(txtLine, "border", strlen("border"))==0){
bg.screenTop = extractLastIntegral(txtLine);
printf("Border = %d\n", bg.screenTop);
}
continue;
}else{
txtLine[index] = (char)tempChar;
}
index++;
}
}else{
printf("file failed\n");
myVolume = 10;
bg.screenTop = 0;
saveSettings();
}
#endif
}