Subversion Repositories spk

Rev

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

Rev 185 Rev 196
Line 182... Line 182...
182
		CCatFile cat;
182
		CCatFile cat;
183
		if ( cat.open(file + ".cat", m_sAddon, CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
183
		if ( cat.open(file + ".cat", m_sAddon, CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
184
		{
184
		{
185
			for(auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
185
			for(auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
186
			{
186
			{
187
				this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), file + ".cat", m_pMap);
187
				this->_addModFile(CFileIO((*itr)->sFile).fullFilenameStr(), file + ".cat", m_pMap);
188
				m_bLoaded = true;
188
				m_bLoaded = true;
189
			}
189
			}
190
		}
190
		}
191
		++number;
191
		++number;
192
	}
192
	}
Line 203... Line 203...
203
 
203
 
204
 
204
 
205
void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
205
void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
206
{
206
{
207
	CDirIO Dir(sStart + "/" + sDir);
207
	CDirIO Dir(sStart + "/" + sDir);
208
	Utils::CStringList list;
208
	Utils::WStringList list;
209
	if (Dir.dirList(list))
209
	if (Dir.dirList(list))
210
	{
210
	{
211
		for (auto itr = list.begin(); itr != list.end(); itr++)
211
		for (auto itr = list.begin(); itr != list.end(); itr++)
212
		{
212
		{
213
			if (CDirIO(Dir.dir((*itr)->str)).isDir()) _addDir(sStart, sDir + "/" + (*itr)->str);
213
			if (CDirIO(Dir.dir((*itr)->str)).isDir()) _addDir(sStart, sDir + "/" + (*itr)->str.toString());
214
			else if (CFileIO((*itr)->str).isFileExtension("cat")) continue;
214
			else if (CFileIO((*itr)->str).isFileExtension(L"cat")) continue;
215
			else if (CFileIO((*itr)->str).isFileExtension("dat")) continue;
215
			else if (CFileIO((*itr)->str).isFileExtension(L"dat")) continue;
216
			else this->_addFile(sDir + "/" + (*itr)->str, Dir.file((*itr)->str), m_pMap);
216
			else this->_addFile(sDir + "/" + (*itr)->str.toString(), Dir.file((*itr)->str).toString(), m_pMap);
217
		}
217
		}
218
	}
218
	}
219
}
219
}
220
 
220
 
221
 
221
 
222
void CVirtualFileSystem::_removeSameFile(const Utils::String &sFile, const Utils::String &sDest, const Utils::String &ext, FileList *pList)
222
void CVirtualFileSystem::_removeSameFile(const Utils::String &sFile, const Utils::String &sDest, const Utils::String &ext, FileList *pList)
223
{
223
{
224
	CFileIO F(sFile);
224
	CFileIO F(sFile);
225
 
225
 
226
	Utils::String newFile = F.changeFileExtension(ext);
226
	Utils::String newFile = F.changeFileExtension(ext).toString();
227
	newFile = newFile.lower();
227
	newFile = newFile.lower();
228
 
228
 
229
	FileListItr itr = pList->find(newFile);
229
	FileListItr itr = pList->find(newFile);
230
	if ( itr != pList->end() ) {
230
	if ( itr != pList->end() ) {
231
		if ( !CFileIO((*pList)[newFile]).dir().Compare(CFileIO(sDest).dir()) ) {
231
		if ( !CFileIO((*pList)[newFile]).dir().Compare(CFileIO(sDest).dir()) ) {
Line 238... Line 238...
238
{
238
{
239
	Utils::String file = sFile.asFilename().removeIf(0, '/');
239
	Utils::String file = sFile.asFilename().removeIf(0, '/');
240
 
240
 
241
	// check file extension, remove any patching files in previous files
241
	// check file extension, remove any patching files in previous files
242
	CFileIO F(file);
242
	CFileIO F(file);
243
	Utils::String ext = F.extension().toLower();
243
	Utils::WString ext = F.extension().toLower();
244
	if (ext.Compare("bob", true) || ext.Compare("pbd", true) || ext.Compare("bod", true) ) {
244
	if (ext.Compare(L"bob", true) || ext.Compare(L"pbd", true) || ext.Compare(L"bod", true) ) {
245
		_removeSameFile(file, sDest, "pbb", pList);
245
		_removeSameFile(file, sDest, "pbb", pList);
246
		_removeSameFile(file, sDest, "bob", pList);
246
		_removeSameFile(file, sDest, "bob", pList);
247
		_removeSameFile(file, sDest, "pbd", pList);
247
		_removeSameFile(file, sDest, "pbd", pList);
248
	}
248
	}
249
	else if (ext.Compare("xml", true) || ext.Compare("txt", true) )
249
	else if (ext.Compare(L"xml", true) || ext.Compare(L"txt", true) )
250
		_removeSameFile(file, sDest, "pck", pList);
250
		_removeSameFile(file, sDest, "pck", pList);
251
 
251
 
252
	(*pList)[file.lower()] = sDest.findReplace("\\", "/").findReplace("//", "/");
252
	(*pList)[file.lower()] = sDest.findReplace("\\", "/").findReplace("//", "/");
253
}
253
}
254
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
254
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
Line 265... Line 265...
265
	CCatFile cat;
265
	CCatFile cat;
266
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
266
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
267
	{
267
	{
268
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++) 
268
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++) 
269
		{
269
		{
270
			this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), mod, m_pModMap);
270
			this->_addModFile(CFileIO((*itr)->sFile).fullFilenameStr(), mod, m_pModMap);
271
			loaded = true;
271
			loaded = true;
272
		}
272
		}
273
	}
273
	}
274
 
274
 
275
	return loaded;
275
	return loaded;
Line 284... Line 284...
284
	CCatFile cat;
284
	CCatFile cat;
285
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
285
	if ( CCatFile::Opened(cat.open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
286
	{
286
	{
287
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
287
		for (auto itr = cat.GetFiles()->cbegin(); itr != cat.GetFiles()->cend(); itr++)
288
		{
288
		{
289
			this->_addModFile(CFileIO((*itr)->sFile).fullFilename(), mod, m_pMap);
289
			this->_addModFile(CFileIO((*itr)->sFile).fullFilenameStr(), mod, m_pMap);
290
			loaded = true;
290
			loaded = true;
291
		}
291
		}
292
	}
292
	}
293
 
293
 
294
	return loaded;
294
	return loaded;
Line 342... Line 342...
342
{
342
{
343
	Utils::String toFile = file.findReplace("\\", "/").lower();
343
	Utils::String toFile = file.findReplace("\\", "/").lower();
344
 
344
 
345
	if ( m_pModMap && !m_pModMap->empty() ) {
345
	if ( m_pModMap && !m_pModMap->empty() ) {
346
		if ( !m_sAddon.empty() ) {
346
		if ( !m_sAddon.empty() ) {
347
			FileListItr aitr = m_pModMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilename().lower().c_str());
347
			FileListItr aitr = m_pModMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilenameStr().lower().c_str());
348
			if ( aitr == m_pModMap->end() ) aitr = m_pModMap->find(CFileIO(_convertExtension(m_sAddon + "/" + toFile)).fullFilename().lower().c_str());
348
			if ( aitr == m_pModMap->end() ) aitr = m_pModMap->find(CFileIO(_convertExtension(m_sAddon + "/" + toFile)).fullFilenameStr().lower().c_str());
349
			if ( aitr != m_pModMap->end() ) return aitr->second;
349
			if ( aitr != m_pModMap->end() ) return aitr->second;
350
		}
350
		}
351
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilename().lower().c_str());
351
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilenameStr().lower().c_str());
352
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilename().lower().c_str());
352
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilenameStr().lower().c_str());
353
		if ( itr != m_pModMap->end() ) return itr->second;
353
		if ( itr != m_pModMap->end() ) return itr->second;
354
	}
354
	}
355
 
355
 
356
	if ( m_pMap && !m_pMap->empty() ) {
356
	if ( m_pMap && !m_pMap->empty() ) {
357
		if ( !m_sAddon.empty() ) {
357
		if ( !m_sAddon.empty() ) {
358
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilename().lower().c_str());
358
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilenameStr().lower().c_str());
359
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).fullFilename().lower().c_str());
359
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).fullFilenameStr().lower().c_str());
360
			if ( aitr != m_pMap->end() ) return aitr->second;
