Subversion Repositories spk

Rev

Rev 1 | Rev 57 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#include "GameExe.h"
2
#include "File_IO.h"
3
#include "DirIO.h"
4
 
5
/**
6
 * Add Exe
7
 *
8
 * Adds an exe name available
9
 */
56 cycrow 10
int CGameExe::AddExe(const Utils::String &exe)
1 cycrow 11
{
12
	// search if it already exists
13
	int count = 0;
56 cycrow 14
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() ) {
1 cycrow 15
		if ( node->Data()->sExe.Compare(exe) )
16
			return count;
17
		--count;
18
	}
19
 
20
	// not found, we need to add
21
	SGameExe *sExe = new SGameExe;
22
	sExe->sExe = exe;
23
	sExe->iName = 0;
24
	sExe->iFlags = 0;
25
	sExe->iMaxPatch = 1;
26
	sExe->iAddonTo = 0;
27
 
28
	m_lExe.push_back(sExe);
29
 
30
	return m_lExe.size() - 1;
31
}
32
 
33
/**
34
 * Find Exe
35
 *
36
 * Find an exe and return its position in the file
37
 *
38
 * Argument:	exe,	String - name of the exe file to find
39
 */
56 cycrow 40
int CGameExe::FindExe(const Utils::String &exe)
1 cycrow 41
{
42
	int count = 0;
43
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() )
44
	{
45
		if ( node->Data()->sExe.Compare(exe) )
46
			return count;
47
		++count;
48
	}
49
 
50
	return -1;
51
}
52
 
56 cycrow 53
SGameExe *CGameExe::GetGameExe(const Utils::String &exe)
1 cycrow 54
{
55
	int e = FindExe(exe);
56
	if ( e < 0 ) return NULL;
57
	return m_lExe[e];
58
}
59
 
56 cycrow 60
int CGameExe::FindVersion(int exe, int size, Utils::String *fVersion)
1 cycrow 61
{
62
	if ( fVersion )
63
		*fVersion = -1.0;
64
 
65
	if ( exe < 0 )
66
		return -1;
67
 
68
	SGameExe *gameExe = m_lExe[exe];
69
	if ( !gameExe )
70
		return -1;
71
 
72
	int count = 0;
73
	for ( CListNode<SGameExeVersion> *node = gameExe->lVersions.Front(); node; node = node->next() )
74
	{
75
		// check each size of a watch
76
		for ( CListNode<int> *iNode = node->Data()->lSize.Front(); iNode; iNode = iNode->next() )
77
		{
78
			int checkSize = *iNode->Data();
79
			if ( checkSize == size )
80
			{
81
				*fVersion = node->Data()->fVersion;
82
				return count;
83
			}
84
		}
85
 
86
		++count;
87
	}
88
 
89
	return -1;
90
}
91
 
56 cycrow 92
int CGameExe::FindVersion(const Utils::String &exe, int size, Utils::String *fVersion)
1 cycrow 93
{
94
	int iExe = this->FindExe(exe);
95
	if ( iExe < 0 )
96
		return -1;
97
 
98
	int iVersion = this->FindVersion(iExe, size, fVersion);
99
	if ( iVersion < 0 )
100
		return -2 - iExe;
101
 
102
	return -1;
103
}
104
 
56 cycrow 105
Utils::String CGameExe::GetModKey(int game)
1 cycrow 106
{
56 cycrow 107
	if ( game < 0 )	return "";
1 cycrow 108
	SGameExe *sExe = m_lExe[game];
56 cycrow 109
	if ( !sExe ) return "";
1 cycrow 110
 
111
	return sExe->sModKey;
112
}
113
 
