Subversion Repositories spk

Rev

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

Rev 149 Rev 155
Line 268... Line 268...
268
 
268
 
269
C_File *CBaseFile::AddFile(CyString file, CyString dir, int type, int game)
269
C_File *CBaseFile::AddFile(CyString file, CyString dir, int type, int game)
270
{
270
{
271
	return addFile(file.ToString(), dir.ToString(), (FileType)type, game);
271
	return addFile(file.ToString(), dir.ToString(), (FileType)type, game);
272
}
272
}
273
C_File *CBaseFile::addFile(const Utils::String &file, const Utils::String &dir, FileType type, int game)
273
C_File *CBaseFile::addFile(const Utils::String &file, const Utils::String &dir, FileType type, int game, bool packed)
274
{
274
{
275
	C_File *newfile = new C_File(file);
275
	C_File *newfile = new C_File(file);
276
	newfile->SetDir(dir);
276
	newfile->SetDir(dir);
277
	newfile->setFileType(type);
277
	newfile->setFileType(type);
278
	newfile->setGame(game);
278
	newfile->setGame(game);
-
 
279
 
-
 
280
	if (packed)
-
 
281
	{
-
 
282
		if (newfile->PCKFile())
-
 
283
		{
-
 
284
			newfile->setFilename(CFileIO(newfile->filePointer()).changeFileExtension("pck"));
-
 
285
		}
-
 
286
	}
279
 
287
 
280
	// first check if the file already exists
288
	// first check if the file already exists
281
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
289
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
282
	{
290
	{
283
		C_File *f = node->Data();
291
		C_File *f = node->Data();
Line 307... Line 315...
307
					newData = CFileIO(newfile->filePointer()).ReadToData(&newSize);
315
					newData = CFileIO(newfile->filePointer()).ReadToData(&newSize);
308
 
316
 
309
				// compare bytes
317
				// compare bytes
310
				bool matched = false;
318
				bool matched = false;
311
				if (size == newSize)
319
				if (size == newSize)
312
				{
320
				{
313
					matched = true;
321
					matched = true;
314
					for (unsigned long i = 0; i < size; ++i)
322
					for (unsigned long i = 0; i < size; ++i)
315
					{
323
					{
316
						if (data[i] != newData[i])
324
						if (data[i] != newData[i])
317
						{
325
						{
318
							matched = false;
326
							matched = false;
319
							break;
327
							break;
320
						}
328
						}
321
					}
329
					}
322
				}
330
				}
323
 
331
 
324
				if (data)
332
				if (data)
325
					delete data;
333
					delete data;
326
				if (newData)
334
				if (newData)
327
					delete newData;
335
					delete newData;
328
 
336
 
Line 340... Line 348...
340
		}
348
		}
341
 
349
 
342
		// must already exist, delete this one
350
		// must already exist, delete this one
343
		m_lFiles.remove(node, true);
351
		m_lFiles.remove(node, true);
344
		break;
352
		break;
345
	}
353
	}
346
 
354
 
347
	_addFile(newfile);
355
	_addFile(newfile);
348
 
356
 
349
	return newfile;
357
	return newfile;
350
}
358
}
Line 357... Line 365...
357
 
365
 
358
	// compress the file
366
	// compress the file
359
	return f->CompressData ( m_SHeader2.iDataCompression, progress );
367
	return f->CompressData ( m_SHeader2.iDataCompression, progress );
360
}
368
}
361
 
369
 
