Subversion Repositories spk

Rev

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

Rev 85 Rev 94
Line 1... Line 1...
1
 
1
 
2
#include "VirtualFileSystem.h"
2
#include "VirtualFileSystem.h"
3
#include "File_IO.h"
3
#include "File_IO.h"
4
#include "CatFile.h"
4
#include "CatFile.h"
5
#include "XspFile.h"
5
#include "XspFile.h"
-
 
6
#include "TextDB.h"
6
 
7
 
7
#include "Packages.h"
8
#include "Packages.h"
-
 
9
#include "Utils/StringList.h"
-
 
10
 
-
 
11
#define DELETELIST(list) if ( list ) { list->MemoryClear(); delete list; }
8
 
12
 
9
namespace SPK {
13
namespace SPK {
10
 
14
 
11
CVirtualFileSystem::CVirtualFileSystem()
15
CVirtualFileSystem::CVirtualFileSystem() : _lShields(NULL),
-
 
16
	_lLasers(NULL),
-
 
17
	_lMissiles(NULL),
-
 
18
	_lCockpits(NULL),
-
 
19
	_lComponentSections(NULL),
-
 
20
	_lDummySections(NULL),
-
 
21
	_lBodiesSections(NULL)
12
{
22
{
13
	m_bLoaded = false;
23
	m_bLoaded = false;
14
	m_pMap = new FileList;
24
	m_pMap = new FileList;
15
	m_pModMap = new FileList;
25
	m_pModMap = new FileList;
16
 
26
 
17
	m_pTexts = new CTextDB();
27
	m_pTexts = new CTextDB();
18
	m_pModTexts = new CTextDB();
28
	m_pModTexts = new CTextDB();
19
 
29
 
20
	m_sAddon = "";
30
	m_sAddon = "";
21
 
31
 
22
	m_iLang = 0;
32
	m_iLang = 0;
23
}
33
}
24
 
34
 
25
CVirtualFileSystem::~CVirtualFileSystem(void)
35
CVirtualFileSystem::~CVirtualFileSystem(void)
26
{
36
{
27
	if ( m_pMap )		delete m_pMap;
37
	if ( m_pMap )		delete m_pMap;
28
	if ( m_pModMap )	delete m_pModMap;
38
	if ( m_pModMap )	delete m_pModMap;
29
 
39
 
30
	if ( m_pTexts )		delete m_pTexts;
40
	if ( m_pTexts )		delete m_pTexts;
31
	if ( m_pModTexts )  delete m_pModTexts;
41
	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);
32
}
50
}
33
 
51
 
34
void CVirtualFileSystem::setLanguage(int iLang)
52
void CVirtualFileSystem::setLanguage(int iLang)
35
{
53
{
36
	m_iLang = iLang;
54
	m_iLang = iLang;
37
}
55
}
-
 
56
 
-
 
57
Utils::String CVirtualFileSystem::firstShield()
-
 
58
{
-
 
59
	if ( !_lShields || _lShields->empty() ) _updateShields();
-
 
60
	return _returnText(_lShields->First());
-
 
61
}
-
 
62
 
-
 
63
Utils::String CVirtualFileSystem::nextShield()
-
 
64
{
-
 
65
	return _returnText(_lShields->Next());
-
 
66
}
-
 
67
 
-
 
68
Utils::String CVirtualFileSystem::firstComponentSection()
-
 
69
{
-
 
70
	if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
-
 
71
	return _returnLine(_lComponentSections->First());
-
 
72
}
-
 
73
 
-
 
74
Utils::String CVirtualFileSystem::nextComponentSection()
-
 
75
{
-
 
76
	return _returnLine(_lComponentSections->Next());
-
 
77
}
-
 
78
 
-
 
79
Utils::String CVirtualFileSystem::firstDummySection()
-
 
80
{
-
 
81
	if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
-
 
82
	return _returnLine(_lDummySections->First());
-
 
83
}
-
 
84
 
-
 
85
Utils::String CVirtualFileSystem::nextDummySection()
-
 
86
{
-
 
87
	return _returnLine(_lDummySections->Next());
-
 
88
}
-
 
89
 
-
 
90
Utils::String CVirtualFileSystem::firstBodiesSection()
-
 
91
{
-
 
92
	if ( !_lBodiesSections || _lBodiesSections->empty() ) _updateBodiesSections();
-
 
93
	return _returnLine(_lBodiesSections->First());
-
 
94
}
-
 
95
 
-
 
96
Utils::String CVirtualFileSystem::nextBodiesSection()
-
 
97
{
-
 
98
	return _returnLine(_lBodiesSections->Next());
-
 
99
}
-
 
100
 
-
 
101
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextLaser()
-
 
102
{
-
 
103
	return _returnPair(_lLasers->Next());
-
 
104
}
-
 
105
 
-
 
106
std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstLaser()
-
 
107
{
-
 
108
	if ( !_lLasers || _lLasers->empty() ) _updateLasers();
-
 
109
	return _returnPair(_lLasers->First());
-
 
110
}
-
 
111
 
-
 
112
std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstMissile()
-
 
113
{
-
 
114
	if ( !_lMissiles || _lMissiles->empty() ) _updateMissiles();
-
 
115
	return _returnPair(_lMissiles->First());
-
 
116
}
-
 
117
 
-
 
118
std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextMissile()
-
 
119
{
-
 
120
	return _returnPair(_lMissiles->Next());
-
 
121
}
-
 
122
 
-
 
123
Utils::String CVirtualFileSystem::firstCockpit()
-
 
124
{
-
 
125
	if ( !_lCockpits || _lCockpits->empty() ) _updateCockpits();
-
 
126
	return _returnID(_lCockpits->First());
-
 
127
}
-
 
128
 
-
 
129
Utils::String CVirtualFileSystem::nextCockpit()
-
 
130
{
-
 
131
	return _returnID(_lCockpits->Next());
-
 
132
}
-
 
133
 
-
 
134
std::pair<Utils::String, Utils::String> CVirtualFileSystem::_returnPair(Utils::SStringList *s)
-
 
135
{
-
 
136
	if ( s && !s->data.empty() && !s->data.left(8).Compare("ReadText") ) return std::make_pair<Utils::String, Utils::String>(s->str, s->data);
-
 
137
	if ( s ) return std::make_pair<Utils::String, Utils::String>(s->str, s->str.token(";", -2));
-
 
138
	return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
-
 
139
}
-
 
140
 
-
 
141
Utils::String CVirtualFileSystem::_returnText(Utils::SStringList *s)
-
 
142
{
-
 
143
	if ( s && !s->data.empty() && !s->data.left(8).Compare("ReadText") ) return s->data;
-
 
144
	if ( s ) return s->str.token(";", -2);
-
 
145
	return Utils::String::Null();
-
 
146
}
-
 
147
 
-
 
148
Utils::String CVirtualFileSystem::_returnID(Utils::SStringList *s)
-
 
149
{
-
 
150
	if ( s ) return s->str.token(";", -2);
-
 
151
	return Utils::String::Null();
-
 
152
}
-
 
153
 
-
 
154
Utils::String CVirtualFileSystem::_returnLine(Utils::SStringList *s)
-
 
155
{
-
 
156
	if ( s ) return s->str;
-
 
157
	return Utils::String::Null();
-
 
158
}
-
 
159
 
38
 
160
 
39
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, int maxPatch)
161
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, int maxPatch)
40
{
162
{
41
	return this->LoadFilesystem(dir, "", maxPatch);
163
	return this->LoadFilesystem(dir, "", maxPatch);
42
}
164
}
Line 137... Line 259...
137
	return loaded;