56 cycrow 114
void CGameExe::ParseExe(const Utils::String &line)
1 cycrow 115
{
116
	// get the exe file
56 cycrow 117
	Utils::String exe = line.token(":", 1);
118
	int iTextNum = -1;
119
	if ( line.isin("|") ) {
120
		iTextNum = line.token("|", 2);
121
		exe = line.token("|", 1);
122
	}
123
 
1 cycrow 124
	int iExe = this->AddExe(exe);
125
 
126
	SGameExe *sExe = m_lExe[iExe];
56 cycrow 127
	sExe->iMaxPatch = line.token(":", 2);
128
	sExe->iFlags = this->ParseFlags(line.token(":", 3));
129
	sExe->sModKey = line.token(":", 4);
130
	sExe->iTextNum = iTextNum;
1 cycrow 131
 
132
	// get the name
56 cycrow 133
	Utils::String gameName = line.token(":", 5);
1 cycrow 134
	this->_SetExeName(&sExe->sName, &sExe->iName, gameName);
135
 
136
	// get mydocs
56 cycrow 137
	sExe->sMyDoc = line.token(":", 6);
1 cycrow 138
 
139
	// now get the versions
140
	int pos = EXE_VERSIONPOS;
141
	int namestart = EXE_VERSION_NAMESTART;
142
	int sizestart = EXE_VERSION_SIZESTART;
143
 
144
	if ( sExe->iFlags & EXEFLAG_ADDON ) {
145
		++pos;
146
		++namestart;
147
		++sizestart;
56 cycrow 148
		sExe->sAddon = line.token(":", EXE_VERSIONPOS);
149
		if ( sExe->sAddon.isin("!") ) {
150
			sExe->iAddonTo = this->FindExe(sExe->sAddon.token("!", 2));
151
			sExe->sAddon = sExe->sAddon.token("!", 1);
1 cycrow 152
		}
153
	}
154
 
56 cycrow 155
	int iVersions = line.token(":", pos);
1 cycrow 156
	int i;
157
 
158
	for ( i = 0; i < iVersions; i++ )
159
	{
160
		SGameExeVersion *sGameVersion = new SGameExeVersion;
161
		sGameVersion->iName = 0;
56 cycrow 162
		sGameVersion->fVersion = line.token(":", namestart + (i * 2)).token(" ", 1);
1 cycrow 163
 
56 cycrow 164
		Utils::String sSize = line.token(":", sizestart + (i * 2));
1 cycrow 165
		// multiple versions available, we need to split them up
56 cycrow 166
		if ( sSize.isin("!") ) {
1 cycrow 167
			int max = 0;
56 cycrow 168
			Utils::String *sizes = sSize.tokenise("!", &max);
169
			if ( sizes && max ) {
170
				for ( int j = 0; j < max; j++ ) {
1 cycrow 171
					int *size = new int;
56 cycrow 172
					(*size) = sizes[j];
173
					if ( *size ) sGameVersion->lSize.push_back(size);
1 cycrow 174
				}
175
				CLEANSPLIT(sizes, max);
176
			}
177
		}
56 cycrow 178
		else {
1 cycrow 179
			int *size = new int;
56 cycrow 180
			(*size) = sSize;
181
			if ( *size ) sGameVersion->lSize.push_back(size);
1 cycrow 182
		}
183
 
56 cycrow 184
		if ( !sGameVersion->lSize.empty() )	{
1 cycrow 185
			// finally, add the version names
56 cycrow 186
			this->_SetExeName(&sGameVersion->sName, &sGameVersion->iName, line.token(":", namestart + (i * 2)));
1 cycrow 187
			sExe->lVersions.push_back(sGameVersion);
188
		}
189
	}
190
}
191
 
56 cycrow 192
int CGameExe::ParseFlags(const Utils::String &flags)
1 cycrow 193
{
194
	int max;
56 cycrow 195
	Utils::String *sFlags = flags.tokenise("|", &max);
196
	if ( !sFlags || !max ) return EXEFLAG_NONE;
1 cycrow 197
 
198
	int f = 0;
56 cycrow 199
	for ( int i = 0; i < max; i++ ) {
200
		Utils::String str = sFlags[i];
1 cycrow 201
		if ( str.Compare("TC_TEXT") )
202
			f |= EXEFLAG_TCTEXT;
203
		else if ( str.Compare("NO_XOR") )
204
			f |= EXEFLAG_NOXOR;
205
		else if ( str.Compare("ADDON") )
206
			f |= EXEFLAG_ADDON;
207
		else if ( str.Compare("MYDOCLOG") )
208
			f |= EXEFLAG_MYDOCLOG;
209
		else if ( str.Compare("NOSAVESUBDIR") )
210
			f |= EXEFLAG_NOSAVESUBDIR;
56 cycrow 211
		else {
212
			if ( str.isNumber() )
213
				f |= (long)str;
1 cycrow 214
		}
215
	}
216
 
217
	CLEANSPLIT(sFlags, max);
218
 
219
	return f;
220
}
221
 
