Subversion Repositories spk

Rev

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

Rev 264 Rev 274
Line 28... Line 28...
28
	m_pModTexts = new CTextDB();
28
	m_pModTexts = new CTextDB();
29
 
29
 
30
	m_sAddon = L"";
30
	m_sAddon = L"";
31
 
31
 
32
	m_iLang = 0;
32
	m_iLang = 0;
-
 
33
 
-
 
34
	_lAddons = new Utils::WStringList();
-
 
35
	_lAddons->pushBack("addon2");
-
 
36
	_lAddons->pushBack("addon");
33
}
37
}
34
 
38
 
35
CVirtualFileSystem::~CVirtualFileSystem(void)
39
CVirtualFileSystem::~CVirtualFileSystem(void)
36
{
40
{
37
	_clear();
41
	_clear();
38
 
42
 
39
	if ( m_pTexts )		delete m_pTexts;
43
	if ( m_pTexts )		delete m_pTexts;
40
	if ( m_pModTexts )  delete m_pModTexts;
44
	if ( m_pModTexts )  delete m_pModTexts;
-
 
45
	if (_lAddons) delete _lAddons;
41
}
46
}
42
 
47
 
43
void CVirtualFileSystem::setAddon(const Utils::WString &addon)
48
void CVirtualFileSystem::setAddon(const Utils::WString &addon)
44
{ 
49
{ 
45
	m_sAddon = addon; 
50
	m_sAddon = addon; 
46
}
51
}
47
void CVirtualFileSystem::setLanguage(int iLang)
52
void CVirtualFileSystem::setLanguage(int iLang)
48
{
53
{
49
	m_iLang = iLang;
54
	m_iLang = iLang;
50
}
55
}
51
 
56
 
52
Utils::WString CVirtualFileSystem::firstShield()
57
Utils::WString CVirtualFileSystem::firstShield()
53
{
58
{
54
	if ( !_lShields || _lShields->empty() ) _updateShields();
59
	if ( !_lShields || _lShields->empty() ) _updateShields();
55
	return _returnText(_lShields->first());
60
	return _returnText(_lShields->first());
56
}
61
}
57
 
62
 
58
Utils::WString CVirtualFileSystem::nextShield()
63
Utils::WString CVirtualFileSystem::nextShield()
59
{
64
{
60
	return _returnText(_lShields->next());
65
	return _returnText(_lShields->next());
61
}
66
}
62
 
67
 
63
Utils::WString CVirtualFileSystem::firstComponentSection()
68
Utils::WString CVirtualFileSystem::firstComponentSection()
64
{
69
{
65
	if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
70
	if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
66
	return _returnLine(_lComponentSections->first());
71
	return _returnLine(_lComponentSections->first());
67
}
72
}
68
 
73
 
69
Utils::WString CVirtualFileSystem::nextComponentSection()
74
Utils::WString CVirtualFileSystem::nextComponentSection()
70
{
75
{
71
	return _returnLine(_lComponentSections->next());
76
	return _returnLine(_lComponentSections->next());
72
}
77
}
73
 
78
 
74
Utils::WString CVirtualFileSystem::firstDummySection()
79
Utils::WString CVirtualFileSystem::firstDummySection()
75
{
80
{
76
	if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
81
	if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
77
	return _returnLine(_lDummySections->first());
82
	return _returnLine(_lDummySections->first());
78
}
83
}
79
 
84
 
80
Utils::WString CVirtualFileSystem::nextDummySection()
85
Utils::WString CVirtualFileSystem::nextDummySection()
81
{
86
{
82
	return _returnLine(_lDummySections->next());
87
	return _returnLine(_lDummySections->next());
83
}
88
}
Line 254... Line 259...
254
{
259
{
255
	this->_addFile(sFile, sMod + L"::" + sFile, pList);
260
	this->_addFile(sFile, sMod + L"::" + sFile, pList);
256
}
261
}
257
 
262
 
258
bool CVirtualFileSystem::loadMod(const Utils::WString &mod)
263
bool CVirtualFileSystem::loadMod(const Utils::WString &mod)
259
{
264
{
260
	bool loaded = false;
265
	bool loaded = false;
261
 
266
 
262
	if ( !m_pModMap ) m_pModMap = new FileList;
267
	if ( !m_pModMap ) m_pModMap = new FileList;
263
 
268
 
264
	CCatFile cat;
269
	CCatFile cat;
265
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false))
270
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false))
266
	{
271
	{
267
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++) 
272
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++) 
268
		{
273
		{
269
			this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), mod, m_pModMap);
274
			this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), mod, m_pModMap);
270
			loaded = true;
275
			loaded = true;
271
		}
276
		}
272
	}
277
	}
273
 
278
 
274
	return loaded;
279
	return loaded;
275
}
280
}
276
 
281
 
