Subversion Repositories spk

Rev

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

Rev 94 Rev 101
Line 5... Line 5...
5
#include "XspFile.h"
5
#include "XspFile.h"
6
#include "TextDB.h"
6
#include "TextDB.h"
7
 
7
 
8
#include "Packages.h"
8
#include "Packages.h"
9
#include "Utils/StringList.h"
9
#include "Utils/StringList.h"
-
 
10
#include "CyString.h"
10
 
11
 
11
#define DELETELIST(list) if ( list ) { list->MemoryClear(); delete list; }
12
#define DELETELIST(list) if ( list ) { list->MemoryClear(); delete list; }
12
 
13
 
13
namespace SPK {
14
namespace SPK {
14
 
15
 
Line 16... Line 17...
16
	_lLasers(NULL),
17
	_lLasers(NULL),
17
	_lMissiles(NULL),
18
	_lMissiles(NULL),
18
	_lCockpits(NULL),
19
	_lCockpits(NULL),
19
	_lComponentSections(NULL),
20
	_lComponentSections(NULL),
20
	_lDummySections(NULL),
21
	_lDummySections(NULL),
21
	_lBodiesSections(NULL)
22
	_lBodiesSections(NULL),
-
 
23
	_lShips(NULL)
22
{
24
{
23
	m_bLoaded = false;
25
	m_bLoaded = false;
24
	m_pMap = new FileList;
26
	m_pMap = new FileList;
25
	m_pModMap = new FileList;
27
	m_pModMap = new FileList;
26
 
28
 
Line 32... Line 34...
32
	m_iLang = 0;
34
	m_iLang = 0;
33
}
35
}
34
 
36
 
35
CVirtualFileSystem::~CVirtualFileSystem(void)
37
CVirtualFileSystem::~CVirtualFileSystem(void)
36
{
38
{
37
	if ( m_pMap )		delete m_pMap;
39
	_clear();
38
	if ( m_pModMap )	delete m_pModMap;
-
 
39
 
40
 
40
	if ( m_pTexts )		delete m_pTexts;
41
	if ( m_pTexts )		delete m_pTexts;
41
	if ( m_pModTexts )  delete m_pModTexts;
42
	if ( m_pModTexts )  delete m_pModTexts;
42
 
-
 
43
	DELETELIST(_lShields);
-
 
44
	DELETELIST(_lLasers);
-
 
45
	DELETELIST(_lMissiles);
-
 
46
	DELETELIST(_lCockpits);
-
 
47
	DELETELIST(_lComponentSections);
-
 
48
	DELETELIST(_lDummySections);
-
 
49
	DELETELIST(_lBodiesSections);
-
 
50
}
43
}
51
 
44
 
-
 
45
void CVirtualFileSystem::setAddon(const Utils::String &addon)
-
 
46
{ 
-
 
47
	m_sAddon = addon; 
-
 
48
}
52
void CVirtualFileSystem::setLanguage(int iLang)
49
void CVirtualFileSystem::setLanguage(int iLang)
53
{
50
{
54
	m_iLang = iLang;
51
	m_iLang = iLang;
55
}
52
}
56
 
53
 
Line 61... Line 58...
61
}
58
}
62
 
59
 
63
Utils::String CVirtualFileSystem::nextShield()
60
Utils::String CVirtualFileSystem::nextShield()
64
{
61
{
65
	return _returnText(_lShields->Next());
62
	return _returnText(_lShields->Next());
66
}
63
}
67
 
64
 
68
Utils::String CVirtualFileSystem::firstComponentSection()
65
Utils::String CVirtualFileSystem::firstComponentSection()
69
{
66
{
70
	if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
67
	if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
71
	return _returnLine(_lComponentSections->First());
68
	return _returnLine(_lComponentSections->First());
Line 78... Line 75...
78
 
75
 
79
Utils::String CVirtualFileSystem::firstDummySection()
76
Utils::String CVirtualFileSystem::firstDummySection()
80
{
77
{
81
	if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
78
	if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
82
	return _returnLine(_lDummySections->First());
79
	return _returnLine(_lDummySections->First());
83
}
80
}
84
 
81
 
85
Utils::String CVirtualFileSystem::nextDummySection()
82
Utils::String CVirtualFileSystem::nextDummySection()
86
{
83
{
87
	return _returnLine(_lDummySections->Next());
84
	return _returnLine(_lDummySections->Next());
88
}
85
}
Line 94... Line 91...
94
}
91
}
95
 
