Subversion Repositories spk

Rev

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

Rev 211 Rev 213
Line 577... Line 577...
577
		{
577
		{
578
			if (!fit->UncompressData(progress))
578
			if (!fit->UncompressData(progress))
579
			{
579
			{
580
				if (fit->GetCompressionType() == SPKCOMPRESS_7ZIP)
580
				if (fit->GetCompressionType() == SPKCOMPRESS_7ZIP)
581
				{
581
				{
582
					if (!fit->uncompressToFile("temp", this, false, progress))
582
					if (!fit->uncompressToFile(L"temp", this, false, progress))
583
						return false;
583
						return false;
584
					else
584
					else
585
					{
585
					{
586
						uncomprToFile = true;
586
						uncomprToFile = true;
587
						fit->setFullDir("temp");
587
						fit->setFullDir(L"temp");
588
					}
588
					}
589
				}
589
				}
590
 
590
 
591
				if (!uncomprToFile)
591
				if (!uncomprToFile)
592
					return false;
592
					return false;
Line 900... Line 900...
900
		// only do fake patchs
900
		// only do fake patchs
901
		if ( !fit->IsFakePatch() )
901
		if ( !fit->IsFakePatch() )
902
			continue;
902
			continue;
903
 
903
 
904
		// we should only have cat and dat files, but lets check just incase they have been added incorrectly
904
		// we should only have cat and dat files, but lets check just incase they have been added incorrectly
905
		if ( !fit->checkFileExt ("cat") && !fit->checkFileExt("dat") )
905
		if ( !fit->checkFileExt (L"cat") && !fit->checkFileExt(L"dat") )
906
			continue;
906
			continue;
907
 
907
 
908
		// search for the name on the list
908
		// search for the name on the list
909
		Utils::WString newname;
909
		Utils::WString newname;
910
		bool isOpposite = false;
910
		bool isOpposite = false;
Line 919... Line 919...
919
			lPatches.pushBack(fit->baseName(), newname);
919
			lPatches.pushBack(fit->baseName(), newname);
920
		}
920
		}
921
 
921
 
922
		// rename the file
922
		// rename the file
923
		fit->FixOriginalName();
923
		fit->FixOriginalName();
924
		CLog::logf(CLog::Log_Install, 2, "Adjusting fake patch number, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
924
		CLog::logf(CLog::Log_Install, 2, "Adjusting fake patch number, %s => %s", fit->getNameDirectory(this).c_str(), (newname + L"." + fit->fileExt()).c_str());
925
		fit->setName(newname + "." + fit->fileExt());
925
		fit->setName(newname + L"." + fit->fileExt());
926
 
926
 
927
		// find the next gap
927
		// find the next gap
928
		if ( !isOpposite ) {
928
		if ( !isOpposite ) {
929
			startfake = pPackages->findNextFakePatch(startfake + 1);
929
			startfake = pPackages->findNextFakePatch(startfake + 1);
930
		}
930
		}
Line 952... Line 952...
952
{
952
{
953
	if ( !bEnable )
953
	if ( !bEnable )
954
	{
954
	{
955
		if ( (fit->GetFileType() == FILETYPE_UNINSTALL) || (fit->GetFileType() == FILETYPE_README) || (fit->GetFileType() == FILETYPE_ADVERT) )
955
		if ( (fit->GetFileType() == FILETYPE_UNINSTALL) || (fit->GetFileType() == FILETYPE_README) || (fit->GetFileType() == FILETYPE_ADVERT) )
956
			bEnable = true;
956
			bEnable = true;
957
		else if ( (fit->GetFileType() == FILETYPE_EXTRA) && (fit->dir().left(7).lower() == "Extras/") )
957
		else if ( (fit->GetFileType() == FILETYPE_EXTRA) && (fit->dir().left(7).lower() == L"Extras/") )
958
			bEnable = true;
958
			bEnable = true;
959
		else if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) && (!fit->IsFakePatch()) )
959
		else if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) && (!fit->IsFakePatch()) )
960
			bEnable = true;
960
			bEnable = true;
961
 
961
 
962
		if ( bEnable ) CLog::logf(CLog::Log_Install, 3, "Filetype(%d) is always enabled, setting enabled flag", fit->GetFileType());
962
		if ( bEnable ) CLog::logf(CLog::Log_Install, 3, "Filetype(%d) is always enabled, setting enabled flag", fit->GetFileType());
Line 971... Line 971...
971
	_sLastError = fit->getNameDirectory(this);
971
	_sLastError = fit->getNameDirectory(this);
972
	_iLastError = SPKERR_UNCOMPRESS;
972
	_iLastError = SPKERR_UNCOMPRESS;
973
 
973
 
974
	if ( !fit->UncompressData ( progress ) )
974
	if ( !fit->UncompressData ( progress ) )
975
	{
975
	{
976
		CLog::log(CLog::Log_Install, 2, "Failed to uncompress data, attempting file decompression");
976
		CLog::log(CLog::Log_Install, 2, L"Failed to uncompress data, attempting file decompression");
977
		if ( fit->GetCompressionType() == SPKCOMPRESS_7ZIP )
977
		if ( fit->GetCompressionType() == SPKCOMPRESS_7ZIP )
978
		{
978
		{
979
			if ( fit->uncompressToFile(Utils::WString::Null(), this, false, progress ) )
979
			if ( fit->uncompressToFile(Utils::WString::Null(), this, false, progress ) )
980
				*uncomprToFile = true;
980
				*uncomprToFile = true;
981
		}
981
		}
982
 
982
 
983
		if ( !uncomprToFile )
983
		if ( !uncomprToFile )
984
		{
984
		{
985
			if ( errorStr )
985
			if ( errorStr )
986
				errorStr->pushBack(_sLastError, ERRORLOG(SPKINSTALL_UNCOMPRESS_FAIL));
986
				errorStr->pushBack(_sLastError, ERRORLOG(SPKINSTALL_UNCOMPRESS_FAIL));
987
			CLog::log(CLog::Log_Install, 1, "Unable to decompress file, skipping");
987
			CLog::log(CLog::Log_Install, 1, L"Unable to decompress file, skipping");
988
			return false;
988
			return false;
989
		}
989
		}
990
	}
990
	}
991
	ClearError ();
991
	ClearError ();
992
 
992
 
Line 997... Line 997...
997
{
997
{
998
	// new check if we should install the file
998
	// new check if we should install the file
999
	// first get the version
999
	// first get the version
1000
	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
1000
	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
1001
	{
1001
	{
1002
		CLog::log(CLog::Log_Install, 2, "Checking for existing file version");
1002
		CLog::log(CLog::Log_Install, 2, L"Checking for existing file version");
1003
		C_File checkfile;
1003
		C_File checkfile;
1004
		Utils::WString checkfilename = sDestination;
1004
		Utils::WString checkfilename = sDestination;
1005
		if ( !checkfilename.empty() ) checkfilename += L"/";
1005
		if ( !checkfilename.empty() ) checkfilename += L"/";
1006
		checkfilename += pFile->getNameDirectory(this);
1006
		checkfilename += pFile->getNameDirectory(this);
1007
		checkfile.setFilename(checkfilename);
1007
		checkfile.setFilename(checkfilename);
1008
		checkfile.setFileType(pFile->fileType());
1008
		checkfile.setFileType(pFile->fileType());
1009
		if ( checkfile.CheckValidFilePointer() ) {
1009
		if ( checkfile.CheckValidFilePointer() ) {
1010
			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
1010
			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
1011
				CLog::log(CLog::Log_Install, 1, "Newer version of the file found in directory, skipping");
1011
				CLog::log(CLog::Log_Install, 1, L"Newer version of the file found in directory, skipping");
1012
				return false;
1012
				return false;
1013
			}
1013
			}
1014
		}
1014
		}
1015
	}
1015
	}
1016
 
1016
 
Line 1062... Line 1062...
1062
		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
1062
		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
1063
		{
1063
		{
1064
			if ( !cFile->MatchFile(pFile) ) continue;
1064
			if ( !cFile->MatchFile(pFile) ) continue;
1065
			if ( !m_bOverrideFiles && !cFile->CompareNew(pFile) ) {
1065
			if ( !m_bOverrideFiles && !cFile->CompareNew(pFile) ) {
1066
				if ( errorStr ) errorStr->pushBack(pFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_SKIPFILE));
1066
				if ( errorStr ) errorStr->pushBack(pFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_SKIPFILE));
1067
				CLog::log(CLog::Log_Install, 1, "Newer version of the file already installed, skipping");
1067
				CLog::log(CLog::Log_Install, 1, L"Newer version of the file already installed, skipping");
1068
				*bDoFile = false;
1068
				*bDoFile = false;
1069
			}
1069
			}
1070
			break;
1070
			break;
1071
		}
1071
		}
1072
 
1072
 
Line 1172... Line 1172...
1172
			sInstalledFile.erase(0, 1);
1172
			sInstalledFile.erase(0, 1);
1173
	}