56 cycrow 222
void CGameExe::_SetExeName(Utils::String *sName, int *iName, const Utils::String &n)
1 cycrow 223
{
56 cycrow 224
	Utils::String str = n;
225
	if ( n.isin("!") )
1 cycrow 226
	{
56 cycrow 227
		Utils::String gameNum = str.token("!", 1);
228
		str = str.token("!", 2);
1 cycrow 229
 
56 cycrow 230
		if ( gameNum.isNumber() )
231
			*iName = gameNum;
1 cycrow 232
		else
233
			*sName = gameNum;
234
	}
235
 
56 cycrow 236
	if ( str.isNumber() )
237
		*iName = str;
1 cycrow 238
	else
56 cycrow 239
		*sName = str;
1 cycrow 240
}
241
 
242
void CGameExe::Reset()
243
{
244
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() )
245
	{
246
		for ( CListNode<SGameExeVersion> *vNode = node->Data()->lVersions.Front(); vNode; vNode = vNode->next() )
247
			vNode->Data()->lSize.MemoryClear();
248
		node->Data()->lVersions.MemoryClear();
249
	}
250
	m_lExe.MemoryClear();
251
}
252
 
56 cycrow 253
bool CGameExe::ReadFile(const Utils::String &file)
1 cycrow 254
{
56 cycrow 255
	CFileIO File(file);
256
	if ( !File.startRead() ) return false;
1 cycrow 257
 
56 cycrow 258
	while ( !File.atEnd() ) {
259
		Utils::String line = File.readEndOfLine();
260
		line.removeFirstSpace();
261
		if ( line.empty() ) continue;
262
		if ( line[0] == '/' ) continue;
1 cycrow 263
		this->ParseExe(line);
264
	}
56 cycrow 265
	File.close();
1 cycrow 266
	return true;
267
}
268
 
56 cycrow 269
Utils::String CGameExe::GetGameRunExe(const Utils::String &dir)
1 cycrow 270
{
271
	CDirIO Dir(dir);
272
	int count = 0;
273
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() )
274
	{
275
		SGameExe *exe = node->Data();
276
		if ( Dir.Exists(exe->sExe) )
277
			return dir + "/" + exe->sExe;
56 cycrow 278
		if ( !exe->sAddon.empty() ) {
279
			if ( Dir.TopDir().Compare(CyString(exe->sAddon)) )
1 cycrow 280
				return this->GetGameDir(dir) + "/" + exe->sExe;
281
		}
282
		++count;
283
	}
284
 
56 cycrow 285
	return "";
1 cycrow 286
}
287
 
56 cycrow 288
Utils::String CGameExe::GetGameName(const Utils::String &gameExe)
1 cycrow 289
{
290
	int gameType = this->GetGameType(gameExe);
56 cycrow 291
	Utils::String gameName = ExtractGameName(gameExe);
292
	if ( gameName.empty() )	gameName = this->GetGameNameFromType(gameType);
293
	if ( gameName.empty() )	return "";
1 cycrow 294
 
295
	// no version
56 cycrow 296
	Utils::String fVersion;
297
	Utils::String versionName;
1 cycrow 298
 
56 cycrow 299
	if ( this->GetGameVersionName(gameExe, &versionName) ) {
300
		if ( !versionName.empty() )
1 cycrow 301
			return gameName + " V" + versionName;
302
		else
303
			return gameName;
304
	}
305
 
56 cycrow 306
	Utils::String sGameVersion = this->GetGameVersionFromType(gameType, this->GetGameVersion(gameExe, &fVersion), fVersion);
307
	if ( sGameVersion.empty() )
1 cycrow 308
	{
56 cycrow 309
		if ( !fVersion.empty() )
1 cycrow 310
			return gameName + " V" + fVersion;
311
		else
312
			return gameName;
313
	}
314
 
315
	// return the name and the version
316
	return gameName + " " + sGameVersion;
317
}
318
 
319
 
56 cycrow 320
int CGameExe::GetGameAddons(const Utils::String &dir, CyStringList &exes)
1 cycrow 321
{
322
	int count = 0;
323
 
324
	CDirIO Dir(dir);
325
 
326
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() )
327
	{
328
		SGameExe *exe = node->Data();
329
		if ( !(exe->iFlags & EXEFLAG_ADDON) )
330
			continue;
331
		if ( Dir.Exists(exe->sExe) ) {
332
			if ( Dir.Exists(exe->sAddon) ) {			
56 cycrow 333
				exes.PushBack(CyString(exe->sExe), CyString(exe->sAddon));
1 cycrow 334
				++count;
335
			}
336
		}
337
	}
