1 |
douglas |
67 |
// Renegade Map Selector |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// RenegadeConfig.cpp |
6 |
|
|
|
7 |
|
|
#include "RenegadeConfig.h" |
8 |
|
|
|
9 |
|
|
bool RenegadeConfig::load() |
10 |
|
|
{ |
11 |
douglas |
68 |
ifstream fin(file.c_str()); |
12 |
|
|
|
13 |
|
|
if (!fin.is_open()) return false; |
14 |
|
|
|
15 |
|
|
do |
16 |
|
|
{ |
17 |
|
|
string line; |
18 |
|
|
getline(fin, line); |
19 |
douglas |
89 |
|
20 |
|
|
if (line[line.length() - 1] == '\r') |
21 |
|
|
{ |
22 |
|
|
line.erase(line.length() - 1); |
23 |
|
|
linux = true; |
24 |
|
|
} |
25 |
douglas |
68 |
|
26 |
|
|
if (line.find("MapName=") == 0) |
27 |
|
|
{ |
28 |
|
|
text << "MapName=" << (fin.good() ? "\n" : ""); |
29 |
|
|
} |
30 |
|
|
else if (line.find("MapName") == 0) |
31 |
|
|
{ |
32 |
|
|
if (line.find("MapName00=") == 0) |
33 |
|
|
{ |
34 |
|
|
text << "MapName00=" << (fin.good() ? "\n" : ""); |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
maps.push_back(line.substr(10)); |
38 |
|
|
} |
39 |
|
|
else |
40 |
|
|
{ |
41 |
|
|
text << line << (fin.good() ? "\n" : ""); |
42 |
|
|
} |
43 |
|
|
} |
44 |
|
|
while (fin.good()); |
45 |
|
|
|
46 |
|
|
fin.close(); |
47 |
|
|
|
48 |
|
|
if (debug) |
49 |
|
|
{ |
50 |
douglas |
89 |
cerr << "linux = " << (linux ? "true" : "false") << "\nmaps = {\n"; |
51 |
douglas |
68 |
|
52 |
|
|
for (unsigned index = 0; index < maps.size(); index++) |
53 |
|
|
{ |
54 |
|
|
cerr << " [" << index << "] = " << maps[index] << "\n"; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
cerr << "}\n"; |
58 |
|
|
} |
59 |
|
|
|
60 |
douglas |
67 |
return true; |
61 |
|
|
} |
62 |
|
|
|
63 |
douglas |
68 |
void RenegadeConfig::save() |
64 |
douglas |
67 |
{ |
65 |
douglas |
68 |
ofstream fout(file.c_str()); |
66 |
|
|
|
67 |
|
|
if (debug) |
68 |
|
|
{ |
69 |
|
|
cerr << "maps = {\n"; |
70 |
|
|
|
71 |
|
|
for (unsigned index = 0; index < maps.size(); index++) |
72 |
|
|
{ |
73 |
|
|
cerr << " [" << index << "] = " << maps[index] << "\n"; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
cerr << "}\n"; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
do |
80 |
|
|
{ |
81 |
|
|
string line; |
82 |
|
|
getline(text, line); |
83 |
|
|
|
84 |
|
|
if (line == "MapName=") |
85 |
|
|
{ |
86 |
douglas |
89 |
fout << "MapName=" << maps[0] << (text.good() ? (linux ? "\r\n" : |
87 |
|
|
"\n") : ""); |
88 |
douglas |
68 |
} |
89 |
|
|
else if (line == "MapName00=") |
90 |
|
|
{ |
91 |
|
|
for (unsigned index = 0; index < maps.size(); index++) |
92 |
|
|
{ |
93 |
|
|
char* number = new char[3]; |
94 |
|
|
sprintf(number, "%02u", index); |
95 |
|
|
|
96 |
|
|
fout << "MapName" << number << "=" << maps[index] << (index + 1 |
97 |
douglas |
89 |
< maps.size() || text.good() ? (linux ? "\r\n" : "\n") : "" |
98 |
|
|
); |
99 |
douglas |
68 |
|
100 |
|
|
delete [] number; |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
else |
104 |
|
|
{ |
105 |
douglas |
89 |
fout << line << (text.good() ? (linux ? "\r\n" : "\n") : ""); |
106 |
douglas |
68 |
} |
107 |
|
|
} |
108 |
|
|
while (text.good()); |
109 |
|
|
|
110 |
|
|
fout.close(); |
111 |
douglas |
67 |
} |