1173
	}
1174
 
1174
 
1175
	if ( !pFile->writeFilePointer() )
1175
	if ( !pFile->writeFilePointer() )
1176
	{
1176
	{
1177
		CLog::log(CLog::Log_Install, 1, "Failed to write the file");
1177
		CLog::log(CLog::Log_Install, 1, L"Failed to write the file");
1178
		if ( errorStr )
1178
		if ( errorStr )
1179
			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
1179
			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
1180
	}
1180
	}
1181
	else
1181
	else
1182
	{
1182
	{
1183
		CLog::log(CLog::Log_Install, 1, "File written successfully");
1183
		CLog::log(CLog::Log_Install, 1, L"File written successfully");
1184
		CLog::log(CLog::Log_Install, 2, "Checking signed status of the file");
1184
		CLog::log(CLog::Log_Install, 2, L"Checking signed status of the file");
1185
		pFile->UpdateSigned();
1185
		pFile->UpdateSigned();
1186
		if ( errorStr )
1186
		if ( errorStr )
1187
			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
1187
			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
1188
 
1188
 
1189
		switch(pFile->GetFileType())
1189
		switch(pFile->GetFileType())
1190
		{
1190
		{
1191
			case FILETYPE_SCRIPT:
1191
			case FILETYPE_SCRIPT:
1192
			case FILETYPE_UNINSTALL:
1192
			case FILETYPE_UNINSTALL:
1193
				CLog::log(CLog::Log_Install, 2, "Updating file signature");
1193
				CLog::log(CLog::Log_Install, 2, L"Updating file signature");
1194
				pFile->updateSignature();
1194
				pFile->updateSignature();
1195
				break;
1195
				break;
1196
		}
1196
		}
1197
	}
1197
	}