360
			if ( aitr != m_pMap->end() ) return aitr->second;
361
		}
361
		}
362
		FileListItr itr = m_pMap->find(CFileIO(file).fullFilename().lower().c_str());
362
		FileListItr itr = m_pMap->find(CFileIO(file).fullFilenameStr().lower().c_str());
363
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).fullFilename().lower().c_str());
363
		if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).fullFilenameStr().lower().c_str());
364
		if ( itr != m_pMap->end() ) return itr->second;
364
		if ( itr != m_pMap->end() ) return itr->second;
365
	}
365
	}
366
	return "";
366
	return "";
367
}
367
}
368
 
368
 
Line 384... Line 384...
384
Utils::String CVirtualFileSystem::_extract(const Utils::String &sFile, const Utils::String &sTo)
384
Utils::String CVirtualFileSystem::_extract(const Utils::String &sFile, const Utils::String &sTo)
385
{
385
{
386
	// check if we need to unpack the file
386
	// check if we need to unpack the file
387
	if ( CCatFile::CheckPackedExtension(sFile) ) {
387
	if ( CCatFile::CheckPackedExtension(sFile) ) {
388
		CFileIO File(sFile);
388
		CFileIO File(sFile);
389
		C_File f(File.fullFilename());
389
		C_File f(File.fullFilenameStr());
390
		if ( !f.readFromFile(File) ) return "";
390
		if ( !f.readFromFile(File) ) return "";
391
		if ( !f.UnPCKFile() ) return "";
391
		if ( !f.UnPCKFile() ) return "";
392
		if ( !f.writeToFile(sTo) ) return "";
392
		if ( !f.writeToFile(sTo) ) return "";
393
		return sTo;
393
		return sTo;
394
	}
394
	}
Line 412... Line 412...
412
}
412
}
413
 
