Subversion Repositories spk

Rev

Rev 196 | Rev 202 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 196 Rev 197
Line 26... Line 26...
26
	m_pModMap = new FileList;
26
	m_pModMap = new FileList;
27
 
27
 
28
	m_pTexts = new CTextDB();
28
	m_pTexts = new CTextDB();
29
	m_pModTexts = new CTextDB();
29
	m_pModTexts = new CTextDB();
30
 
30
 
31
	m_sAddon = "";
31
	m_sAddon = L"";
32
 
32
 
33
	m_iLang = 0;
33
	m_iLang = 0;
34
}
34
}
35
 
35
 
36
CVirtualFileSystem::~CVirtualFileSystem(void)
36
CVirtualFileSystem::~CVirtualFileSystem(void)
Line 39... Line 39...
39
 
39
 
40
	if ( m_pTexts )		delete m_pTexts;
40
	if ( m_pTexts )		delete m_pTexts;
41
	if ( m_pModTexts )  delete m_pModTexts;
41
	if ( m_pModTexts )  delete m_pModTexts;
42
}
42
}
43
 
43
 
44
void CVirtualFileSystem::setAddon(const Utils::String &addon)
44
void CVirtualFileSystem::setAddon(const Utils::WString &addon)
45
{ 
45
{ 
46
	m_sAddon = addon; 
46
	m_sAddon = addon; 
47
}
47
}
48
void CVirtualFileSystem::setLanguage(int iLang)
48
void CVirtualFileSystem::setLanguage(int iLang)
49
{
49
{
50
	m_iLang = iLang;
50
	m_iLang = iLang;
51
}
51
}
52
 
52
 
53
Utils::String CVirtualFileSystem::firstShield()
53
Utils::WString CVirtualFileSystem::firstShield()
54
{
54
{
55
	if ( !_lShields || _lShields->empty() ) _updateShields();
55
	if ( !_lShields || _lShields->empty() ) _updateShields();
56
	return _returnText(_lShields->first());
56
	return _returnText(_lShields->first());
57
}
57
}
58
 
58
 
59
Utils::String CVirtualFileSystem::nextShield()
59
Utils::WString CVirtualFileSystem::nextShield()
60
{
60
{
61
	return _returnText(_lShields->next());
61
	return _returnText(_lShields->next());
62
}
62
}
63
 
63
 
64
Utils::String CVirtualFileSystem::firstComponentSection()
64
Utils::WString CVirtualFileSystem::firstComponentSection()
65
{
65
{
66
	if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
66
	if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
67
	return _returnLine(_lComponentSections->first());
67
	return _returnLine(_lComponentSections->first());
68
}
68
}
69
 
69
 
70
Utils::String CVirtualFileSystem::nextComponentSection()
70
Utils::WString CVirtualFileSystem::nextComponentSection()
71
{
71
{
72
	return _returnLine(_lComponentSections->next());
72
	return _returnLine(_lComponentSections->next());
73
}
73
}
74
 
74
 
75
Utils::String CVirtualFileSystem::firstDummySection()
75
Utils::WString CVirtualFileSystem::firstDummySection()
76
{
76
{
77
	if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
77
	if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
78
	return _returnLine(_lDummySections->first());
78
	return _returnLine(_lDummySections->first());
79
}
79
}
80
 
80
 
81
Utils::String CVirtualFileSystem::nextDummySection()
81
Utils::WString CVirtualFileSystem::nextDummySection()
82
{
82
{
83
	return _returnLine(_lDummySections->next());
83
	return _returnLine(_lDummySections->next());
84
}
84
}
85
 
85
 
86
Utils::String CVirtualFileSystem::firstBodiesSection()
86
Utils::WString CVirtualFileSystem::firstBodiesSection()
87
{
87
{
88
	if ( !_lBodiesSections || _lBodiesSections->empty() ) _updateBodiesSections();
88
	if ( !_lBodiesSections || _lBodiesSections->empty() ) _updateBodiesSections();
89
	return _returnLine(_lBodiesSections->first());
89
	return _returnLine(_lBodiesSections->first());
90
}
90
}
91
 
91
 
92
Utils::String CVirtualFileSystem::nextBodiesSection()
92
Utils::WString CVirtualFileSystem::nextBodiesSection()
93
{
93
{
94
	return _returnLine(_lBodiesSections->next());
94
	return _returnLine(_lBodiesSections->next());
95
}
95
}
96
 
96
 
97
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextLaser()
97
std::pair<Utils::WString, Utils::WString> CVirtualFileSystem::nextLaser()
98
{
98
{
99
	return _returnPair(_lLasers->next());
99
	return _returnPair(_lLasers->next());
100
}
100
}
101
 
101
 
102
std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstLaser()
102
std::pair<Utils::WString, Utils::WString>  CVirtualFileSystem::firstLaser()
103
{
103
{
104
	if ( !_lLasers || _lLasers->empty() ) _updateLasers();
104
	if ( !_lLasers || _lLasers->empty() ) _updateLasers();
105
	return _returnPair(_lLasers->first());
105
	return _returnPair(_lLasers->first());
106
}
106
}
107
 
107
 
108
std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstMissile()
108
std::pair<Utils::WString, Utils::WString>  CVirtualFileSystem::firstMissile()
109
{
109
{
110
	if ( !_lMissiles || _lMissiles->empty() ) _updateMissiles();
110
	if ( !_lMissiles || _lMissiles->empty() ) _updateMissiles();
111
	return _returnPair(_lMissiles->first());
111
	return _returnPair(_lMissiles->first());
112
}
112
}
113
 
113
 
114
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextMissile()
114
std::pair<Utils::WString, Utils::WString> CVirtualFileSystem::nextMissile()
115
{
115
{
116
	return _returnPair(_lMissiles->next());
116
	return _returnPair(_lMissiles->next());
117
}
117
}
118
 
118
 
119
Utils::String CVirtualFileSystem::firstCockpit()
119
Utils::WString CVirtualFileSystem::firstCockpit()
120
{
120
{
121
	if ( !_lCockpits || _lCockpits->empty() ) _updateCockpits();
121
	if ( !_lCockpits || _lCockpits->empty() ) _updateCockpits();
122
	return _returnID(_lCockpits->first());
122
	return _returnID(_lCockpits->first());
123
}
123
}
124
 
124
 
125
Utils::String CVirtualFileSystem::nextCockpit()
125
Utils::WString CVirtualFileSystem::nextCockpit()
126
{
126
{
127
	return _returnID(_lCockpits->next());
127
	return _returnID(_lCockpits->next());
128
}
128
}
129
 
129
 
