Subversion Repositories spk

Rev

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

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