338
 
339
	return count;
340
}
341
 
56 cycrow 342
Utils::String CGameExe::GetAddonDir(const Utils::String &dir)
1 cycrow 343
{
344
	int gameType = this->GetGameType(dir);
345
	if ( gameType != -1 ) {
346
		return m_lExe[gameType]->sAddon;
347
	}
348
 
349
	return "";
350
}
351
 
56 cycrow 352
Utils::String CGameExe::GetProperDir(const Utils::String &dir)
1 cycrow 353
{
354
	CDirIO Dir(dir);
355
	int gameType = this->GetGameType(dir);
356
	if ( gameType != -1 ) {
56 cycrow 357
		if ( !m_lExe[gameType]->sAddon.empty() ) {
358
			if ( CDirIO(dir).IsFile() ) return CFileIO(dir).GetDir().ToString() + "/" + m_lExe[gameType]->sAddon;
359
			return Dir.Dir(m_lExe[gameType]->sAddon).ToString();
1 cycrow 360
		}
361
	}
362
 
363
	return dir;
364
}
365
 
366
int CGameExe::GetGameFlags(int game)
367
{
368
	if ( game == -1 )
369
		return 0;
370
 
371
	SGameExe *exe = m_lExe[game];
372
	if ( !exe )
373
		return 0;
374
 
375
	return exe->iFlags;
376
}
377
 
378
int CGameExe::GetMaxPatch(int game)
379
{
380
	if ( game == -1 )
381
		return 0;
382
 
383
	SGameExe *exe = m_lExe[game];
384
	if ( !exe )
385
		return 0;
386
 
387
	return exe->iMaxPatch;
388
}
389
 
56 cycrow 390
Utils::String CGameExe::GetGameNameFromType(int type)
1 cycrow 391
{
56 cycrow 392
	if ( type == -1 ) return "";
1 cycrow 393
 
394
	SGameExe *exe = m_lExe[type];
56 cycrow 395
	if ( !exe ) return "";
1 cycrow 396
 
397
	return exe->sName;
398
}
399
 
56 cycrow 400
Utils::String CGameExe::GetGameVersionFromType(int game, int gameVersion, const Utils::String &fGameVersion)
1 cycrow 401
{
402
	SGameExe *exe = m_lExe[game];
56 cycrow 403
	if ( !exe ) return "";
1 cycrow 404
 
405
	SGameExeVersion *version = exe->lVersions[gameVersion];
406
	if ( !version )
407
	{
56 cycrow 408
		if ( !fGameVersion.empty() ) return fGameVersion;
409
		return "";
1 cycrow 410
	}
411
 
412
	return version->sName;
413
}
414
 
56 cycrow 415
Utils::String CGameExe::GetGameDir(const Utils::String &dir) 
1 cycrow 416
{
417
	CDirIO Dir(dir);
418
 
419
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() )
420
	{
421
		SGameExe *exe = node->Data();
422
		if ( CDirIO(dir).IsFile() ) {
56 cycrow 423
			if ( CFileIO(dir).filename().Compare(exe->sExe) )
424
				return CFileIO(dir).GetDir().ToString();
1 cycrow 425
		}
426
		else {
56 cycrow 427
			if ( Dir.Exists(exe->sExe) ) return dir;
1 cycrow 428
			// check for addon dir
56 cycrow 429
			if ( !exe->sAddon.empty() ) {
430
				if ( exe->sAddon.Compare(Dir.TopDir().ToString()) )
431
					return Dir.Back().ToString();
1 cycrow 432
			}
433
		}
434
	}
435
 
436
	return dir;
437
}
56 cycrow 438
int CGameExe::GetGameType(const Utils::String &gameExe)
1 cycrow 439
{
440
	CDirIO Dir(gameExe);
441
	int count = 0;
442
 
443
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() )
444
	{
445
		SGameExe *exe = node->Data();
446
		if ( CDirIO(gameExe).IsFile() ) {
56 cycrow 447
			if ( CFileIO(gameExe).filename().Compare(exe->sExe) )
1 cycrow 448
				return count;
449
		}
450
		else {
451
			if ( Dir.Exists(exe->sExe) )
452
				return count;
453
			// check for addon dir
56 cycrow 454
			if ( !exe->sAddon.empty() ) {
1 cycrow 455
				CyString top = Dir.TopDir();
56 cycrow 456
				if ( exe->sAddon.Compare(Dir.TopDir().ToString()) )
1 cycrow 457
					return count;
458
			}
459
		}
460
		++count;
461
	}