92
 
96
Utils::String CVirtualFileSystem::nextBodiesSection()
93
Utils::String CVirtualFileSystem::nextBodiesSection()
97
{
94
{
98
	return _returnLine(_lBodiesSections->Next());
95
	return _returnLine(_lBodiesSections->Next());
99
}
96
}
100
 
97
 
101
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextLaser()
98
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextLaser()
102
{
99
{
103
	return _returnPair(_lLasers->Next());
100
	return _returnPair(_lLasers->Next());
104
}
101
}
105
 
102
 
Line 111... Line 108...
111
 
108
 
112
std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstMissile()
109
std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstMissile()
113
{
110
{
114
	if ( !_lMissiles || _lMissiles->empty() ) _updateMissiles();
111
	if ( !_lMissiles || _lMissiles->empty() ) _updateMissiles();
115
	return _returnPair(_lMissiles->First());
112
	return _returnPair(_lMissiles->First());
116
}
113
}
117
 
114
 
118
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextMissile()
115
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextMissile()
119
{
116
{
120
	return _returnPair(_lMissiles->Next());
117
	return _returnPair(_lMissiles->Next());
121
}
118
}
122
 
119
 
Line 146... Line 143...
146
}
143
}
147
 
144
 
148
Utils::String CVirtualFileSystem::_returnID(Utils::SStringList *s)
145
Utils::String CVirtualFileSystem::_returnID(Utils::SStringList *s)
149
{
146
{
150
	if ( s ) return s->str.token(";", -2);
147
	if ( s ) return s->str.token(";", -2);
151
	return Utils::String::Null();
148
	return Utils::String::Null();
152
}
149
}
153
 
150
 
154
Utils::String CVirtualFileSystem::_returnLine(Utils::SStringList *s)
151
Utils::String CVirtualFileSystem::_returnLine(Utils::SStringList *s)
155
{
152
{
156
	if ( s ) return s->str;
153
	if ( s ) return s->str;
157
	return Utils::String::Null();
154
	return Utils::String::Null();
158
}
155
}
159
 
156
 
160
 
157
 
161
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, int maxPatch)
158
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, int maxPatch)
162
{
159
{
163
	return this->LoadFilesystem(dir, "", maxPatch);
160
	return this->LoadFilesystem(dir, "", maxPatch);
164
}
161
}
165
 
162
 
Line 168... Line 165...
168
	m_sDir = dir;
165
	m_sDir = dir;
169
 
166
 
170
	this->_clear();
167
	this->_clear();
171
 
168
 
172
	int number = 1;
169
	int number = 1;
173
	while ( CFileIO(CyString(dir) + "/" + CyString::Number(number).PadNumber(2) + ".cat").ExistsOld() )
170
	while ( CFileIO::Exists(dir + "/" + Utils::String::PadNumber(number, 2) + ".cat") )
174
	{
171
	{
175
		if ( maxPatch && maxPatch < number ) break;
172
		if ( maxPatch && maxPatch < number ) break;
176
		CyString file = CyString(dir) + "/" + CyString::Number(number).PadNumber(2);
173
		Utils::String file = dir + "/" + Utils::String::PadNumber(number, 2);
177
		if ( !CFileIO(file + ".dat").ExistsOld() )
174
		if ( !CFileIO::Exists(file + ".dat") )
178
			break;
175
			break;
179
 
176
 
180
		CCatFile cat;
177
		CCatFile cat;
181
		if ( cat.Open(file + ".cat", m_sAddon, CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
178
		if ( cat.Open(file + ".cat", m_sAddon, CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
182
		{
179
		{
183
			for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() ) {
180
			for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() ) {
184
				this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), CyString(file + ".cat").ToString(), m_pMap);
181
				this->_addModFile(CFileIO(c->Data()->sFile).fullFilename(), file + ".cat", m_pMap);
185
				m_bLoaded = true;
182
				m_bLoaded = true;
186
			}
183
			}
187
		}
184
		}
188
		++number;
185
		++number;
189
	}
186
	}
190
 
187
 
191
	// add all the files from the mod
188
	// add all the files from the mod
192
	if ( !mod.empty() )
