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 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
	}
Line 285... Line 282...
285
	}
282
	}
286
 
283
 
287
	return Utils::String("ReadText") + (long)iPage + "-" + (long)iID;
284
	return Utils::String("ReadText") + (long)iPage + "-" + (long)iID;
288
}
285
}
289
 
286
 
-
 
287
const Utils::String &CVirtualFileSystem::directory() const
-
 
288
{
-
 
289
	return m_sDir;
-
 
290
}
-
 
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
}
294
 
296
 
-
 
297
bool CVirtualFileSystem::isTextUpdated() const
-
 
298
{
-
 
299
	if ( m_pTexts ) return m_pTexts->anyTextLoaded();
-
 
300
	return false;
-
 
301
}
-
 
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
 
299
	if ( m_pModMap && !m_pModMap->empty() ) {
307
	if ( m_pModMap && !m_pModMap->empty() ) {
Line 387... Line 395...
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);
Line 470... Line 428...
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
Line 569... Line 530...
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
}
533
}
573
 
534
 
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
}
-
 
617
 
-
 
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();
621
 
538
 
622
	Utils::String file = this->ExtractGameFile("types\\" + typesFile + ".pck", CPackages::tempDirectory() + "/" + typesFile + ".txt");
539
	Utils::String file = this->ExtractGameFile("types\\" + typesFile + ".pck", CPackages::tempDirectory() + "/" + typesFile + ".txt");
Line 683... Line 600...
683
{
600
{
684
	DELETELIST(_lCockpits);
601
	DELETELIST(_lCockpits);
685
	_lCockpits = _updateList("TCockpits", -1);
602
	_lCockpits = _updateList("TCockpits", -1);
686
}
603
}
687
 
604
 
-
 
605
void CVirtualFileSystem::_updateShips()
-
 
606
{
-
 
607
	DELETELIST(_lShips);
-
 
608
	_lShips = _updateList("TShips", -1);
-
 
609
}
-
 
610
 
688
void CVirtualFileSystem::_updateComponentSections()
611
void CVirtualFileSystem::_updateComponentSections()
689
{
612
{
690
	DELETELIST(_lComponentSections);
613
	DELETELIST(_lComponentSections);
691
 
614
 
692
	_lComponentSections = new Utils::CStringList();
615
	_lComponentSections = new Utils::CStringList();