Subversion Repositories spk

Rev

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

Rev 123 Rev 197
Line 4... Line 4...
4
#include "Packages.h"
4
#include "Packages.h"
5
#include "GameExe.h"
5
#include "GameExe.h"
6
 
6
 
7
namespace SPK {
7
namespace SPK {
8
 
8
 
9
	CGameDirectories::CGameDirectories(const Utils::String &mydoc) : _pSelected(NULL),
9
	CGameDirectories::CGameDirectories(const Utils::WString &mydoc) : _pSelected(NULL),
10
		_pCurrentItr(NULL),
10
		_pCurrentItr(NULL),
11
		_iLanguage(0)
11
		_iLanguage(0)
12
	{
12
	{
13
		_pDirs = new std::vector<SGameDir *>();
13
		_pDirs = new std::vector<SGameDir *>();
14
 
14
 
Line 20... Line 20...
20
		clear();
20
		clear();
21
		delete _pDirs;
21
		delete _pDirs;
22
		_lControlledDirs.clear();
22
		_lControlledDirs.clear();
23
	}
23
	}
24
 
24
 
25
	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::WString &dir, const Utils::WString &name, int iGame, const Utils::WString &addon, bool bLoad)
26
	{
26
	{
27
		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++ ) {
28
			if ( dir.Compare((*itr)->dir) ) return false;
28
			if ( dir.Compare((*itr)->dir) ) return false;
29
		}
29
		}
30
 
30
 
31
		_add(dir, name, iGame, addon, bLoad);
31
		_add(dir, name, iGame, addon, bLoad);
32
		return true;
32
		return true;
33
	}
33
	}
34
 
34
 
35
	bool CGameDirectories::remove(const Utils::String &dir)
35
	bool CGameDirectories::remove(const Utils::WString &dir)
36
	{
36
	{
37
		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++ ) {
38
			if ( dir.Compare((*itr)->dir) ) {
38
			if ( dir.Compare((*itr)->dir) ) {
39
				delete (*itr);
39
				delete (*itr);
40
				_pDirs->erase(itr);
40
				_pDirs->erase(itr);
Line 43... Line 43...
43
		}
43
		}
44
 
44
 
45
		return false;
45
		return false;
46
	}
46
	}
47
 
47
 
48
	bool CGameDirectories::findDir(const Utils::String &dir)
48
	bool CGameDirectories::findDir(const Utils::WString &dir)
49
	{
49
	{
50
		SGameDir *d = _findGameDir(dir);
50
		SGameDir *d = _findGameDir(dir);
51
		if ( d ) {
51
		if ( d ) {
52
			_pCurrentItr = d;
52
			_pCurrentItr = d;
53
			return true;
53
			return true;
54
		}
54
		}
55
 
55
 
56
		return false;
56
		return false;
57
	}
57
	}
58
 
58
 
59
	bool CGameDirectories::parse(const Utils::String &data, CPackages *pPackages)
59
	bool CGameDirectories::parse(const Utils::WString &data, CPackages *pPackages)
60
	{
60
	{
61
		int iGame = data.token(";", 2).tokens(" ", 1).toLong();
61
		int iGame = data.token(L";", 2).tokens(L" ", 1).toLong();
62
		SGameExe *exe = pPackages->GetGameExe()->GetGame(iGame);
62
		SGameExe *exe = pPackages->GetGameExe()->game(iGame);
63
		_add(data.token(";", 1), data.token(";", 2).tokens(" ", 2), iGame, (exe) ? exe->sAddon : Utils::String::Null(), data.token(";", 3).toBool());
63
		_add(data.token(L";", 1), data.token(L";", 2).tokens(L" ", 2), iGame, (exe) ? exe->sAddon : Utils::WString::Null(), data.token(L";", 3).toBool());
64
 
64
 
65
		return true;
65
		return true;
66
	}
66
	}
67
 
67
 
68
	bool CGameDirectories::writeData(Utils::CStringList *lines)
68
	bool CGameDirectories::writeData(Utils::WStringList *lines)
69
	{
69
	{
70
		bool writeAny = false;
70
		bool writeAny = false;
71
		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++) {
72
			SGameDir *gd = *itr;
72
			SGameDir *gd = *itr;
73
			lines->pushBack("GameDir:" + gd->dir + ";" + Utils::String::Number(gd->iGame) + " " + gd->name + ((gd->bLoad) ? ";1" : ";0"));
73
			lines->pushBack(L"GameDir:" + gd->dir + L";" + Utils::WString::Number(gd->iGame) + L" " + gd->name + ((gd->bLoad) ? L";1" : L";0"));
74
			writeAny = true;
74
			writeAny = true;
75
		}
75
		}