189
	if ( !mod.empty() )
193
		this->addMod(mod);
190
		this->addMod(mod);
194
 
191
 
195
	// now add all the extracted data
192
	// now add all the extracted data
196
	this->_addDir(m_sDir, "");
193
	this->_addDir(m_sDir, "");
197
 
194
 
198
	return m_bLoaded;
195
	return m_bLoaded;
199
}
196
}
200
 
197
 
201
 
198
 
202
void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
199
void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
Line 207... Line 204...
207
		for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next ) {
204
		for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next ) {
208
			if ( CDirIO(Dir.Dir(strNode->str)).IsDir() ) _addDir(sStart, sDir + "/" + strNode->str.ToString());
205
			if ( CDirIO(Dir.Dir(strNode->str)).IsDir() ) _addDir(sStart, sDir + "/" + strNode->str.ToString());
209
			else if ( CFileIO(strNode->str).CheckFileExtension("cat") ) continue;
206
			else if ( CFileIO(strNode->str).CheckFileExtension("cat") ) continue;
210
			else if ( CFileIO(strNode->str).CheckFileExtension("dat") ) continue;
207
			else if ( CFileIO(strNode->str).CheckFileExtension("dat") ) continue;
211
			else this->_addFile(sDir + "/" + strNode->str.ToString(), Dir.File(strNode->str).ToString(), m_pMap);
208
			else this->_addFile(sDir + "/" + strNode->str.ToString(), Dir.File(strNode->str).ToString(), m_pMap);
212
		}
209
		}
213
	}
210
	}
214
}
211
}
215
 
212
 
216
void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
213
void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
217
{
214
{
218
	(*pList)[sFile.asFilename().removeIf(0, '/').lower()] = sDest.findReplace("//", "/");
215
	(*pList)[sFile.asFilename().removeIf(0, '/').lower()] = sDest.findReplace("//", "/");
219
}
216
}
Line 221... Line 218...
221
{
218
{
222
	this->_addFile(sFile, sMod + "::" + sFile, pList);
219
	this->_addFile(sFile, sMod + "::" + sFile, pList);
223
}
220
}
224
 
221
 
225
bool CVirtualFileSystem::loadMod(const Utils::String &mod)
222
bool CVirtualFileSystem::loadMod(const Utils::String &mod)
226
{
223
{
227
	bool loaded = false;
224
	bool loaded = false;
228
 
225
 
229
	if ( !m_pModMap ) m_pModMap = new FileList;
226
	if ( !m_pModMap ) m_pModMap = new FileList;
230
 
227
 
231
	CCatFile cat;
228
	CCatFile cat;
232
	if ( CCatFile::Opened(cat.Open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
229
	if ( CCatFile::Opened(cat.Open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
233
	{
230
	{
234
		for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() ) {
231
		for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() ) {
235
			this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), mod, m_pModMap);
232
			this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), mod, m_pModMap);
236
			loaded = true;
233
			loaded = true;
237
		}
234
		}
238
	}
235
	}
239
 
236
 
240
	return loaded;
237
	return loaded;
241
}
238
}
242
 
239
 
243
bool CVirtualFileSystem::addMod(const Utils::String &mod)
240
bool CVirtualFileSystem::addMod(const Utils::String &mod)
244
{
241
{
Line 251... Line 248...
251
	{
248
	{
252
		for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() )
249
		for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() )
253
		{
250
		{
254
			this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), mod, m_pMap);
251
			this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), mod, m_pMap);
255
			loaded = true;
252
			loaded = true;
256
		}
253
		}
257
	}
254
	}
258
 
255
 
259
	return loaded;
256
	return loaded;
260
}
257
}
261
 
258
 
262
bool CVirtualFileSystem::textExists(int iLang, int iPage, int iID) const
259
bool CVirtualFileSystem::textExists(int iLang, int iPage, int iID) const
263
{
260
{
264
	if ( iLang <= 0 ) iLang = m_iLang;
261
	if ( iLang <= 0 ) iLang = m_iLang;
265
 
262
 
266
	if ( m_pTexts ) {
263
	if ( m_pTexts ) {
267
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
264
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
268
	}
265
	}
269
	if ( m_pModTexts ) {
266
	if ( m_pModTexts ) {
270
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->exists(iLang, iPage, iID);
267
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->exists(iLang, iPage, iID);
271
	}
268
	}
272
 
269
 
273
	return false;
270
	return false;
274
}
271
}
275
 