259
	return loaded;
138
}
260
}
139
 
261
 
140
bool CVirtualFileSystem::textExists(int iLang, int iPage, int iID) const
262
bool CVirtualFileSystem::textExists(int iLang, int iPage, int iID) const
141
{
263
{
-
 
264
	if ( iLang <= 0 ) iLang = m_iLang;
-
 
265
 
142
	if ( m_pTexts ) {
266
	if ( m_pTexts ) {
143
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
267
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
144
	}
268
	}
145
	if ( m_pModTexts ) {
269
	if ( m_pModTexts ) {
146
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->exists(iLang, iPage, iID);
270
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->exists(iLang, iPage, iID);
147
	}
271
	}
148
 
272
 
149
	return false;
273
	return false;
150
}
274
}
151
 
275
 
152
Utils::String CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
276
Utils::String CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
153
{
277
{
-
 
278
	if ( iLang <= 0 ) iLang = m_iLang;
-
 
279
 
154
	if ( m_pTexts ) {
280
	if ( m_pTexts ) {
155
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
281
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
156
	}
282
	}
157
	if ( m_pModTexts ) {
283
	if ( m_pModTexts ) {
158
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
284
		if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
Line 366... Line 492...
366
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "\\t\\") )
492
			if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "\\t\\") )
367
				continue;