76
 
76
 
77
		return writeAny;
77
		return writeAny;
78
	}
78
	}
Line 102... Line 102...
102
		if ( temp ) _pTemporary = _pSelected;
102
		if ( temp ) _pTemporary = _pSelected;
103
		_pSelected = _findGameDir(iGame);
103
		_pSelected = _findGameDir(iGame);
104
		return hasSelected();
104
		return hasSelected();
105
	}
105
	}
106
 
106
 
107
	bool CGameDirectories::setSelectedDirectory(const Utils::String &dir, bool temp)
107
	bool CGameDirectories::setSelectedDirectory(const Utils::WString &dir, bool temp)
108
	{
108
	{
109
		_pTemporary = NULL;
109
		_pTemporary = NULL;
110
		if ( temp ) _pTemporary = _pSelected;
110
		if ( temp ) _pTemporary = _pSelected;
111
		_pSelected = _findGameDir(dir);
111
		_pSelected = _findGameDir(dir);
112
		return hasSelected();
112
		return hasSelected();
Line 135... Line 135...
135
		}
135
		}
136
 
136
 
137
		return true;
137
		return true;
138
	}
138
	}
139
 
139
 
140
	bool CGameDirectories::isDir(const Utils::String &dir) const
140
	bool CGameDirectories::isDir(const Utils::WString &dir) const
141
	{
141
	{
142
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
142
		for ( std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++ ) {
143
			if ( dir.Compare((*itr)->dir) ) return true;
143
			if ( dir.Compare((*itr)->dir) ) return true;
144
		}
144
		}
145
 
145
 
Line 165... Line 165...
165
		}
165
		}
166
 
166
 
167
		return highest;
167
		return highest;
168
	}
168
	}
169
 
169
 
170
	Utils::String CGameDirectories::currentName() const
170
	Utils::WString CGameDirectories::currentName() const
171
	{
171
	{
172
		if ( !_pCurrentItr ) return Utils::String::Null();
172
		if ( !_pCurrentItr ) return Utils::WString::Null();
173
		return _pCurrentItr->name;
173
		return _pCurrentItr->name;
174
	}
174
	}
175
 
175
 
176
	int CGameDirectories::currentGame() const
176
	int CGameDirectories::currentGame() const
177
	{
177
	{
Line 191... Line 191...
191
		return NULL;
191
		return NULL;
192
	}
192
	}
193
 
193
 
194
	void CGameDirectories::syncWithControlled(CGameExe *exe)
194
	void CGameDirectories::syncWithControlled(CGameExe *exe)
195
	{
195
	{
196
		for(Utils::CStringListIterator itr = _lControlledDirs.begin(); itr != _lControlledDirs.end(); itr++) {
196
		for(Utils::WStringListIterator itr = _lControlledDirs.begin(); itr != _lControlledDirs.end(); itr++) {
197
			add(exe->GetProperDir((*itr)->str), (*itr)->data, exe->GetGameType((*itr)->str), exe->GetAddonDir((*itr)->str), true);
197
			add(exe->properDir((*itr)->str), (*itr)->data, exe->getGameType((*itr)->str), exe->addonDir((*itr)->str), true);
198
		}
198
		}
199
	}
199
	}
200
 
200
 
201
	Utils::String CGameDirectories::findText(int iLanguage, int iPage, int iID, Utils::String missing)
201
	Utils::WString CGameDirectories::findText(int iLanguage, int iPage, int iID, Utils::WString missing)