272
 
276
Utils::String CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
273
Utils::String CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
277
{
274
{
278
	if ( iLang <= 0 ) iLang = m_iLang;
275
	if ( iLang <= 0 ) iLang = m_iLang;
279
 
276
 
280
	if ( m_pTexts ) {
277
	if ( m_pTexts ) {
281
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
278
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
282
	}
279
	}
283
	if ( m_pModTexts ) {
280
	if ( m_pModTexts ) {
284
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
281
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
285
	}
282
	}
286
 
283
 
287
	return Utils::String("ReadText") + (long)iPage + "-" + (long)iID;
284
	return Utils::String("ReadText") + (long)iPage + "-" + (long)iID;
288
}
285
}
-
 
286
 
-
 
287
const Utils::String &CVirtualFileSystem::directory() const
-
 
288
{
-
 
289
	return m_sDir;
-
 
290
}
289
 
291
 
290
bool CVirtualFileSystem::isFileAvailable(const Utils::String &file)
292
bool CVirtualFileSystem::isFileAvailable(const Utils::String &file)
291
{
293
{
292
	return !this->_findFile(file).empty();
294
	return !this->_findFile(file).empty();
293
}
295
}
-
 
296
 
-
 
297
bool CVirtualFileSystem::isTextUpdated() const
-
 
298
{
-
 
299
	if ( m_pTexts ) return m_pTexts->anyTextLoaded();
-
 
300
	return false;
-
 
301
}
294
 
302
 
295
Utils::String CVirtualFileSystem::_findFile(const Utils::String &file)
303
Utils::String CVirtualFileSystem::_findFile(const Utils::String &file)
296
{
304
{
297
	Utils::String toFile = file.findReplace("\\", "/").lower();
305
	Utils::String toFile = file.findReplace("\\", "/").lower();
298
 
306
 
Line 313... Line 321...
313
			if ( aitr != m_pMap->end() ) return aitr->second;
321
			if ( aitr != m_pMap->end() ) return aitr->second;
314
		}
322
		}
315
		FileListItr itr = m_pMap->find(CFileIO(file).GetFullFilename().ToLower().c_str());
323
		FileListItr itr = m_pMap->find(CFileIO(file).GetFullFilename().ToLower().c_str());
316
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).GetFullFilename().ToLower().c_str());
324
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).GetFullFilename().ToLower().c_str());
317
		if ( itr != m_pMap->end() ) return itr->second;
325
		if ( itr != m_pMap->end() ) return itr->second;
318
	}
326
	}
319
	return "";
327
	return "";
320
}
328
}
321
 
329
 
322
Utils::String CVirtualFileSystem::_extractFromCat(const Utils::String &sCat, const Utils::String &sFile, const Utils::String &sTo)
330
Utils::String CVirtualFileSystem::_extractFromCat(const Utils::String &sCat, const Utils::String &sFile, const Utils::String &sTo)
323
{
331
{
Line 330... Line 338...
330
			if ( catFile.ExtractFile(sFile) ) return sFile;
338
			if ( catFile.ExtractFile(sFile) ) return sFile;
331
		}
339
		}
332
	}
340
	}
333
 
341
 
334
	return "";
342
	return "";
335
}
343
}
336
 
344
 
337
Utils::String CVirtualFileSystem::_extract(const Utils::String &sFile, const Utils::String &sTo)
345
Utils::String CVirtualFileSystem::_extract(const Utils::String &sFile, const Utils::String &sTo)
338
{
346
{
339
	// check if we need to unpack the file
347
	// check if we need to unpack the file
340
	if ( CCatFile::CheckPackedExtension(sFile) ) {
348
	if ( CCatFile::CheckPackedExtension(sFile) ) {
Line 347... Line 355...
347
	}
355
	}
348
	return sFile;
356
	return sFile;
349
}
357
}
350
 
358
 