493
				continue;
368
		}
494
		}
369
		else {
495
		else {
370
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") && !str.left(8).Compare("addon\t\\") && !str.left(8).Compare("addon/t/") )
496
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") && !str.left(8).Compare("addon\t\\") && !str.left(8).Compare("addon/t/") )
371
				continue;
497
				continue;
372
		}
498
		}
373
 
499
 
374
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
500
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
375
		if ( !sTo.empty() ) {
501
		if ( !sTo.empty() ) {
376
			pPackage->AddTextFromFile(sTo, textId);
502
			pPackage->AddTextFromFile(sTo, textId);
Line 487... Line 613...
487
	}
613
	}
488
 
614
 
489
	return ret;
615
	return ret;
490
}
616
}
491
 
617
 
-
 
618
Utils::CStringList *CVirtualFileSystem::_updateList(const Utils::String &typesFile, int iTextPos)
-
 
619
{
-
 
620
	Utils::CStringList *list = new Utils::CStringList();
-
 
621
 
-
 
622
	Utils::String file = this->ExtractGameFile("types\\" + typesFile + ".pck", CPackages::tempDirectory() + "/" + typesFile + ".txt");
-
 
623
 
-
 
624
	CFileIO f(file);
-
 
625
 
-
 
626
	if ( f.exists() && f.startRead() ) {
-
 
627
		int itemsLeft = -1;
-
 
628
 
-
 
629
		while(!f.atEnd()) {
-
 
630
			// read the next line
-
 
631
			Utils::String line = f.readEndOfLine();
-
 
632
 
-
 
633
			// remove the unneeded characters
-
 
634
			line.removeChar('\r');
-
 
635
			line.removeChar(9);
-
 
636
			line.removeFirstSpace();
-
 
637
 
-
 
638
			// blank line ? skip it
-
 
639
			if ( line.empty() ) continue;
-
 
640
			// skip anything starting with / as its a comment
-
 
641
			if ( line[0] == '/' ) continue;
-
 
642
 
-
 
643
			// first line is the count
-
 
644
			if ( itemsLeft == -1 )
-
 
645
				itemsLeft = line.token(";", 2);
-
 
646
			else {
-
 
647
				if ( iTextPos == 0 )
-
 
648
					list->pushBack(line, line);
-
 
649
				else if ( iTextPos == -1 ) 
-
 
650
					list->pushBack(line, line.token(";", -2));
-
 
651
				else
-
 
652
					list->pushBack(line, this->findText(m_iLang, TEXTPAGE_OBJECTS, line.token(";", iTextPos).toLong()));
-
 
653
				--itemsLeft;
-
 
654
			}
-
 
655
		}
-
 
656
		
-
 
657
		f.close();
-
 
658
		f.remove();
-
 
659
	}
-
 
660
 
-
 
661
	return list;
-
 
662
}
-
 
663
 
-
 
664
void CVirtualFileSystem::_updateShields()
-
 
665
{
-
 
666
	DELETELIST(_lShields);
-
 
667
	_lShields = _updateList("TShields", 7);
-
 
668
}
-
 
669
 
-
 
670
void CVirtualFileSystem::_updateLasers()
-
 
671
{
-
 
672
	DELETELIST(_lLasers);
-
 
673
	_lLasers = _updateList("TLaser", 7);
-
 
674
}
-
 