362
C_File *CBaseFile::AppendFile ( CyString file, int type, int game, CyString dir, CProgressInfo *progress )
370
C_File *CBaseFile::appendFile(const Utils::String &file, int type, int game, bool packed, const Utils::String &dir, CProgressInfo *progress )
363
{
371
{
364
	C_File *newfile = AddFile ( file, dir, type, game );
372
	C_File *newfile = addFile(file, dir, static_cast<FileType>(type), game, packed);
365
	if ( !newfile )
373
	if ( !newfile )
366
		return NULL;
374
		return NULL;
367
 
-
 
368
 
375
 
369
	// read the file into memory
376
	// read the file into memory
-
 
377
	if (newfile->GetData() && newfile->GetDataSize())
-
 
378
	{
-
 
379
		// now compress the file
-
 
380
		if (newfile->CompressData(m_SHeader2.iDataCompression, progress))
-
 
381
			return newfile;
-
 
382
	}
370
	if ( newfile->ReadFromFile () )
383
	if ( newfile->ReadFromFile () )
371
	{
384
	{
372
		// now compress the file
385
		// now compress the file
373
		if ( newfile->CompressData ( m_SHeader2.iDataCompression, progress ) )
386
		if ( newfile->CompressData ( m_SHeader2.iDataCompression, progress ) )
374
			return newfile;
387
			return newfile;
Line 946... Line 959...
946
		fit->SetName ( newname + "." + fit->GetFileExt() );
959
		fit->SetName ( newname + "." + fit->GetFileExt() );
947
 
960
 
948
		// find the next gap
961
		// find the next gap
949
		if ( !opposite ) {
962
		if ( !opposite ) {
950
			startfake = pPackages->FindNextFakePatch(startfake + 1);
963
			startfake = pPackages->FindNextFakePatch(startfake + 1);
951
		}
964
		}
952
	}
965
	}
953
 
966
 
954
}
967
}
955
 
968
 
956
void CBaseFile::_install_renameText(CPackages *pPackages)
969
void CBaseFile::_install_renameText(CPackages *pPackages)
957
{
970
{
958
	int starttext = pPackages->findNextTextFile();
971
	int starttext = pPackages->findNextTextFile();
Line 2959... Line 2972...
2959
	}
2972
	}
2960
	else
2973
	else
2961
	{
2974
	{
2962
		Utils::String checkType = sFirst;
2975
		Utils::String checkType = sFirst;
2963
		bool shared = false;
2976
		bool shared = false;
2964
		if ( checkType.left(6).Compare("Shared") )
2977
		if (checkType.left(6).Compare("Shared"))
2965
		{
2978
		{
2966
			checkType = sFirst.right(-6);
2979
			checkType = sFirst.right(-6);
2967
			shared = true;
2980
			shared = true;
-
 
2981
		}
-
 
2982
		bool packed = false;
-
 
2983
		if (checkType.right(3).Compare("PCK"))
-
 
2984
		{
-
 
2985
			checkType = sFirst.left(-3);
-
 
2986
			packed = true;
2968
		}
2987
		}
2969
 
2988
 
2970
		// now check type name
2989
		// now check type name
2971
		FileType filetype = GetFileTypeFromString(checkType);
2990
		FileType filetype = GetFileTypeFromString(checkType);
2972
		if (filetype != FILETYPE_UNKNOWN)
2991
		if (filetype != FILETYPE_UNKNOWN)
2973
			this->AddFileScript(filetype, shared, sRest, sMainGame, otherGames, gameAddons, progress);
2992
			this->AddFileScript(filetype, shared, packed, sRest, sMainGame, otherGames, gameAddons, progress);
2974
		else if ( !checkType.Compare("changelog") )
2993
		else if ( !checkType.Compare("changelog") )
2975
			return false;
2994
			return false;
2976
	}
2995
	}
2977
 
2996
 
2978
	return true;
2997
	return true;
2979
}
2998
}
2980
 
2999
 
