Subversion Repositories spk

Rev

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

Rev 94 Rev 95
Line 4... Line 4...
4
#include "Packages.h"
4
#include "Packages.h"
-
 
5
#include "GameExe.h"
5
 
6
 
6
namespace SPK {
7
namespace SPK {
7
 
8
 
8
	CGameDirectories::CGameDirectories(void) : _pSelected(NULL),
9
	CGameDirectories::CGameDirectories(const Utils::String &mydoc) : _pSelected(NULL),
9
		_pCurrentItr(NULL),
10
		_pCurrentItr(NULL),
10
		_iLanguage(0)
11
		_iLanguage(0)
11
	{
12
	{
12
		_pDirs = new std::vector<SGameDir *>();
13
		_pDirs = new std::vector<SGameDir *>();
-
 
14
 
-
 
15
		_updateControlledDirs(mydoc);
13
	}
16
	}
14
 
17
 
15
	CGameDirectories::~CGameDirectories(void)
18
	CGameDirectories::~CGameDirectories(void)
16
	{
19
	{
17
		clear();
20
		clear();
18
		delete _pDirs;
21
		delete _pDirs;
-
 
22
		_lControlledDirs.MemoryClear();
19
	}
23
	}
20
 
24
 
21
	bool CGameDirectories::add(const Utils::String &dir, const Utils::String &name, int iGame, const Utils::String &addon, bool bLoad)
25
	bool CGameDirectories::add(const Utils::String &dir, const Utils::String &name, int iGame, const Utils::String &addon, bool bLoad)
22
	{
26
	{
23
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
27
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
24
			if ( dir.Compare((*itr)->dir) ) return false;
28
			if ( dir.Compare((*itr)->dir) ) return false;
25
		}
29
		}
26
 
30
 
27
		_add(dir, name, iGame, addon, bLoad);
31
		_add(dir, name, iGame, addon, bLoad);
28
		return true;
32
		return true;
29
	}
33
	}
30
 
34
 
31
	bool CGameDirectories::remove(const Utils::String &dir)
35
	bool CGameDirectories::remove(const Utils::String &dir)
32
	{
36
	{
33
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
37
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
34
			if ( dir.Compare((*itr)->dir) ) {
38
			if ( dir.Compare((*itr)->dir) ) {
35
				delete (*itr);
39
				delete (*itr);
36
				_pDirs->erase(itr);
40
				_pDirs->erase(itr);
37
				return true;
41
				return true;
38
			}
42
			}
39
		}
43
		}
40
 
44
 
41
		return false;
45
		return false;
42
	}
46
	}
43
 
47
 
44
	bool CGameDirectories::findDir(const Utils::String &dir)
48
	bool CGameDirectories::findDir(const Utils::String &dir)
45
	{
49
	{
46
		SGameDir *d = _findGameDir(dir);
50
		SGameDir *d = _findGameDir(dir);
47
		if ( d ) {
51
		if ( d ) {
48
			_pCurrentItr = d;
52
			_pCurrentItr = d;
49
			return true;
53
			return true;
50
		}
54
		}
51
 
55
 
52
		return false;
56
		return false;
53
	}
57
	}
54
 
58
 
55
	bool CGameDirectories::parse(const Utils::String &data, CPackages *pPackages)
59
	bool CGameDirectories::parse(const Utils::String &data, CPackages *pPackages)
56
	{
60
	{
57
		int iGame = data.token(";", 2).tokens(" ", 1).toLong();
61
		int iGame = data.token(";", 2).tokens(" ", 1).toLong();
58
		SGameExe *exe = pPackages->GetGameExe()->GetGame(iGame);
62
		SGameExe *exe = pPackages->GetGameExe()->GetGame(iGame);
59
		_add(data.token(";", 1), data.token(";", 2).tokens(" ", 2), iGame, (exe) ? exe->sAddon : Utils::String::Null(), data.token(";", 3).toBool());
63
		_add(data.token(";", 1), data.token(";", 2).tokens(" ", 2), iGame, (exe) ? exe->sAddon : Utils::String::Null(), data.token(";", 3).toBool());
60
 
64
 
61
		return true;
65
		return true;
62
	}
66
	}