277
bool CVirtualFileSystem::addMod(const Utils::WString &mod)
282
bool CVirtualFileSystem::addMod(const Utils::WString &mod)
278
{
283
{
Line 300... Line 305...
300
	if ( m_pTexts ) {
305
	if ( m_pTexts ) {
301
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
306
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
302
	}
307
	}
303
	if ( m_pModTexts ) {
308
	if ( m_pModTexts ) {
304
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->exists(iLang, iPage, iID);
309
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->exists(iLang, iPage, iID);
305
	}
310
	}
306
 
311
 
307
	return false;
312
	return false;
308
}
313
}
309
 
314
 
310
Utils::WString CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
315
Utils::WString CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
311
{
316
{
312
	if ( iLang <= 0 ) iLang = m_iLang;
317
	if ( iLang <= 0 ) iLang = m_iLang;
313
 
318
 
314
	if ( m_pTexts ) {
319
	if ( m_pTexts ) {
315
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
320
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
316
	}
321
	}
317
	if ( m_pModTexts ) {
322
	if ( m_pModTexts ) {
318
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
323
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
Line 320... Line 325...
320
 
325
 
321
	return Utils::WString(L"ReadText") + (long)iPage + L"-" + (long)iID;
326
	return Utils::WString(L"ReadText") + (long)iPage + L"-" + (long)iID;
322
}
327
}
323
 
328
 
324
const Utils::WString &CVirtualFileSystem::directory() const
329
const Utils::WString &CVirtualFileSystem::directory() const
325
{
330
{
326
	return m_sDir;
331
	return m_sDir;
327
}
332
}
328
 
333
 
329
bool CVirtualFileSystem::isFileAvailable(const Utils::WString &file) const
334
bool CVirtualFileSystem::isFileAvailable(const Utils::WString &file) const
330
{
335
{
331
	return !this->_findFile(file).empty();
336
	return !this->_findFile(file).empty();
332
}
337
}
333
 
338
 
334
bool CVirtualFileSystem::isTextUpdated() const
339
bool CVirtualFileSystem::isTextUpdated() const
335
{
340
{
Line 348... Line 353...
348
			if ( aitr != m_pModMap->end() ) return aitr->second;
353
			if ( aitr != m_pModMap->end() ) return aitr->second;
349
		}
354
		}
350
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilename().lower().c_str());
355
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilename().lower().c_str());
351
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilename().lower().c_str());
356
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilename().lower().c_str());
352
		if ( itr != m_pModMap->end() ) return itr->second;
357
		if ( itr != m_pModMap->end() ) return itr->second;
353
	}
358
	}
354
 
359
 
355
	if ( m_pMap && !m_pMap->empty() ) {
360
	if ( m_pMap && !m_pMap->empty() ) {
356
		if ( !m_sAddon.empty() ) {
361
		if ( !m_sAddon.empty() ) {
357
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + L"/" + toFile).fullFilename().lower().c_str());
362
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + L"/" + toFile).fullFilename().lower().c_str());
358
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + L"/" + file)).fullFilename().lower().c_str());
363
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + L"/" + file)).fullFilename().lower().c_str());
359
			if ( aitr != m_pMap->end() ) return aitr->second;
364
			if ( aitr != m_pMap->end() ) return aitr->second;
360
		}
365
		}
361
		FileListItr itr = m_pMap->find(CFileIO(file).fullFilename().lower().c_str());
366
		FileListItr itr = m_pMap->find(CFileIO(file).fullFilename().lower().c_str());
362
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).fullFilename().lower().c_str());
367
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).fullFilename().lower().c_str());
363
		if ( itr != m_pMap->end() ) return itr->second;
368
		if ( itr != m_pMap->end() ) return itr->second;
364
	}
369
	}
365
	return L"";
370
	return L"";
366
}
371
}
367
 
372
 
368
Utils::WString CVirtualFileSystem::_extractFromCat(const Utils::WString &sCat, const Utils::WString &sFile, const Utils::WString &sTo)
373
Utils::WString CVirtualFileSystem::_extractFromCat(const Utils::WString &sCat, const Utils::WString &sFile, const Utils::WString &sTo)
369
{
374
{
370
	CCatFile catFile;
375
	CCatFile catFile;
Line 376... Line 381...
376
			if ( catFile.extractFile(sFile) ) return sFile;
381
			if ( catFile.extractFile(sFile) ) return sFile;
377
		}
382
		}
378
	}
383
	}
379
 
384
 
380
	return L"";
385
	return L"";
381
}
386
}
382
 
387
 
