Subversion Repositories spk

Rev

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

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