130
std::pair<Utils::String, Utils::String> CVirtualFileSystem::_returnPair(Utils::SStringList *s)
130
std::pair<Utils::WString, Utils::WString> CVirtualFileSystem::_returnPair(Utils::WStringNode *s)
131
{
131
{
132
	if ( s && !s->data.empty() && !s->data.left(8).Compare("ReadText") ) return std::make_pair<Utils::String, Utils::String>(std::move(s->str), std::move(s->data));
132
	if ( s && !s->data.empty() && !s->data.left(8).Compare(L"ReadText") ) return std::make_pair<Utils::WString, Utils::WString>(std::move(s->str), std::move(s->data));
133
	if ( s ) return std::make_pair<Utils::String, Utils::String>(std::move(s->str), s->str.token(";", -2));
133
	if ( s ) return std::make_pair<Utils::WString, Utils::WString>(std::move(s->str), s->str.token(L";", -2));
134
	return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
134
	return std::make_pair<Utils::WString, Utils::WString>(Utils::WString::Null(), Utils::WString::Null());
135
}
135
}
136
 
136
 
137
Utils::String CVirtualFileSystem::_returnText(Utils::SStringList *s)
137
Utils::WString CVirtualFileSystem::_returnText(Utils::WStringNode *s)
138
{
138
{
139
	if ( s && !s->data.empty() && !s->data.left(8).Compare("ReadText") ) return s->data;
139
	if ( s && !s->data.empty() && !s->data.left(8).Compare(L"ReadText") ) return s->data;
140
	if ( s ) return s->str.token(";", -2);
140
	if ( s ) return s->str.token(L";", -2);
141
	return Utils::String::Null();
141
	return Utils::WString::Null();
142
}
142
}
143
 
143
 
144
Utils::String CVirtualFileSystem::_returnID(Utils::SStringList *s)
144
Utils::WString CVirtualFileSystem::_returnID(Utils::WStringNode *s)
145
{
145
{
146
	if ( s ) return s->str.token(";", -2);
146
	if ( s ) return s->str.token(L";", -2);
147
	return Utils::String::Null();
147
	return Utils::WString::Null();
148
}
148
}
149
 
149
 
150
Utils::String CVirtualFileSystem::_returnLine(Utils::SStringList *s)
150
Utils::WString CVirtualFileSystem::_returnLine(Utils::WStringNode *s)
151
{
151
{
152
	if ( s ) return s->str;
152
	if ( s ) return s->str;
153
	return Utils::String::Null();
153
	return Utils::WString::Null();
154
}
154
}
155
 
155
 
156
 
156
 
157
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, int maxPatch)
157
bool CVirtualFileSystem::LoadFilesystem(const Utils::WString &dir, int maxPatch)
158
{
158
{
159
	return this->LoadFilesystem(dir, "", maxPatch);
159
	return this->LoadFilesystem(dir, L"", maxPatch);
160
}
160
}
161
 
161
 
162
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, const Utils::String &mod, int maxPatch)
162
bool CVirtualFileSystem::LoadFilesystem(const Utils::WString &dir, const Utils::WString &mod, int maxPatch)
163
{
163
{
164
	m_sDir = dir.findReplace("\\", "/");
164
	m_sDir = dir.findReplace(L"\\", L"/");
165
 
165
 
166
	this->_clear();
166
	this->_clear();
167
 
167
 
168
	// if we are in the addon directory, then also read the previous directory
168
	// if we are in the addon directory, then also read the previous directory
169
	Utils::String s = dir.token("/", -1);
169
	Utils::WString s = dir.token(L"/", -1);
170
	if ( !this->m_sAddon.empty() && dir.token("/", -1).Compare(this->m_sAddon) ) {
170
	if ( !this->m_sAddon.empty() && dir.token(L"/", -1).Compare(this->m_sAddon) ) {
171
		//LoadFilesystem(dir.tokens("/", 1, -2), "", 0);
171
		//LoadFilesystem(dir.tokens("/", 1, -2), "", 0);
172
	}
172
	}
173
 
173
 
174
	int number = 1;
174
	int number = 1;
175
	while ( CFileIO::Exists(dir + "/" + Utils::String::PadNumber(number, 2) + ".cat") )
175
	while ( CFileIO::Exists(dir + L"/" + Utils::WString::PadNumber(number, 2) + L".cat") )
176
	{
176
	{
177
		if ( maxPatch && maxPatch < number ) break;
177
		if ( maxPatch && maxPatch < number ) break;
178
		Utils::String file = dir + "/" + Utils::String::PadNumber(number, 2);
178
		Utils::WString file = dir + L"/" + Utils::WString::PadNumber(number, 2);
179
		if ( !CFileIO::Exists(file + ".dat") )
179
		if ( !CFileIO::Exists(file + L".dat") )
180
			break;
180
			break;
181
 
181
 
182
		CCatFile cat;
182
		CCatFile cat;
183
		if ( cat.open(file + ".cat", m_sAddon, CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
183
		if ( cat.open(file + L".cat", m_sAddon, CATREAD_JUSTCONTENTS, false) == CATERR_NONE)
184
		{
184
		{
185
			for(auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
185
			for(auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
186
			{
186
			{
187
				this->_addModFile(CFileIO((*itr)->sFile).fullFilenameStr(), file + ".cat", m_pMap);
187
				this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), file + L".cat", m_pMap);
188
				m_bLoaded = true;
188
				m_bLoaded = true;
189
			}
189
			}
190
		}
190
		}
191
		++number;
191
		++number;
192
	}
192
	}
Line 194... Line 194...
194
	// add all the files from the mod
194
	// add all the files from the mod
195
	if ( !mod.empty() )
195
	if ( !mod.empty() )
196
		this->addMod(mod);
196
		this->addMod(mod);
197
 
197
 
198
	// now add all the extracted data
198
	// now add all the extracted data
199
	this->_addDir(m_sDir, "");
199
	this->_addDir(m_sDir, L"");
200
 
200
 
201
	return m_bLoaded;
201
	return m_bLoaded;
202
}
202
}
203
 
203
 
204
 
204
 
205
void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
205
void CVirtualFileSystem::_addDir(const Utils::WString &sStart, const Utils::WString &sDir)
206
{
206
{
207
	CDirIO Dir(sStart + "/" + sDir);
207
	CDirIO Dir(sStart + L"/" + sDir);
208
	Utils::WStringList list;
208
	Utils::WStringList list;
209
	if (Dir.dirList(list))
209
	if (Dir.dirList(list))
210
	{
210
	{
211
		for (auto itr = list.begin(); itr != list.end(); itr++)
211
		for (auto itr = list.begin(); itr != list.end(); itr++)
212
		{
212
		{
213
			if (CDirIO(Dir.dir((*itr)->str)).isDir()) _addDir(sStart, sDir + "/" + (*itr)->str.toString());
213
			if (CDirIO(Dir.dir((*itr)->str)).isDir()) _addDir(sStart, sDir + L"/" + (*itr)->str);
214
			else if (CFileIO((*itr)->str).isFileExtension(L"cat")) continue;
214
			else if (CFileIO((*itr)->str).isFileExtension(L"cat")) continue;
215
			else if (CFileIO((*itr)->str).isFileExtension(L"dat")) continue;
215
			else if (CFileIO((*itr)->str).isFileExtension(L"dat")) continue;
216
			else this->_addFile(sDir + "/" + (*itr)->str.toString(), Dir.file((*itr)->str).toString(), m_pMap);
216
			else this->_addFile(sDir + L"/" + (*itr)->str, Dir.file((*itr)->str), m_pMap);
217
		}
217
		}
218
	}
218
	}
219
}
219
}
220
 
220
 
221
 
221
 
222
void CVirtualFileSystem::_removeSameFile(const Utils::String &sFile, const Utils::String &sDest, const Utils::String &ext, FileList *pList)
222
void CVirtualFileSystem::_removeSameFile(const Utils::WString &sFile, const Utils::WString &sDest, const Utils::WString &ext, FileList *pList)
223
{
223
{
224
	CFileIO F(sFile);
224
	CFileIO F(sFile);
225
 
225
 
226
	Utils::String newFile = F.changeFileExtension(ext).toString();
226
	Utils::WString newFile = F.changeFileExtension(ext);
227
	newFile = newFile.lower();
227
	newFile = newFile.lower();
228
 
228
 
229
	FileListItr itr = pList->find(newFile);
229
	FileListItr itr = pList->find(newFile);
230
	if ( itr != pList->end() ) {
230
	if ( itr != pList->end() ) {
231
		if ( !CFileIO((*pList)[newFile]).dir().Compare(CFileIO(sDest).dir()) ) {
231
		if ( !CFileIO((*pList)[newFile]).dir().Compare(CFileIO(sDest).dir()) ) {
232
			pList->erase(newFile);
232
			pList->erase(newFile);
233
		}
233
		}
234
	}
234
	}
235
}
235
}
236
 
236
 
237
void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
237
void CVirtualFileSystem::_addFile(const Utils::WString &sFile, const Utils::WString &sDest, FileList *pList)
238
{
238
{
239
	Utils::String file = sFile.asFilename().removeIf(0, '/');
239
	Utils::WString file = sFile.asFilename().removeIf(0, '/');
240
 
240
 
241
	// check file extension, remove any patching files in previous files
241
	// check file extension, remove any patching files in previous files
242
	CFileIO F(file);
242
	CFileIO F(file);
243
	Utils::WString ext = F.extension().toLower();
243
	Utils::WString ext = F.extension().toLower();
244
	if (ext.Compare(L"bob", true) || ext.Compare(L"pbd", true) || ext.Compare(L"bod", true) ) {
244
	if (ext.Compare(L"bob", true) || ext.Compare(L"pbd", true) || ext.Compare(L"bod", true) ) {
Line 249... Line 249...
249
	else if (ext.Compare(L"xml", true) || ext.Compare(L"txt", true) )
249
	else if (ext.Compare(L"xml", true) || ext.Compare(L"txt", true) )
250
		_removeSameFile(file, sDest, "pck", pList);
250
		_removeSameFile(file, sDest, "pck", pList);
251
 
251
 
252
	(*pList)[file.lower()] = sDest.findReplace("\\", "/").findReplace("//", "/");
252
	(*pList)[file.lower()] = sDest.findReplace("\\", "/").findReplace("//", "/");
253
}
253
}
254
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
254
void CVirtualFileSystem::_addModFile(const Utils::WString &sFile, const Utils::WString &sMod, FileList *pList)
255
{
255
{
256
	this->_addFile(sFile, sMod + "::" + sFile, pList);
256
	this->_addFile(sFile, sMod + L"::" + sFile, pList);
257
}
257
}
258
 
258
 
259
bool CVirtualFileSystem::loadMod(const Utils::String &mod)
259
bool CVirtualFileSystem::loadMod(const Utils::WString &mod)
260
{
260
{
261
	bool loaded = false;
261
	bool loaded = false;
262
 
262
 
263
	if ( !m_pModMap ) m_pModMap = new FileList;
263
	if ( !m_pModMap ) m_pModMap = new FileList;
264
 
264
 
265
	CCatFile cat;
265
	CCatFile cat;
266
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
266
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false))
267
	{
267
	{
268
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++) 
268
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++) 
269
		{
269
		{
270
			this->_addModFile(CFileIO((*itr)->sFile).fullFilenameStr(), mod, m_pModMap);
270
			this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), mod, m_pModMap);
271
			loaded = true;
271
			loaded = true;
272
		}
272
		}
273
	}
273
	}
