ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/RenegadeMapSelector/RenegadeConfig.cpp
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (16 years, 9 months ago) by douglas
File size: 1856 byte(s)
Log Message:
Rearranged everything else.

File Contents

# User Rev Content
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 douglas 142 linux_ = true;
24 douglas 89 }
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 143 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 143 fout << "MapName=" << maps[0] << (text.good() ? (linux_ ? "\r\n" :
87 douglas 89 "\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 143 < maps.size() || text.good() ? (linux_ ? "\r\n" : "\n") :
98     "");
99 douglas 68
100     delete [] number;
101     }
102     }
103     else
104     {
105 douglas 143 fout << line << (text.good() ? (linux_ ? "\r\n" : "\n") : "");
106 douglas 68 }
107     }
108     while (text.good());
109    
110     fout.close();
111 douglas 67 }