383
Utils::WString CVirtualFileSystem::_extract(const Utils::WString &sFile, const Utils::WString &sTo)
388
Utils::WString CVirtualFileSystem::_extract(const Utils::WString &sFile, const Utils::WString &sTo)
384
{
389
{
385
	// check if we need to unpack the file
390
	// check if we need to unpack the file
386
	if ( CCatFile::CheckPackedExtension(sFile) ) {
391
	if ( CCatFile::CheckPackedExtension(sFile) ) {
387
		CFileIO File(sFile);
392
		CFileIO File(sFile);
388
		C_File f(File.fullFilename());
393
		C_File f(File.fullFilename());
389
		if ( !f.readFromFile(File) ) return L"";
394
		if ( !f.readFromFile(File) ) return L"";
390
		if ( !f.UnPCKFile() ) return L"";
395
		if ( !f.UnPCKFile() ) return L"";
391
		if ( !f.writeToFile(sTo) ) return L"";
396
		if ( !f.writeToFile(sTo) ) return L"";
392
		return sTo;
397
		return sTo;
393
	}
398
	}
394
	return sFile;
399
	return sFile;
395
}
400
}
396
 
401
 
397
Utils::WString CVirtualFileSystem::extractGameFile(const Utils::WString &file, const Utils::WString &to)
402
Utils::WString CVirtualFileSystem::extractGameFile(const Utils::WString &file, const Utils::WString &to)
398
{
403
{
399
	Utils::WString sIn = _findFile(file);
404
	Utils::WString sIn;
400
	Utils::WString sFile = file;
405
	Utils::WString sFile;
-
 
406
 
-
 
407
	if (!m_sAddon.empty())
-
 
408
	{
-
 
409
		sIn = _findFile(m_sAddon + L"\\" + file);
-
 
410
		sFile = m_sAddon + L"\\" + file;
-
 
411
		if (sIn.empty())
-
 
412
		{
-
 
413
			sIn = _findFile(file);
-
 
414
			sFile = file;
-
 
415
		}
-
 
416
	}
-
 
417
	else
-
 
418
	{
-
 
419
		sIn = _findFile(file);
-
 
420
		sFile = file;
-
 
421
	}
-
 
422
 
-
 
423
	if (sIn.empty() && _lAddons)
-
 
424
	{
-
 
425
		for (auto itr = _lAddons->begin(); itr != _lAddons->end(); itr++)
-
 
426
		{
-
 
427
			sIn = _findFile((*itr)->str + L"\\" + file);
-
 
428
			sFile = (*itr)->str + L"\\" + file;
-
 
429
			if (!sIn.empty())
-
 
430
				break;
-
 
431
		}
-
 
432
	}
401
 
433
 
402
	if (sIn.empty()) return L"";
434
	if (sIn.empty())
-
 
435
		return L"";
403
 
436
 
404
	if (sIn.contains(L"::"))
437
	if (sIn.contains(L"::"))
405
	{
438
	{
406
		sFile = sIn.token(L"::", 2);
439
		sFile = sIn.token(L"::", 2);
407
		sIn = sIn.token(L"::", 1);
440
		sIn = sIn.token(L"::", 1);
Line 478... Line 511...
478
	//TODO: check for better finding of files in map
511
	//TODO: check for better finding of files in map
479
	for ( FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); ++itr ) {
512
	for ( FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); ++itr ) {
480
		Utils::WString str = itr->first;
513
		Utils::WString str = itr->first;
481
 
514
 
482
		if ( !m_sAddon.empty() ) {
515
		if ( !m_sAddon.empty() ) {
483
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L&quot;/t/";) &&amp; !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L"\\t\\") )
516
			if ( !str.left(static_cast&lt;long>;(m_sAddon.length()) + 3).Compare(m_sAddon + L"/t/";) &&amp; !str.left(static_cast<long>(m_sAddon.length()) + 3).Compare(m_sAddon + L"\\t\\") )
484
				continue;
517
				continue;
485
		}
518
		}
486
		else {
519
		else {
487
			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/") )
520
			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;
521
				continue;
Line 537... Line 570...
537
	// read all text files
570
	// read all text files
538
	for ( FileListItr itr = pFileList->begin(); itr != pFileList->end(); ++itr ) {
571
	for ( FileListItr itr = pFileList->begin(); itr != pFileList->end(); ++itr ) {
539
		Utils::WString str = itr->first;
572
		Utils::WString str = itr->first;
540
 
573
 
541
		if ( !m_sAddon.empty() ) {
574
		if ( !m_sAddon.empty() ) {
542
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L&quot;/t/";) &&amp; !str.left(m_sAddon.length() + 3).Compare(m_sAddon + L"\\t\\") )
575
			if ( !str.left(static_cast&lt;long>;(m_sAddon.length()) + 3).Compare(m_sAddon + L"/t/";) &&amp; !str.left(static_cast<long>(m_sAddon.length()) + 3).Compare(m_sAddon + L"\\t\\") )
543
				continue;
576
				continue;
544
		}
577
		}
545
		else {
578
		else {
546
			if ( !str.left(2).Compare(L"t\\") && !str.left(2).Compare(L"t/") )
579
			if ( !str.left(2).Compare(L"t\\") && !str.left(2).Compare(L"t/") )
547
				continue;
580
				continue;