274
 
274
 
275
	return loaded;
275
	return loaded;
276
}
276
}
277
 
277
 
278
bool CVirtualFileSystem::addMod(const Utils::String &mod)
278
bool CVirtualFileSystem::addMod(const Utils::WString &mod)
279
{
279
{
280
	bool loaded = false;
280
	bool loaded = false;
281
 
281
 
282
	if ( !m_pMap ) m_pMap = new FileList;
282
	if ( !m_pMap ) m_pMap = new FileList;
283
 
283
 
284
	CCatFile cat;
284
	CCatFile cat;
285
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
285
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false))
286
	{
286
	{
287
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
287
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
288
		{
288
		{
289
			this->_addModFile(CFileIO((*itr)->sFile).fullFilenameStr(), mod, m_pMap);
289
			this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), mod, m_pMap);
290
			loaded = true;
290
			loaded = true;
291
		}
291
		}
292
	}
292
	}
293
 
293
 
294
	return loaded;
294
	return loaded;
Line 306... Line 306...
306
	}
306
	}
307
 
307
 
308
	return false;
308
	return false;
309
}
309
}
310
 
310
 
311
Utils::String CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
311
Utils::WString CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
312
{
312
{
313
	if ( iLang <= 0 ) iLang = m_iLang;
313
	if ( iLang <= 0 ) iLang = m_iLang;
314
 
314
 
315
	if ( m_pTexts ) {
315
	if ( m_pTexts ) {
316
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
316
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
317
	}
317
	}
318
	if ( m_pModTexts ) {
318
	if ( m_pModTexts ) {
319
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
319
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
320
	}
320
	}
321
 
321
 
322
	return Utils::String("ReadText") + (long)iPage + "-" + (long)iID;
322
	return Utils::WString(L"ReadText") + (long)iPage + L"-" + (long)iID;
323
}
323
}
324
 
324
 
325
const Utils::String &CVirtualFileSystem::directory() const
325
const Utils::WString &CVirtualFileSystem::directory() const
326
{
326
{
327
	return m_sDir;
327
	return m_sDir;
328
}
328
}
329
 
329
 
330
bool CVirtualFileSystem::isFileAvailable(const Utils::String &file) const
330
bool CVirtualFileSystem::isFileAvailable(const Utils::WString &file) const
331
{
331
{
332
	return !this->_findFile(file).empty();
332
	return !this->_findFile(file).empty();
333
}
333
}
334
 
334
 
335
bool CVirtualFileSystem::isTextUpdated() const
335
bool CVirtualFileSystem::isTextUpdated() const
336
{
336
{
337
	if ( m_pTexts ) return m_pTexts->anyTextLoaded();
337
	if ( m_pTexts ) return m_pTexts->anyTextLoaded();
338
	return false;
338
	return false;
339
}
339
}
340
 