462
 
463
	return -1;
464
}
465
 
56 cycrow 466
Utils::String CGameExe::ExtractGameName(const Utils::String &gameDir)
1 cycrow 467
{
468
	CDirIO Dir(gameDir);
469
 
56 cycrow 470
	Utils::String sText = this->_extractTextData(this->_readTextFile(gameDir), 1910, 1216);
471
	if ( sText.empty() ) return "";
472
	int end = sText.findPos("\\n");
473
	if ( end >= 0 ) return sText.left(end);
1 cycrow 474
 
56 cycrow 475
	return "";
476
}
477
 
478
Utils::String CGameExe::_textFileName(const Utils::String &sGameDir)
479
{
480
	CDirIO Dir(sGameDir);
481
	if ( Dir.Exists("t") && Dir.Exists("t/0002.pck") ) return "t/0002.pck";
482
	else if ( Dir.Exists("t") && Dir.Exists("t/440002.pck") ) return "t/440002.pck";
483
	else if ( Dir.Exists("t") && Dir.Exists("t/0002-L044.pck") ) return "t/0002-L044.pck";
484
	return "";
485
}
486
 
487
Utils::String CGameExe::_readTextFile(const Utils::String &sGameDir)
488
{
489
	Utils::String textFileName = _textFileName(sGameDir);;
490
	if ( !textFileName.empty() ) {
491
		Utils::String sVersion;
492
 
493
		CDirIO Dir(sGameDir);
1 cycrow 494
		CFileIO File(Dir.File(textFileName));
495
		size_t fileSize;
56 cycrow 496
		unsigned char *fileData = File.readAll(&fileSize);
497
		if ( fileData && fileSize) {
1 cycrow 498
			size_t newFileSize;
499
			unsigned char *pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize);
56 cycrow 500
			delete fileData;
501
			pckData[newFileSize -1] = '\0';
502
			Utils::String Data((char *)pckData);
503
			delete pckData;
504
			return Data;
505
		}
506
	}
1 cycrow 507
 
56 cycrow 508
	return "";
509
}
1 cycrow 510
 
56 cycrow 511
Utils::String CGameExe::_extractTextData(const Utils::String &sData, long iPage, long iID)
512
{
513
	Utils::String sPage = Utils::String("<page id=\"") + iPage + "\"";
514
	Utils::String sID = Utils::String("<t id=\"") + iID + "\">";
515
 
516
	int startpage = sData.findPos(sPage);
517
	if ( startpage >= 0 ) {
518
		int start = sData.findPos(sID, startpage);
519
		if ( start >= 0 ) {
520
			start += sID.length();
521
			int end = sData.findPos("</t>", start);
522
			return sData.mid(start, end);
1 cycrow 523
		}
524
	}
56 cycrow 525
 
526
	return "";
1 cycrow 527
}
528
 
56 cycrow 529
bool CGameExe::GetGameVersionName(const Utils::String &sGameExe, Utils::String *versionName)
1 cycrow 530
{
56 cycrow 531
	int gameType = this->GetGameType(sGameExe);
1 cycrow 532
 
533
	if ( gameType == -1 )
534
		return false;
535
 
56 cycrow 536
	Utils::String gameDir = sGameExe;
537
	Utils::String gameExe = this->GetGameDir(sGameExe) + "/" + m_lExe[gameType]->sExe;
1 cycrow 538
	int size = (int)CFileIO(gameExe).GetFilesize();
539
 
56 cycrow 540
	Utils::String fVersion;
1 cycrow 541
	int version = this->FindVersion(gameType, size, &fVersion);
542
	// not matched version
543
	// lets read the text file
544
 
56 cycrow 545
	if ( version != -1 ) {
1 cycrow 546
		(*versionName) = this->GetGameVersionFromType(gameType, version, fVersion);
547
		return true;
548
	}
549
 
56 cycrow 550
	Utils::String sText = this->_extractTextData(this->_readTextFile(gameDir), 1910, 1216);
551
	Utils::String sVersion = sText.between("Version ", ", ");
552
	if ( sVersion.empty() ) sVersion = sText.between("ver=", "&amp");
1 cycrow 553
 
56 cycrow 554
	if ( !sVersion.empty() ) {
555
		// lets match the version
556
		(*versionName) = sVersion;
557
		float fVersion = sVersion;
558
		SGameExe *gameExe = m_lExe[gameType];
559
		if ( gameExe )
1 cycrow 560
		{
56 cycrow 561
			int count = 0;
562
			int lower = -1;
563
			for ( CListNode<SGameExeVersion> *node = gameExe->lVersions.Front(); node; node = node->next() )
1 cycrow 564
			{
56 cycrow 565
				if ( (float)node->Data()->fVersion == fVersion )
1 cycrow 566
				{
56 cycrow 567
					(*versionName) = node->Data()->sName;
568
					return true;
1 cycrow 569
				}
56 cycrow 570
				++count;
1 cycrow 571
			}
572
 
56 cycrow 573
			version = lower;
574
		}				
1 cycrow 575
	}
576
 
577
	return true;
578
}
579
 
