Subversion Repositories spk

Rev

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

Rev 57 Rev 58
Line 46... Line 46...
46
	this->_clear();
46
	this->_clear();
47
 
47
 
48
	int number = 1;
48
	int number = 1;
49
	while ( CFileIO(CyString(dir) + "/" + CyString::Number(number).PadNumber(2) + ".cat").ExistsOld() )
49
	while ( CFileIO(CyString(dir) + "/" + CyString::Number(number).PadNumber(2) + ".cat").ExistsOld() )
50
	{
50
	{
51
		if ( maxPatch && maxPatch > number ) break;
51
		if ( maxPatch && maxPatch < number ) break;
52
		CyString file = CyString(dir) + "/" + CyString::Number(number).PadNumber(2);
52
		CyString file = CyString(dir) + "/" + CyString::Number(number).PadNumber(2);
53
		if ( !CFileIO(file + ".dat").ExistsOld() )
53
		if ( !CFileIO(file + ".dat").ExistsOld() )
54
			break;
54
			break;
55
 
55
 
56
		CCatFile cat;
56
		CCatFile cat;
Line 79... Line 79...
79
{
79
{
80
	CDirIO Dir(sStart + "/" + sDir);
80
	CDirIO Dir(sStart + "/" + sDir);
81
	CyStringList *list = Dir.DirList();
81
	CyStringList *list = Dir.DirList();
82
	if ( list ) {
82
	if ( list ) {
83
		for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next ) {
83
		for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next ) {
84
			if ( CDirIO(Dir.Dir(strNode->str)).IsDir() ) {
-
 
85
				_addDir(sStart, sDir + "/" + strNode->str.ToString());
84
			if ( CDirIO(Dir.Dir(strNode->str)).IsDir() ) _addDir(sStart, sDir + "/" + strNode->str.ToString());
86
			}
-
 
87
			else if ( CFileIO(strNode->str).CheckFileExtension("cat") ) continue;
85
			else if ( CFileIO(strNode->str).CheckFileExtension("cat") ) continue;
88
			else if ( CFileIO(strNode->str).CheckFileExtension("dat") ) continue;
86
			else if ( CFileIO(strNode->str).CheckFileExtension("dat") ) continue;
89
			else {
-
 
90
				this->_addFile(Dir.File(strNode->str).ToString(), Dir.File(strNode->str).ToString(), m_pMap);
87
			else this->_addFile(sDir + "/" + strNode->str.ToString(), Dir.File(strNode->str).ToString(), m_pMap);
91
			}
-
 
92
		}
88
		}
93
	}
89
	}
94
}
90
}
95
 
91
 
96
void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
92
void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
97
{
93
{
-
 
94
	Utils::String test = sFile.findReplace("\\", "/").findReplace("//", "/").removeIf(0, '/').lower();
98
	(*pList)[sFile.findReplace("\\", "/").findReplace("//", "/").lower()] = sDest.findReplace("//", "/");
95
	(*pList)[sFile.findReplace("\\", "/").findReplace("//", "/";).removeIf(0, '/').lower()] = sDest.findReplace("//", "/");
99
}
96
}
100
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
97
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
101
{
98
{
102
	this->_addFile(sFile, sMod + "::" + sFile, pList);
99
	this->_addFile(sFile, sMod + "::" + sFile, pList);
103
}
100
}
Line 135... Line 132...
135
			loaded = true;
132
			loaded = true;
136
		}
133
		}
137
	}
134
	}
138
 
135
 
139
	return loaded;
136
	return loaded;
140
}
137
}
141
 
138
 
142
bool CVirtualFileSystem::textExists(int iLang, int iPage, int iID) const
139
bool CVirtualFileSystem::textExists(int iLang, int iPage, int iID) const
143
{
140
{
144
	if ( m_pTexts ) {
141
	if ( m_pTexts ) {
145
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
142
		if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
146
	}
143
	}
Line 182... Line 179...
182
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).GetFullFilename().ToLower().c_str());
179
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).GetFullFilename().ToLower().c_str());
183
		if ( itr != m_pModMap->end() ) return itr->second;