340
 
341
Utils::String CVirtualFileSystem::_findFile(const Utils::String &file) const
341
Utils::WString CVirtualFileSystem::_findFile(const Utils::WString &file) const
342
{
342
{
343
	Utils::String toFile = file.findReplace("\\", "/").lower();
343
	Utils::WString toFile = file.findReplace(L"\\", L"/").lower();
344
 
344
 
345
	if ( m_pModMap && !m_pModMap->empty() ) {
345
	if ( m_pModMap && !m_pModMap->empty() ) {
346
		if ( !m_sAddon.empty() ) {
346
		if ( !m_sAddon.empty() ) {
347
			FileListItr aitr = m_pModMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilenameStr().lower().c_str());
347
			FileListItr aitr = m_pModMap->find(CFileIO(m_sAddon + L"/" + toFile).fullFilename().lower().c_str());
348
			if ( aitr == m_pModMap->end() ) aitr = m_pModMap->find(CFileIO(_convertExtension(m_sAddon + "/" + toFile)).fullFilenameStr().lower().c_str());
348
			if ( aitr == m_pModMap->end() ) aitr = m_pModMap->find(CFileIO(_convertExtension(m_sAddon + L"/" + toFile)).fullFilename().lower().c_str());
349
			if ( aitr != m_pModMap->end() ) return aitr->second;
349
			if ( aitr != m_pModMap->end() ) return aitr->second;
350
		}
350
		}
351
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilenameStr().lower().c_str());
351
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilename().lower().c_str());
352
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilenameStr().lower().c_str());
352
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilename().lower().c_str());
353
		if ( itr != m_pModMap->end() ) return itr->second;
353
		if ( itr != m_pModMap->end() ) return itr->second;
354
	}
354
	}
355
 
355
 
356
	if ( m_pMap && !m_pMap->empty() ) {
356
	if ( m_pMap && !m_pMap->empty() ) {
357
		if ( !m_sAddon.empty() ) {
357
		if ( !m_sAddon.empty() ) {
358
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilenameStr().lower().c_str());
358
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + L"/" + toFile).fullFilename().lower().c_str());
359
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).fullFilenameStr().lower().c_str());
359
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + L"/" + file)).fullFilename().lower().c_str());
360
			if ( aitr != m_pMap->end() ) return aitr->second;
360
			if ( aitr != m_pMap->end() ) return aitr->second;
361
		}
361
		}
362
		FileListItr itr = m_pMap->find(CFileIO(file).fullFilenameStr().lower().c_str());
362
		FileListItr itr = m_pMap->find(CFileIO(file).fullFilename().lower().c_str());
363
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).fullFilenameStr().lower().c_str());
363
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).fullFilename().lower().c_str());
364
		if ( itr != m_pMap->end() ) return itr->second;
364
		if ( itr != m_pMap->end() ) return itr->second;
365
	}
365
	}
366
	return "";
366
	return L"";
367
}
367
}
368
 
368
 
369
Utils::String CVirtualFileSystem::_extractFromCat(const Utils::String &sCat, const Utils::String &sFile, const Utils::String &sTo)
369
Utils::WString CVirtualFileSystem::_extractFromCat(const Utils::WString &sCat, const Utils::WString &sFile, const Utils::WString &sTo)
370
{
370
{
371
	CCatFile catFile;
371
	CCatFile catFile;
372
	if ( catFile.open(sCat, m_sAddon, CATREAD_CATDECRYPT, false) == CATERR_NONE )
372
	if ( catFile.open(sCat, m_sAddon, CATREAD_CATDECRYPT, false) == CATERR_NONE)
373
	{
373
	{
374
		// check for the file
374
		// check for the file
375
		if ( catFile.extractFile(sFile, sTo) ) return sTo;
375
		if ( catFile.extractFile(sFile, sTo)) return sTo;
376
		if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR ) {
376
		if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR ) {
377
			if ( catFile.extractFile(sFile) ) return sFile;
377
			if ( catFile.extractFile(sFile) ) return sFile;
378
		}
378
		}
379
	}
379
	}
380
 
380
 
381
	return "";
381
	return "";
382
}
382
}
383
 
383
 
384
Utils::String CVirtualFileSystem::_extract(const Utils::String &sFile, const Utils::String &sTo)
384
Utils::WString CVirtualFileSystem::_extract(const Utils::WString &sFile, const Utils::WString &sTo)
385
{
385
{
386
	// check if we need to unpack the file
386
	// check if we need to unpack the file
387
	if ( CCatFile::CheckPackedExtension(sFile) ) {
387
	if ( CCatFile::CheckPackedExtension(sFile) ) {
388
		CFileIO File(sFile);
388
		CFileIO File(sFile);
389
		C_File f(File.fullFilenameStr());
389
		C_File f(File.fullFilename());
390
		if ( !f.readFromFile(File) ) return "";
390
		if ( !f.readFromFile(File) ) return L"";
391
		if ( !f.UnPCKFile() ) return "";
391
		if ( !f.UnPCKFile() ) return L"";
392
		if ( !f.writeToFile(sTo) ) return "";
392
		if ( !f.writeToFile(sTo) ) return L"";
393
		return sTo;
393
		return sTo;
394
	}
394
	}
395
	return sFile;
395
	return sFile;
396
}
396
}
397
 
397
 
398
Utils::String CVirtualFileSystem::ExtractGameFile(const Utils::String &file, const Utils::String &to)
398
Utils::WString CVirtualFileSystem::extractGameFile(const Utils::WString &file, const Utils::WString &to)
399
{
399
{
400
	Utils::String sIn = _findFile(file);
400
	Utils::WString sIn = _findFile(file);
401
	Utils::String sFile = file;
401
	Utils::WString sFile = file;
402
 
-
 
403
	if ( sIn.empty() ) return "";
-
 
404
 
402
 
-
 
403
	if (sIn.empty()) return L"";
-
 
404
 
405
	if ( sIn.isin("::") ) {
405
	if (sIn.contains(L"::"))
-
 
406
	{
406
		sFile = sIn.token("::", 2);
407
		sFile = sIn.token(L"::", 2);
407
		sIn = sIn.token("::", 1);
408
		sIn = sIn.token(L"::", 1);
408
		return _extractFromCat(sIn, sFile, to);
409
		return _extractFromCat(sIn, sFile, to);
409
	}
410
	}
410
	
411
	
411
	return _extract(sIn, to);
412
	return _extract(sIn, to);
412
}
413
}
413
 
414
 