1198
}
1198
}
Line 1320... Line 1320...
1320
			else
1320
			else
1321
			{
1321
			{
1322
				// old file is found in list, switch to using new one
1322
				// old file is found in list, switch to using new one
1323
				if ( (filelist) && (adjustPointer) ) {
1323
				if ( (filelist) && (adjustPointer) ) {
1324
					adjustPointer->CopyData(fit, false);
1324
					adjustPointer->CopyData(fit, false);
1325
					CLog::log(CLog::Log_Install, 2, "Copying data into existing file");
1325
					CLog::log(CLog::Log_Install, 2, L"Copying data into existing file");
1326
				}
1326
				}
1327
 
1327
 
1328
				Utils::WString fpointer = fit->filePointer();
1328
				Utils::WString fpointer = fit->filePointer();
1329
				_iLastError = SPKERR_CREATEDIRECTORY;
1329
				_iLastError = SPKERR_CREATEDIRECTORY;
1330
				Utils::WString dir = CFileIO(fit->filePointer()).dir();
1330
				Utils::WString dir = CFileIO(fit->filePointer()).dir();
Line 1343... Line 1343...
1343
			ClearError ();
1343
			ClearError ();
1344
		}
1344
		}
1345
 
1345
 
1346
		if ( adjustPointer )
1346
		if ( adjustPointer )
1347
		{
1347
		{
1348
			CLog::log(CLog::Log_Install, 2, "Adjusting pointers to existing file and deleting new file pointer");
1348
			CLog::log(CLog::Log_Install, 2, L"Adjusting pointers to existing file and deleting new file pointer");
1349
			node->ChangeData(adjustPointer);
1349
			node->ChangeData(adjustPointer);
1350
			delete fit;
1350
			delete fit;
1351
		}
1351
		}
1352
 
1352
 
1353
		CLog::log(CLog::Log_Install, 1, "File installation completed");
1353
		CLog::log(CLog::Log_Install, 1, L"File installation completed");
1354
	}
1354
	}
1355
 
1355
 
1356
	// now clear or data memory
1356
	// now clear or data memory
1357
	CLog::log(CLog::Log_Install, 2, "Delting temporary file data from memory");
1357
	CLog::log(CLog::Log_Install, 2, L"Delting temporary file data from memory");
1358
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) node->Data()->DeleteData();
1358
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) node->Data()->DeleteData();
1359
 
1359
 
1360
	return !bFailed;
1360
	return !bFailed;
1361
}
1361
}
1362
 
1362
 
Line 1597... Line 1597...
1597
		Utils::WString game = line.token(L":", 9);
1597
		Utils::WString game = line.token(L":", 9);
1598
		if (game.contains(L"_"))
1598
		if (game.contains(L"_"))