202
	{
202
	{
203
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
203
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
204
		if ( _pSelected ) {
204
		if ( _pSelected ) {
205
			if ( _pSelected->pVfs->textExists(iLanguage, iPage, iID) ) {
205
			if ( _pSelected->pVfs->textExists(iLanguage, iPage, iID) ) {
206
				return _pSelected->pVfs->findText(iLanguage, iPage, iID);
206
				return _pSelected->pVfs->findText(iLanguage, iPage, iID);
Line 208... Line 208...
208
		}
208
		}
209
 
209
 
210
		return missing;
210
		return missing;
211
	}
211
	}
212
 
212
 
213
	Utils::String CGameDirectories::findText(int iGame, int iLanguage, int iPage, int iID)
213
	Utils::WString CGameDirectories::findText(int iGame, int iLanguage, int iPage, int iID)
214
	{
214
	{
215
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
215
		if ( iLanguage == 0 ) iLanguage = _iLanguage;
216
		if ( iGame == -1 ) {
216
		if ( iGame == -1 ) {
217
			for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
217
			for ( int game = (GAME_MAX - 1); game >= 0; game-- ) {
218
				SGameDir *gd = _findGameDir(game - 1);
218
				SGameDir *gd = _findGameDir(game - 1);
Line 229... Line 229...
229
					return gd->pVfs->findText(iLanguage, iPage, iID);
229
					return gd->pVfs->findText(iLanguage, iPage, iID);
230
				}
230
				}
231
			}
231
			}
232
		}
232
		}
233
 
233
 
234
		return Utils::String::Null();
234
		return Utils::WString::Null();
235
	}
235
	}
236
 
236
 
237
	Utils::String CGameDirectories::first(int iGame)
237
	Utils::WString CGameDirectories::first(int iGame)
238
	{
238
	{
239
		if ( _pDirs->empty() ) return Utils::String::Null();
239
		if ( _pDirs->empty() ) return Utils::WString::Null();
240
 
240
 
241
		_pCurrentItr = *_pDirs->begin();
241
		_pCurrentItr = *_pDirs->begin();
242
		if ( iGame > -1 && _pCurrentItr->iGame != iGame ) return next(iGame);
242
		if ( iGame > -1 && _pCurrentItr->iGame != iGame ) return next(iGame);
243
		return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
243
		return (_pCurrentItr) ? _pCurrentItr->dir : Utils::WString::Null();
244
	}
244
	}
245
 
245
 
246
	Utils::String CGameDirectories::next(int iGame)
246
	Utils::WString CGameDirectories::next(int iGame)
247
	{
247
	{
248
		if ( !_pCurrentItr ) return Utils::String::Null();
248
		if ( !_pCurrentItr ) return Utils::WString::Null();
249
 
249
 
250
		bool found = false;
250
		bool found = false;
251
		for(std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
251
		for(std::vector<SGameDir *>::iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
252
			if ( (*itr) == _pCurrentItr ) found = true;
252
			if ( (*itr) == _pCurrentItr ) found = true;
253
			else if ( found && ((*itr)->iGame == iGame || iGame == -1) ) {
253
			else if ( found && ((*itr)->iGame == iGame || iGame == -1) ) {
254
				_pCurrentItr = *(itr);
254
				_pCurrentItr = *(itr);
255
				return (_pCurrentItr) ? _pCurrentItr->dir : Utils::String::Null();
255
				return (_pCurrentItr) ? _pCurrentItr->dir : Utils::WString::Null();
256
			}
256
			}
257
		}
257
		}
258
 
258
 
259
		return Utils::String::Null();
259
		return Utils::WString::Null();
260
	}
260
	}
261
 
261
 
262
	Utils::String CGameDirectories::firstShield()
262
	Utils::WString CGameDirectories::firstShield()
263
	{
263
	{
264
		if ( !_pSelected ) return Utils::String::Null();
264
		if ( !_pSelected ) return Utils::WString::Null();
265
		return _pSelected->pVfs->firstShield();
265
		return _pSelected->pVfs->firstShield();
266
	}
266
	}
267
 
267
 
268
	Utils::String CGameDirectories::nextShield()
268
	Utils::WString CGameDirectories::nextShield()
269
	{
269
	{
270
		if ( !_pSelected ) return Utils::String::Null();
270
		if ( !_pSelected ) return Utils::WString::Null();
271
		return _pSelected->pVfs->nextShield();
271
		return _pSelected->pVfs->nextShield();
272
	}
272
	}
273
 
273
 
274
	Utils::String CGameDirectories::firstComponentSection()
274
	Utils::WString CGameDirectories::firstComponentSection()
275
	{
275
	{
276
		if ( !_pSelected ) return Utils::String::Null();
276
		if ( !_pSelected ) return Utils::WString::Null();
277
		return _pSelected->pVfs->firstComponentSection();
277
		return _pSelected->pVfs->firstComponentSection();
278
	}
278
	}
279
 
279
 
280
	Utils::String CGameDirectories::nextComponentSection()
280
	Utils::WString CGameDirectories::nextComponentSection()
