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