414
Utils::String CVirtualFileSystem::_convertExtension(const Utils::String &sFile) const
415
Utils::WString CVirtualFileSystem::_convertExtension(const Utils::WString &sFile) const
415
{
416
{
416
	CFileIO File(sFile);
417
	CFileIO File(sFile);
417
	if ( File.isFileExtension(L"pck") ) {
418
	if ( File.isFileExtension(L"pck") ) {
418
		return File.changeFileExtension(L"xml").toString();
419
		return File.changeFileExtension(L"xml");
419
	}
420
	}
420
	else if ( File.isFileExtension(L"xml") ) {
421
	else if ( File.isFileExtension(L"xml") ) {
421
		return File.changeFileExtension(L"pck").toString();
422
		return File.changeFileExtension(L"pck");
422
	}
423
	}
423
	else if ( File.isFileExtension(L"pbb") ) {
424
	else if ( File.isFileExtension(L"pbb") ) {
424
		return File.changeFileExtension(L"bob").toString();
425
		return File.changeFileExtension(L"bob");
425
	}
426
	}
426
	else if ( File.isFileExtension(L"bob") ) {
427
	else if ( File.isFileExtension(L"bob") ) {
427
		return File.changeFileExtension(L"pbb").toString();
428
		return File.changeFileExtension(L"pbb");
428
	}
429
	}
429
	else if ( File.isFileExtension(L"pbd") ) {
430
	else if ( File.isFileExtension(L"pbd") ) {
430
		return File.changeFileExtension(L"bod").toString();
431
		return File.changeFileExtension(L"bod");
431
	}
432
	}
432
	else if ( File.isFileExtension(L"bod") ) {
433
	else if ( File.isFileExtension(L"bod") ) {
433
		return File.changeFileExtension(L"pbd").toString();
434
		return File.changeFileExtension(L"pbd");
434
	}
435
	}
435
 
436
 
436
	return sFile;
437
	return sFile;
437
}
438
}
438
 
439
 
439
Utils::CStringList *CVirtualFileSystem::getTShipsEntries()
440
Utils::WStringList *CVirtualFileSystem::getTShipsEntries()
440
{
441
{
441
	if ( !_lShips || _lShips->empty() ) _updateShips();
442
	if ( !_lShips || _lShips->empty() ) _updateShips();
442
	return _lShips;
443
	return _lShips;
443
}
444
}
444
 
445
 
445
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType)
446
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::WString &sFile, FileType iFileType)
446
{
447
{
447
	return this->extractGameFileToPackage(pPackage, sFile, iFileType, sFile);
448
	return this->extractGameFileToPackage(pPackage, sFile, iFileType, sFile);
448
}
449
}
449
 
450
 
450
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType, const Utils::String &sTo)
451
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::WString &sFile, FileType iFileType, const Utils::WString &sTo)
451
{
452
{
452
	Utils::String to = this->ExtractGameFile(sFile, CPackages::tempDirectory() + "tmp.dat");
453
	Utils::WString to = this->extractGameFile(sFile, CPackages::tempDirectory() + L"tmp.dat");
453
	if ( !to.empty() ) {
454
	if ( !to.empty() ) {
454
		CFileIO File(to);
455
		CFileIO File(to);
455
 
456
 
456
		C_File *f = pPackage->addFile(CFileIO(sTo).filenameStr(), CFileIO(sTo).dir().toString(), iFileType);
457
		C_File *f = pPackage->addFile(CFileIO(sTo).filename(), CFileIO(sTo).dir(), iFileType);
457
		if ( f ) {
458
		if ( f ) {
458
			if ( f->readFromFile(CPackages::tempDirectory() + "tmp.dat") ) {
459
			if ( f->readFromFile(CPackages::tempDirectory() + L"tmp.dat") ) {
459
				File.remove();
460
				File.remove();
460
				return f;
461
				return f;
461
			}
462
			}
462
		}
463
		}
463
 
464
 
464
		File.remove();
465
		File.remove();
465
	}
466
	}
466
 
467
 
467
	return NULL;
468
	return NULL;
468
}
469
}
469
 
470
 
470
Utils::String CVirtualFileSystem::getTShipsEntry(const Utils::String &sId)
471
Utils::WString CVirtualFileSystem::getTShipsEntry(const Utils::WString &sId)
471
{
472
{
472
	if ( !_lShips || _lShips->empty() ) _updateShips();
473
	if ( !_lShips || _lShips->empty() ) _updateShips();
473
	return _lShips->findData(sId, true);
474
	return _lShips->findData(sId, true);
474
}
475
}
475
 
476
 
476
void CVirtualFileSystem::extractTexts(CXspFile *pPackage, int textId)
477
void CVirtualFileSystem::extractTexts(CXspFile *pPackage, int textId)
477
{
478
{
478
	//TODO: check for better finding of files in map
479
	//TODO: check for better finding of files in map
479
	for ( FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); ++itr ) {
480
	for ( FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); ++itr ) {
480
		Utils::String str = itr->first;
481
		Utils::WString str = itr->first;
481
 
482
 
482
		if ( !m_sAddon.empty() ) {
483
		if ( !m_sAddon.empty() ) {
483
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "\\t\\") )
484
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L"/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L"\\t\\") )
484
				continue;
485
				continue;
485
		}
486
		}
486
		else {
487
		else {
487
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") && !str.left(8).Compare("addon\t\\") && !str.left(8).Compare("addon/t/") )
488
			if ( !str.left(2).Compare(L"t\\") && !str.left(2).Compare(L"t/") && !str.left(8).Compare(L"addon\t\\") && !str.left(8).Compare(L"addon/t/") )
488
				continue;
489
				continue;
489
		}
490
		}
490
 
491
 
491
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
492
		Utils::WString sTo = this->extractGameFile(str, CPackages::tempDirectory() + L"tmp.dat");
492
		if ( !sTo.empty() ) {
493
		if ( !sTo.empty() ) {
493
			pPackage->AddTextFromFile(sTo, textId);
494
			pPackage->addTextFromFile(sTo, textId);
494
			CFileIO::Remove(sTo);
495
			CFileIO::Remove(sTo);
495
		}
496
		}
496
	}
497
	}
497
}
498
}
498
 
499
 
Line 503... Line 504...
503
void CVirtualFileSystem::updateTexts(int iPage)
504
void CVirtualFileSystem::updateTexts(int iPage)
504
{
505
{
505
	this->_updateTexts(iPage, iPage, m_pMap, m_pTexts);
506
	this->_updateTexts(iPage, iPage, m_pMap, m_pTexts);
506
}
507
}
507
void CVirtualFileSystem::updateModTexts(int iFromPage, int iToPage)
508
void CVirtualFileSystem::updateModTexts(int iFromPage, int iToPage)
508
{
509
{
509
	this->_updateTexts(iFromPage, iToPage, m_pModMap, m_pModTexts);
510
	this->_updateTexts(iFromPage, iToPage, m_pModMap, m_pModTexts);
510
}
511
}
511
void CVirtualFileSystem::updateModTexts(int iPage)
512
void CVirtualFileSystem::updateModTexts(int iPage)
512
{
513
{
513
	this->_updateTexts(iPage, iPage, m_pModMap, m_pModTexts);
514
	this->_updateTexts(iPage, iPage, m_pModMap, m_pModTexts);
514
}
515
}
515
 