281
	{
281
	{
282
		if ( !_pSelected ) return Utils::String::Null();
282
		if ( !_pSelected ) return Utils::WString::Null();
283
		return _pSelected->pVfs->nextComponentSection();
283
		return _pSelected->pVfs->nextComponentSection();
284
	}
284
	}
285
 
285
 
286
	Utils::String CGameDirectories::firstDummySection()
286
	Utils::WString CGameDirectories::firstDummySection()
287
	{
287
	{
288
		if ( !_pSelected ) return Utils::String::Null();
288
		if ( !_pSelected ) return Utils::WString::Null();
289
		return _pSelected->pVfs->firstDummySection();
289
		return _pSelected->pVfs->firstDummySection();
290
	}
290
	}
291
 
291
 
292
	Utils::String CGameDirectories::nextDummySection()
292
	Utils::WString CGameDirectories::nextDummySection()
293
	{
293
	{
294
		if ( !_pSelected ) return Utils::String::Null();
294
		if ( !_pSelected ) return Utils::WString::Null();
295
		return _pSelected->pVfs->nextDummySection();
295
		return _pSelected->pVfs->nextDummySection();
296
	}
296
	}
297
 
297
 
298
	Utils::String CGameDirectories::firstBodiesSection()
298
	Utils::WString CGameDirectories::firstBodiesSection()
299
	{
299
	{
300
		if ( !_pSelected ) return Utils::String::Null();
300
		if ( !_pSelected ) return Utils::WString::Null();
301
		return _pSelected->pVfs->firstBodiesSection();
301
		return _pSelected->pVfs->firstBodiesSection();
302
	}
302
	}
303
 
303
 
304
	Utils::String CGameDirectories::nextBodiesSection()
304
	Utils::WString CGameDirectories::nextBodiesSection()
305
	{
305
	{
306
		if ( !_pSelected ) return Utils::String::Null();
306
		if ( !_pSelected ) return Utils::WString::Null();
307
		return _pSelected->pVfs->nextBodiesSection();
307
		return _pSelected->pVfs->nextBodiesSection();
308
	}
308
	}
309
 
309
 
310
	Utils::String CGameDirectories::firstCockpit()
310
	Utils::WString CGameDirectories::firstCockpit()
311
	{
311
	{
312
		if ( !_pSelected ) return Utils::String::Null();
312
		if ( !_pSelected ) return Utils::WString::Null();
313
		return _pSelected->pVfs->firstCockpit();
313
		return _pSelected->pVfs->firstCockpit();
314
	}
314
	}
315
 
315
 
316
	Utils::String CGameDirectories::nextCockpit()
316
	Utils::WString CGameDirectories::nextCockpit()
317
	{
317
	{
318
		if ( !_pSelected ) return Utils::String::Null();
318
		if ( !_pSelected ) return Utils::WString::Null();
319
		return _pSelected->pVfs->nextCockpit();
319
		return _pSelected->pVfs->nextCockpit();
320
	}
320
	}
321
 
321
 
322
	std::pair<Utils::String, Utils::String> CGameDirectories::firstLaser()
322
	std::pair<Utils::WString, Utils::WString> CGameDirectories::firstLaser() const
323
	{
323
	{
324
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
324
		if ( !_pSelected ) return std::make_pair<Utils::WString, Utils::WString>(Utils::WString::Null(), Utils::WString::Null());
325
		return _pSelected->pVfs->firstLaser();
325
		return _pSelected->pVfs->firstLaser();
326
	}
326
	}
327
 
327
 
328
	std::pair<Utils::String, Utils::String> CGameDirectories::nextLaser()
328
	std::pair<Utils::WString, Utils::WString> CGameDirectories::nextLaser() const
329
	{
329
	{
330
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
330
		if ( !_pSelected ) return std::make_pair<Utils::WString, Utils::WString>(Utils::WString::Null(), Utils::WString::Null());
331
		return _pSelected->pVfs->nextLaser();
331
		return _pSelected->pVfs->nextLaser();
332
	}
332
	}
333
 
333
 
334
	std::pair<Utils::String, Utils::String> CGameDirectories::firstMissile()
334
	std::pair<Utils::WString, Utils::WString> CGameDirectories::firstMissile() const