56 cycrow 580
int CGameExe::GetGameVersion(const Utils::String &sGameExe, Utils::String *a_fVersion)
1 cycrow 581
{
56 cycrow 582
	Utils::String gameExe = sGameExe;
583
 
1 cycrow 584
	int gameType = this->GetGameType(gameExe);
585
 
586
	if ( gameType == -1 )
587
		return -1;
588
 
56 cycrow 589
	Utils::String gameDir = gameExe;
590
	if ( !m_lExe[gameType]->sAddon.empty() )
591
		gameExe = CDirIO(gameExe).Back().ToString() + "/" + m_lExe[gameType]->sExe;
1 cycrow 592
	else
593
		gameExe = gameExe + "/" + m_lExe[gameType]->sExe;
594
	int size = (int)CFileIO(gameExe).GetFilesize();
595
 
596
	int version = this->FindVersion(gameType, size, a_fVersion);
597
 
56 cycrow 598
	Utils::String sText = this->_extractTextData(this->_readTextFile(gameDir), 1910, 10000);
599
	Utils::String sVersion = sText.between("ver=", "&amp");
1 cycrow 600
 
56 cycrow 601
	if ( !sVersion.empty() )
602
	{
603
		// lets match the version
604
		Utils::String fVersion = sVersion;
605
		if ( a_fVersion ) *a_fVersion = fVersion;
606
		SGameExe *gameExe = m_lExe[gameType];
607
		if ( gameExe ) {
608
			int count = 0;
609
			int lower = -1;
610
			for ( CListNode<SGameExeVersion> *node = gameExe->lVersions.Front(); node; node = node->next() )
1 cycrow 611
			{
56 cycrow 612
				if ( fVersion.compareVersion(node->Data()->fVersion) == COMPARE_OLDER )
613
					lower = count;
614
				if (  fVersion.compareVersion(node->Data()->fVersion) == COMPARE_SAME )
615
					return count;
616
				++count;
1 cycrow 617
			}
618
 
56 cycrow 619
			version = lower;
620
		}				
1 cycrow 621
	}
56 cycrow 622
 
1 cycrow 623
	return version;
624
}
625
 
626
int CGameExe::ConvertGameType(int gametype, int *version)
627
{
628
	int count = 0, game = 0;
629
 
630
	switch ( gametype )
631
	{
632
		case 1:
633
			*version = 0;
634
			return 1;
635
		case 2:
636
			*version = 0;
637
			return 2;
638
		case 3:
639
			*version = 1;
640
			return 2;
641
		case 4:
642
			*version = 0;
643
			return 3;
644
		case 5:
645
			*version = 1;
646
			return 3;
647
		case 6:
648
			*version = 2;
649
			return 3;
650
	}
651
 
652
	for ( CListNode<SGameExe> *node = m_lExe.Front(); node; node = node->next() )
653
	{
654
		++count;
655
		++game;
656
		SGameExe *exe = node->Data();
657
 
658
		// found the game type, the version is 0, which is any version
659
		if ( count == gametype )
660
		{
661
			*version = 0;
662
			return game;
663
		}
664
 
665
		int v = 0;
666
		for ( CListNode<SGameExeVersion> *vNode = exe->lVersions.Front(); vNode; vNode = vNode->next() )
667
		{
668
			++count;
669
			++v;
670
			if ( count == gametype )
671
			{
672
				*version = v;
673
				return game;
674
			}
675
		}
676
	}
677
 
678
	// not found ?? just set to all versions
679
	*version = 0;
680
	return 0;
681
}