675
 
-
 
676
void CVirtualFileSystem::_updateMissiles()
-
 
677
{
-
 
678
	DELETELIST(_lMissiles);
-
 
679
	_lMissiles = _updateList("TMissiles", 7);
-
 
680
}
-
 
681
 
-
 
682
void CVirtualFileSystem::_updateCockpits()
-
 
683
{
-
 
684
	DELETELIST(_lCockpits);
-
 
685
	_lCockpits = _updateList("TCockpits", -1);
-
 
686
}
-
 
687
 
-
 
688
void CVirtualFileSystem::_updateComponentSections()
-
 
689
{
-
 
690
	DELETELIST(_lComponentSections);
-
 
691
 
-
 
692
	_lComponentSections = new Utils::CStringList();
-
 
693
 
-
 
694
	Utils::String file = this->ExtractGameFile("types\\Components.pck", CPackages::tempDirectory() + "/Components.txt");
-
 
695
 
-
 
696
	CFileIO f(file);
-
 
697
 
-
 
698
	if ( f.exists() && f.startRead() ) {
-
 
699
		int sectionRemaining = 0;
-
 
700
		int itemsRemaining = 0;
-
 
701
 
-
 
702
		while(!f.atEnd()) {
-
 
703
			// read the next line
-
 
704
			Utils::String line = f.readEndOfLine();
-
 
705
 
-
 
706
			// remove the unneeded characters
-
 
707
			line.removeChar('\r');
-
 
708
			line.removeChar(9);
-
 
709
			line.removeFirstSpace();
-
 
710
 
-
 
711
			// blank line ? skip it
-
 
712
			if ( line.empty() ) continue;
-
 
713
			// skip anything starting with / as its a comment
-
 
714
			if ( line[0] == '/' ) continue;
-
 
715
 
-
 
716
			if ( itemsRemaining )
-
 
717
				--itemsRemaining;
-
 
718
			else if ( !sectionRemaining )
-
 
719
			{
-
 
720
				sectionRemaining = line.token(";", 2).toLong();
-
 
721
				Utils::String section = line.token(";", 1);
-
 
722
				if ( !section.empty() )
-
 
723
					_lComponentSections->pushBack(section, section);
-
 
724
			}
-
 
725
			else if ( !itemsRemaining )
-
 
726
			{
-
 
727
				itemsRemaining = line.token(";", 2).toLong();
-
 
728
				--sectionRemaining;
-
 
729
			}
-
 
730
		}
-
 
731
		
-
 
732
		f.close();
-
 
733
		f.remove();
-
 
734
	}
-
 
735
 
-
 
736
	if ( _lComponentSections->empty() )
-
 
737
	{
-
 
738
		_lComponentSections->pushBack("SCTYPE_LASER", "SCTYPE_LASER");
-
 
739
		_lComponentSections->pushBack("SCTYPE_COCKPIT", "SCTYPE_COCKPIT");
-
 
740
		_lComponentSections->pushBack("SCTYPE_DOCKING", "SCTYPE_DOCKING");
-
 
741
	}
-
 
742
}
-
 
743
 
-
 
744
Utils::CStringList *CVirtualFileSystem::_updateSectionList(const Utils::String &sFile, bool singleEntry)
-
 