335
	{
335
	{
336
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
336
		if ( !_pSelected ) return std::make_pair<Utils::WString, Utils::WString>(Utils::WString::Null(), Utils::WString::Null());
337
		return _pSelected->pVfs->firstMissile();
337
		return _pSelected->pVfs->firstMissile();
338
	}
338
	}
339
 
339
 
340
	std::pair<Utils::String, Utils::String> CGameDirectories::nextMissile()
340
	std::pair<Utils::WString, Utils::WString> CGameDirectories::nextMissile() const
341
	{
341
	{
342
		if ( !_pSelected ) return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
342
		if ( !_pSelected ) return std::make_pair<Utils::WString, Utils::WString>(Utils::WString::Null(), Utils::WString::Null());
343
		return _pSelected->pVfs->nextMissile();
343
		return _pSelected->pVfs->nextMissile();
344
	}
344
	}
345
 
345
 
346
	SGameDir *CGameDirectories::_findGameDir(int iGame) const
346
	SGameDir *CGameDirectories::_findGameDir(int iGame) const
347
	{
347
	{
Line 358... Line 358...
358
			}
358
			}
359
		}
359
		}
360
		return NULL;
360
		return NULL;
361
	}
361
	}
362
 
362
 
363
	SGameDir *CGameDirectories::_findGameDir(const Utils::String &dir) const
363
	SGameDir *CGameDirectories::_findGameDir(const Utils::WString &dir) const
364
	{
364
	{
365
		for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
365
		for(std::vector<SGameDir *>::const_iterator itr = _pDirs->begin(); itr != _pDirs->end(); itr++) {
366
			if ( (*itr)->dir.Compare(dir) )
366
			if ( (*itr)->dir.Compare(dir) )
367
				return *itr;
367
				return *itr;
368
		}
368
		}
369
 
369
 
370
		return NULL;
370
		return NULL;
371
	}
371
	}
372
 
372
 
373
	void CGameDirectories::_add(const Utils::String &dir, const Utils::String &name, int iGame, const Utils::String &addon, bool bLoad)
373
	void CGameDirectories::_add(const Utils::WString &dir, const Utils::WString &name, int iGame, const Utils::WString &addon, bool bLoad)
374
	{
374
	{
375
		SGameDir *gd = new SGameDir;
375
		SGameDir *gd = new SGameDir;
376
		
376
		
377
		gd->dir = dir;
377
		gd->dir = dir;
378
		gd->name = name;
378
		gd->name = name;
Line 385... Line 385...
385
		gd->pVfs->LoadFilesystem(gd->dir);
385
		gd->pVfs->LoadFilesystem(gd->dir);
386
 
386
 
387
		_pDirs->push_back(gd);
387
		_pDirs->push_back(gd);
388
	}
388
	}
389
 
389
 
390
	void CGameDirectories::_updateControlledDirs(const Utils::String &mydoc)
390
	void CGameDirectories::_updateControlledDirs(const Utils::WString &mydoc)
391
	{
391
	{
392
		_lControlledDirs.clear();
392
		_lControlledDirs.clear();
393
 
393
 
394
		CFileIO configFile(mydoc + "/Egosoft/pluginmanager.dat");
394
		CFileIO configFile(mydoc + L"/Egosoft/pluginmanager.dat");
395
		if ( configFile.startRead() ) {
395
		if ( configFile.startRead() ) {
396
			while(!configFile.atEnd()) {
396
			while(!configFile.atEnd()) {
397
				Utils::String line = configFile.readEndOfLine();
397
				Utils::WString line = configFile.readEndOfLine();
398
				if ( line.token(":", 1).Compare("DirExe") ) {
398
				if ( line.token(L":", 1).Compare(L"DirExe") ) {
399
					Utils::String rest = line.tokens(":", 2).removeFirstSpace();
399
					Utils::WString rest = line.tokens(L":", 2).removeFirstSpace();
400
					if ( rest.countToken("|" ) > 2 )
400
					if ( rest.countToken(L"|" ) > 2 )
401
						_lControlledDirs.pushBack(rest.token("|", 3), rest.token("|", 2));
401
						_lControlledDirs.pushBack(rest.token(L"|", 3), rest.token(L"|", 2));
402
					else
402
					else
403
						_lControlledDirs.pushBack(rest.token("|", 2), rest.token("|", 1));
403
						_lControlledDirs.pushBack(rest.token(L"|", 2), rest.token(L"|", 1));
404
				}
404
				}
405
			}
405
			}
406
		}
406
		}
407
	}
407
	}
408
}
408
}