180
		if ( itr != m_pModMap->end() ) return itr->second;
184
	}
181
	}
185
	else if ( m_pMap && !m_pMap->empty() ) {
182
	else if ( m_pMap && !m_pMap->empty() ) {
186
		if ( !m_sAddon.empty() ) {
183
		if ( !m_sAddon.empty() ) {
187
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).GetFullFilename().ToLower().c_str());
184
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilename().lower().c_str());
188
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).GetFullFilename().ToLower().c_str());
185
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).fullFilename().lower().c_str());
189
			if ( aitr != m_pMap->end() ) return aitr->second;
186
			if ( aitr != m_pMap->end() ) return aitr->second;
190
		}
187
		}
191
		FileListItr itr = m_pMap->find(CFileIO(file).GetFullFilename().ToLower().c_str());
188
		FileListItr itr = m_pMap->find(CFileIO(file).GetFullFilename().ToLower().c_str());
192
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).GetFullFilename().ToLower().c_str());
189
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).GetFullFilename().ToLower().c_str());
193
		if ( itr != m_pMap->end() ) return itr->second;
190
		if ( itr != m_pMap->end() ) return itr->second;
194
	}
191
	}
195
	return "";
192
	return "";
196
}
193
}
197
 
194
 
-
 
195
Utils::String CVirtualFileSystem::_extractFromCat(const Utils::String &sCat, const Utils::String &sFile, const Utils::String &sTo)
-
 
196
{
-
 
197
	CCatFile catFile;
-
 
198
	if ( catFile.Open(sCat, m_sAddon, CATREAD_CATDECRYPT, false) == CATERR_NONE )
-
 
199
	{
-
 
200
		// check for the file
-
 
201
		if ( catFile.ExtractFile(sFile, sTo) ) return sTo;
-
 
202
		if ( catFile.Error() == CATERR_INVALIDDEST || catFile.Error() == CATERR_CANTCREATEDIR ) {
-
 
203
			if ( catFile.ExtractFile(sFile) ) return sFile;
-
 
204
		}
-
 
205
	}
-
 
206
 
-
 
207
	return "";
-
 
208
}
-
 
209
 
-
 
210
Utils::String CVirtualFileSystem::_extract(const Utils::String &sFile, const Utils::String &sTo)
-
 
211
{
-
 
212
	// check if we need to unpack the file
-
 
213
	if ( CCatFile::CheckPackedExtension(sFile) ) {
-
 
214
		CFileIO File(sFile);
-
 
215
		C_File f(CyString(File.fullFilename()));
-
 
216
		if ( !f.readFromFile(File) ) return "";
-
 
217
		if ( !f.UnPCKFile() ) return "";
-
 
218
		if ( !f.WriteToFile(sTo) ) return "";
-
 
219
		return sTo;
-
 
220
	}
-
 
221
	return sFile;
-
 
222
}
-
 
223
 
