ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/RenegadeMapSelector/RenegadeConfig.cpp
Revision: 68
Committed: 2003-03-11T17:16:41-08:00 (22 years, 3 months ago) by douglas
File size: 1639 byte(s)
Log Message:
Did some more stuff.

File Contents

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