351
Utils::String CVirtualFileSystem::ExtractGameFile(const Utils::String &file, const Utils::String &to)
359
Utils::String CVirtualFileSystem::ExtractGameFile(const Utils::String &file, const Utils::String &to)
352
{
360
{
353
	Utils::String sIn = _findFile(file);
361
	Utils::String sIn = _findFile(file);
354
	Utils::String sFile = file;
362
	Utils::String sFile = file;
355
 
363
 
356
	if ( sIn.empty() ) return "";
364
	if ( sIn.empty() ) return "";
357
 
365
 
Line 373... Line 381...
373
	else if ( File.CheckFileExtension("xml") ) {
381
	else if ( File.CheckFileExtension("xml") ) {
374
		return File.ChangeFileExtension("pck").ToString();
382
		return File.ChangeFileExtension("pck").ToString();
375
	}
383
	}
376
	else if ( File.CheckFileExtension("pbb") ) {
384
	else if ( File.CheckFileExtension("pbb") ) {
377
		return File.ChangeFileExtension("bob").ToString();
385
		return File.ChangeFileExtension("bob").ToString();
378
	}
386
	}
379
	else if ( File.CheckFileExtension("bob") ) {
387
	else if ( File.CheckFileExtension("bob") ) {
380
		return File.ChangeFileExtension("pbb").ToString();
388
		return File.ChangeFileExtension("pbb").ToString();
381
	}
389
	}
382
	else if ( File.CheckFileExtension("pbd") ) {
390
	else if ( File.CheckFileExtension("pbd") ) {
383
		return File.ChangeFileExtension("bod").ToString();
391
		return File.ChangeFileExtension("bod").ToString();
384
	}
392
	}
385
	else if ( File.CheckFileExtension("bod") ) {
393
	else if ( File.CheckFileExtension("bod") ) {
386
		return File.ChangeFileExtension("pbd").ToString();
394
		return File.ChangeFileExtension("pbd").ToString();
387
	}
395
	}
388
 
396
 
389
	return sFile;
397
	return sFile;
390
}
398
}
391
 
399
 
392
CyStringList *CVirtualFileSystem::GetTShipsEntries()
400
Utils::CStringList *CVirtualFileSystem::getTShipsEntries()
393
{
401
{
394
	Utils::String sTo = this->ExtractGameFile("types/tships.pck", CPackages::tempDirectory() + "/tships.txt");
-
 
395
	if ( !sTo.empty() ) {
-
 
396
		CFileIO TShips(sTo);
-
 
397
		if ( TShips.exists() )
-
 
398
		{
-
 
399
			CyStringList *lines = TShips.ReadLinesStr();
-
 
400
			if ( lines )
-
 
401
			{
-
 
402
				// remove any commands, blank lines, and start
-
 
403
				// and put the id as the data
-
 
404
				int entries = -1;
-
 
405
				for ( SStringList *str = lines->Head(); str; str = str->next )
-
 
406
				{
-
 
407
					str->str.RemoveFirstSpace();
-
 
408
					str->str.RemoveChar(9);
-
 
409
					str->str.RemoveChar('\r');
-
 
410
					str->str.RemoveChar('\n');
-
 
411
					if ( str->str.Empty() )
-
 
412
					{
-
 
413
						str->remove = true;
-
 
414
						continue;
-
 
415
					}
-
 
416
 
-
 
417
					if ( str->str[0] == '/' )
-
 
418
					{
-
 
419
						str->remove = true;
-
 
420
						continue;
-
 
421
					}
-
 
422
 
-
 
423
					if ( entries == -1 )
-
 
424
					{
-
 
425
						entries = str->str.GetToken(";", 2, 2).ToInt();
-
 
426
						str->remove = true;
-
 
427
						continue;
-
 
428
					}
-
 
429
 
-
 
430
					// hopefully we now have a valid tships line
402
	if ( !_lShips || _lShips->empty() ) _updateShips();
431
					int num = -1;
-
 
432
					while ( str->data.Empty() )
-
 
433
						str->data = str->str.GetToken(";", num--, (num + 2));
-
 
434
				}
-
 
435
			}
-
 
436
			// remove the tmp file
-
 
437
			TShips.remove();
-
 
438
 
-
 
439
			if ( lines )
-
 
440
				lines->RemoveMarked();
-
 
441
			return lines;
403
	return _lShips;
442
		}
-
 
443
	}
-
 
444
 
-
 
445
	return NULL;
-
 
446
}
404
}
447
 
405
 
448
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType)
406
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType)
449
{
407
{
450
	return this->extractGameFileToPackage(pPackage, sFile, iFileType, sFile);
408
	return this->extractGameFileToPackage(pPackage, sFile, iFileType, sFile);
451
}
409
}
452
 