1599
		{
1599
		{
1600
			unsigned int iGame = game.token(L"_", 2).toInt();
1600
			unsigned int iGame = game.token(L"_", 2).toInt();
1601
			if (iGame)
1601
			if (iGame)
1602
				file->setGame(1 << 31 | 1 << iGame);
1602
				file->setGame(1 << 31 | 1 << iGame);
1603
			else
1603
			else
1604
				file->setGame(0);
1604
				file->setGame(0);
1605
		}
1605
		}
1606
		else
1606
		else
1607
		{
1607
		{
Line 1817... Line 1817...
1817
	{
1817
	{
1818
		long len = uncomprLen;
1818
		long len = uncomprLen;
1819
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader2.lSize, (size_t*)&len, NULL );
1819
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader2.lSize, (size_t*)&len, NULL );
1820
		// update the progress for each section
1820
		// update the progress for each section
1821
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
1821
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
-
 
1822
		if (compr) 
-
 
1823
		{
-
 
1824
			if (m_SHeader.fVersion < 4.4f)
-
 
1825
			{
1822
		if ( compr ) _readFiles((char *)compr);
1826
				std::string data((char*)compr);
-
 
1827
				_readFiles(std::wstring(data.begin(), data.end()));
-
 
1828
			}
-
 
1829
			else
-
 
1830
			{
-
 
1831
				std::wstring data((wchar_t*)compr);
-
 
1832
				_readFiles(data);
-
 
1833
			}
-
 
1834
		}
1823
	}
1835
	}
1824
	else
1836
	else
-
 
1837
	{
-
 
1838
		if (m_SHeader.fVersion < 4.4f)
-
 
1839
		{
1825
		_readFiles((char *)readData);
1840
			std::string data((char*)readData);
-
 
1841
			_readFiles(std::wstring(data.begin(), data.end()));
-
 
1842
		}
-
 
1843
		else
-
 
1844
		{
-
 
1845
			std::wstring data((wchar_t*)readData);
-
 
1846
			_readFiles(data);
-
 
1847
		}
-
 
1848
	}
1826
 
1849
 
1827
	delete []readData;
1850
	delete []readData;
1828
	return true;
1851
	return true;
1829
}
1852
}
1830
 
1853
 
Line 1937... Line 1960...
1937
	for(auto itr = webMirrors().begin(); itr != webMirrors().end(); itr++)
1960
	for(auto itr = webMirrors().begin(); itr != webMirrors().end(); itr++)
1938
		values += Utils::WString(L"WebMirror: ") + (*itr)->str + L"\n";
1961
		values += Utils::WString(L"WebMirror: ") + (*itr)->str + L"\n";
1939
	if ( !this->description().empty() ) {
1962
	if ( !this->description().empty() ) {
1940
		Utils::WString desc = this->description();
1963
		Utils::WString desc = this->description();
1941
		desc = desc.findReplace(L"<newline>", L"<br>");
1964
		desc = desc.findReplace(L"<newline>", L"<br>");
1942
		desc = desc.findReplace(L"\n", "L<br>");
1965
		desc = desc.findReplace(L"\n", L"<br>");
1943
		desc.remove(L'\r');
1966
		desc.remove(L'\r');
1944
		values += L"Desc: " + desc + L"\n";
1967
		values += L"Desc: " + desc + L"\n";
1945
	}
1968
	}
1946
 
1969
 
1947
	for ( CListNode<SGameCompat> *gc = m_lGames.Front(); gc; gc = gc->next() ) {
1970
	for ( CListNode<SGameCompat> *gc = m_lGames.Front(); gc; gc = gc->next() ) {
Line 2800... Line 2823...
2800
}
2823
}
2801
 
2824
 