745
{
-
 
746
	Utils::CStringList *list = new Utils::CStringList();
-
 
747
 
-
 
748
	Utils::String file = this->ExtractGameFile("types\\" + sFile + ".pck", CPackages::tempDirectory() + "/" + sFile + ".txt");
-
 
749
 
-
 
750
	CFileIO f(file);
-
 
751
 
-
 
752
	if ( f.exists() && f.startRead() ) {
-
 
753
		int sectionRemaining = 0;
-
 
754
 
-
 
755
		while(!f.atEnd()) {
-
 
756
			// read the next line
-
 
757
			Utils::String line = f.readEndOfLine();
-
 
758
 
-
 
759
			// remove the unneeded characters
-
 
760
			line.removeChar('\r');
-
 
761
			line.removeChar(9);
-
 
762
			line.removeFirstSpace();
-
 
763
 
-
 
764
			// blank line ? skip it
-
 
765
			if ( line.empty() ) continue;
-
 
766
			// skip anything starting with / as its a comment
-
 
767
			if ( line[0] == '/' ) continue;
-
 
768
 
-
 
769
			if ( !sectionRemaining )
-
 
770
			{
-
 
771
				sectionRemaining = line.token(";", 2).toLong();
-
 
772
				Utils::String section = line.token(";", 1);
-
 
773
				if ( !section.empty() )
-
 
774
					list->pushBack(section, section);
-
 
775
			}
-
 
776
			else {
-
 
777
				if ( singleEntry )
-
 
778
					sectionRemaining -= (line.countToken(";") - 1);
-
 
779
				else 
-
 
780
					--sectionRemaining;
-
 
781
			}
-
 
782
		}
-
 
783
		
-
 
784
		f.close();
-
 
785
		f.remove();
-
 
786
	}
-
 
787
 
-
 
788
	return list;
-
 
789
}
-
 
790
 
-
 
791
void CVirtualFileSystem::_updateDummySections()
-
 
792
{
-
 
793
	DELETELIST(_lDummySections);
-
 
794
 
-
 
795
	_lDummySections = _updateSectionList("Dummies", false);
-
 
796
 
-
 
797
	if ( _lDummySections->empty() )
-
 
798
	{
-
 
799
		_lDummySections->pushBack("SDTYPE_ANIMATED", "SDTYPE_ANIMATED");
-
 
800
		_lDummySections->pushBack("SDTYPE_DOCK", "SDTYPE_DOCK");
-
 
801
		_lDummySections->pushBack("SDTYPE_DOORWAY", "SDTYPE_DOORWAY");
-
 
802
		_lDummySections->pushBack("SDTYPE_GUN", "SDTYPE_GUN");
-
 
803
		_lDummySections->pushBack("SDTYPE_CONNECTION", "SDTYPE_CONNECTION");
-
 
804
	}
-
 
805
}
-
 
806
 
-
 
807
void CVirtualFileSystem::_updateBodiesSections()
-
 
808
{
-
 
809
	DELETELIST(_lBodiesSections);
-
 
810
 
-
 
811
	_lBodiesSections = _updateSectionList("Bodies", true);
-
 
812
 
-
 
813
	if ( _lBodiesSections->empty() )
-
 
814
	{
-
 
815
		_lBodiesSections->pushBack("SBTYPE_2D", "SBTYPE_2D");
-
 
816
		_lBodiesSections->pushBack("SBTYPE_FACECAMERA", "SBTYPE_FACECAMERA");
-
 
817
		_lBodiesSections->pushBack("SBTYPE_2D2", "SBTYPE_2D2");
-
 
818
		_lBodiesSections->pushBack("SBTYPE_2DY", "SBTYPE_2DY");
-
 
819
		_lBodiesSections->pushBack("SBTYPE_LOGO", "SBTYPE_LOGO");
-
 
820
		_lBodiesSections->pushBack("SBTYPE_FC", "SBTYPE_FC");
-
 
821
		_lBodiesSections->pushBack("SBTYPE_TURRET", "SBTYPE_TURRET");
-
 
822
		_lBodiesSections->pushBack("SBTYPE_JET", "SBTYPE_JET");
-
 
823
		_lBodiesSections->pushBack("SBTYPE_RADAR", "SBTYPE_RADAR");
-
 
824
		_lBodiesSections->pushBack("SBTYPE_CONTAINER", "SBTYPE_CONTAINER");
-
 
825
		_lBodiesSections->pushBack("SBTYPE_DISPLAY", "SBTYPE_DISPLAY");
-
 
826
		_lBodiesSections->pushBack("SBTYPE_DOCKPOINT", "SBTYPE_DOCKPOINT");
-
 
827
		_lBodiesSections->pushBack("SBTYPE_SMALLJET", "SBTYPE_SMALLJET");
-
 
828
	}
-
 
829
}
492
 
830
 
493
} //NAMESPACE
831
} //NAMESPACE