198
bool CVirtualFileSystem::ExtractGameFile(const Utils::String &file, const Utils::String &to)
224
Utils::String CVirtualFileSystem::ExtractGameFile(const Utils::String &file, const Utils::String &to)
199
{
225
{
200
	Utils::String sIn = _findFile(file);
226
	Utils::String sIn = _findFile(file);
201
	Utils::String sFile = file;
227
	Utils::String sFile = file;
202
 
228
 
203
	if ( sIn.empty() ) return false;
229
	if ( sIn.empty() ) return "";
204
 
230
 
205
	if ( sIn.isin("::") ) {
231
	if ( sIn.isin("::") ) {
206
		sFile = sIn.token("::", 2);
232
		sFile = sIn.token("::", 2);
207
		sIn = sIn.token("::", 1);
233
		sIn = sIn.token("::", 1);
-
 
234
		return _extractFromCat(sIn, sFile, to);
208
	}
235
	}
209
 
-
 
210
	CCatFile catFile;
-
 
211
	if ( catFile.Open(sIn, m_sAddon, CATREAD_CATDECRYPT, false) == CATERR_NONE )
-
 
212
	{
236
	
213
		// check for the file
-
 
214
		if ( catFile.ExtractFile(file, to) )
-
 
215
			return true;
-
 
216
		if ( catFile.Error() == CATERR_INVALIDDEST || catFile.Error() == CATERR_CANTCREATEDIR )
-
 
217
		{
-
 
218
			if ( catFile.ExtractFile(file) )
-
 
219
				return true;
-
 
220
		}
-
 
221
	}
-
 
222
	return false;
237
	return _extract(sIn, to);
223
}
238
}
224
 
239
 
225
Utils::String CVirtualFileSystem::_convertExtension(const Utils::String &sFile)
240
Utils::String CVirtualFileSystem::_convertExtension(const Utils::String &sFile)
226
{
241
{
227
	CFileIO File(sFile);
242
	CFileIO File(sFile);
Line 247... Line 262...
247
	return sFile;
262
	return sFile;
248
}
263
}
249
 
264
 
250
CyStringList *CVirtualFileSystem::GetTShipsEntries()
265
CyStringList *CVirtualFileSystem::GetTShipsEntries()
251
{
266
{
252
	if ( this->ExtractGameFile("types/tships.pck", "tships.txt") ) {
267
	Utils::String sTo = this->ExtractGameFile("types/tships.pck", "tships.txt");
-
 
268
	if ( !sTo.empty() ) {
253
		CFileIO TShips("tships.txt");
269
		CFileIO TShips(sTo);
254
		if ( TShips.exists() )
270
		if ( TShips.exists() )
255
		{
271
		{
256
			CyStringList *lines = TShips.ReadLinesStr();
272
			CyStringList *lines = TShips.ReadLinesStr();
257
			if ( lines )
273
			if ( lines )
258
			{
274
			{
Line 281... Line 297...
281
					{
297
					{
282
						entries = str->str.GetToken(";", 2, 2).ToInt();
298
						entries = str->str.GetToken(";", 2, 2).ToInt();
283
						str->remove = true;
299
						str->remove = true;
284
						continue;
300
						continue;
285
					}
301
					}
286
 
302
 
287
					// hopefully we now have a valid tships line
303
					// hopefully we now have a valid tships line
288
					int num = -1;
304
					int num = -1;
289
					while ( str->data.Empty() )
305
					while ( str->data.Empty() )
290
						str->data = str->str.GetToken(";", num--, (num + 2));
306
						str->data = str->str.GetToken(";", num--, (num + 2));
291
				}
307
				}
Line 298... Line 314...
298
			return lines;
314
			return lines;
299
		}
315
		}
300
	}
316
	}
301
 
317
 
302
	return NULL;
318
	return NULL;
303
}
319
}
304
 
320
 
305
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType)
321
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType)
306
{
322
{
307
	return this->extractGameFileToPackage(pPackage, sFile, iFileType, sFile);
323
	return this->extractGameFileToPackage(pPackage, sFile, iFileType, sFile);
308
}
324
}
309
 
325
 