2981
void CBaseFile::AddFileScript(FileType filetype, bool shared, CyString sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons, CProgressInfo *progress)
3000
void CBaseFile::AddFileScript(FileType filetype, bool shared, bool packed, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons, CProgressInfo *progress)
2982
{
3001
{
2983
	Utils::String dir;
3002
	Utils::String dir;
2984
	Utils::String rest = sRest.ToString();
3003
	Utils::String rest = sRest;
2985
 
3004
 
2986
	unsigned int mainGame = CBaseFile::GetGameFromString(sMainGame);
3005
	unsigned int mainGame = CBaseFile::GetGameFromString(sMainGame);
2987
	unsigned int game = 0;
3006
	unsigned int game = 0;
2988
	if ( rest.token(" ", 1).left(4).Compare("GAME") ) {
3007
	if ( rest.token(" ", 1).left(4).Compare("GAME") ) {
2989
		Utils::String gameStr = rest.token(" ", 2);
3008
		Utils::String gameStr = rest.token(" ", 2);
Line 3036... Line 3055...
3036
						CFileIO F(file);
3055
						CFileIO F(file);
3037
						for(Utils::String g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
3056
						for(Utils::String g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
3038
							Utils::String checkDir = F.dir() + "/" + g;
3057
							Utils::String checkDir = F.dir() + "/" + g;
3039
							if ( CDirIO(checkDir).exists(F.filename()) ) {
3058
							if ( CDirIO(checkDir).exists(F.filename()) ) {
3040
								addGame = mainGame;
3059
								addGame = mainGame;
3041
								C_File *newfile = this->AppendFile(CDirIO(checkDir).File(F.filename()), filetype, CBaseFile::GetGameFromString(g), dir);
3060
								C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()), filetype, CBaseFile::GetGameFromString(g), packed, dir);
3042
								if (newfile && progress)
3061
								if (newfile && progress)
3043
									progress->UpdateFile(newfile);
3062
									progress->UpdateFile(newfile);
3044
								if ( newfile ) newfile->SetShared(shared);
3063
								if ( newfile ) newfile->SetShared(shared);
3045
							}
3064
							}
3046
						}
3065
						}
3047
					}
3066
					}
3048
 
3067
 
3049
					C_File *newfile = this->AppendFile(file, filetype, addGame, dir);
3068
					C_File *newfile = this->appendFile(file, filetype, addGame, dir);
3050
					if (newfile && progress)
3069
					if (newfile && progress)
3051
						progress->UpdateFile(newfile);
3070
						progress->UpdateFile(newfile);
3052
					if ( newfile )
3071
					if ( newfile )
3053
						newfile->SetShared(shared);
3072
						newfile->SetShared(shared);
3054
				}
3073
				}
Line 3064... Line 3083...
3064
			CFileIO F(rest);
3083
			CFileIO F(rest);
3065
			for(Utils::String g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
3084
			for(Utils::String g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
3066
				Utils::String checkDir = F.dir() + "/" + g;
3085
				Utils::String checkDir = F.dir() + "/" + g;
3067
				if ( CDirIO(checkDir).exists(F.filename()) ) {
3086
				if ( CDirIO(checkDir).exists(F.filename()) ) {
3068
					addGame = mainGame;
3087
					addGame = mainGame;
3069
					C_File *newfile = this->AppendFile(CDirIO(checkDir).file(F.filename()), filetype, CBaseFile::GetGameFromString(g), dir);
3088
					C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()), filetype, CBaseFile::GetGameFromString(g), packed, dir);
3070
					if (newfile && progress)
3089
					if (newfile && progress)
3071
						progress->UpdateFile(newfile);
3090
						progress->UpdateFile(newfile);
3072
					if ( newfile ) newfile->SetShared(shared);
3091
					if ( newfile ) newfile->SetShared(shared);
3073
				}
3092
				}
3074
			}
3093
			}
Line 3094... Line 3113...
3094
				Utils::String dir = C_File::GetDirectory(filetype, rest, this);
3113
				Utils::String dir = C_File::GetDirectory(filetype, rest, this);
3095
				Utils::String filename = rest;
3114
				Utils::String filename = rest;
3096
				if (CCatFile::IsAddonDir(dir) && !filename.contains(addon))
3115
				if (CCatFile::IsAddonDir(dir) && !filename.contains(addon))
3097
				{
3116
				{
3098
					filename = filename.findReplace(dir + "/", addon + "/" + dir + "/");
3117
					filename = filename.findReplace(dir + "/", addon + "/" + dir + "/");
3099
					file = this->AppendFile(filename, filetype, addGame, dir);
3118
					file = this->appendFile(filename, filetype, addGame, packed, dir);
3100
				}
3119
				}
3101
			}
3120
			}
3102
		}
3121
		}
3103
 
3122
 
3104
		if(!file)
3123
		if(!file)
3105
			file = this->AppendFile(rest, filetype, addGame, dir);
3124
			file = this->appendFile(rest, filetype, addGame, packed, dir);
3106
 
3125
 
3107
		if (file && progress)
3126
		if (file && progress)
3108
			progress->UpdateFile(file);
3127
			progress->UpdateFile(file);
3109
		if (file)
3128
		if (file)
3110
			file->SetShared(shared);
3129
			file->SetShared(shared);