63
 
67
 
64
	bool CGameDirectories::writeData(CyStringList *lines)
68
	bool CGameDirectories::writeData(CyStringList *lines)
65
	{
69
	{
66
		bool writeAny = false;
70
		bool writeAny = false;
67
		for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
71
		for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
Line 79... Line 83...
79
 
83
 
80
		_pCurrentItr->pVfs->updateTexts(0);
84
		_pCurrentItr->pVfs->updateTexts(0);
81
	}
85
	}
82
 
86
 
83
	void CGameDirectories::clear()
87
	void CGameDirectories::clear()
84
	{
88
	{
85
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
89
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
86
			delete *itr;
90
			delete *itr;
87
		}
91
		}
88
		_pDirs->clear();
92
		_pDirs->clear();
89
	}
93
	}
90
 
94
 
91
	bool CGameDirectories::setSelectedGameDirectory(int iGame, bool temp)
95
	bool CGameDirectories::setSelectedGameDirectory(int iGame, bool temp)
92
	{
96
	{
93
		_pTemporary = NULL;
97
		_pTemporary = NULL;
94
		if ( temp ) _pTemporary = _pSelected;
98
		if ( temp ) _pTemporary = _pSelected;
95
		_pSelected = _findGameDir(iGame);
99
		_pSelected = _findGameDir(iGame);
96
		return hasSelected();
100
		return hasSelected();
97
	}
101
	}
98
 
102
 
99
	bool CGameDirectories::setSelectedDirectory(const Utils::String &dir, bool temp)
103
	bool CGameDirectories::setSelectedDirectory(const Utils::String &dir, bool temp)
100
	{
104
	{
101
		_pTemporary = NULL;
105
		_pTemporary = NULL;
102
		if ( temp ) _pTemporary = _pSelected;
106
		if ( temp ) _pTemporary = _pSelected;
103
		_pSelected = _findGameDir(dir);
107
		_pSelected = _findGameDir(dir);
104
		return hasSelected();
108
		return hasSelected();
105
	}
109
	}
Line 170... Line 174...
170
 
174
 
171
	CVirtualFileSystem *CGameDirectories::selectedVFS() const
175
	CVirtualFileSystem *CGameDirectories::selectedVFS() const
172
	{
176
	{
173
		if ( _pSelected ) return _pSelected->pVfs;
177
		if ( _pSelected ) return _pSelected->pVfs;
174
		return NULL;
178
		return NULL;
-
 
179
	}
-
 
180
 
-
 
181
	void CGameDirectories::syncWithControlled(CGameExe *exe)
-
 
182
	{
-
 
183
		for(CListNode<Utils::SStringList> *node = _lControlledDirs.Front(); node; node = node->next()) {
-
 
184
			Utils::SStringList *str = node->Data();
-
 
185
			add(exe->GetProperDir(str->str), str->data, exe->GetGameType(str->str), exe->GetAddonDir(str->str), true);
-
 
186
		}
175
	}
187
	}
176
 
188
 
177
	Utils::String CGameDirectories::findText(int iLanguage, int iPage, int iID, Utils::String missing)
189
	Utils::String CGameDirectories::findText(int iLanguage, int iPage, int iID, Utils::String missing)
178
	{
190
	{
179
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
191
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
Line 182... Line 194...
182
				return _pSelected->pVfs->findText(iLanguage, iPage, iID);
194
				return _pSelected->pVfs->findText(iLanguage, iPage, iID);
183
			}
195
			}
184
		}
196
		}
185
 
197
 
186
		return missing;
198
		return missing;
187
	}
199
	}
188
 
200
 
189
	Utils::String CGameDirectories::findText(int iGame, int iLanguage, int iPage, int iID)
201
	Utils::String CGameDirectories::findText(int iGame, int iLanguage, int iPage, int iID)
