94 |
cycrow |
1 |
|
|
|
2 |
#include "GameDirectories.h"
|
|
|
3 |
#include "GameExe.h"
|
|
|
4 |
#include "Packages.h"
|
95 |
cycrow |
5 |
#include "GameExe.h"
|
94 |
cycrow |
6 |
|
|
|
7 |
namespace SPK {
|
|
|
8 |
|
95 |
cycrow |
9 |
CGameDirectories::CGameDirectories(const Utils::String &mydoc) : _pSelected(NULL),
|
94 |
cycrow |
10 |
_pCurrentItr(NULL),
|
|
|
11 |
_iLanguage(0)
|
|
|
12 |
{
|
|
|
13 |
_pDirs = new std::vector<SGameDir *>();
|
95 |
cycrow |
14 |
|
|
|
15 |
_updateControlledDirs(mydoc);
|
94 |
cycrow |
16 |
}
|
|
|
17 |
|
|
|
18 |
CGameDirectories::~CGameDirectories(void)
|
|
|
19 |
{
|
|
|
20 |
clear();
|
|
|
21 |
delete _pDirs;
|
112 |
cycrow |
22 |
_lControlledDirs.clear();
|
94 |
cycrow |
23 |
}
|
|
|
24 |
|
|
|
25 |
bool CGameDirectories::add(const Utils::String &dir, const Utils::String &name, int iGame, const Utils::String &addon, bool bLoad)
|
|
|
26 |
{
|
|
|
27 |
for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
|
|
|
28 |
if ( dir.Compare((*itr)->dir) ) return false;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
_add(dir, name, iGame, addon, bLoad);
|
|
|
32 |
return true;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
bool CGameDirectories::remove(const Utils::String &dir)
|
|
|
36 |
{
|
|
|
37 |
for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
|
|
|
38 |
if ( dir.Compare((*itr)->dir) ) {
|
|
|
39 |
delete (*itr);
|
|
|
40 |
_pDirs->erase(itr);
|
|
|
41 |
return true;
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
return false;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
bool CGameDirectories::findDir(const Utils::String &dir)
|
|
|
49 |
{
|
|
|
50 |
SGameDir *d = _findGameDir(dir);
|
|
|
51 |
if ( d ) {
|
|
|
52 |
_pCurrentItr = d;
|
|
|
53 |
return true;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
return false;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
bool CGameDirectories::parse(const Utils::String &data, CPackages *pPackages)
|
|
|
60 |
{
|
|
|
61 |
int iGame = data.token(";", 2).tokens(" ", 1).toLong();
|
|
|
62 |
SGameExe *exe = pPackages->GetGameExe()->GetGame(iGame);
|
|
|
63 |
_add(data.token(";", 1), data.token(";", 2).tokens(" ", 2), iGame, (exe) ? exe->sAddon : Utils::String::Null(), data.token(";", 3).toBool());
|
|
|
64 |
|
|
|
65 |
return true;
|
|
|
66 |
}
|
|
|
67 |
|
123 |
cycrow |
68 |
bool CGameDirectories::writeData(Utils::CStringList *lines)
|
94 |
cycrow |
69 |
{
|
|
|
70 |
bool writeAny = false;
|
|
|
71 |
for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
|
|
|
72 |
SGameDir *gd = *itr;
|
123 |
cycrow |
73 |
lines->pushBack("GameDir:" + gd->dir + ";" + Utils::String::Number(gd->iGame) + " " + gd->name + ((gd->bLoad) ? ";1" : ";0"));
|
94 |
cycrow |
74 |
writeAny = true;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
return writeAny;
|
|
|
78 |
}
|
|
|
79 |
|
101 |
cycrow |
80 |
void CGameDirectories::updateCurrentVFS(bool bReload)
|
94 |
cycrow |
81 |
{
|
|
|
82 |
if ( !_pCurrentItr ) return;
|
|
|
83 |
|
101 |
cycrow |
84 |
// dont load text if its already been loaded, unless we need to reload them
|
|
|
85 |
if ( !bReload && _pCurrentItr->pVfs->isTextUpdated() ) return;
|
|
|
86 |
|
|
|
87 |
// update the texts for all pages
|
94 |
cycrow |
88 |
_pCurrentItr->pVfs->updateTexts(0);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
void CGameDirectories::clear()
|
|
|
92 |
{
|
|
|
93 |
for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
|
|
|
94 |
delete *itr;
|
|
|
95 |
}
|
|
|
96 |
_pDirs->clear();
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
bool CGameDirectories::setSelectedGameDirectory(int iGame, bool temp)
|
|
|
100 |
{
|
|
|
101 |
_pTemporary = NULL;
|
|
|
102 |
if ( temp ) _pTemporary = _pSelected;
|
|
|
103 |
_pSelected = _findGameDir(iGame);
|
|
|
104 |
return hasSelected();
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
bool CGameDirectories::setSelectedDirectory(const Utils::String &dir, bool temp)
|
|
|
108 |
{
|
|
|
109 |
_pTemporary = NULL;
|
|
|
110 |
if ( temp ) _pTemporary = _pSelected;
|
|
|
111 |
_pSelected = _findGameDir(dir);
|
|
|
112 |
return hasSelected();
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
void CGameDirectories::reselectTemporaryDirectory()
|
|
|
116 |
{
|
|
|
117 |
if ( _pTemporary ) _pSelected = _pTemporary;
|
|
|
118 |
_pTemporary = NULL;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
void CGameDirectories::setLanguage(int iLang)
|
|
|
122 |
{
|
|
|
123 |
_iLanguage = iLang;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
void CGameDirectories::setLoad(bool bLoad)
|
|
|
127 |
{
|
|
|
128 |
if ( _pCurrentItr ) _pCurrentItr->bLoad = bLoad;
|
|
|
129 |
}
|
|
|
130 |
|
101 |
cycrow |
131 |
bool CGameDirectories::isAllTextLoaded() const
|
|
|
132 |
{
|
|
|
133 |
for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
|
|
|
134 |
if ( !(*itr)->pVfs->isTextUpdated() ) return false;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
return true;
|
|
|
138 |
}
|
|
|
139 |
|
94 |
cycrow |
140 |
bool CGameDirectories::isDir(const Utils::String &dir) const
|
|
|
141 |
{
|
|
|
142 |
for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
|
|
|
143 |
if ( dir.Compare((*itr)->dir) ) return true;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
return false;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
bool CGameDirectories::hasSelected() const
|
|
|
150 |
{
|
|
|
151 |
return (_pSelected) ? true : false;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
bool CGameDirectories::isEmpty() const
|
|
|
155 |
{
|
|
|
156 |
return _pDirs->empty();
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
int CGameDirectories::highestGame() const
|
|
|
160 |
{
|
|
|
161 |
int highest = 1;
|
|
|
162 |
for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
|
|
|
163 |
if ( (*itr)->iGame > highest )
|
|
|
164 |
highest = (*itr)->iGame;
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
return highest;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
Utils::String CGameDirectories::currentName() const
|
|
|
171 |
{
|
|
|
172 |
if ( !_pCurrentItr ) return Utils::String::Null();
|
|
|
173 |
return _pCurrentItr->name;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
int CGameDirectories::currentGame() const
|
|
|
177 |
{
|
|
|
178 |
if ( !_pCurrentItr ) return -1;
|
|
|
179 |
return _pCurrentItr->iGame;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
bool CGameDirectories::currentLoad() const
|
|
|
183 |
{
|
|
|
184 |
if ( !_pCurrentItr ) return false;
|
|
|
185 |
return _pCurrentItr->bLoad;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
CVirtualFileSystem *CGameDirectories::selectedVFS() const
|
|
|
189 |
{
|
|
|
190 |
if ( _pSelected ) return _pSelected->pVfs;
|
|
|
191 |
return NULL;
|
|
|
192 |
}
|
|
|
193 |
|
95 |
cycrow |
194 |
void CGameDirectories::syncWithControlled(CGameExe *exe)
|
|
|
195 |
{
|
112 |
cycrow |
196 |
for(Utils::CStringListIterator itr = _lControlledDirs.begin(); itr != _lControlledDirs.end(); itr++) {
|
|
|
197 |
add(exe->GetProperDir((*itr)->str), (*itr)->data, exe->GetGameType((*itr)->str), exe->GetAddonDir((*itr)->str), true);
|
95 |
cycrow |
198 |
}
|
|
|
199 |
}
|
|
|
200 |
|
94 |
cycrow |
201 |
Utils::String CGameDirectories::findText(int iLanguage, int iPage, int iID, Utils::String missing)
|
|
|
202 |
{
|
|
|
203 |
if ( iLanguage == 0 ) iLanguage = _iLanguage;
|
|
|
204 |
if ( _pSelected ) {
|
|
|
205 |
if ( _pSelected->pVfs->textExists(iLanguage, iPage, iID) ) {
|
|
|
206 |
return _pSelected->pVfs->findText(iLanguage, iPage, iID);
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
return missing;
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
Utils::String CGameDirectories::findText(int iGame, int iLanguage, int iPage, int iID)
|
|
|
214 |
{
|
|
|
215 |
if ( iLanguage == 0 ) iLanguage = _iLanguage;
|
|
|
216 |
if ( iGame == -1 ) {
|
|
|
217 |
for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
|
|
|
218 |
SGameDir *gd = _findGameDir(game - 1);
|
|
|
219 |
if ( !gd ) continue;
|
|
|
220 |
if ( gd->pVfs->textExists(iLanguage, iPage, iID) ) {
|
|
|
221 |
return gd->pVfs->findText(iLanguage, iPage, iID);
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
else {
|
|
|
226 |
SGameDir *gd = _findGameDir(iGame);
|
|
|
227 |
if ( gd ) {
|
|
|
228 |
if ( gd->pVfs->textExists(iLanguage, iPage, iID) ) {
|
|
|
229 |
return gd->pVfs->findText(iLanguage, iPage, iID);
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
return Utils::String::Null();
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
Utils::String CGameDirectories::first(int iGame)
|
|
|
238 |
{
|
|
|
239 |
if ( _pDirs->empty() ) return Utils::String::Null();
|
|
|
240 |
|
|
|
241 |
_pCurrentItr = *_pDirs->begin();
|
|
|
242 |
if ( iGame > -1 && _pCurrentItr->iGame != iGame ) return next(iGame);
|
|
|
243 |
return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
Utils::String CGameDirectories::next(int iGame)
|
|
|
247 |
{
|
|
|
248 |
if ( !_pCurrentItr ) return Utils::String::Null();
|
|
|
249 |
|
|
|
250 |
bool found = false;
|
|
|
251 |
for(std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
|
|
|
252 |
if ( (*itr) == _pCurrentItr ) found = true;
|
|
|
253 |
else if ( found && ((*itr)->iGame == iGame || iGame == -1) ) {
|
|
|
254 |
_pCurrentItr = *(itr);
|
|
|
255 |
return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
return Utils::String::Null();
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
Utils::String CGameDirectories::firstShield()
|
|
|
263 |
{
|
|
|
264 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
265 |
return _pSelected->pVfs->firstShield();
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
Utils::String CGameDirectories::nextShield()
|
|
|
269 |
{
|
|
|
270 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
271 |
return _pSelected->pVfs->nextShield();
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
Utils::String CGameDirectories::firstComponentSection()
|
|
|
275 |
{
|
|
|
276 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
277 |
return _pSelected->pVfs->firstComponentSection();
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
Utils::String CGameDirectories::nextComponentSection()
|
|
|
281 |
{
|
|
|
282 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
283 |
return _pSelected->pVfs->nextComponentSection();
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
Utils::String CGameDirectories::firstDummySection()
|
|
|
287 |
{
|
|
|
288 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
289 |
return _pSelected->pVfs->firstDummySection();
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
Utils::String CGameDirectories::nextDummySection()
|
|
|
293 |
{
|
|
|
294 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
295 |
return _pSelected->pVfs->nextDummySection();
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
Utils::String CGameDirectories::firstBodiesSection()
|
|
|
299 |
{
|
|
|
300 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
301 |
return _pSelected->pVfs->firstBodiesSection();
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
Utils::String CGameDirectories::nextBodiesSection()
|
|
|
305 |
{
|
|
|
306 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
307 |
return _pSelected->pVfs->nextBodiesSection();
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
Utils::String CGameDirectories::firstCockpit()
|
|
|
311 |
{
|
|
|
312 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
313 |
return _pSelected->pVfs->firstCockpit();
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
Utils::String CGameDirectories::nextCockpit()
|
|
|
317 |
{
|
|
|
318 |
if ( !_pSelected ) return Utils::String::Null();
|
|
|
319 |
return _pSelected->pVfs->nextCockpit();
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
std::pair<Utils::String, Utils::String> CGameDirectories::firstLaser()
|
|
|
323 |
{
|
|
|
324 |
if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
|
|
|
325 |
return _pSelected->pVfs->firstLaser();
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
std::pair<Utils::String, Utils::String> CGameDirectories::nextLaser()
|
|
|
329 |
{
|
|
|
330 |
if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
|
|
|
331 |
return _pSelected->pVfs->nextLaser();
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
std::pair<Utils::String, Utils::String> CGameDirectories::firstMissile()
|
|
|
335 |
{
|
|
|
336 |
if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
|
|
|
337 |
return _pSelected->pVfs->firstMissile();
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
std::pair<Utils::String, Utils::String> CGameDirectories::nextMissile()
|
|
|
341 |
{
|
|
|
342 |
if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
|
|
|
343 |
return _pSelected->pVfs->nextMissile();
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
SGameDir *CGameDirectories::_findGameDir(int iGame) const
|
|
|
347 |
{
|
|
|
348 |
if ( iGame == -1 ) {
|
|
|
349 |
for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
|
|
|
350 |
SGameDir *gd = _findGameDir(game);
|
|
|
351 |
if ( !gd ) continue;
|
|
|
352 |
return gd;
|
|
|
353 |
}
|
|
|
354 |
}
|
|
|
355 |
else {
|
|
|
356 |
for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
|
|
|
357 |
if ( (*itr)->iGame == iGame ) return *itr;
|
|
|
358 |
}
|
|
|
359 |
}
|
|
|
360 |
return NULL;
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
SGameDir *CGameDirectories::_findGameDir(const Utils::String &dir) const
|
|
|
364 |
{
|
|
|
365 |
for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
|
|
|
366 |
if ( (*itr)->dir.Compare(dir) )
|
|
|
367 |
return *itr;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
return NULL;
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
void CGameDirectories::_add(const Utils::String &dir, const Utils::String &name, int iGame, const Utils::String &addon, bool bLoad)
|
|
|
374 |
{
|
|
|
375 |
SGameDir *gd = new SGameDir;
|
|
|
376 |
|
|
|
377 |
gd->dir = dir;
|
|
|
378 |
gd->name = name;
|
|
|
379 |
gd->iGame = iGame;
|
|
|
380 |
|
|
|
381 |
gd->bLoad = bLoad;
|
|
|
382 |
gd->pVfs = new CVirtualFileSystem();
|
|
|
383 |
gd->pVfs->setLanguage(44);
|
114 |
cycrow |
384 |
gd->pVfs->setAddon(addon);
|
94 |
cycrow |
385 |
gd->pVfs->LoadFilesystem(gd->dir);
|
|
|
386 |
|
|
|
387 |
_pDirs->push_back(gd);
|
|
|
388 |
}
|
95 |
cycrow |
389 |
|
|
|
390 |
void CGameDirectories::_updateControlledDirs(const Utils::String &mydoc)
|
|
|
391 |
{
|
112 |
cycrow |
392 |
_lControlledDirs.clear();
|
95 |
cycrow |
393 |
|
|
|
394 |
CFileIO configFile(mydoc + "/Egosoft/pluginmanager.dat");
|
|
|
395 |
if ( configFile.startRead() ) {
|
|
|
396 |
while(!configFile.atEnd()) {
|
|
|
397 |
Utils::String line = configFile.readEndOfLine();
|
|
|
398 |
if ( line.token(":", 1).Compare("DirExe") ) {
|
|
|
399 |
Utils::String rest = line.tokens(":", 2).removeFirstSpace();
|
|
|
400 |
if ( rest.countToken("|" ) > 2 )
|
|
|
401 |
_lControlledDirs.pushBack(rest.token("|", 3), rest.token("|", 2));
|
|
|
402 |
else
|
|
|
403 |
_lControlledDirs.pushBack(rest.token("|", 2), rest.token("|", 1));
|
|
|
404 |
}
|
|
|
405 |
}
|
|
|
406 |
}
|
|
|
407 |
}
|
94 |
cycrow |
408 |
}
|