-
Notifications
You must be signed in to change notification settings - Fork 6
/
UserSettings.cpp
74 lines (60 loc) · 1.89 KB
/
UserSettings.cpp
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
#include "StdAfx.h"
#include "usersettings.h"
/** The global instance of user settings */
CUserSettings g_userSettings;
void CUserSettings::WriteToFile() {
FILE* f = fopen(m_userSettingsFile, "w");
if (f == nullptr)
return;
fprintf(f, "LANGUAGE=%d\n", m_language);
fprintf(f, "FLUXUNIT=%d\n", m_fluxUnit);
fprintf(f, "COLUMNUNIT=%d\n", m_columnUnit);
fclose(f);
}
/** Reads the settings from file */
void CUserSettings::ReadSettings(const CString* fileName) {
char nl[2] = { 0x0a, 0 };
char lf[2] = { 0x0d, 0 };
char* pt;
char txt[256];
if (fileName != nullptr) {
m_userSettingsFile.Format("%s", (LPCTSTR)*fileName);
}
FILE* f = fopen(m_userSettingsFile, "r");
if (f == nullptr)
return;
while (fgets(txt, sizeof(txt) - 1, f)) {
if (strlen(txt) > 4 && txt[0] != '%') {
pt = txt;
if (pt = strstr(txt, nl)) {
pt[0] = 0;
}
pt = txt;
if (pt = strstr(txt, lf)) {
pt[0] = 0;
}
// 1. Parse the flux unit
if (pt = strstr(txt, "FLUXUNIT=")) {
pt = strstr(txt, "=");
if (pt) {
int ret = sscanf(&pt[1], "%d", &m_fluxUnit);
}
}
// 2. Parse the column unit
if (pt = strstr(txt, "COLUMNUNIT=")) {
pt = strstr(txt, "=");
if (pt) {
int ret = sscanf(&pt[1], "%d", &m_columnUnit);
}
}
// 3. Parse the language
if (pt = strstr(txt, "LANGUAGE=")) {
pt = strstr(txt, "=");
if (pt) {
int ret = sscanf(&pt[1], "%d", &m_language);
}
}
}
}
fclose(f);
}