516
 
516
void CVirtualFileSystem::_clear()
517
void CVirtualFileSystem::_clear()
517
{
518
{
Line 534... Line 535...
534
 
535
 
535
void CVirtualFileSystem::_updateTexts(int iFromPage, int iToPage, FileList *pFileList, CTextDB *pTextList)
536
void CVirtualFileSystem::_updateTexts(int iFromPage, int iToPage, FileList *pFileList, CTextDB *pTextList)
536
{
537
{
537
	// read all text files
538
	// read all text files
538
	for ( FileListItr itr = pFileList->begin(); itr != pFileList->end(); ++itr ) {
539
	for ( FileListItr itr = pFileList->begin(); itr != pFileList->end(); ++itr ) {
539
		Utils::String str = itr->first;
540
		Utils::WString str = itr->first;
540
 
541
 
541
		if ( !m_sAddon.empty() ) {
542
		if ( !m_sAddon.empty() ) {
542
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "\\t\\") )
543
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L"/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L"\\t\\") )
543
				continue;
544
				continue;
544
		}
545
		}
545
		else {
546
		else {
546
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") )
547
			if ( !str.left(2).Compare(L"t\\") && !str.left(2).Compare(L"t/") )
547
				continue;
548
				continue;
548
		}
549
		}
549
 
550
 
550
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
551
		Utils::WString sTo = this->extractGameFile(str, CPackages::tempDirectory() + L"tmp.dat");
551
		if ( !sTo.empty() ) {
552
		if ( !sTo.empty() ) {
552
			// add all texts into the map, id=(pageid, tid) data=text
553
			// add all texts into the map, id=(pageid, tid) data=text
553
			Utils::WString baseFile = CFileIO(str).baseName();
554
			Utils::WString baseFile = CFileIO(str).baseName();
554
			int lang = (baseFile.contains(L"-L")) ? baseFile.right(3) : baseFile.truncate(-4);
555
			int lang = (baseFile.contains(L"-L")) ? baseFile.right(3) : baseFile.truncate(-4);
555
 
556
 
Line 569... Line 570...
569
 
570
 
570
	if ( m_pModTexts ) delete m_pModTexts;
571
	if ( m_pModTexts ) delete m_pModTexts;
571
	m_pModTexts = new CTextDB();
572
	m_pModTexts = new CTextDB();
572
}
573
}
573
 
574
 
574
Utils::CStringList *CVirtualFileSystem::_updateList(const Utils::String &typesFile, int iTextPos)
575
Utils::WStringList *CVirtualFileSystem::_updateList(const Utils::WString &typesFile, int iTextPos)
575
{
576
{
576
	Utils::CStringList *list = new Utils::CStringList();
577
	Utils::WStringList *list = new Utils::WStringList();
577
 
578
 
578
	Utils::String file = this->ExtractGameFile("types\\" + typesFile + ".pck", CPackages::tempDirectory() + "/" + typesFile + ".txt");
579
	Utils::WString file = this->extractGameFile(L"types\\" + typesFile + L".pck", CPackages::tempDirectory() + L"/" + typesFile + L".txt");
579
 
580
 
580
	CFileIO f(file);
581
	CFileIO f(file);
581
 
582
 
582
	if ( f.exists() && f.startRead() ) {
583
	if ( f.exists() && f.startRead() ) {
583
		int itemsLeft = -1;
584
		int itemsLeft = -1;
584
 
585
 
585
		while(!f.atEnd()) {
586
		while(!f.atEnd()) {
586
			// read the next line
587
			// read the next line
587
			Utils::String line = f.readEndOfLine();
588
			Utils::WString line = f.readEndOfLineStr();
588
 
589
 
589
			// remove the unneeded characters
590
			// remove the unneeded characters
590
			line.removeChar('\r');
591
			line.removeChar('\r');
591
			line.removeChar(9);
592
			line.removeChar(9);
592
			line.removeFirstSpace();
593
			line.removeFirstSpace();
593
 
594
 
594
			// blank line ? skip it
595
			// blank line ? skip it
595
			if ( line.empty() ) continue;
596
			if ( line.empty() ) continue;
596
			// skip anything starting with / as its a comment
597
			// skip anything starting with / as its a comment
597
			if ( line[0] == '/' ) continue;
598
			if ( line[0] == '/' ) continue;
598
 
599
 
599
			// first line is the count
600
			// first line is the count
600
			if ( itemsLeft == -1 )
601
			if ( itemsLeft == -1 )
601
				itemsLeft = line.token(";", 2);
602
				itemsLeft = line.token(L";", 2);
602
			else {
603
			else {
603
				if ( iTextPos == 0 )
604
				if ( iTextPos == 0 )
604
					list->pushBack(line, line);
605
					list->pushBack(line, line);
605
				else if ( iTextPos == -1 ) 
606
				else if ( iTextPos == -1 ) 
606
					list->pushBack(line, line.token(";", -2));
607
					list->pushBack(line, line.token(L";", -2));
607
				else
608
				else
608
					list->pushBack(line, this->findText(m_iLang, TEXTPAGE_OBJECTS, line.token(";", iTextPos).toLong()));
609
					list->pushBack(line, this->findText(m_iLang, TEXTPAGE_OBJECTS, line.token(L";", iTextPos).toLong()));
609
				--itemsLeft;
610
				--itemsLeft;
610
			}
611
			}
611
		}
612
		}
612
		
613
		
613
		f.close();
614
		f.close();
Line 618... Line 619...
618
}
619
}
619
 
620
 
620
void CVirtualFileSystem::_updateShields()
621
void CVirtualFileSystem::_updateShields()
621
{
622
{
622
	DELETELIST(_lShields);
623
	DELETELIST(_lShields);
623
	_lShields = _updateList("TShields", 7);
624
	_lShields = _updateList(L"TShields", 7);
624
}
625
}
625
 
626
 
626
void CVirtualFileSystem::_updateLasers()
627
void CVirtualFileSystem::_updateLasers()
627
{
628
{
628
	DELETELIST(_lLasers);
629
	DELETELIST(_lLasers);
629
	_lLasers = _updateList("TLaser", 7);
630
	_lLasers = _updateList(L"TLaser", 7);
630
}
631
}
631
 
632
 
632
void CVirtualFileSystem::_updateMissiles()
633
void CVirtualFileSystem::_updateMissiles()
633
{
634
{
634
	DELETELIST(_lMissiles);
635
	DELETELIST(_lMissiles);
635
	_lMissiles = _updateList("TMissiles", 7);
636
	_lMissiles = _updateList(L"TMissiles", 7);
636
}
637
}
637
 
638
 
638
void CVirtualFileSystem::_updateCockpits()
639
void CVirtualFileSystem::_updateCockpits()
639
{
640
{
640
	DELETELIST(_lCockpits);
641
	DELETELIST(_lCockpits);
641
	_lCockpits = _updateList("TCockpits", -1);
642
	_lCockpits = _updateList(L"TCockpits", -1);
642
}
643
}
643
 
644
 
644
void CVirtualFileSystem::_updateShips()
645
void CVirtualFileSystem::_updateShips()
645
{
646
{
646
	DELETELIST(_lShips);
647
	DELETELIST(_lShips);
647
	_lShips = _updateList("TShips", -1);
648
	_lShips = _updateList(L"TShips", -1);
648
}
649
}
649
 
650
 
650
void CVirtualFileSystem::_updateComponentSections()
651
void CVirtualFileSystem::_updateComponentSections()
651
{
652
{
652
	DELETELIST(_lComponentSections);
653
	DELETELIST(_lComponentSections);
653
 
654
 
654
	_lComponentSections = new Utils::CStringList();
655
	_lComponentSections = new Utils::WStringList();
655
 
656
 
656
	Utils::String file = this->ExtractGameFile("types\\Components.pck", CPackages::tempDirectory() + "/Components.txt");
657
	Utils::WString file = this->extractGameFile(L"types\\Components.pck", CPackages::tempDirectory() + L"/Components.txt");
657
 
658
 
658
	CFileIO f(file);
659
	CFileIO f(file);
659
 
660
 
660
	if ( f.exists() && f.startRead() ) {
661
	if ( f.exists() && f.startRead() ) {
661
		int sectionRemaining = 0;
662
		int sectionRemaining = 0;
662
		int itemsRemaining = 0;
663
		int itemsRemaining = 0;
663
 
664
 
664
		while(!f.atEnd()) {
665
		while(!f.atEnd()) {
665
			// read the next line
666
			// read the next line
666
			Utils::String line = f.readEndOfLine();
667
			Utils::WString line = f.readEndOfLineStr();
667
 
668
 
668
			// remove the unneeded characters
669
			// remove the unneeded characters
669
			line.removeChar('\r');
670
			line.removeChar('\r');
670
			line.removeChar(9);
671
			line.removeChar(9);
671
			line.removeFirstSpace();
672
			line.removeFirstSpace();
672
 
673
 
673
			// blank line ? skip it
674
			// blank line ? skip it
674
			if ( line.empty() ) continue;
675
			if ( line.empty() ) continue;
675
			// skip anything starting with / as its a comment
676
			// skip anything starting with / as its a comment
676
			if ( line[0] == '/' ) continue;
677
			if ( line[0] == L'/' ) continue;
677
 
678
 
678
			if ( itemsRemaining )
679
			if ( itemsRemaining )
679
				--itemsRemaining;
680
				--itemsRemaining;
680
			else if ( !sectionRemaining )
681
			else if ( !sectionRemaining )
681
			{
682
			{
682
				sectionRemaining = line.token(";", 2).toLong();
683
				sectionRemaining = line.token(L";", 2).toLong();
683
				Utils::String section = line.token(";", 1);
684
				Utils::WString section = line.token(L";", 1);
684
				if ( !section.empty() )
685
				if ( !section.empty() )
685
					_lComponentSections->pushBack(section, section);
686
					_lComponentSections->pushBack(section, section);
686
			}
687
			}
687
			else if ( !itemsRemaining )
688
			else if ( !itemsRemaining )
688
			{
689
			{
689
				itemsRemaining = line.token(";", 2).toLong();
690
				itemsRemaining = line.token(L";", 2).toLong();
690
				--sectionRemaining;
691
				--sectionRemaining;
691
			}
692
			}
692
		}
693
		}
693
		
694
		
694
		f.close();
695
		f.close();
695
		f.remove();
696
		f.remove();
696
	}
697
	}
697
 
698
 
698
	if ( _lComponentSections->empty() )
699
	if ( _lComponentSections->empty() )
699
	{
700
	{
700
		_lComponentSections->pushBack("SCTYPE_LASER", "SCTYPE_LASER");
701
		_lComponentSections->pushBack(L"SCTYPE_LASER", L"SCTYPE_LASER");
701
		_lComponentSections->pushBack("SCTYPE_COCKPIT", "SCTYPE_COCKPIT");
702
		_lComponentSections->pushBack(L"SCTYPE_COCKPIT", L"SCTYPE_COCKPIT");
702
		_lComponentSections->pushBack("SCTYPE_DOCKING", "SCTYPE_DOCKING");
703
		_lComponentSections->pushBack(L"SCTYPE_DOCKING", L"SCTYPE_DOCKING");
703
	}
704
	}
704
}
705
}
705
 
706
 
706
Utils::CStringList *CVirtualFileSystem::_updateSectionList(const Utils::String &sFile, bool singleEntry)
707
Utils::WStringList *CVirtualFileSystem::_updateSectionList(const Utils::WString &sFile, bool singleEntry)
707
{
708
{
708
	Utils::CStringList *list = new Utils::CStringList();
709
	Utils::WStringList *list = new Utils::WStringList();
709
 
710
 
710
	Utils::String file = this->ExtractGameFile("types\\" + sFile + ".pck", CPackages::tempDirectory() + "/" + sFile + ".txt");
711
	Utils::WString file = this->extractGameFile(L"types\\" + sFile + L".pck", CPackages::tempDirectory() + L"/" + sFile + L".txt");
711
 
712
 
712
	CFileIO f(file);
713
	CFileIO f(file);
713
 
714
 
714
	if ( f.exists() && f.startRead() ) {
715
	if ( f.exists() && f.startRead() ) {
715
		int sectionRemaining = 0;
716
		int sectionRemaining = 0;
716
 
717
 
717
		while(!f.atEnd()) {
718
		while(!f.atEnd()) {
718
			// read the next line
719
			// read the next line
719
			Utils::String line = f.readEndOfLine();
720
			Utils::WString line = f.readEndOfLineStr();
720
 
721
 
721
			// remove the unneeded characters
722
			// remove the unneeded characters
722
			line.removeChar('\r');
723
			line.removeChar('\r');
723
			line.removeChar(9);
724
			line.removeChar(9);
724
			line.removeFirstSpace();
725
			line.removeFirstSpace();
725
 
726
 
726
			// blank line ? skip it
727
			// blank line ? skip it
727
			if ( line.empty() ) continue;
728
			if ( line.empty() ) continue;
728
			// skip anything starting with / as its a comment
729
			// skip anything starting with / as its a comment
729
			if ( line[0] == '/' ) continue;
730
			if ( line[0] == L'/' ) continue;
730
 
731
 
731
			if ( !sectionRemaining )
732
			if ( !sectionRemaining )
732
			{
733
			{
733
				sectionRemaining = line.token(";", 2).toLong();
734
				sectionRemaining = line.token(L";", 2).toLong();
734
				Utils::String section = line.token(";", 1);
735
				Utils::WString section = line.token(L";", 1);
735
				if ( !section.empty() )
736
				if ( !section.empty() )
736
					list->pushBack(section, section);
737
					list->pushBack(section, section);
737
			}
738
			}
738
			else {
739
			else {
739
				if ( singleEntry )
740
				if ( singleEntry )
740
					sectionRemaining -= (line.countToken(";") - 1);
741
					sectionRemaining -= (line.countToken(L";") - 1);
741
				else 
742
				else 
742
					--sectionRemaining;
743
					--sectionRemaining;
743
			}
744
			}
744
		}
745
		}
745
		
746
		
Line 752... Line 753...
752
 
753
 
753
void CVirtualFileSystem::_updateDummySections()
754
void CVirtualFileSystem::_updateDummySections()
754
{
755
{
755
	DELETELIST(_lDummySections);
756
	DELETELIST(_lDummySections);
756
 
757
 
757
	_lDummySections = _updateSectionList("Dummies", false);
758
	_lDummySections = _updateSectionList(L"Dummies", false);
758
 
759
 
759
	if ( _lDummySections->empty() )
760
	if ( _lDummySections->empty() )
760
	{
761
	{
761
		_lDummySections->pushBack("SDTYPE_ANIMATED", "SDTYPE_ANIMATED");
762
		_lDummySections->pushBack(L"SDTYPE_ANIMATED", L"SDTYPE_ANIMATED");
762
		_lDummySections->pushBack("SDTYPE_DOCK", "SDTYPE_DOCK");
763
		_lDummySections->pushBack(L"SDTYPE_DOCK", L"SDTYPE_DOCK");
763
		_lDummySections->pushBack("SDTYPE_DOORWAY", "SDTYPE_DOORWAY");
764
		_lDummySections->pushBack(L"SDTYPE_DOORWAY", L"SDTYPE_DOORWAY");
764
		_lDummySections->pushBack("SDTYPE_GUN", "SDTYPE_GUN");
765
		_lDummySections->pushBack(L"SDTYPE_GUN", L"SDTYPE_GUN");
765
		_lDummySections->pushBack("SDTYPE_CONNECTION", "SDTYPE_CONNECTION");
766
		_lDummySections->pushBack(L"SDTYPE_CONNECTION", L"SDTYPE_CONNECTION");
766
	}
767
	}
767
}
768
}
768
 
769
 
769
void CVirtualFileSystem::_updateBodiesSections()
770
void CVirtualFileSystem::_updateBodiesSections()
770
{
771
{
771
	DELETELIST(_lBodiesSections);
772
	DELETELIST(_lBodiesSections);
772
 
773
 
773
	_lBodiesSections = _updateSectionList("Bodies", true);
774
	_lBodiesSections = _updateSectionList(L"Bodies", true);
774
 
775
 
775
	if ( _lBodiesSections->empty() )
776
	if ( _lBodiesSections->empty() )
776
	{
777
	{
777
		_lBodiesSections->pushBack("SBTYPE_2D", "SBTYPE_2D");
778
		_lBodiesSections->pushBack(L"SBTYPE_2D", L"SBTYPE_2D");
778
		_lBodiesSections->pushBack("SBTYPE_FACECAMERA", "SBTYPE_FACECAMERA");
779
		_lBodiesSections->pushBack(L"SBTYPE_FACECAMERA", L"SBTYPE_FACECAMERA");
779
		_lBodiesSections->pushBack("SBTYPE_2D2", "SBTYPE_2D2");
780
		_lBodiesSections->pushBack(L"SBTYPE_2D2", L"SBTYPE_2D2");
780
		_lBodiesSections->pushBack("SBTYPE_2DY", "SBTYPE_2DY");
781
		_lBodiesSections->pushBack(L"SBTYPE_2DY", L"SBTYPE_2DY");
781
		_lBodiesSections->pushBack("SBTYPE_LOGO", "SBTYPE_LOGO");
782
		_lBodiesSections->pushBack(L"SBTYPE_LOGO", L"SBTYPE_LOGO");
782
		_lBodiesSections->pushBack("SBTYPE_FC", "SBTYPE_FC");
783
		_lBodiesSections->pushBack(L"SBTYPE_FC", L"SBTYPE_FC");
783
		_lBodiesSections->pushBack("SBTYPE_TURRET", "SBTYPE_TURRET");
784
		_lBodiesSections->pushBack(L"SBTYPE_TURRET", L"SBTYPE_TURRET");
784
		_lBodiesSections->pushBack("SBTYPE_JET", "SBTYPE_JET");
785
		_lBodiesSections->pushBack(L"SBTYPE_JET", L"SBTYPE_JET");
785
		_lBodiesSections->pushBack("SBTYPE_RADAR", "SBTYPE_RADAR");
786
		_lBodiesSections->pushBack(L"SBTYPE_RADAR", L"SBTYPE_RADAR");
786
		_lBodiesSections->pushBack("SBTYPE_CONTAINER", "SBTYPE_CONTAINER");
787
		_lBodiesSections->pushBack(L"SBTYPE_CONTAINER", L"SBTYPE_CONTAINER");
787
		_lBodiesSections->pushBack("SBTYPE_DISPLAY", "SBTYPE_DISPLAY");
788
		_lBodiesSections->pushBack(L"SBTYPE_DISPLAY", L"SBTYPE_DISPLAY");
788
		_lBodiesSections->pushBack("SBTYPE_DOCKPOINT", "SBTYPE_DOCKPOINT");
789
		_lBodiesSections->pushBack(L"SBTYPE_DOCKPOINT", L"SBTYPE_DOCKPOINT");
789
		_lBodiesSections->pushBack("SBTYPE_SMALLJET", "SBTYPE_SMALLJET");
790
		_lBodiesSections->pushBack(L"SBTYPE_SMALLJET", L"SBTYPE_SMALLJET");
790
	}
791
	}
791
}
792
}
792
 
793
 
793
 
794
 
794
/////////////////////////////////////////////////////////////////////////////////////////
795
/////////////////////////////////////////////////////////////////////////////////////////
795
//	DEBUG Functions
796
//	DEBUG Functions
796
 
797
 
797
 
798
 
798
void CVirtualFileSystem::DEBUG_LogContents(const Utils::String &sFile)
799
void CVirtualFileSystem::DEBUG_LogContents(const Utils::WString &sFile)
799
{
800
{
800
	CFileIO File(sFile);
801
	CFileIO File(sFile);
801
 
802
 
802
	if ( File.startWrite() ) {
803
	if ( File.startWrite() ) {
803
		if ( m_pMap ) {
804
		if ( m_pMap ) {
804
			for(FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); itr++) {
805
			for(FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); itr++) {
805
				Utils::String line = itr->first + " => " + itr->second + "\r\n";
806
				Utils::WString line = itr->first + L" => " + itr->second + L"\r\n";
-
 
807
				std::string str = std::string(line.begin(), line.end());
806
				File.write(line.c_str(), line.length());
808
				File.write(str.c_str(), str.length());
807
			}
809
			}
808
		}
810
		}
809
 
811
 
810
		File.close();
812
		File.close();
811
	}
813
	}