410
 
453
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType, const Utils::String &sTo)
411
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType, const Utils::String &sTo)
454
{
412
{
Line 461... Line 419...
461
			if ( f->ReadFromFile(CPackages::GetTempDirectory() + "tmp.dat") ) {
419
			if ( f->ReadFromFile(CPackages::GetTempDirectory() + "tmp.dat") ) {
462
				File.remove();
420
				File.remove();
463
				return f;
421
				return f;
464
			}
422
			}
465
		}
423
		}
466
 
424
 
467
		File.remove();
425
		File.remove();
468
	}
426
	}
469
 
427
 
470
	return NULL;
428
	return NULL;
471
}
429
}
472
 
430
 
473
Utils::String CVirtualFileSystem::getTShipsEntry(const Utils::String &sId)
431
Utils::String CVirtualFileSystem::getTShipsEntry(const Utils::String &sId)
474
{
432
{
475
	CyStringList *ships = this->GetTShipsEntries();
433
	if ( !_lShips || _lShips->empty() ) _updateShips();
476
	if ( ships )
-
 
477
	{
-
 
478
		SStringList *node = ships->FindData(CyString(sId).upper());
434
	return _lShips->findData(sId, true);
479
		if ( node )
-
 
480
			return node->str.ToString();
-
 
481
	}
-
 
482
	return "";
-
 
483
}
435
}
484
 
436
 
485
void CVirtualFileSystem::extractTexts(CXspFile *pPackage, int textId)
437
void CVirtualFileSystem::extractTexts(CXspFile *pPackage, int textId)
486
{
438
{
487
	//TODO: check for better finding of files in map
439
	//TODO: check for better finding of files in map
Line 528... Line 480...
528
 
480
 
529
	if ( m_pMap ) delete m_pMap;
481
	if ( m_pMap ) delete m_pMap;
530
	m_pMap = new FileList;
482
	m_pMap = new FileList;
531
	if ( m_pModMap ) delete m_pModMap;
483
	if ( m_pModMap ) delete m_pModMap;
532
	m_pModMap = new FileList;
484
	m_pModMap = new FileList;
-
 
485
 
-
 
486
	DELETELIST(_lShields);
-
 
487
	DELETELIST(_lLasers);
-
 
488
	DELETELIST(_lMissiles);
-
 
489
	DELETELIST(_lCockpits);
-
 
490
	DELETELIST(_lComponentSections);
-
 
491
	DELETELIST(_lDummySections);
-
 
492
	DELETELIST(_lBodiesSections);
-
 
493
	DELETELIST(_lShips);
533
}
494
}
534
 
495
 
535
void CVirtualFileSystem::_updateTexts(int iFromPage, int iToPage, FileList *pFileList, CTextDB *pTextList)
496
void CVirtualFileSystem::_updateTexts(int iFromPage, int iToPage, FileList *pFileList, CTextDB *pTextList)
536
{
497
{
537
	// read all text files
498
	// read all text files
538
	for ( FileListItr itr = pFileList->begin(); itr != pFileList->end(); ++itr ) {
499
	for ( FileListItr itr = pFileList->begin(); itr != pFileList->end(); ++itr ) {
539
		Utils::String str = itr->first;
500
		Utils::String str = itr->first;
540
 
501
 
541
		if ( !m_sAddon.empty() ) {
502
		if ( !m_sAddon.empty() ) {
Line 543... Line 504...
543
				continue;
504
				continue;
544
		}
505
		}
545
		else {
506
		else {
546
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") )
507
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") )
547
				continue;
508
				continue;
548
		}
509
		}
549
 
510
 
550
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
511
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
551
		if ( !sTo.empty() ) {
512
		if ( !sTo.empty() ) {
552
			// add all texts into the map, id=(pageid, tid) data=text
513
			// add all texts into the map, id=(pageid, tid) data=text
553
			Utils::String baseFile = CFileIO(str).baseName();
514
			Utils::String baseFile = CFileIO(str).baseName();
554
			int lang = (baseFile.isin("-L")) ? baseFile.right(3) : baseFile.truncate(-4);
515
			int lang = (baseFile.isin("-L")) ? baseFile.right(3) : baseFile.truncate(-4);
555
 
516
 
556
			if ( m_iLang && lang != m_iLang ) continue;
517
			if ( m_iLang && lang != m_iLang ) continue;
557
			// open the text file to add
518
			// open the text file to add
558
			pTextList->parseTextFile(iFromPage, iToPage, sTo, lang);
519
			pTextList->parseTextFile(iFromPage, iToPage, sTo, lang);
559
		}
520
		}
560
	}
521
	}
561
}
522
}
562
 