413
 
414
Utils::String CVirtualFileSystem::_convertExtension(const Utils::String &sFile) const
414
Utils::String CVirtualFileSystem::_convertExtension(const Utils::String &sFile) const
415
{
415
{
416
	CFileIO File(sFile);
416
	CFileIO File(sFile);
417
	if ( File.isFileExtension("pck") ) {
417
	if ( File.isFileExtension(L"pck") ) {
418
		return File.changeFileExtension("xml");
418
		return File.changeFileExtension(L"xml").toString();
419
	}
419
	}
420
	else if ( File.isFileExtension("xml") ) {
420
	else if ( File.isFileExtension(L"xml") ) {
421
		return File.changeFileExtension("pck");
421
		return File.changeFileExtension(L"pck").toString();
422
	}
422
	}
423
	else if ( File.isFileExtension("pbb") ) {
423
	else if ( File.isFileExtension(L"pbb") ) {
424
		return File.changeFileExtension("bob");
424
		return File.changeFileExtension(L"bob").toString();
425
	}
425
	}
426
	else if ( File.isFileExtension("bob") ) {
426
	else if ( File.isFileExtension(L"bob") ) {
427
		return File.changeFileExtension("pbb");
427
		return File.changeFileExtension(L"pbb").toString();
428
	}
428
	}
429
	else if ( File.isFileExtension("pbd") ) {
429
	else if ( File.isFileExtension(L"pbd") ) {
430
		return File.changeFileExtension("bod");
430
		return File.changeFileExtension(L"bod").toString();
431
	}
431
	}
432
	else if ( File.isFileExtension("bod") ) {
432
	else if ( File.isFileExtension(L"bod") ) {
433
		return File.changeFileExtension("pbd");
433
		return File.changeFileExtension(L"pbd").toString();
434
	}
434
	}
435
 
435
 
436
	return sFile;
436
	return sFile;
437
}
437
}
438
 
438
 
Line 451... Line 451...
451
{
451
{
452
	Utils::String to = this->ExtractGameFile(sFile, CPackages::tempDirectory() + "tmp.dat");
452
	Utils::String to = this->ExtractGameFile(sFile, CPackages::tempDirectory() + "tmp.dat");
453
	if ( !to.empty() ) {
453
	if ( !to.empty() ) {
454
		CFileIO File(to);
454
		CFileIO File(to);
455
 
455
 
456
		C_File *f = pPackage->addFile(CFileIO(sTo).filename(), CFileIO(sTo).dir(), iFileType);
456
		C_File *f = pPackage->addFile(CFileIO(sTo).filenameStr(), CFileIO(sTo).dir().toString(), iFileType);
457
		if ( f ) {
457
		if ( f ) {
458
			if ( f->readFromFile(CPackages::tempDirectory() + "tmp.dat") ) {
458
			if ( f->readFromFile(CPackages::tempDirectory() + "tmp.dat") ) {
459
				File.remove();
459
				File.remove();
460
				return f;
460
				return f;
461
			}
461
			}
Line 548... Line 548...
548
		}
548
		}
549
 
549
 
550
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
550
		Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
551
		if ( !sTo.empty() ) {
551
		if ( !sTo.empty() ) {
552
			// add all texts into the map, id=(pageid, tid) data=text
552
			// add all texts into the map, id=(pageid, tid) data=text
553
			Utils::String baseFile = CFileIO(str).baseName();
553
			Utils::WString baseFile = CFileIO(str).baseName();
554
			int lang = (baseFile.isin("-L")) ? baseFile.right(3) : baseFile.truncate(-4);
554
			int lang = (baseFile.contains(L"-L")) ? baseFile.right(3) : baseFile.truncate(-4);
555
 
555
 
556
			if ( m_iLang && lang != m_iLang ) continue;
556
			if ( m_iLang && lang != m_iLang ) continue;
557
			// open the text file to add
557
			// open the text file to add
558
			pTextList->parseTextFile(iFromPage, iToPage, sTo, lang);
558
			pTextList->parseTextFile(iFromPage, iToPage, sTo, lang);
559
		}
559
		}