190
	{
202
	{
191
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
203
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
192
		if ( iGame == -1 ) {
204
		if ( iGame == -1 ) {
193
			for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
205
			for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
194
				SGameDir *gd = _findGameDir(game - 1);
206
				SGameDir *gd = _findGameDir(game - 1);
195
				if ( !gd ) continue;
207
				if ( !gd ) continue;
196
				if ( gd->pVfs->textExists(iLanguage, iPage, iID) ) {
208
				if ( gd->pVfs->textExists(iLanguage, iPage, iID) ) {
197
					return gd->pVfs->findText(iLanguage, iPage, iID);
209
					return gd->pVfs->findText(iLanguage, iPage, iID);
198
				}
210
				}
199
			}
211
			}
200
		}
212
		}
201
		else {
213
		else {
202
			SGameDir *gd = _findGameDir(iGame);
214
			SGameDir *gd = _findGameDir(iGame);
203
			if ( gd ) {
215
			if ( gd ) {
204
				if ( gd->pVfs->textExists(iLanguage, iPage, iID) ) {
216
				if ( gd->pVfs->textExists(iLanguage, iPage, iID) ) {
Line 211... Line 223...
211
	}
223
	}
212
 
224
 
213
	Utils::String CGameDirectories::first(int iGame)
225
	Utils::String CGameDirectories::first(int iGame)
214
	{
226
	{
215
		if ( _pDirs->empty() ) return Utils::String::Null();
227
		if ( _pDirs->empty() ) return Utils::String::Null();
216
 
228
 
217
		_pCurrentItr = *_pDirs->begin();
229
		_pCurrentItr = *_pDirs->begin();
218
		if ( iGame > -1 && _pCurrentItr->iGame != iGame ) return next(iGame);
230
		if ( iGame > -1 && _pCurrentItr->iGame != iGame ) return next(iGame);
219
		return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
231
		return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
220
	}
232
	}
221
 
233
 
222
	Utils::String CGameDirectories::next(int iGame)
234
	Utils::String CGameDirectories::next(int iGame)
223
	{
235
	{
224
		if ( !_pCurrentItr ) return Utils::String::Null();
236
		if ( !_pCurrentItr ) return Utils::String::Null();
225
 
237
 
226
		bool found = false;
238
		bool found = false;
227
		for(std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
239
		for(std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
228
			if ( (*itr) == _pCurrentItr ) found = true;
240
			if ( (*itr) == _pCurrentItr ) found = true;
229
			else if ( found && ((*itr)->iGame == iGame || iGame == -1) ) {
241
			else if ( found && ((*itr)->iGame == iGame || iGame == -1) ) {
230
				_pCurrentItr = *(itr);
242
				_pCurrentItr = *(itr);
231
				return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
243
				return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
232
			}
244
			}
233
		}
245
		}
234
 
246
 
235
		return Utils::String::Null();
247
		return Utils::String::Null();
236
	}
248
	}
237
 
249
 
238
	Utils::String CGameDirectories::firstShield()
250
	Utils::String CGameDirectories::firstShield()
239
	{
251
	{
240
		if ( !_pSelected ) return Utils::String::Null();
252
		if ( !_pSelected ) return Utils::String::Null();
241
		return _pSelected->pVfs->firstShield();
253
		return _pSelected->pVfs->firstShield();
242
	}
254
	}
243
 
255
 
244
	Utils::String CGameDirectories::nextShield()
256
	Utils::String CGameDirectories::nextShield()
245
	{
257
	{
246
		if ( !_pSelected ) return Utils::String::Null();
258
		if ( !_pSelected ) return Utils::String::Null();
247
		return _pSelected->pVfs->nextShield();
259
		return _pSelected->pVfs->nextShield();
248
	}
260
	}
249
 
261
 
250
	Utils::String CGameDirectories::firstComponentSection()
262
	Utils::String CGameDirectories::firstComponentSection()
251
	{
263
	{
252
		if ( !_pSelected ) return Utils::String::Null();
264
		if ( !_pSelected ) return Utils::String::Null();
253
		return _pSelected->pVfs->firstComponentSection();
265
		return _pSelected->pVfs->firstComponentSection();
254
	}
266
	}
255
 
267
 
256
	Utils::String CGameDirectories::nextComponentSection()
268
	Utils::String CGameDirectories::nextComponentSection()
257
	{
269
	{
258
		if ( !_pSelected ) return Utils::String::Null();
270
		if ( !_pSelected ) return Utils::String::Null();
259
		return _pSelected->pVfs->nextComponentSection();
271
		return _pSelected->pVfs->nextComponentSection();
260
	}
272
	}
261
 
273
 
262
	Utils::String CGameDirectories::firstDummySection()
274
	Utils::String CGameDirectories::firstDummySection()
263
	{
275
	{
264
		if ( !_pSelected ) return Utils::String::Null();
276
		if ( !_pSelected ) return Utils::String::Null();
265
		return _pSelected->pVfs->firstDummySection();
277
		return _pSelected->pVfs->firstDummySection();
266
	}
278
	}
267
 
279
 
268
	Utils::String CGameDirectories::nextDummySection()
280
	Utils::String CGameDirectories::nextDummySection()
269
	{
281
	{
270
		if ( !_pSelected ) return Utils::String::Null();
282
		if ( !_pSelected ) return Utils::String::Null();
271
		return _pSelected->pVfs->nextDummySection();
283
		return _pSelected->pVfs->nextDummySection();
272
	}
284
	}
273
 
285
 
274
	Utils::String CGameDirectories::firstBodiesSection()
286
	Utils::String CGameDirectories::firstBodiesSection()
275
	{
287
	{
276
		if ( !_pSelected ) return Utils::String::Null();
288
		if ( !_pSelected ) return Utils::String::Null();
277
		return _pSelected->pVfs->firstBodiesSection();
289
		return _pSelected->pVfs->firstBodiesSection();
278
	}
290
	}
279
 
291
 
280
	Utils::String CGameDirectories::nextBodiesSection()
292
	Utils::String CGameDirectories::nextBodiesSection()
281
	{
293
	{
282
		if ( !_pSelected ) return Utils::String::Null();
294
		if ( !_pSelected ) return Utils::String::Null();
283
		return _pSelected->pVfs->nextBodiesSection();
295
		return _pSelected->pVfs->nextBodiesSection();
284
	}
296
	}
285
 
297
 
286
	Utils::String CGameDirectories::firstCockpit()
298
	Utils::String CGameDirectories::firstCockpit()
287
	{
299
	{
288
		if ( !_pSelected ) return Utils::String::Null();
300
		if ( !_pSelected ) return Utils::String::Null();
289
		return _pSelected->pVfs->firstCockpit();
301
		return _pSelected->pVfs->firstCockpit();
290
	}
302
	}
291
 
303
 
292
	Utils::String CGameDirectories::nextCockpit()
304
	Utils::String CGameDirectories::nextCockpit()
293
	{
305
	{
294
		if ( !_pSelected ) return Utils::String::Null();
306
		if ( !_pSelected ) return Utils::String::Null();
295
		return _pSelected->pVfs->nextCockpit();
307
		return _pSelected->pVfs->nextCockpit();
296
	}
308
	}
297
 
309
 
298
	std::pair<Utils::String, Utils::String> CGameDirectories::firstLaser()
310
	std::pair<Utils::String, Utils::String> CGameDirectories::firstLaser()
Line 303... Line 315...
303
 
315
 
304
	std::pair<Utils::String, Utils::String> CGameDirectories::nextLaser()
316
	std::pair<Utils::String, Utils::String> CGameDirectories::nextLaser()
305
	{
317
	{
306
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
318
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
307
		return _pSelected->pVfs->nextLaser();
319
		return _pSelected->pVfs->nextLaser();
308
	}
320
	}
309
 
321
 
310
	std::pair<Utils::String, Utils::String> CGameDirectories::firstMissile()
322
	std::pair<Utils::String, Utils::String> CGameDirectories::firstMissile()
311
	{
323
	{
312
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
324
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
313
		return _pSelected->pVfs->firstMissile();
325
		return _pSelected->pVfs->firstMissile();
314
	}
326
	}
315
 
327
 
316
	std::pair<Utils::String, Utils::String> CGameDirectories::nextMissile()
328
	std::pair<Utils::String, Utils::String> CGameDirectories::nextMissile()
317
	{
329
	{
318
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
330
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
319
		return _pSelected->pVfs->nextMissile();
331
		return _pSelected->pVfs->nextMissile();
320
	}
332
	}
321
 
333
 
322
	SGameDir *CGameDirectories::_findGameDir(int iGame) const
334
	SGameDir *CGameDirectories::_findGameDir(int iGame) const
323
	{
335
	{
324
		if ( iGame == -1 ) {
336
		if ( iGame == -1 ) {
325
			for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
337
			for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
Line 329... Line 341...
329
			}
341
			}
330
		}
342
		}
331
		else {
343
		else {
332
			for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
344
			for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
333
				if ( (*itr)->iGame == iGame ) return *itr;
345
				if ( (*itr)->iGame == iGame ) return *itr;
334
			}
346
			}
335
		}
347
		}
336
		return NULL;
348
		return NULL;
337
	}
349
	}
