-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathglobalstat.h
More file actions
60 lines (51 loc) · 1014 Bytes
/
globalstat.h
File metadata and controls
60 lines (51 loc) · 1014 Bytes
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
#pragma once
map<string, size_t> globalstats;
const vector<string> globalstats_keys
{
"game_cnt",
};
void InitGlobalsStatKeys()
{
for (const auto& k : globalstats_keys)
{
globalstats[k] = 0L;
}
}
#define GLOBALSTATS_PATH L"./global/stats.csv"
void ReadGlobalStats()
{
vector<string> lines = ReadFileLines(GLOBALSTATS_PATH);
//No such file
if (lines.empty())
{
InitGlobalsStatKeys();
return;
}
for (const auto& line : lines)
{
vector<string> cut = CutLine(line, '=');
if (cut.size() < 2)
continue;
string key = cut[0];
string value = cut[1];
globalstats[key] = ToSize_t(value);
}
}
void SaveGlobalStats()
{
if (!ExistFile(L"./global"))
_wmkdir(L"./global");
fstream fout(GLOBALSTATS_PATH, ios::out);
//Open file failed
if (!fout || fout.fail())
{
MessageBoxA(nullptr, "Cannot Save Global Stats!", "SaveGlobalStats",
MB_SYSTEMMODAL | MB_ICONERROR);
return;
}
for (auto& pr : globalstats)
{
fout << pr.first << "=" << pr.second << '\n';
}
fout.close();
}