523
 
563
void CVirtualFileSystem::clearMods(bool bIncludeStandard)
524
void CVirtualFileSystem::clearMods(bool bIncludeStandard)
564
{
525
{
565
	if ( bIncludeStandard ) {
526
	if ( bIncludeStandard ) {
Line 567... Line 528...
567
		m_pTexts = new CTextDB();
528
		m_pTexts = new CTextDB();
568
	}
529
	}
569
 
530
 
570
	if ( m_pModTexts ) delete m_pModTexts;
531
	if ( m_pModTexts ) delete m_pModTexts;
571
	m_pModTexts = new CTextDB();
532
	m_pModTexts = new CTextDB();
572
}
-
 
573
 
-
 
574
bool CVirtualFileSystem::loadShipData(CyStringList *list)
-
 
575
{
-
 
576
	bool ret = false;
-
 
577
 
-
 
578
	Utils::String sTo = this->ExtractGameFile("types/TShips.pck", CPackages::tempDirectory() + "tmp.dat");
-
 
579
	if ( !sTo.empty() ) {
-
 
580
		CFileIO File(sTo);
-
 
581
		CyStringList *lines = File.ReadLinesStr();
-
 
582
		if ( lines )
-
 
583
		{
-
 
584
			bool readFirst = false;
-
 
585
			for ( SStringList *str = lines->Head(); str; str = str->next )
-
 
586
			{
-
 
587
				if ( str->str.Empty() )
-
 
588
					continue;
-
 
589
				str->str.RemoveChar('\r');
-
 
590
				str->str.RemoveChar(9);
-
 
591
				str->str.RemoveFirstSpace();
-
 
592
				if ( str->str.Empty() )
-
 
593
					continue;
-
 
594
				if ( str->str[0] == '/' || str->str[0] == '#' )
-
 
595
					continue;
-
 
596
 
-
 
597
				if ( !readFirst )
-
 
598
					readFirst = true;
-
 
599
				else
-
 
600
				{
-
 
601
					CyString t = str->str.GetToken(";", -2);
-
 
602
					while ( t.Right(1) == ";" )
-
 
603
						t.Truncate((int)t.Length() - 1);
-
 
604
					list->PushBack(t, str->str);
-
 
605
				}
-
 
606
			}
-
 
607
 
-
 
608
			delete lines;
-
 
609
			ret = true;
-
 
610
		}
-
 
611
 
-
 
612
		File.remove();
-
 
613
	}
-
 
614
 
-
 
615
	return ret;
-
 
616
}
533
}
617
 
534
 
618
Utils::CStringList *CVirtualFileSystem::_updateList(const Utils::String &typesFile, int iTextPos)
535
Utils::CStringList *CVirtualFileSystem::_updateList(const Utils::String &typesFile, int iTextPos)
619
{
536
{
620
	Utils::CStringList *list = new Utils::CStringList();
537
	Utils::CStringList *list = new Utils::CStringList();
Line 681... Line 598...
681
 
598
 
682
void CVirtualFileSystem::_updateCockpits()
599
void CVirtualFileSystem::_updateCockpits()
683
{
600
{
684
	DELETELIST(_lCockpits);
601
	DELETELIST(_lCockpits);
685
	_lCockpits = _updateList("TCockpits", -1);
602
	_lCockpits = _updateList("TCockpits", -1);
-
 
603
}
-
 
604
 
-
 
605
void CVirtualFileSystem::_updateShips()
-
 
606
{
-
 
607
	DELETELIST(_lShips);
-
 
608
	_lShips = _updateList("TShips", -1);
686
}
609
}
687
 
610
 
688
void CVirtualFileSystem::_updateComponentSections()
611
void CVirtualFileSystem::_updateComponentSections()
689
{
612
{
690
	DELETELIST(_lComponentSections);
613
	DELETELIST(_lComponentSections);