Subversion Repositories spk

Rev

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

Rev 129 Rev 130
Line 43... Line 43...
43
	m_SHeader2.iFileCompression = SPKCOMPRESS_ZLIB;
43
	m_SHeader2.iFileCompression = SPKCOMPRESS_ZLIB;
44
	m_SHeader2.iDataCompression = SPKCOMPRESS_LZMA;
44
	m_SHeader2.iDataCompression = SPKCOMPRESS_LZMA;
45
	m_pParent = NULL;
45
	m_pParent = NULL;
46
	_changed();
46
	_changed();
47
	m_bUpdate = false;
47
	m_bUpdate = false;
-
 
48
	_bCombineFiles = false;
48
 
49
 
49
	ClearError();
50
	ClearError();
50
 
51
 
51
	m_iLoadError = 0;
52
	m_iLoadError = 0;
52
 
53
 
Line 198... Line 199...
198
	{
199
	{
199
		f->Data()->DeleteData();
200
		f->Data()->DeleteData();
200
	}
201
	}
201
}
202
}
202
 
203
 
-
 
204
Utils::String CBaseFile::getNameValidFile() const
-
 
205
{
-
 
206
	Utils::String name = this->name();
-
 
207
	name.removeChar(':');
-
 
208
	name.removeChar('/');
-
 
209
	name.removeChar('\\');
-
 
210
	name.removeChar('*');
-
 
211
	name.removeChar('?');
-
 
212
	name.removeChar('"');
-
 
213
	name.removeChar('<');
-
 
214
	name.removeChar('>');
-
 
215
	name.removeChar('|');
-
 
216
	return name;
-
 
217
}
203
CyString CBaseFile::GetNameValidFile ()
218
CyString CBaseFile::GetNameValidFile()
204
{
219
{
205
	CyString name = this->name();
220
	CyString name = this->name();
206
	name.RemoveChar ( ':' );
221
	name.RemoveChar ( ':' );
207
	name.RemoveChar ( '/' );
222
	name.RemoveChar ( '/' );
208
	name.RemoveChar ( '\\' );
223
	name.RemoveChar ( '\\' );
Line 243... Line 258...
243
void CBaseFile::AddFile ( C_File *file )
258
void CBaseFile::AddFile ( C_File *file )
244
{
259
{
245
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
260
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
246
	{
261
	{
247
		C_File *f = node->Data();
262
		C_File *f = node->Data();
248
		if ( f->GetFileType() != file->GetFileType() )
263
		if ( f->fileType() != file->fileType() )
249
			continue;
264
			continue;
250
		if ( f->GetName() != file->GetName () )
265
		if ( f->name() != file->name () )
251
			continue;
266
			continue;
252
		if ( f->GetDir() != file->GetDir() )
267
		if ( f->GetDir() != file->GetDir() )
253
			continue;
268
			continue;
254
		if ( f->game() != file->game() )
269
		if ( f->game() != file->game() )
255
			continue;
270
			continue;
Line 267... Line 282...
267
}
282
}
268
C_File *CBaseFile::addFile(const Utils::String &file, const Utils::String &dir, FileType type, int game)
283
C_File *CBaseFile::addFile(const Utils::String &file, const Utils::String &dir, FileType type, int game)
269
{
284
{
270
	C_File *newfile = new C_File(file);
285
	C_File *newfile = new C_File(file);
271
	newfile->SetDir(dir);
286
	newfile->SetDir(dir);
272
	newfile->SetFileType(type);
287
	newfile->setFileType(type);
273
	newfile->setGame(game);
288
	newfile->setGame(game);
274
 
289
 
275
	// first check if the file already exists
290
	// first check if the file already exists
276
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
291
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
277
	{
292
	{
278
		C_File *f = node->Data();
293
		C_File *f = node->Data();
279
		if ( f->GetFileType() != newfile->GetFileType() )
294
		if ( f->fileType() != newfile->fileType() )
280
			continue;
295
			continue;
281
		if ( f->GetName() != newfile->GetName () )
296
		if ( f->name() != newfile->name () )
282
			continue;
297
			continue;
283
		if ( f->GetDir() != newfile->GetDir() )
298
		if ( f->GetDir() != newfile->GetDir() )
284
			continue;
299
			continue;
285
		if ( f->game() != newfile->game() )
300
		if (f->game() != newfile->game())
-
 
301
		{
-
 
302
			//same file, for different game, check if they are the same and combine them
-
 
303
			if (_bCombineFiles)
-
 
304
			{
-
 
305
				char *data = NULL;
-
 
306
				char *newData = NULL;
-
 
307
				size_t size = 0;
-
 
308
				size_t newSize = 0;
-
 
309
 
-
 
310
				if (f->GetData() && f->GetDataSize())
-
 
311
				{
-
 
312
					data = (char *)f->GetData();
-
 
313
					size = static_cast<size_t>(f->GetDataSize());
-
 
314
				}
-
 
315
				else if(f->isExternalFile())
-
 
316
					data = CFileIO(f->filePointer()).ReadToData(&size);
-
 
317
				if (newfile->GetData() && newfile->GetDataSize())
-
 
318
				{
-
 
319
					newData = (char *)newfile->GetData();
-
 
320
					newSize = static_cast<size_t>(newfile->GetDataSize());
-
 
321
				}
-
 
322
				else
-
 
323
					newData = CFileIO(newfile->filePointer()).ReadToData(&newSize);
-
 
324
 
-
 
325
				// compare bytes
-
 
326
				bool matched = false;
-
 
327
				if (size == newSize)
-
 
328
				{
-
 
329
					matched = true;
-
 
330
					for (unsigned long i = 0; i < size; ++i)
-
 
331
					{
-
 
332
						if (data[i] != newData[i])
-
 
333
						{
-
 
334
							matched = false;
-
 
335
							break;
-
 
336
						}
-
 
337
					}
-
 
338
				}
-
 
339
 
-
 
340
				if (data && !f->GetData())
-
 
341
					delete data;
-
 
342
				if (newData && !newfile->GetData())
-
 
343
					delete newData;
-
 
344
 
-
 
345
				if (matched)
-
 
346
				{
-
 
347
					if(!f->game() || f->game() == GAME_ALLNEW)
-
 
348
						newfile->setGame(0);
-
 
349
					else
-
 
350
						newfile->setGame(newfile->game() | f->game());
-
 
351
					m_lFiles.remove(node, true);
-
 
352
					break;
-
 
353
				}
-
 
354
			}
286
			continue;
355
			continue;
-
 
356
		}
287
 
357
 
288
		// must already exist, delete this one
358
		// must already exist, delete this one
289
		m_lFiles.remove(node, true);
359
		m_lFiles.remove(node, true);
290
		break;
360
		break;
291
	}
361
	}
Line 899... Line 969...
899
 
969
 
900
}
970
}
901
 
971
 
902
void CBaseFile::_install_renameText(CPackages *pPackages)
972
void CBaseFile::_install_renameText(CPackages *pPackages)
903
{
973
{
904
	int starttext = pPackages->FindNextTextFile();
974
	int starttext = pPackages->findNextTextFile();
905
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
975
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
906
		C_File *fit = node->Data();
976
		C_File *fit = node->Data();
907
		if ( !fit->IsAutoTextFile() )
977
		if ( !fit->isAutoTextFile() )
908
			continue;
978
			continue;
909
 
979
 
910
		CyString newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
980
		Utils::String newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
911
		fit->FixOriginalName();
981
		fit->FixOriginalName();
912
		CLog::logf(CLog::Log_Install, 2, "Adjusting text file, %s => %s", fit->GetNameDirectory(this).c_str(), (newname + "." + fit->GetFileExt()).c_str());
982
		CLog::logf(CLog::Log_Install, 2, "Adjusting text file, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
913
		fit->SetName ( newname + "." + fit->GetFileExt() );
983
		fit->setName(newname + "." + fit->fileExt());
914
 
984
 
915
		++starttext;
985
		++starttext;
916
	}
986
	}
917
}
987
}
918
 
988
 
Line 985... Line 1055...
985
	return true;
1055
	return true;
986
}
1056
}
987
 
1057
 
988
Utils::String CBaseFile::_install_adjustFilepointer(C_File *pFile, bool bEnabled, const Utils::String &sDestination)
1058
Utils::String CBaseFile::_install_adjustFilepointer(C_File *pFile, bool bEnabled, const Utils::String &sDestination)
989
{
1059
{
990
	CyString filename = sDestination;
1060
	Utils::String filename = sDestination;
991
	if ( !filename.Empty() ) filename += "/";
1061
	if ( !filename.empty() ) filename += "/";
992
 
1062
 
993
	if ( (IsPatch()) && (pFile->GetFileType() == FILETYPE_MOD) )
1063
	if ( (IsPatch()) && (pFile->fileType() == FILETYPE_MOD) )
994
		pFile->SetDir ( CyString("Patch") );
1064
		pFile->SetDir ( CyString("Patch") );
995
 
1065
 
996
	if ( pFile->IsInMod() )
1066
	if ( pFile->IsInMod() )
997
	{
1067
	{
998
		if ( bEnabled )
1068
		if ( bEnabled )
999
			pFile->SetFilename(filename + pFile->GetInMod() + "::" + pFile->GetNameDirectory(this));
1069
			pFile->setFilename(filename + pFile->GetInMod().ToString() + "::" + pFile->getNameDirectory(this));
1000
		else
1070
		else
1001
			pFile->SetFilename(filename + "PluginManager/DisabledFiles.cat::" + pFile->GetNameDirectory(this));
1071
			pFile->setFilename(filename + "PluginManager/DisabledFiles.cat::" + pFile->getNameDirectory(this));
1002
	}
1072
	}
1003
	else
1073
	else
1004
		pFile->SetFilename ( filename + pFile->GetNameDirectory(this) );
1074
		pFile->setFilename ( filename + pFile->getNameDirectory(this) );
1005
 
1075
 
1006
	if ( !bEnabled )
1076
	if ( !bEnabled )
1007
	{
1077
	{
1008
		if ( !pFile->IsInMod() )
1078
		if ( !pFile->IsInMod() )
1009
		{
1079
		{
1010
			if ( pFile->IsFakePatch() )
1080
			if ( pFile->IsFakePatch() )
1011
				pFile->SetFilename ( filename + "PluginManager/Disabled/FakePatches/FakePatch_" + this->GetNameValidFile() + "_" + this->author() + "_" + pFile->GetName() );
1081
				pFile->setFilename ( filename + "PluginManager/Disabled/FakePatches/FakePatch_" + this->getNameValidFile() + "_" + this->author() + "_" + pFile->name() );
1012
			else if ( pFile->IsAutoTextFile() )
1082
			else if ( pFile->isAutoTextFile() )
1013
				pFile->SetFilename ( filename + "PluginManager/Disabled/TextFiles/Text_" + this->GetNameValidFile() + "_" + this->author() + "_" + pFile->GetName() );
1083
				pFile->setFilename ( filename + "PluginManager/Disabled/TextFiles/Text_" + this->getNameValidFile() + "_" + this->author() + "_" + pFile->name() );
1014
			else
1084
			else
1015
				pFile->SetFullDir ( filename + "PluginManager/Disabled/" + pFile->GetDirectory(this) );
1085
				pFile->SetFullDir ( filename + "PluginManager/Disabled/" + pFile->getDirectory(this) );
1016
		}
1086
		}
1017
		pFile->SetDisabled(true);
1087
		pFile->SetDisabled(true);
1018
	}
1088
	}
1019
 
1089
 
1020
	CLog::logf(CLog::Log_Install, 2, "Adjusting the file pointer to correct install destintation, %s", pFile->filePointer().c_str());
1090
	CLog::logf(CLog::Log_Install, 2, "Adjusting the file pointer to correct install destintation, %s", pFile->filePointer().c_str());
1021
 
1091
 
1022
	return filename.ToString();
1092
	return filename;
1023
}
1093
}
1024
 
1094
 
1025
C_File *CBaseFile::_install_checkFile(C_File *pFile, CyStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
1095
C_File *CBaseFile::_install_checkFile(C_File *pFile, CyStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
1026
{
1096
{
1027
	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
1097
	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
Line 1556... Line 1626...
1556
		return false;
1626
		return false;
1557
 
1627
 
1558
	C_File *file = new C_File();
1628
	C_File *file = new C_File();
1559
 
1629
 
1560
	if (dir.left(5).Compare("GAME_")) {
1630
	if (dir.left(5).Compare("GAME_")) {
1561
		file->setGame(1 << 31 | 1 << dir.token("_", 2).toInt());
1631
		unsigned int iGame = dir.token("_", 2).toInt();
-
 
1632
		if (!iGame)
-
 
1633
			file->setGame(0);
-
 
1634
		else
-
 
1635
			file->setGame(1 << 31 | 1 << iGame);
1562
		dir = Utils::String::Null();
1636
		dir = Utils::String::Null();
1563
	} 
1637
	} 
1564
	else if ( line.countToken(":") >= 9 ) 
1638
	else if ( line.countToken(":") >= 9 ) 
1565
	{
1639
	{
1566
		Utils::String game = line.token(":", 9);
1640
		Utils::String game = line.token(":", 9);
1567
		if (game.contains("_"))
1641
		if (game.contains("_"))
-
 
1642
		{
1568
			file->setGame(1 << 31 | 1 << game.token("_", 2).toInt());
1643
			unsigned int iGame = game.token("_", 2).toInt();
-
 
1644
			if (iGame)
-
 
1645
				file->setGame(1 << 31 | 1 << iGame);
-
 
1646
			else
-
 
1647
				file->setGame(0);
-
 
1648
		}
1569
		else
1649
		else
1570
		{
1650
		{
1571
			int iGame = game.toInt();
1651
			int iGame = game.toInt();
1572
			if (iGame & (1 << 31))
1652
			if (iGame & (1 << 31))
1573
				file->setGame(iGame);
1653
				file->setGame(iGame);
-
 
1654
			else if (!iGame)
-
 
1655
				file->setGame(0);
1574
			else
1656
			else
1575
				file->setGame(1 << 31 | 1 << iGame);
1657
				file->setGame(1 << 31 | 1 << iGame);
1576
		}
1658
		}
1577
	}
1659
	}
1578
 
1660
 
Line 1619... Line 1701...
1619
	Input:  filename - the name of the file to open and read
1701
	Input:  filename - the name of the file to open and read
1620
			readdata - If falses, dont read the files to memory, just read the headers and values
1702
			readdata - If falses, dont read the files to memory, just read the headers and values
1621
	Return: boolean - return ture if acceptable format
1703
	Return: boolean - return ture if acceptable format
1622
	Desc:   Opens and reads the spk file and loads all data into class
1704
	Desc:   Opens and reads the spk file and loads all data into class
1623
*/
1705
*/
1624
bool CBaseFile::ReadFile ( CyString filename, int readtype, CProgressInfo *progress )
1706
bool CBaseFile::ReadFile(CyString filename, int readtype, CProgressInfo *progress)
-
 
1707
{
-
 
1708
	return readFile(filename.ToString(), readtype, progress);
-
 
1709
}
-
 
1710
bool CBaseFile::readFile(const Utils::String &filename, int readtype, CProgressInfo *progress)
1625
{
1711
{
1626
	CFileIO File(filename.ToString());
1712
	CFileIO File(filename);
1627
	if ( !File.startRead() ) return false;
1713
	if ( !File.startRead() ) return false;
1628
 
1714
 
1629
	bool ret = this->readFile(File, readtype, progress);
1715
	bool ret = this->readFile(File, readtype, progress);
1630
	if ( ret ) this->setFilename(filename.ToString());
1716
	if ( ret ) this->setFilename(filename);
1631
 
1717
 
1632
	File.close();
1718
	File.close();
1633
	return ret;
1719
	return ret;
1634
}
1720
}
1635
 
1721
 
Line 2745... Line 2831...
2745
		{
2831
		{
2746
			this->AddNeededLibrary(spk->name(), spk->author(), spk->version());
2832
			this->AddNeededLibrary(spk->name(), spk->author(), spk->version());
2747
			delete spk;
2833
			delete spk;
2748
		}
2834
		}
2749
	}
2835
	}
2750
	else if ( sFirst.Compare("Icon") )
2836
	else if (sFirst.Compare("Icon"))
2751
	{
2837
	{
2752
		C_File *icon = new C_File(sRest.c_str());
2838
		C_File *icon = new C_File(sRest.c_str());
2753
		if ( icon->ReadFromFile() )
2839
		if ( icon->ReadFromFile() )
2754
			this->SetIcon(icon, CFileIO(sRest).GetFileExtension());
2840
			this->SetIcon(icon, CFileIO(sRest).GetFileExtension());
2755
	}
2841
	}
-
 
2842
	else if (sFirst.Compare("CombineGameFiles"))
-
 
2843
		_bCombineFiles = sRest.Compare("true") || sRest.Compare("yes") || sRest.toInt();
2756
	else
2844
	else
2757
	{
2845
	{
2758
		Utils::String checkType = sFirst;
2846
		Utils::String checkType = sFirst;
2759
		bool shared = false;
2847
		bool shared = false;
2760
		if ( checkType.left(6).Compare("Shared") )
2848
		if ( checkType.left(6).Compare("Shared") )
Line 2877... Line 2965...
2877
			Utils::String addon = gameAddons.findString(Utils::String::Number(foundGame));
2965
			Utils::String addon = gameAddons.findString(Utils::String::Number(foundGame));
2878
			if (!addon.empty())
2966
			if (!addon.empty())
2879
			{
2967
			{
2880
				Utils::String dir = C_File::GetDirectory(filetype, rest, this);
2968
				Utils::String dir = C_File::GetDirectory(filetype, rest, this);
2881
				Utils::String filename = rest;
2969
				Utils::String filename = rest;
2882
				if (CCatFile::IsAddonDir(dir))
2970
				if (CCatFile::IsAddonDir(dir) && !filename.contains(addon))
-
 
2971
				{
2883
					filename = filename.findReplace(dir + "/", addon + "/" + dir + "/");
2972
					filename = filename.findReplace(dir + "/", addon + "/" + dir + "/");
2884
 
-
 
2885
				file = this->AppendFile(filename, filetype, addGame, dir);
2973
					file = this->AppendFile(filename, filetype, addGame, dir);
-
 
2974
				}
2886
			}
2975
			}
2887
		}
2976
		}
2888
 
2977
 
2889
		if(!file)
2978
		if(!file)
2890
			file = this->AppendFile(rest, filetype, addGame, dir);
2979
			file = this->AppendFile(rest, filetype, addGame, dir);