2802
Utils::WString CBaseFile::_replaceFilename(const Utils::WString &fname)
2825
Utils::WString CBaseFile::_replaceFilename(const Utils::WString &fname)
2803
{
2826
{
2804
	Utils::WString filename = fname;
2827
	Utils::WString filename = fname;
2805
	Utils::WString cdate = this->creationDate().findReplace("/", ".").remove(' ');
2828
	Utils::WString cdate = this->creationDate().findReplace(L"/", L".").remove(' ');
2806
	if (filename.contains(L"$AUTOSAVE"))
2829
	if (filename.contains(L"$AUTOSAVE"))
2807
	{
2830
	{
2808
		if (this->GetType() == TYPE_XSP)
2831
		if (this->GetType() == TYPE_XSP)
2809
			filename = filename.findReplace(L"$AUTOSAVE", L"$NAME-V$VERSION-$CDATE.xsp");
2832
			filename = filename.findReplace(L"$AUTOSAVE", L"$NAME-V$VERSION-$CDATE.xsp");
2810
		else
2833
		else
Line 2858... Line 2881...
2858
			this->setExportFilename(CFileIO(filename).changeFileExtension(L"rar"));
2881
			this->setExportFilename(CFileIO(filename).changeFileExtension(L"rar"));
2859
		else
2882
		else
2860
			this->setFilename(filename);
2883
			this->setFilename(filename);
2861
	}
2884
	}
2862
	else if (sFirst.Compare(L"WebSite"))		this->setWebSite(sRest);
2885
	else if (sFirst.Compare(L"WebSite"))		this->setWebSite(sRest);
2863
	else if (sFirst.Compare(L"ForumLink") || sFirst.Compare("Forum")) this->setForumLink(sRest);
2886
	else if (sFirst.Compare(L"ForumLink") || sFirst.Compare(L"Forum")) this->setForumLink(sRest);
2864
	else if (sFirst.Compare(L"Email"))			this->setEmail(sRest);
2887
	else if (sFirst.Compare(L"Email"))			this->setEmail(sRest);
2865
	else if (sFirst.Compare(L"WebAddress"))		this->setWebAddress(sRest);
2888
	else if (sFirst.Compare(L"WebAddress"))		this->setWebAddress(sRest);
2866
	else if (sFirst.Compare(L"WebMirror"))
2889
	else if (sFirst.Compare(L"WebMirror"))
2867
		this->addWebMirror(sRest);
2890
		this->addWebMirror(sRest);
2868
	else if (sFirst.Compare(L"WebMirror1"))
2891
	else if (sFirst.Compare(L"WebMirror1"))
Line 2962... Line 2985...
2962
 
2985
 
2963
		// now check type name
2986
		// now check type name
2964
		FileType filetype = GetFileTypeFromString(checkType);
2987
		FileType filetype = GetFileTypeFromString(checkType);
2965
		if (filetype != FILETYPE_UNKNOWN)
2988
		if (filetype != FILETYPE_UNKNOWN)
2966
			this->addFileScript(filetype, shared, packed, sRest, sMainGame, otherGames, gameAddons, progress);
2989
			this->addFileScript(filetype, shared, packed, sRest, sMainGame, otherGames, gameAddons, progress);
2967
		else if ( !checkType.Compare("changelog") )
2990
		else if ( !checkType.Compare(L"changelog") )
2968
			return false;
2991
			return false;
2969
	}
2992
	}
2970
 
2993
 
2971
	return true;
2994
	return true;
2972
}
2995
}
Line 3106... Line 3129...
3106
Utils::WString CBaseFile::fileSizeString() const { return SPK::GetSizeString ( this->fileSize() ); }
3129
Utils::WString CBaseFile::fileSizeString() const { return SPK::GetSizeString ( this->fileSize() ); }
3107
 
3130
 
3108
// used for a multiple spk file
3131
// used for a multiple spk file
3109
unsigned char *CBaseFile::createData(size_t *size, CProgressInfo *progress)
3132
unsigned char *CBaseFile::createData(size_t *size, CProgressInfo *progress)
3110
{
3133
{
3111
	if ( this->writeFile("temp.dat", progress) ) {
3134
	if ( this->writeFile(L"temp.dat", progress) ) {
3112
		CFileIO File(L"temp.dat");
3135
		CFileIO File(L"temp.dat");
3113
		File.setAutoDelete(true);
3136
		File.setAutoDelete(true);
3114
		return File.readAll(size);
3137
		return File.readAll(size);
3115
	}
3138
	}
3116
	return NULL;
3139
	return NULL;
Line 3138... Line 3161...
3138
void CBaseFile::convertAutoText(C_File *f) const
3161
void CBaseFile::convertAutoText(C_File *f) const
3139
{
3162
{
3140
	Utils::WString to;
3163
	Utils::WString to;
3141
	if ( f->baseName().contains(L"-L") )
3164
	if ( f->baseName().contains(L"-L") )
3142
		to = L"0000-L" + f->baseName().token(L"-L", 2);
3165
		to = L"0000-L" + f->baseName().token(L"-L", 2);
3143
	else if ( f->baseName().contains("-l") )
3166
	else if ( f->baseName().contains(L"-l") )
3144
		to = L"0000-L" + f->baseName().token(L"-l", 2);
3167
		to = L"0000-L" + f->baseName().token(L"-l", 2);
3145
	else
3168
	else
3146
		to = f->baseName().left(-4) + L"0000";
3169
		to = f->baseName().left(-4) + L"0000";
3147
 
3170
 
3148
	// file link
3171
	// file link