310
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType, const Utils::String &sTo)
326
C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType, const Utils::String &sTo)
311
{
327
{
312
 
-
 
313
	if ( this->ExtractGameFile(sFile, ";tmp") ) {
328
	Utils::String to = this->ExtractGameFile(sFile, ";tmp");
-
 
329
	if ( !to.empty() ) {
314
		CFileIO File("tmp");
330
		CFileIO File(to);
315
 
331
 
316
		C_File *f = pPackage->AddFile(CFileIO(sTo).GetFilename(), CFileIO(sTo).GetDir(), iFileType);
332
		C_File *f = pPackage->AddFile(CFileIO(sTo).GetFilename(), CFileIO(sTo).GetDir(), iFileType);
317
		if ( f ) {
333
		if ( f ) {
318
			if ( f->ReadFromFile("tmp") ) {
334
			if ( f->ReadFromFile("tmp") ) {
319
				File.remove();
335
				File.remove();
Line 352... Line 368...
352
		else {
368
		else {
353
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") && !str.left(8).Compare("addon\t\\") && !str.left(8).Compare("addon/t/") )
369
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") && !str.left(8).Compare("addon\t\\") && !str.left(8).Compare("addon/t/") )
354
				continue;
370
				continue;
355
		}
371
		}
356
 
372
 
357
		if ( this->ExtractGameFile(str, ";tmp") ) {
373
		Utils::String sTo = this->ExtractGameFile(str, ";tmp");
-
 
374
		if ( !sTo.empty() ) {
358
			pPackage->AddTextFromFile("tmp", textId);
375
			pPackage->AddTextFromFile(sTo, textId);
359
			CFileIO::Remove("tmp");
376
			CFileIO::Remove(sTo);
360
		}
377
		}
361
	}
378
	}
362
}
379
}
363
 
380
 
364
void CVirtualFileSystem::updateTexts(int iFromPage, int iToPage)
381
void CVirtualFileSystem::updateTexts(int iFromPage, int iToPage)
Line 401... Line 418...
401
		else {
418
		else {
402
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") )
419
			if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") )
403
				continue;
420
				continue;
404
		}
421
		}
405
 
422
 
406
		if ( this->ExtractGameFile(str, ";tmp") ) {
423
		Utils::String sTo = this->ExtractGameFile(str, ";tmp");
-
 
424
		if ( !sTo.empty() ) {
407
			// add all texts into the map, id=(pageid, tid) data=text
425
			// add all texts into the map, id=(pageid, tid) data=text
408
			Utils::String baseFile = CFileIO(str).baseName();
426
			Utils::String baseFile = CFileIO(str).baseName();
409
			int lang = (baseFile.isin("-L")) ? baseFile.right(3) : baseFile.truncate(-4);
427
			int lang = (baseFile.isin("-L")) ? baseFile.right(3) : baseFile.truncate(-4);
410
 
428
 
411
			if ( m_iLang && lang != m_iLang ) continue;
429
			if ( m_iLang && lang != m_iLang ) continue;
412
			// open the text file to add
430
			// open the text file to add
413
			pTextList->parseTextFile(iFromPage, iToPage, "tmp", lang);
431
			pTextList->parseTextFile(iFromPage, iToPage, sTo, lang);
414
		}
432
		}
415
	}
433
	}
416
}
434
}
417
 
435
 
418
void CVirtualFileSystem::clearMods()
436
void CVirtualFileSystem::clearMods()
Line 425... Line 443...
425
 
443
 
426
bool CVirtualFileSystem::loadShipData(CyStringList *list)
444
bool CVirtualFileSystem::loadShipData(CyStringList *list)
427
{
445
{
428
	bool ret = false;
446
	bool ret = false;
429
 
447
 
430
	if ( this->ExtractGameFile("types/TShips.pck", "tmp") ) {
448
	Utils::String sTo = this->ExtractGameFile("types/TShips.pck", "tmp");
-
 
449
	if ( !sTo.empty() ) {
431
		CFileIO File("tmp");
450
		CFileIO File(sTo);
432
		CyStringList *lines = File.ReadLinesStr();
451
		CyStringList *lines = File.ReadLinesStr();
433
		if ( lines )
452
		if ( lines )
434
		{
453
		{
435
			bool readFirst = false;
454
			bool readFirst = false;
436
			for ( SStringList *str = lines->Head(); str; str = str->next )
455
			for ( SStringList *str = lines->Head(); str; str = str->next )