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