338
 
350
 
339
	SGameDir *CGameDirectories::_findGameDir(const Utils::String &dir) const
351
	SGameDir *CGameDirectories::_findGameDir(const Utils::String &dir) const
340
	{
352
	{
341
		for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
353
		for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
342
			if ( (*itr)->dir.Compare(dir) )
354
			if ( (*itr)->dir.Compare(dir) )
343
				return *itr;
355
				return *itr;
344
		}
356
		}
345
 
357
 
346
		return NULL;
358
		return NULL;
347
	}
359
	}
348
 
360
 
349
	void CGameDirectories::_add(const Utils::String &dir, const Utils::String &name, int iGame, const Utils::String &addon, bool bLoad)
361
	void CGameDirectories::_add(const Utils::String &dir, const Utils::String &name, int iGame, const Utils::String &addon, bool bLoad)
350
	{
362
	{
351
		SGameDir *gd = new SGameDir;
363
		SGameDir *gd = new SGameDir;
352
		
364
		
Line 359... Line 371...
359
		gd->pVfs->setLanguage(44);
371
		gd->pVfs->setLanguage(44);
360
		gd->pVfs->LoadFilesystem(gd->dir);
372
		gd->pVfs->LoadFilesystem(gd->dir);
361
		gd->pVfs->SetAddon(addon);
373
		gd->pVfs->SetAddon(addon);
362
 
374
 
363
		_pDirs->push_back(gd);
375
		_pDirs->push_back(gd);
-
 
376
	}
-
 
377
 
-
 
378
	void CGameDirectories::_updateControlledDirs(const Utils::String &mydoc)
-
 
379
	{
-
 
380
		_lControlledDirs.MemoryClear();
-
 
381
 
-
 
382
		CFileIO configFile(mydoc + "/Egosoft/pluginmanager.dat");
-
 
383
		if ( configFile.startRead() ) {
-
 
384
			while(!configFile.atEnd()) {
-
 
385
				Utils::String line = configFile.readEndOfLine();
-
 
386
				if ( line.token(":", 1).Compare("DirExe") ) {
-
 
387
					Utils::String rest = line.tokens(":", 2).removeFirstSpace();
-
 
388
					if ( rest.countToken("|" ) > 2 )
-
 
389
						_lControlledDirs.pushBack(rest.token("|", 3), rest.token("|", 2));
-
 
390
					else
-
 
391
						_lControlledDirs.pushBack(rest.token("|", 2), rest.token("|", 1));
-
 
392
				}
-
 
393
			}
-
 
394
		}
364
	}
395
	}
365
}
396
}