Subversion Repositories spk

Rev

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

Rev 172 Rev 175
Line 193... Line 193...
193
	}
193
	}
194
 
194
 
195
	return NULL;
195
	return NULL;
196
}
196
}
197
 
197
 
198
int CBaseFile::CheckFile ( CyString filename, float *version )
198
int CBaseFile::CheckFile(const Utils::String &filename, float *version )
199
{
199
{
200
	CFileIO File(filename);
200
	CFileIO File(filename);
201
	if ( !File.startRead() ) return 0;
201
	if ( !File.startRead() ) return 0;
202
	Utils::String line = File.readEndOfLine();
202
	Utils::String line = File.readEndOfLine();
203
	Utils::String type = line.token(";", 1);
203
	Utils::String type = line.token(";", 1);
Line 620... Line 620...
620
	        line - Pointed to hold the line number thats read
620
	        line - Pointed to hold the line number thats read
621
			upper - true if it converts to uppercase
621
			upper - true if it converts to uppercase
622
	Return: String - the string it has read
622
	Return: String - the string it has read
623
	Desc:   Reads a string from a file, simlar to readLine() classes, reads to the end of the line in a file
623
	Desc:   Reads a string from a file, simlar to readLine() classes, reads to the end of the line in a file
624
*/
624
*/
625
CyString CBaseFile::GetEndOfLine ( FILE *id, int *line, bool upper )
625
Utils::String CBaseFile::GetEndOfLine ( FILE *id, int *line, bool upper )
626
{
626
{
627
	CyString word;
627
	Utils::String word;
628
 
628
 
629
	char c = fgetc ( id );
629
	char c = fgetc ( id );
630
	if ( c == -1 )
630
	if ( c == -1 )
631
		return "";
631
		return "";
632
 
632
 
Line 638... Line 638...
638
 
638
 
639
	if ( line )
639
	if ( line )
640
		++(*line);
640
		++(*line);
641
 
641
 
642
	if ( upper )
642
	if ( upper )
643
		return word.ToUpper();
643
		return word.upper();
644
 
644
 
645
	return word;
645
	return word;
646
}
646
}
647
 
647
 
648
size_t CBaseFile::countFiles(FileType filetype) const
648
size_t CBaseFile::countFiles(FileType filetype) const
Line 662... Line 662...
662
/*
662
/*
663
	Func:   CreateFilesLine
663
	Func:   CreateFilesLine
664
	Return: String - returns the full string for files list
664
	Return: String - returns the full string for files list
665
	Desc:   Creates a signle line list of all the files
665
	Desc:   Creates a signle line list of all the files
666
*/
666
*/
667
Utils::String CBaseFile::createFilesLine(bool updateheader, CProgressInfo* progress)
667
Utils::String CBaseFile::createFilesLine(SSPKHeader2 *header, CProgressInfo* progress) const
668
{
668
{
669
	Utils::String line;
669
	Utils::String line;
670
 
670
 
671
	if (progress)
671
	if (progress)
672
	{
672
	{
673
		progress->SetDone(0);
673
		progress->SetDone(0);
674
		progress->UpdateStatus(STATUS_COMPRESS);
674
		progress->UpdateStatus(STATUS_COMPRESS);
675
	}
675
	}
676
 
676
 
677
	if (updateheader)
677
	if (header)
678
	{
678
	{
-
 
679
		header->iDataCompression = m_SHeader2.iDataCompression;
-
 
680
		header->iFileCompression = m_SHeader2.iFileCompression;
-
 
681
		header->lSize = m_SHeader2.lSize;
679
		m_SHeader2.iNumFiles = 0;
682
		header->iNumFiles = 0;
680
		m_SHeader2.lFullSize = 0;
683
		header->lFullSize = 0;
681
	}
684
	}
682
 
685
 
683
	if (m_pIconFile)
686
	if (m_pIconFile)
684
	{
687
	{
685
		// no data, read it from file
688
		// no data, read it from file
Line 689... Line 692...
689
		// compress the file
692
		// compress the file
690
		if (!m_pIconFile->CompressData(m_SHeader2.iDataCompression, progress))
693
		if (!m_pIconFile->CompressData(m_SHeader2.iDataCompression, progress))
691
			m_pIconFile->SetDataCompression(SPKCOMPRESS_NONE);
694
			m_pIconFile->SetDataCompression(SPKCOMPRESS_NONE);
692
 
695
 
693
		line += "Icon:" + Utils::String::Number(m_pIconFile->GetDataSize() + (long)4) + ":" + m_pIconFile->GetUncompressedDataSize() + ":" + (long)m_pIconFile->GetCompressionType() + ":" + _sIconExt + "\n";
696
		line += "Icon:" + Utils::String::Number(m_pIconFile->GetDataSize() + (long)4) + ":" + m_pIconFile->GetUncompressedDataSize() + ":" + (long)m_pIconFile->GetCompressionType() + ":" + _sIconExt + "\n";
694
		if (updateheader)
697
		if (header)
695
		{
698
		{
696
			++m_SHeader2.iNumFiles;
699
			++header->iNumFiles;
697
			m_SHeader2.lFullSize += (m_pIconFile->GetDataSize() + 4);
700
			header->lFullSize += (m_pIconFile->GetDataSize() + 4);
698
		}
701
		}
699
	}
702
	}
700
 
703
 
701
	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
704
	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
702
	{
705
	{
Line 737... Line 740...
737
		if (file->dir().empty())
740
		if (file->dir().empty())
738
			line += command + ":" + (file->GetDataSize() + (long)4) + ":" + file->GetUncompressedDataSize() + ":" + (long)file->GetCompressionType() + ":" + (long)file->GetCreationTime() + ":" + ((file->IsCompressedToFile()) ? "1" : "0") + ":" + file->filename() + ":NULL:" + (long)file->game() + "\n";
741
			line += command + ":" + (file->GetDataSize() + (long)4) + ":" + file->GetUncompressedDataSize() + ":" + (long)file->GetCompressionType() + ":" + (long)file->GetCreationTime() + ":" + ((file->IsCompressedToFile()) ? "1" : "0") + ":" + file->filename() + ":NULL:" + (long)file->game() + "\n";
739
		else
742
		else
740
			line += command + ":" + (file->GetDataSize() + (long)4) + ":" + file->GetUncompressedDataSize() + ":" + (long)file->GetCompressionType() + ":" + (long)file->GetCreationTime() + ":" + ((file->IsCompressedToFile()) ? "1" : "0") + ":" + file->filename() + ":" + file->dir() + ":" + (long)file->game() + "\n";
743
			line += command + ":" + (file->GetDataSize() + (long)4) + ":" + file->GetUncompressedDataSize() + ":" + (long)file->GetCompressionType() + ":" + (long)file->GetCreationTime() + ":" + ((file->IsCompressedToFile()) ? "1" : "0") + ":" + file->filename() + ":" + file->dir() + ":" + (long)file->game() + "\n";
741
 
744
 
742
		if (updateheader)
745
		if (header)
743
		{
746
		{
744
			++m_SHeader2.iNumFiles;
747
			++header->iNumFiles;
745
			m_SHeader2.lFullSize += (file->GetDataSize() + 4);
748
			header->lFullSize += (file->GetDataSize() + 4);
746
		}
749
		}
747
	}
750
	}
748
 
751
 
749
	return line;
752
	return line;
750
}
753
}
Line 888... Line 891...
888
	delete File;
891
	delete File;
889
}
892
}
890
 
893
 
891
void CBaseFile::_install_adjustFakePatches(CPackages *pPackages)
894
void CBaseFile::_install_adjustFakePatches(CPackages *pPackages)
892
{
895
{
893
	CyStringList lPatches;
896
	Utils::CStringList lPatches;
894
	int startfake = pPackages->FindNextFakePatch();
897
	int startfake = pPackages->FindNextFakePatch();
895
 
898
 
896
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
899
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
897
	{
900
	{
898
		C_File *fit = node->Data();
901
		C_File *fit = node->Data();
Line 903... Line 906...
903
		// we should only have cat and dat files, but lets check just incase they have been added incorrectly
906
		// we should only have cat and dat files, but lets check just incase they have been added incorrectly
904
		if ( !fit->CheckFileExt ("cat") && !fit->CheckFileExt("dat") )
907
		if ( !fit->CheckFileExt ("cat") && !fit->CheckFileExt("dat") )
905
			continue;
908
			continue;
906
 
909
 
907
		// search for the name on the list
910
		// search for the name on the list
908
		SStringList *opposite = lPatches.FindString(fit->GetBaseName());
-
 
909
		CyString newname;
911
		Utils::String newname;
910
		if ( opposite )
912
		bool isOpposite = false;
-
 
913
		if (lPatches.contains(fit->baseName()))
-
 
914
		{
-
 
915
			newname = lPatches.findString(fit->baseName());
911
			newname = opposite->data;
916
			isOpposite = true;
-
 
917
		}
912
		else
918
		else
913
		{
919
		{
914
			newname = CyString::Number((long)startfake).PadNumber(2);
920
			newname = Utils::String::PadNumber((long)startfake, 2);
915
			lPatches.PushBack(fit->GetBaseName(), newname);
921
			lPatches.pushBack(fit->baseName(), newname);
916
		}
922
		}
917
 
923
 
918
		// rename the file
924
		// rename the file
919
		fit->FixOriginalName();
925
		fit->FixOriginalName();
920
		CLog::logf(CLog::Log_Install, 2, "Adjusting fake patch number, %s => %s", fit->GetNameDirectory(this).c_str(), (newname + "." + fit->GetFileExt()).c_str());
926
		CLog::logf(CLog::Log_Install, 2, "Adjusting fake patch number, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
921
		fit->SetName ( newname + ".&quot; + fit->GetFileExt() );
927
		fit->setName(newname + ".&quot; + fit->fileExt());
922
 
928
 
923
		// find the next gap
929
		// find the next gap
924
		if ( !opposite ) {
930
		if ( !isOpposite ) {
925
			startfake = pPackages->FindNextFakePatch(startfake + 1);
931
			startfake = pPackages->FindNextFakePatch(startfake + 1);
926
		}
932
		}
927
	}
933
	}
928
 
-
 
929
}
934
}
930
 
935
 
931
void CBaseFile::_install_renameText(CPackages *pPackages)
936
void CBaseFile::_install_renameText(CPackages *pPackages)
932
{
937
{
933
	int starttext = pPackages->findNextTextFile();
938
	int starttext = pPackages->findNextTextFile();
934
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
939
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
935
		C_File *fit = node->Data();
940
		C_File *fit = node->Data();
936
		if ( !fit->isAutoTextFile() )
941
		if ( !fit->isAutoTextFile() )
937
			continue;
942
			continue;
938
 
943
 
939
		Utils::String newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
944
		Utils::String newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
940
		fit->FixOriginalName();
945
		fit->FixOriginalName();
941
		CLog::logf(CLog::Log_Install, 2, "Adjusting text file, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
946
		CLog::logf(CLog::Log_Install, 2, "Adjusting text file, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
942
		fit->setName(newname + "." + fit->fileExt());
947
		fit->setName(newname + "." + fit->fileExt());
943
 
948
 
944
		++starttext;
949
		++starttext;
945
	}
950
	}
946
}
951
}
947
 
952
 
948
bool CBaseFile::_install_setEnabled(bool bEnable, C_File *fit)
953
bool CBaseFile::_install_setEnabled(bool bEnable, C_File *fit)
949
{
954
{
950
	if ( !bEnable )
955
	if ( !bEnable )
951
	{
956
	{
952
		if ( (fit->GetFileType() == FILETYPE_UNINSTALL) || (fit->GetFileType() == FILETYPE_README) || (fit->GetFileType() == FILETYPE_ADVERT) )
957
		if ( (fit->GetFileType() == FILETYPE_UNINSTALL) || (fit->GetFileType() == FILETYPE_README) || (fit->GetFileType() == FILETYPE_ADVERT) )
953
			bEnable = true;
958
			bEnable = true;
954
		else if ( (fit->GetFileType() == FILETYPE_EXTRA) && (fit->GetDir().Left(7).ToLower() == "Extras/") )
959
		else if ( (fit->GetFileType() == FILETYPE_EXTRA) && (fit->GetDir().Left(7).ToLower() == "Extras/") )
955
			bEnable = true;
960
			bEnable = true;
956
		else if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) && (!fit->IsFakePatch()) )
961
		else if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) && (!fit->IsFakePatch()) )
Line 960... Line 965...
960
	}
965
	}
961
 
966
 
962
	return bEnable;
967
	return bEnable;
963
}
968
}
964
 
969
 
965
bool CBaseFile::_install_uncompress(C_File *fit, CProgressInfo *progress, CyStringList *errorStr, bool *uncomprToFile)
970
bool CBaseFile::_install_uncompress(C_File *fit, CProgressInfo *progress, Utils::CStringList *errorStr, bool *uncomprToFile)
966
{
971
{
967
	*uncomprToFile = false;
972
	*uncomprToFile = false;
968
	_sLastError = fit->getNameDirectory(this);
973
	_sLastError = fit->getNameDirectory(this);
969
	_iLastError = SPKERR_UNCOMPRESS;
974
	_iLastError = SPKERR_UNCOMPRESS;
970
 
975
 
Line 978... Line 983...
978
		}
983
		}
979
 
984
 
980
		if ( !uncomprToFile )
985
		if ( !uncomprToFile )
981
		{
986
		{
982
			if ( errorStr )
987
			if ( errorStr )
983
				errorStr->PushBack(CyString(_sLastError), ERRORLOG_OLD(SPKINSTALL_UNCOMPRESS_FAIL));
988
				errorStr->pushBack(_sLastError, ERRORLOG(SPKINSTALL_UNCOMPRESS_FAIL));
984
			CLog::log(CLog::Log_Install, 1, "Unable to decompress file, skipping");
989
			CLog::log(CLog::Log_Install, 1, "Unable to decompress file, skipping");
985
			return false;
990
			return false;
986
		}
991
		}
987
	}
992
	}
988
	ClearError ();
993
	ClearError ();
Line 996... Line 1001...
996
	// first get the version
1001
	// first get the version
997
	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
1002
	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
998
	{
1003
	{
999
		CLog::log(CLog::Log_Install, 2, "Checking for existing file version");
1004
		CLog::log(CLog::Log_Install, 2, "Checking for existing file version");
1000
		C_File checkfile;
1005
		C_File checkfile;
1001
		CyString checkfilename = sDestination;
1006
		Utils::String checkfilename = sDestination;
1002
		if ( !checkfilename.Empty() ) checkfilename += "/";
1007
		if ( !checkfilename.empty() ) checkfilename += "/";
1003
		checkfilename += pFile->GetNameDirectory(this);
1008
		checkfilename += pFile->getNameDirectory(this);
1004
		checkfile.SetFilename ( checkfilename );
1009
		checkfile.setFilename(checkfilename);
1005
		checkfile.setFileType(pFile->fileType());
1010
		checkfile.setFileType(pFile->fileType());
1006
		if ( checkfile.CheckValidFilePointer() ) {
1011
		if ( checkfile.CheckValidFilePointer() ) {
1007
			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
1012
			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
1008
				CLog::log(CLog::Log_Install, 1, "Newer version of the file found in directory, skipping");
1013
				CLog::log(CLog::Log_Install, 1, "Newer version of the file found in directory, skipping");
1009
				return false;
1014
				return false;
Line 1018... Line 1023...
1018
{
1023
{
1019
	Utils::String filename = sDestination;
1024
	Utils::String filename = sDestination;
1020
	if ( !filename.empty() ) filename += "/";
1025
	if ( !filename.empty() ) filename += "/";
1021
 
1026
 
1022
	if ( (IsPatch()) && (pFile->fileType() == FILETYPE_MOD) )
1027
	if ( (IsPatch()) && (pFile->fileType() == FILETYPE_MOD) )
1023
		pFile->SetDir ( CyString("Patch") );
1028
		pFile->setDir("Patch");
1024
 
1029
 
1025
	if ( pFile->isInMod() )
1030
	if ( pFile->isInMod() )
1026
	{
1031
	{
1027
		if ( bEnabled )
1032
		if ( bEnabled )
1028
			pFile->setFilename(filename + pFile->getInMod() + "::" + pFile->getNameDirectory(this));
1033
			pFile->setFilename(filename + pFile->getInMod() + "::" + pFile->getNameDirectory(this));
Line 1049... Line 1054...
1049
	CLog::logf(CLog::Log_Install, 2, "Adjusting the file pointer to correct install destintation, %s", pFile->filePointer().c_str());
1054
	CLog::logf(CLog::Log_Install, 2, "Adjusting the file pointer to correct install destintation, %s", pFile->filePointer().c_str());
1050
 
1055
 
1051
	return filename;
1056
	return filename;
1052
}
1057
}
1053
 
1058
 
1054
C_File *CBaseFile::_install_checkFile(C_File *pFile, CyStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
1059
C_File *CBaseFile::_install_checkFile(C_File *pFile, Utils::CStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
1055
{
1060
{
1056
	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
1061
	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
1057
	{
1062
	{
1058
		C_File *cFile;
1063
		C_File *cFile;
1059
		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
1064
		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
1060
		{
1065
		{
1061
			if ( !cFile->MatchFile(pFile) ) continue;
1066
			if ( !cFile->MatchFile(pFile) ) continue;
1062
			if ( !m_bOverrideFiles && !cFile->CompareNew(pFile) ) {
1067
			if ( !m_bOverrideFiles && !cFile->CompareNew(pFile) ) {
1063
				if ( errorStr ) errorStr->PushBack(pFile->GetNameDirectory(this), ERRORLOG_OLD(SPKINSTALL_SKIPFILE));
1068
				if ( errorStr ) errorStr->pushBack(pFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_SKIPFILE));
1064
				CLog::log(CLog::Log_Install, 1, "Newer version of the file already installed, skipping");
1069
				CLog::log(CLog::Log_Install, 1, "Newer version of the file already installed, skipping");
1065
				*bDoFile = false;
1070
				*bDoFile = false;
1066
			}
1071
			}
1067
			break;
1072
			break;
1068
		}
1073
		}
Line 1071... Line 1076...
1071
	}
1076
	}
1072
 
1077
 
1073
	return NULL;
1078
	return NULL;
1074
}
1079
}
1075
 
1080
 
1076
bool CBaseFile::_install_checkFileEnable(C_File *pCheckFile, C_File *fit, const Utils::String &sDestination, bool bEnabled, CyStringList *errorStr)
1081
bool CBaseFile::_install_checkFileEnable(C_File *pCheckFile, C_File *fit, const Utils::String &sDestination, bool bEnabled, Utils::CStringList *errorStr)
1077
{
1082
{
1078
	// found a file, check if its in the disabled directory
1083
	// found a file, check if its in the disabled directory
1079
	Utils::String dir = CFileIO(pCheckFile->filePointer()).dir();
1084
	Utils::String dir = CFileIO(pCheckFile->filePointer()).dir();
1080
	Utils::String lastDir = CDirIO(dir).topDir().lower();
1085
	Utils::String lastDir = CDirIO(dir).topDir().lower();
1081
 
1086
 
Line 1083... Line 1088...
1083
	if ( ((pCheckFile->IsDisabled()) || (lastDir == "disabled") || (dir.lower().isin("/disabled/"))) && (bEnabled) )
1088
	if ( ((pCheckFile->IsDisabled()) || (lastDir == "disabled") || (dir.lower().isin("/disabled/"))) && (bEnabled) )
1084
	{
1089
	{
1085
		CLog::logf(CLog::Log_Install, 2, "Existing file, %s, is disabled, re-enabling it", pCheckFile->filePointer().c_str());
1090
		CLog::logf(CLog::Log_Install, 2, "Existing file, %s, is disabled, re-enabling it", pCheckFile->filePointer().c_str());
1086
		// first check if the directory exists
1091
		// first check if the directory exists
1087
		if ( pCheckFile->isInMod() ) {
1092
		if ( pCheckFile->isInMod() ) {
1088
			CyString tofile = pCheckFile->filePointer().token("::", 2);
1093
			Utils::String tofile = pCheckFile->filePointer().token("::", 2);
1089
 
1094
 
1090
			CCatFile tocat;
1095
			CCatFile tocat;
1091
			int err = tocat.open(fit->filePointer().token("::", 1), "", CATREAD_CATDECRYPT, true);
1096
			int err = tocat.open(fit->filePointer().token("::", 1), "", CATREAD_CATDECRYPT, true);
1092
			if ( (err == CATERR_NONE) || (err == CATERR_CREATED) ) {
1097
			if ( (err == CATERR_NONE) || (err == CATERR_CREATED) ) {
1093
				tocat.AppendFile(pCheckFile->filePointer(), tofile.ToString());
1098
				tocat.AppendFile(pCheckFile->filePointer(), tofile);
1094
				CLog::logf(CLog::Log_Install, 2, "Adding existing file into new mod File, %s => %s", fit->filePointer().token("::", 1).c_str(), tofile.c_str());
1099
				CLog::logf(CLog::Log_Install, 2, "Adding existing file into new mod File, %s => %s", fit->filePointer().token("::", 1).c_str(), tofile.c_str());
1095
			}
1100
			}
1096
 
1101
 
1097
			CCatFile fromcat;
1102
			CCatFile fromcat;
1098
			err = fromcat.open(pCheckFile->filePointer().token("::", 1), "", CATREAD_CATDECRYPT, false);
1103
			err = fromcat.open(pCheckFile->filePointer().token("::", 1), "", CATREAD_CATDECRYPT, false);
1099
			if ( err == CATERR_NONE ) {
1104
			if ( err == CATERR_NONE ) {
1100
				fromcat.removeFile(tofile.ToString());
1105
				fromcat.removeFile(tofile);
1101
				CLog::logf(CLog::Log_Install, 2, "Removing file from existing mod, %s::%s", pCheckFile->filePointer().token("::", 1).c_str(), tofile.c_str());
1106
				CLog::logf(CLog::Log_Install, 2, "Removing file from existing mod, %s::%s", pCheckFile->filePointer().token("::", 1).c_str(), tofile.c_str());
1102
			}
1107
			}
1103
 
1108
 
1104
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing file name %s => %s", pCheckFile->filePointer().c_str(), fit->filePointer().c_str());
1109
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing file name %s => %s", pCheckFile->filePointer().c_str(), fit->filePointer().c_str());
1105
			pCheckFile->SetFilename ( fit->GetFilePointer() );
1110
			pCheckFile->SetFilename ( fit->GetFilePointer() );
1106
			CLog::logf(CLog::Log_Install, 2, "Adjusting In Mod setting, %s => %s", pCheckFile->getInMod().c_str(), fit->getInMod().c_str());
1111
			CLog::logf(CLog::Log_Install, 2, "Adjusting In Mod setting, %s => %s", pCheckFile->getInMod().c_str(), fit->getInMod().c_str());
1107
			pCheckFile->setInMod(fit->getInMod());
1112
			pCheckFile->setInMod(fit->getInMod());
1108
		}
1113
		}
1109
		else {
1114
		else {
1110
			Utils::String to = pCheckFile->getDirectory(this);
1115
			Utils::String to = pCheckFile->getDirectory(this);
1111
			CDirIO Dir(sDestination);
1116
			CDirIO Dir(sDestination);
1112
			if ( !Dir.exists(to) ) {
1117
			if ( !Dir.exists(to) ) {
1113
				if ( !Dir.create ( to ) ) {
1118
				if ( !Dir.create ( to ) ) {
1114
					if ( errorStr )	errorStr->PushBack(CyString(to), ERRORLOG_OLD(SPKINSTALL_CREATEDIRECTORY_FAIL));
1119
					if ( errorStr )	errorStr->pushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
1115
					return false;
1120
					return false;
1116
				}
1121
				}
1117
				if ( errorStr )	errorStr->PushBack(CyString(to), ERRORLOG_OLD(SPKINSTALL_CREATEDIRECTORY));
1122
				if ( errorStr )	errorStr->pushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
1118
			}
1123
			}
1119
 
1124
 
1120
			CyString destfile = CyString(sDestination) + "/" + pCheckFile->GetNameDirectory(this);
1125
			Utils::String destfile = sDestination + "/" + pCheckFile->getNameDirectory(this);
1121
			if ( CFileIO(destfile).ExistsOld() ) CFileIO::Remove(destfile.ToString());
1126
			if ( CFileIO(destfile).ExistsOld() ) CFileIO::Remove(destfile);
1122
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing filename, %s => %s", pCheckFile->GetFilePointer().c_str(), destfile.c_str());
1127
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing filename, %s => %s", pCheckFile->GetFilePointer().c_str(), destfile.c_str());
1123
			rename ( pCheckFile->GetFilePointer().c_str(), destfile.c_str() );
1128
			rename ( pCheckFile->filePointer().c_str(), destfile.c_str() );
1124
			pCheckFile->SetFilename ( CyString(sDestination) + "/" + pCheckFile->GetNameDirectory(this) );
1129
			pCheckFile->setFilename (sDestination + "/" + pCheckFile->getNameDirectory(this) );
1125
		}
1130
		}
1126
		pCheckFile->SetDisabled(false);
1131
		pCheckFile->SetDisabled(false);
1127
 
1132
 
1128
		if ( errorStr ) errorStr->PushBack(pCheckFile->GetNameDirectory(this), ERRORLOG_OLD(SPKINSTALL_ENABLEFILE));
1133
		if ( errorStr ) errorStr->pushBack(pCheckFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
1129
	}
1134
	}
1130
 
1135
 
1131
	return true;
1136
	return true;
1132
}
1137
}
1133
 
1138
 
1134
bool CBaseFile::_install_createDirectory(CDirIO &Dir, const Utils::String &sTo, C_File *pFile, CyStringList *errorStr)
1139
bool CBaseFile::_install_createDirectory(CDirIO &Dir, const Utils::String &sTo, C_File *pFile, Utils::CStringList *errorStr)
1135
{
1140
{
1136
	_sLastError = sTo;
1141
	_sLastError = sTo;
1137
	if ( !sTo.contains( "::" ) )
1142
	if ( !sTo.contains( "::" ) )
1138
	{
1143
	{
1139
		if ( !Dir.exists(sTo) )
1144
		if ( !Dir.exists(sTo) )
1140
		{
1145
		{
1141
			CLog::logf(CLog::Log_Install, 2, "Creating directory to install file into, %s", sTo.c_str());
1146
			CLog::logf(CLog::Log_Install, 2, "Creating directory to install file into, %s", sTo.c_str());
1142
			if ( !Dir.create(sTo) )
1147
			if ( !Dir.create(sTo) )
1143
			{
1148
			{
1144
				if ( errorStr )
1149
				if ( errorStr )
1145
					errorStr->PushBack(CyString(sTo), ERRORLOG_OLD(SPKINSTALL_CREATEDIRECTORY_FAIL));
1150
					errorStr->pushBack(sTo, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
1146
				return false;
1151
				return false;
1147
			}
1152
			}
1148
			if ( errorStr )
1153
			if ( errorStr )
1149
				errorStr->PushBack(CyString(sTo), ERRORLOG_OLD(SPKINSTALL_CREATEDIRECTORY));
1154
				errorStr->pushBack(sTo, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
1150
		}
1155
		}
1151
	}
1156
	}
1152
	else {
1157
	else {
1153
		CLog::logf(CLog::Log_Install, 2, "Adjusting file extension for file in mod, %s => %s", pFile->filePointer().c_str(), CCatFile::PckChangeExtension(pFile->filePointer()).c_str());
1158
		CLog::logf(CLog::Log_Install, 2, "Adjusting file extension for file in mod, %s => %s", pFile->filePointer().c_str(), CCatFile::PckChangeExtension(pFile->filePointer()).c_str());
1154
		pFile->setFilename(CCatFile::PckChangeExtension(pFile->filePointer()));
1159
		pFile->setFilename(CCatFile::PckChangeExtension(pFile->filePointer()));
1155
	}
1160
	}
1156
 
1161
 
1157
	return true;
1162
	return true;
1158
}
1163
}
1159
 
1164
 
1160
void CBaseFile::_install_writeFile(C_File *pFile, const Utils::String &sDestination, CyStringList *errorStr)
1165
void CBaseFile::_install_writeFile(C_File *pFile, const Utils::String &sDestination, Utils::CStringList *errorStr)
1161
{
1166
{
1162
	_iLastError = SPKERR_WRITEFILE;
1167
	_iLastError = SPKERR_WRITEFILE;
1163
	_sLastError = pFile->filePointer();
1168
	_sLastError = pFile->filePointer();
1164
	Utils::String sInstalledFile = pFile->getNameDirectory(this);
1169
	Utils::String sInstalledFile = pFile->getNameDirectory(this);
1165
	if ( pFile->IsDisabled() )
1170
	if ( pFile->IsDisabled() )
Line 1171... Line 1176...
1171
 
1176
 
1172
	if ( !pFile->writeFilePointer() )
1177
	if ( !pFile->writeFilePointer() )
1173
	{
1178
	{
1174
		CLog::log(CLog::Log_Install, 1, "Failed to write the file");
1179
		CLog::log(CLog::Log_Install, 1, "Failed to write the file");
1175
		if ( errorStr )
1180
		if ( errorStr )
1176
			errorStr->PushBack(CyString(sInstalledFile), ERRORLOG_OLD(SPKINSTALL_WRITEFILE_FAIL));
1181
			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
1177
	}
1182
	}
1178
	else
1183
	else
1179
	{
1184
	{
1180
		CLog::log(CLog::Log_Install, 1, "File written successfully");
1185
		CLog::log(CLog::Log_Install, 1, "File written successfully");
1181
		CLog::log(CLog::Log_Install, 2, "Checking signed status of the file");
1186
		CLog::log(CLog::Log_Install, 2, "Checking signed status of the file");
1182
		pFile->UpdateSigned();
1187
		pFile->UpdateSigned();
1183
		if ( errorStr )
1188
		if ( errorStr )
1184
			errorStr->PushBack(CyString(sInstalledFile), ERRORLOG_OLD(SPKINSTALL_WRITEFILE));
1189
			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
1185
 
1190
 
1186
		switch(pFile->GetFileType())
1191
		switch(pFile->GetFileType())
1187
		{
1192
		{
1188
			case FILETYPE_SCRIPT:
1193
			case FILETYPE_SCRIPT:
1189
			case FILETYPE_UNINSTALL:
1194
			case FILETYPE_UNINSTALL:
1190
				CLog::log(CLog::Log_Install, 2, "Updating file signature");
1195
				CLog::log(CLog::Log_Install, 2, "Updating file signature");
1191
				pFile->updateSignature();
1196
				pFile->updateSignature();
1192
				break;
1197
				break;
1193
		}
1198
		}
1194
	}
1199
	}
1195
}
1200
}
1196
 
1201
 
1197
bool CBaseFile::InstallFiles ( CyString destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, CyStringList *errorStr, bool enabled, CPackages *packages )
1202
bool CBaseFile::installFiles(const Utils::String &destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, Utils::CStringList *errorStr, bool enabled, CPackages *packages )
1198
{
1203
{
1199
	//TODO: add errorStr and progress as member variables
1204
	//TODO: add errorStr and progress as member variables
1200
	if ( enabled ) {
1205
	if ( enabled ) {
1201
		this->_install_adjustFakePatches(packages);
1206
		this->_install_adjustFakePatches(packages);
1202
		if ( packages ) this->_install_renameText(packages);
1207
		if ( packages ) this->_install_renameText(packages);
Line 1207... Line 1212...
1207
	CDirIO Dir(destdir);
1212
	CDirIO Dir(destdir);
1208
	int fileCount = 0;
1213
	int fileCount = 0;
1209
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
1214
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
1210
	{
1215
	{
1211
		C_File *fit = node->Data();
1216
		C_File *fit = node->Data();
1212
 
1217
 
1213
		// start the install process, check if we need to the file enabled or disabled
1218
		// start the install process, check if we need to the file enabled or disabled
1214
		CLog::logf(CLog::Log_Install, 1, "Preparing to install file: %s", fit->GetNameDirectory(this).c_str());
1219
		CLog::logf(CLog::Log_Install, 1, "Preparing to install file: %s", fit->GetNameDirectory(this).c_str());
1215
		bool fileEnabled = _install_setEnabled(enabled, fit);
1220
		bool fileEnabled = _install_setEnabled(enabled, fit);
1216
 
1221
 
1217
		// check if the file is for the correct game version
1222
		// check if the file is for the correct game version
1218
		if (!fit->isForGame(packages->GetGame())) 
1223
		if (!fit->isForGame(packages->GetGame())) 
1219
		{
1224
		{
1220
			CLog::logf(CLog::Log_Install, 1, "File didn't match game version, skipping, %d != %d", fit->game(), packages->GetGame());
1225
			CLog::logf(CLog::Log_Install, 1, "File didn't match game version, skipping, %d != %d", fit->game(), packages->GetGame());
1221
			continue;
1226
			continue;
1222
		}
1227
		}
1223
 
1228
 
1224
		// update the progress display to show we are processing this file
1229
		// update the progress display to show we are processing this file
1225
		if ( progress ) {
1230
		if ( progress ) {
1226
			if ( progress->IsSecond() ) progress->SwitchSecond();
1231
			if ( progress->IsSecond() ) progress->SwitchSecond();
1227
			progress->UpdateFile ( fit );
1232
			progress->UpdateFile ( fit );
1228
			progress->UpdateProgress(fileCount++, m_lFiles.size());
1233
			progress->UpdateProgress(fileCount++, m_lFiles.size());
Line 1235... Line 1240...
1235
		if ( !this->_install_uncompress(fit, progress, errorStr, &uncomprToFile) ) {
1240
		if ( !this->_install_uncompress(fit, progress, errorStr, &uncomprToFile) ) {
1236
			bFailed = true;
1241
			bFailed = true;
1237
			continue;
1242
			continue;
1238
		}
1243
		}
1239
 
1244
 
1240
		bool dofile = _install_checkVersion(fit, destdir.ToString());
1245
		bool dofile = _install_checkVersion(fit, destdir);
1241
 
1246
 
1242
		// change file pointer
1247
		// change file pointer
1243
		Utils::String sInstallDir = _install_adjustFilepointer(fit, fileEnabled, destdir.ToString());
1248
		Utils::String sInstallDir = _install_adjustFilepointer(fit, fileEnabled, destdir);
1244
 
1249
 
1245
		C_File *adjustPointer = NULL;
1250
		C_File *adjustPointer = NULL;
1246
 
1251
 
1247
		if ( filelist ) {
1252
		if ( filelist ) {
1248
			C_File *cFile = _install_checkFile(fit, errorStr, &dofile, filelist);
1253
			C_File *cFile = _install_checkFile(fit, errorStr, &dofile, filelist);
Line 1261... Line 1266...
1261
						if ( rFile.exists() )
1266
						if ( rFile.exists() )
1262
						{
1267
						{
1263
							if ( errorStr )
1268
							if ( errorStr )
1264
							{
1269
							{
1265
								if ( rFile.remove() )
1270
								if ( rFile.remove() )
1266
									errorStr->PushBack(cFile->GetFilePointer().Remove(destdir), ERRORLOG_OLD(SPKINSTALL_DELETEFILE));
1271
									errorStr->pushBack(cFile->filePointer().findRemove(destdir), ERRORLOG(SPKINSTALL_DELETEFILE));
1267
								else
1272
								else
1268
									errorStr->PushBack(cFile->GetFilePointer().Remove(destdir), ERRORLOG_OLD(SPKINSTALL_DELETEFILE_FAIL));
1273
									errorStr->pushBack(cFile->filePointer().findRemove(destdir), ERRORLOG(SPKINSTALL_DELETEFILE_FAIL));
1269
							}
1274
							}
1270
						}
1275
						}
1271
						cFile->setFilename(fit->filePointer());
1276
						cFile->setFilename(fit->filePointer());
1272
						cFile->SetDisabled(true);
1277
						cFile->SetDisabled(true);
1273
					}
1278
					}
Line 1277... Line 1282...
1277
						fit->SetDisabled(false);
1282
						fit->SetDisabled(false);
1278
					}
1283
					}
1279
				}
1284
				}
1280
				// move it to enabled
1285
				// move it to enabled
1281
				else {
1286
				else {
1282
					if ( !this->_install_checkFileEnable(cFile, fit, destdir.ToString(), fileEnabled, errorStr) ) {
1287
					if ( !this->_install_checkFileEnable(cFile, fit, destdir, fileEnabled, errorStr) ) {
1283
						bFailed = true;
1288
						bFailed = true;
1284
						continue;
1289
						continue;
1285
					}
1290
					}
1286
				}
1291
				}
1287
 
1292
 
Line 1323... Line 1328...
1323
 
1328
 
1324
				Utils::String fpointer = fit->filePointer();
1329
				Utils::String fpointer = fit->filePointer();
1325
				_iLastError = SPKERR_CREATEDIRECTORY;
1330
				_iLastError = SPKERR_CREATEDIRECTORY;
1326
				Utils::String dir = CFileIO(fit->filePointer()).dir();
1331
				Utils::String dir = CFileIO(fit->filePointer()).dir();
1327
 
1332
 
1328
				dir = dir.findRemove(destdir.ToString());
1333
				dir = dir.findRemove(destdir);
1329
				if (!dir.empty() && (dir[0] == '/' || dir[0] == '\\')) 
1334
				if (!dir.empty() && (dir[0] == '/' || dir[0] == '\\')) 
1330
					dir.erase(0, 1);
1335
					dir.erase(0, 1);
1331
 
1336
 
1332
				if ( !_install_createDirectory(Dir, dir, fit, errorStr) ) {
1337
				if ( !_install_createDirectory(Dir, dir, fit, errorStr) ) {
1333
					bFailed = true;
1338
					bFailed = true;
1334
					continue;
1339
					continue;
1335
				}
1340
				}
1336
 
1341
 
1337
				_install_writeFile(fit, destdir.ToString(), errorStr);
1342
				_install_writeFile(fit, destdir, errorStr);
1338
			}
1343
			}
1339
			ClearError ();
1344
			ClearError ();
1340
		}
1345
		}
1341
 
1346
 
1342
		if ( adjustPointer )
1347
		if ( adjustPointer )
Line 1362... Line 1367...
1362
/*
1367
/*
1363
	Func:   ParseHeader
1368
	Func:   ParseHeader
1364
	Input:  Header String - string formated directly from the file
1369
	Input:  Header String - string formated directly from the file
1365
	Return: Boolean - If string is a valid header
1370
	Return: Boolean - If string is a valid header
1366
	Desc:   Splits up the main header string to get all required settings
1371
	Desc:   Splits up the main header string to get all required settings
1367
*/
1372
*/
1368
bool CBaseFile::ParseHeader ( CyString header )
1373
bool CBaseFile::_parseHeader(const Utils::String &header)
1369
{
1374
{
1370
	if ( !this->CheckHeader(header.GetToken ( 1, ';&apos; ).ToString()) )
1375
	if ( !this->_checkHeader(header.token(";&quot;, 1)))
1371
		return false;
1376
		return false;
1372
 
1377
 
1373
	m_SHeader.fVersion = header.GetToken ( 2, &apos;;&apos; ).ToFloat();
1378
	m_SHeader.fVersion = header.token(&quot;;&quot;, 2).toFloat();
1374
	if ( m_SHeader.fVersion > FILEVERSION )
1379
	if ( m_SHeader.fVersion > FILEVERSION )
1375
		return false;
1380
		return false;
1376
 
1381
 
1377
	m_SHeader.iValueCompression = header.GetToken ( 3, &apos;;&apos; ).ToInt();
1382
	m_SHeader.iValueCompression = header.token(&quot;;&quot;, 3).toInt();
1378
	m_SHeader.lValueCompressSize = header.GetToken ( 4, &apos;;&apos; ).ToLong();
1383
	m_SHeader.lValueCompressSize = header.token(&quot;;&quot;, 4).toLong();
1379
 
1384
 
1380
	return true;
1385
	return true;
1381
}
1386
}
1382
 
1387
 
1383
bool CBaseFile::CheckHeader(const Utils::String header) const
1388
bool CBaseFile::_checkHeader(const Utils::String header) const
1384
{
1389
{
1385
	if ( header.Compare("BaseCycrow") )
1390
	if ( header.Compare("BaseCycrow") )
1386
		return true;
1391
		return true;
1387
	return false;
1392
	return false;
1388
}
1393
}
Line 1391... Line 1396...
1391
	Func:   ParseFileHeader
1396
	Func:   ParseFileHeader
1392
	Input:  Header String - string formated directly from the file
1397
	Input:  Header String - string formated directly from the file
1393
	Return: Boolean - If string is a valid header
1398
	Return: Boolean - If string is a valid header
1394
	Desc:   Splits up the file header string to get all required settings
1399
	Desc:   Splits up the file header string to get all required settings
1395
*/
1400
*/
1396
bool CBaseFile::ParseFileHeader ( CyString header )
1401
bool CBaseFile::_parseFileHeader(const Utils::String &header)
1397
{
1402
{
1398
	if ( header.GetToken ( 1, ';' ) != ";FileHeader" )
1403
	if (header.token(";", 1) != ";FileHeader")
1399
		return false;
1404
		return false;
1400
 
1405
 
1401
	m_SHeader2.iNumFiles = header.GetToken ( 2, &apos;;&apos; ).ToInt();
1406
	m_SHeader2.iNumFiles = header.token(&quot;;&quot;, 2).toInt();
1402
	m_SHeader2.lSize = header.GetToken ( 3, &apos;;&apos; ).ToInt();
1407
	m_SHeader2.lSize = header.token(&quot;;&quot;, 3).toInt();
1403
	m_SHeader2.lFullSize = header.GetToken ( 4, &apos;;&apos; ).ToInt();
1408
	m_SHeader2.lFullSize = header.token(&quot;;&quot;, 4).toInt();
1404
	m_SHeader2.iFileCompression = header.GetToken ( 5, &apos;;&apos; ).ToInt();
1409
	m_SHeader2.iFileCompression = header.token(&quot;;&quot;, 5).toInt();
1405
	m_SHeader2.iDataCompression = header.GetToken ( 6, &apos;;&apos; ).ToInt();
1410
	m_SHeader2.iDataCompression = header.token(&quot;;&quot;, 6).toInt();
1406
 
1411
 
1407
	return true;
1412
	return true;
1408
}
1413
}
1409
 
1414
 
1410
 
1415
 
Line 1487... Line 1492...
1487
/*
1492
/*
1488
	Func:   ReadValues
1493
	Func:   ReadValues
1489
	Input:  String - values in one long line
1494
	Input:  String - values in one long line
1490
	Desc:   splits the values data into each line to read the data
1495
	Desc:   splits the values data into each line to read the data
1491
*/
1496
*/
1492
void CBaseFile::ReadValues ( CyString values )
1497
void CBaseFile::_readValues(const Utils::String &values)
1493
{
1498
{
1494
	int num = 0;
1499
	int num = 0;
1495
	CyString *lines = values.SplitToken ( &apos;\n', &num );
1500
	Utils::String *lines = values.tokenise(&quot;\n", &num);
1496
 
1501
 
1497
	for ( int i = 0; i < num; i++ )
1502
	for ( int i = 0; i < num; i++ )
1498
		ParseValueLine ( lines[i].ToString() );
1503
		ParseValueLine(lines[i]);
1499
 
1504
 
1500
	CLEANSPLIT(lines, num)
1505
	CLEANSPLIT(lines, num)
1501
}
1506
}
1502
 
1507
 
1503
/*
1508
/*
1504
	Func:   ParseFilesLine
1509
	Func:   ParseFilesLine
1505
	Input:  String - single line from a file to set
1510
	Input:  String - single line from a file to set
1506
	Return: Boolean - returns true if value exists
1511
	Return: Boolean - returns true if value exists
1507
	Desc:   Reads the line and assigns the parameters for the file
1512
	Desc:   Reads the line and assigns the parameters for the file
1508
*/
1513
*/
1509
bool CBaseFile::ParseFilesLine ( CyString sLine )
1514
bool CBaseFile::_parseFilesLine(const Utils::String &line)
1510
{
1515
{
1511
	Utils::String line = sLine.ToString();
-
 
1512
 
-
 
1513
	if ( !line.contains(":") )
1516
	if ( !line.contains(":") )
1514
		return false;
1517
		return false;
1515
 
1518
 
1516
	Utils::String command = line.token(":", 1);
1519
	Utils::String command = line.token(":", 1);
1517
 
1520
 
Line 1524... Line 1527...
1524
		_sIconExt = line.token (":", 5);
1527
		_sIconExt = line.token (":", 5);
1525
		m_pIconFile = new C_File ();
1528
		m_pIconFile = new C_File ();
1526
		m_pIconFile->SetDataSize ( size - 4 );
1529
		m_pIconFile->SetDataSize ( size - 4 );
1527
		m_pIconFile->SetDataCompression ( compression );
1530
		m_pIconFile->SetDataCompression ( compression );
1528
		m_pIconFile->SetUncompressedDataSize ( usize );
1531
		m_pIconFile->SetUncompressedDataSize ( usize );
1529
 
1532
 
1530
		return true;
1533
		return true;
1531
	}
1534
	}
1532
 
1535
 
1533
	time_t time = line.token(":", 5).toLong();
1536
	time_t time = line.token(":", 5).toLong();
1534
	bool compressToFile = (line.token(":", 6).toInt() == 1) ? true : false;
1537
	bool compressToFile = (line.token(":", 6).toInt() == 1) ? true : false;
1535
	Utils::String name  = line.token(":", 7);
1538
	Utils::String name  = line.token(":", 7);
1536
	Utils::String dir = line.token(":", 8);
1539
	Utils::String dir = line.token(":", 8);
Line 1597... Line 1600...
1597
		Utils::String game = line.token(":", 9);
1600
		Utils::String game = line.token(":", 9);
1598
		if (game.contains("_"))
1601
		if (game.contains("_"))
1599
		{
1602
		{
1600
			unsigned int iGame = game.token("_", 2).toInt();
1603
			unsigned int iGame = game.token("_", 2).toInt();
1601
			if (iGame)
1604
			if (iGame)
1602
				file->setGame(1 << 31 | 1 << iGame);
1605
				file->setGame(1 << 31 | 1 << iGame);
1603
			else
1606
			else
1604
				file->setGame(0);
1607
				file->setGame(0);
1605
		}
1608
		}
1606
		else
1609
		else
1607
		{
1610
		{
1608
			int iGame = game.toInt();
1611
			int iGame = game.toInt();
1609
			if (iGame & (1 << 31))
1612
			if (iGame & (1 << 31))
1610
				file->setGame(iGame);
1613
				file->setGame(iGame);
1611
			else if (!iGame)
1614
			else if (!iGame)
1612
				file->setGame(0);
1615
				file->setGame(0);
1613
			else
1616
			else
1614
				file->setGame(1 << 31 | 1 << iGame);
1617
				file->setGame(1 << 31 | 1 << iGame);
1615
		}
1618
		}
1616
	}
1619
	}
1617
 
1620
 
1618
	if (dir.Compare("NULL")) {
1621
	if (dir.Compare("NULL")) {
1619
		dir = Utils::String::Null();
1622
		dir = Utils::String::Null();
1620
	}
1623
	}
1621
 
1624
 
1622
	file->setFileType(type);
1625
	file->setFileType(type);
1623
	file->SetCreationTime ( time );
1626
	file->SetCreationTime ( time );
1624
	file->SetName ( name );
1627
	file->SetName ( name );
1625
	file->SetDir ( dir );
1628
	file->SetDir ( dir );
1626
	file->SetDataSize ( size - 4 );
1629
	file->SetDataSize ( size - 4 );
Line 1628... Line 1631...
1628
	file->SetUncompressedDataSize ( usize );
1631
	file->SetUncompressedDataSize ( usize );
1629
	file->SetShared ( shared );
1632
	file->SetShared ( shared );
1630
	file->SetCompressedToFile ( compressToFile );
1633
	file->SetCompressedToFile ( compressToFile );
1631
 
1634
 
1632
	_addFile(file, true);
1635
	_addFile(file, true);
1633
 
1636
 
1634
	return true;
1637
	return true;
1635
}
1638
}
1636
 
1639
 
1637
 
1640
 
1638
/*
1641
/*
1639
	Func:   ParseFiles
1642
	Func:   ParseFiles
1640
	Input:  String - values in one long line
1643
	Input:  String - values in one long line
1641
	Desc:   splits the files data into each line to read the data
1644
	Desc:   splits the files data into each line to read the data
1642
*/
1645
*/
1643
void CBaseFile::ReadFiles ( CyString values )
1646
void CBaseFile::_readFiles(const Utils::String &values)
1644
{
1647
{
1645
	int num = 0;
1648
	int num = 0;
1646
	CyString *lines = values.SplitToken ( &apos;\n', &num );
1649
	Utils::String *lines = values.tokenise(&quot;\n", &num);
1647
 
1650
 
1648
	for ( int i = 0; i <; num; i++ )
1651
	for (int i = 0; i <; num; i++)
1649
		ParseFilesLine ( lines[i] );
1652
		_parseFilesLine(lines[i]);
1650
 
1653
 
1651
	CLEANSPLIT(lines, num)
1654
	CLEANSPLIT(lines, num)
1652
}
1655
}
1653
 
1656
 
1654
 
1657
 
1655
 
1658
 
1656
/*
1659
/*
1657
	Func:   ReadFile
1660
	Func:   ReadFile
1658
	Input:  filename - the name of the file to open and read
1661
	Input:  filename - the name of the file to open and read
1659
			readdata - If falses, dont read the files to memory, just read the headers and values
1662
			readdata - If falses, dont read the files to memory, just read the headers and values
1660
	Return: boolean - return ture if acceptable format
1663
	Return: boolean - return ture if acceptable format
1661
	Desc:   Opens and reads the spk file and loads all data into class
1664
	Desc:   Opens and reads the spk file and loads all data into class
1662
*/
1665
*/
1663
bool CBaseFile::ReadFile(CyString filename, int readtype, CProgressInfo *progress)
-
 
1664
{
-
 
1665
	return readFile(filename.ToString(), readtype, progress);
-
 
1666
}
-
 
1667
bool CBaseFile::readFile(const Utils::String &filename, int readtype, CProgressInfo *progress)
1666
bool CBaseFile::readFile(const Utils::String &filename, int readtype, CProgressInfo *progress)
1668
{
1667
{
1669
	CFileIO File(filename);
1668
	CFileIO File(filename);
1670
	if ( !File.startRead() ) return false;
1669
	if ( !File.startRead() ) return false;
1671
 
1670
 
Line 1702... Line 1701...
1702
		try {
1701
		try {
1703
			unsigned char *uncompr = new unsigned char[uncomprLen];
1702
			unsigned char *uncompr = new unsigned char[uncomprLen];
1704
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1703
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1705
			// update the progress for each section
1704
			// update the progress for each section
1706
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1705
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1707
			if ( err == Z_OK ) this->ReadValues ( CyString ((char *)uncompr) );
1706
			if ( err == Z_OK ) this->_readValues((char *)uncompr);
1708
			doneLen = uncomprLen;
1707
			doneLen = uncomprLen;
1709
			delete uncompr;
1708
			delete uncompr;
1710
		}
1709
		}
1711
		catch (std::exception &e) {
1710
		catch (std::exception &e) {
1712
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1711
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
Line 1718... Line 1717...
1718
		long len = uncomprLen;
1717
		long len = uncomprLen;
1719
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
1718
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
1720
		// update the progress for each section
1719
		// update the progress for each section
1721
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1720
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1722
 
1721
 
1723
		if ( compr ) ReadValues ( CyString ((char *)compr) );
1722
		if ( compr ) _readValues((char *)compr);
1724
	}
1723
	}
1725
	// no compression
1724
	// no compression
1726
	else
1725
	else
1727
		ReadValues ( CyString ((char *)readData) );
1726
		_readValues((char *)readData);
1728
 
1727
 
1729
	delete []readData;
1728
	delete []readData;
1730
 
1729
 
1731
	return doneLen;
1730
	return doneLen;
1732
}
1731
}
Line 1749... Line 1748...
1749
	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
1748
	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
1750
 
1749
 
1751
	// check for zlib compression
1750
	// check for zlib compression
1752
	if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB ) {
1751
	if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB ) {
1753
		if ( uncomprLen < (unsigned long)iDoneLen ) uncomprLen = iDoneLen;
1752
		if ( uncomprLen < (unsigned long)iDoneLen ) uncomprLen = iDoneLen;
1754
 
1753
 
1755
		try {
1754
		try {
1756
			unsigned char *uncompr = new unsigned char[uncomprLen];
1755
			unsigned char *uncompr = new unsigned char[uncomprLen];
1757
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader2.lSize );
1756
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader2.lSize );
1758
			// update the progress for each section
1757
			// update the progress for each section
1759
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
1758
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
1760
			if ( err == Z_OK ) ReadFiles ( CyString ((char *)uncompr) );
1759
			if ( err == Z_OK ) _readFiles((char *)uncompr);
1761
			delete uncompr;
1760
			delete uncompr;
1762
		}
1761
		}
1763
		catch (std::exception &e) {
1762
		catch (std::exception &e) {
1764
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_FileHeader() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1763
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_FileHeader() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1765
			delete []readData;
1764
			delete []readData;
Line 1771... Line 1770...
1771
	{
1770
	{
1772
		long len = uncomprLen;
1771
		long len = uncomprLen;
1773
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader2.lSize, (size_t*)&len, NULL );
1772
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader2.lSize, (size_t*)&len, NULL );
1774
		// update the progress for each section
1773
		// update the progress for each section
1775
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
1774
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
1776
		if ( compr ) ReadFiles ( CyString ((char *)compr) );
1775
		if ( compr ) _readFiles((char *)compr);
1777
	}
1776
	}
1778
	else
1777
	else
1779
		ReadFiles ( CyString ((char *)readData) );
1778
		_readFiles((char *)readData);
1780
 
1779
 
1781
	delete []readData;
1780
	delete []readData;
1782
	return true;
1781
	return true;
1783
}
1782
}
1784
 
1783
 
1785
bool CBaseFile::readFile(CFileIO &File, int readtype, CProgressInfo *progress)
1784
bool CBaseFile::readFile(CFileIO &File, int readtype, CProgressInfo *progress)
1786
{
1785
{
1787
	ClearError ();
1786
	ClearError ();
1788
 
1787
 
1789
	// first read the header
1788
	// first read the header
1790
	if ( !ParseHeader(File.readEndOfLine()) ) return false;
1789
	if ( !_parseHeader(File.readEndOfLine()) ) return false;
1791
	if ( readtype == SPKREAD_HEADER ) return true;
1790
	if ( readtype == SPKREAD_HEADER ) return true;
1792
 
1791
 
1793
	// update the progress for each section
1792
	// update the progress for each section
1794
	int maxProgress = (readtype == SPKREAD_VALUES) ? 3 : 6;
1793
	int maxProgress = (readtype == SPKREAD_VALUES) ? 3 : 6;
1795
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(1, maxProgress);
1794
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(1, maxProgress);
1796
 
1795
 
1797
	long doneLen = 0;
1796
	long doneLen = 0;
1798
	// next read the data values for the spk files
1797
	// next read the data values for the spk files
Line 1801... Line 1800...
1801
	// update the progress for each section
1800
	// update the progress for each section
1802
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(3, maxProgress);
1801
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(3, maxProgress);
1803
	if ( readtype == SPKREAD_VALUES ) return true;
1802
	if ( readtype == SPKREAD_VALUES ) return true;
1804
 
1803
 
1805
	// next should be the next header
1804
	// next should be the next header
1806
	if ( !ParseFileHeader(File.readEndOfLine()) ) return false;
1805
	if ( !_parseFileHeader(File.readEndOfLine()) ) return false;
1807
 
1806
 
1808
	// clear the current file list
1807
	// clear the current file list
1809
	m_lFiles.clear(true);
1808
	m_lFiles.clear(true);
1810
	if ( _pTextDB ) {
1809
	if ( _pTextDB ) {
1811
		delete _pTextDB;
1810
		delete _pTextDB;
1812
		_pTextDB = NULL;
1811
		_pTextDB = NULL;
1813
	}
1812
	}
1814
 
1813
 
1815
	// update the progress for each section
1814
	// update the progress for each section
1816
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(4, maxProgress);
1815
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(4, maxProgress);
1817
 
1816
 
1818
	if ( m_SHeader2.lSize ) this->_read_FileHeader(File, readtype, maxProgress, doneLen, progress);
1817
	if ( m_SHeader2.lSize ) this->_read_FileHeader(File, readtype, maxProgress, doneLen, progress);
1819
 
1818
 
1820
	// file mismatch
1819
	// file mismatch
1821
	long numfiles = m_lFiles.size();
1820
	long numfiles = m_lFiles.size();
Line 1824... Line 1823...
1824
		_iLastError = SPKERR_FILEMISMATCH;
1823
		_iLastError = SPKERR_FILEMISMATCH;
1825
		return false;
1824
		return false;
1826
	}
1825
	}
1827
 
1826
 
1828
	// update the progress for each section
1827
	// update the progress for each section
1829
	if ( readtype != SPKREAD_ALL && progress )	progress->UpdateProgress(6, maxProgress);
1828
	if ( readtype != SPKREAD_ALL && progress )	progress->UpdateProgress(6, maxProgress);
1830
 
1829
 
1831
	if ( readtype == SPKREAD_ALL ) {
1830
	if ( readtype == SPKREAD_ALL ) {
1832
		int fileCount = 2;
1831
		int fileCount = 2;
1833
		if ( m_pIconFile ) m_pIconFile->readFromFile(File, m_pIconFile->GetDataSize());
1832
		if ( m_pIconFile ) m_pIconFile->readFromFile(File, m_pIconFile->GetDataSize());
1834
 
1833
 
Line 1874... Line 1873...
1874
	}
1873
	}
1875
 
1874
 
1876
	return false;
1875
	return false;
1877
}
1876
}
1878
 
1877
 
1879
Utils::String CBaseFile::CreateValuesLine () const
1878
Utils::String CBaseFile::createValuesLine () const
1880
{
1879
{
1881
	Utils::String values("Name: ");
1880
	Utils::String values("Name: ");
1882
	values += this->name() + "\n";
1881
	values += this->name() + "\n";
1883
	values += "Author: " + this->author() + "\n";
1882
	values += "Author: " + this->author() + "\n";
1884
	values += "Version: " + this->version() + "\n";
1883
	values += "Version: " + this->version() + "\n";
Line 1894... Line 1893...
1894
		Utils::String desc = this->description();
1893
		Utils::String desc = this->description();
1895
		desc = desc.findReplace("<newline>", "<br>");
1894
		desc = desc.findReplace("<newline>", "<br>");
1896
		desc = desc.findReplace("\n", "<br>");
1895
		desc = desc.findReplace("\n", "<br>");
1897
		desc.remove('\r');
1896
		desc.remove('\r');
1898
		values += "Desc: " + desc + "\n";
1897
		values += "Desc: " + desc + "\n";
1899
	}
1898
	}
1900
 
1899
 
1901
	for ( CListNode<SGameCompat> *gc = m_lGames.Front(); gc; gc = gc->next() ) {
1900
	for ( CListNode<SGameCompat> *gc = m_lGames.Front(); gc; gc = gc->next() ) {
1902
		if ( !gc->Data()->sVersion.empty() )
1901
		if ( !gc->Data()->sVersion.empty() )
1903
			values += Utils::String("GameCompatExact: ") + (long)gc->Data()->iGame + " " + gc->Data()->sVersion + "\n";
1902
			values += Utils::String("GameCompatExact: ") + (long)gc->Data()->iGame + " " + gc->Data()->sVersion + "\n";
1904
		else
1903
		else
1905
			values += Utils::String("GameCompat: ") + (long)gc->Data()->iGame + " " + (long)gc->Data()->iVersion + "\n";
1904
			values += Utils::String("GameCompat: ") + (long)gc->Data()->iGame + " " + (long)gc->Data()->iVersion + "\n";
1906
	}
1905
	}
1907
 
1906
 
1908
	if ( m_bSigned )
1907
	if (computeSigned(true))
1909
		values += "Signed\n";
1908
		values += "Signed\n";
1910
 
1909
 
1911
	for ( int j = 0; j < 2; j++ ) {
1910
	for ( int j = 0; j < 2; j++ ) {
1912
		const CInstallText *text;
1911
		const CInstallText *text;
1913
		Utils::String textStart;
1912
		Utils::String textStart;
Line 1948... Line 1947...
1948
/*
1947
/*
1949
	Func:   WriteFile
1948
	Func:   WriteFile
1950
	Input:  filename - The filename of the spk file to write to
1949
	Input:  filename - The filename of the spk file to write to
1951
	Desc:   Writes the data to an spk file
1950
	Desc:   Writes the data to an spk file
1952
*/
1951
*/
1953
bool CBaseFile::WriteFile ( CyString filename, CProgressInfo *progress )
1952
bool CBaseFile::writeFile(const Utils::String &filename, CProgressInfo *progress) const
1954
{
1953
{
1955
	CFileIO File(filename);
1954
	CFileIO File(filename);
1956
	if ( File.startWrite() ) return WriteData(File, progress);
1955
	if ( File.startWrite() ) return writeData(File, progress);
1957
	return false;
1956
	return false;
1958
}
1957
}
1959
 
1958
 
1960
bool CBaseFile::WriteHeader(CFileIO &file, int valueheader, int valueComprLen)
1959
bool CBaseFile::writeHeader(CFileIO &file, int valueheader, int valueComprLen) const
1961
{
1960
{
1962
	return file.write("BaseCycrow;%.2f;%d;%d\n", FILEVERSION, valueheader, valueComprLen);
1961
	return file.write("BaseCycrow;%.2f;%d;%d\n", FILEVERSION, valueheader, valueComprLen);
1963
}
1962
}
1964
 
1963
 
1965
bool CBaseFile::WriteData(CFileIO &file, CProgressInfo *progress )
1964
bool CBaseFile::writeData(CFileIO &file, CProgressInfo *progress ) const
1966
{
1965
{
1967
	int valueheader = m_SHeader.iValueCompression, fileheader = m_SHeader.iValueCompression;
1966
	int valueheader = m_SHeader.iValueCompression, fileheader = m_SHeader.iValueCompression;
1968
	if ( valueheader == SPKCOMPRESS_7ZIP )
1967
	if ( valueheader == SPKCOMPRESS_7ZIP )
1969
		valueheader = SPKCOMPRESS_ZLIB;
1968
		valueheader = SPKCOMPRESS_ZLIB;
1970
	if ( fileheader == SPKCOMPRESS_7ZIP )
1969
	if ( fileheader == SPKCOMPRESS_7ZIP )
1971
		fileheader = SPKCOMPRESS_ZLIB;
1970
		fileheader = SPKCOMPRESS_ZLIB;
1972
 
1971
 
1973
	// get the script values
1972
	// get the script values
1974
	this->UpdateSigned(true);
-
 
1975
	CyString values = this->CreateValuesLine();
1973
	Utils::String values = this->createValuesLine();
1976
 
1974
 
1977
	// compress the values
1975
	// compress the values
1978
	int valueUncomprLen = (int)values.Length();
1976
	int valueUncomprLen = (int)values.length();
1979
	unsigned long valueComprLen = 0;
1977
	unsigned long valueComprLen = 0;
1980
	unsigned char *valueCompr = NULL;
1978
	unsigned char *valueCompr = NULL;
1981
	bool compressed = false;
1979
	bool compressed = false;
1982
	if ( valueheader == SPKCOMPRESS_ZLIB )
1980
	if ( valueheader == SPKCOMPRESS_ZLIB )
1983
	{
1981
	{
Line 1986... Line 1984...
1986
			valueComprLen = 200;
1984
			valueComprLen = 200;
1987
		else if ( valueComprLen < 1000 )
1985
		else if ( valueComprLen < 1000 )
1988
			valueComprLen *= 2;
1986
			valueComprLen *= 2;
1989
 
1987
 
1990
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
1988
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
1991
		int err = compress ( (unsigned char *)valueCompr, &valueComprLen, (const unsigned char *)values.c_str(), (unsigned long)values.Length(), 0 );
1989
		int err = compress ( (unsigned char *)valueCompr, &valueComprLen, (const unsigned char *)values.c_str(), (unsigned long)values.length(), 0 );
1992
		if ( err == Z_OK )
1990
		if ( err == Z_OK )
1993
			compressed = true;
1991
			compressed = true;
1994
	}
1992
	}
1995
 
1993
 
1996
	if ( !compressed )
1994
	if ( !compressed )
Line 2000... Line 1998...
2000
		memcpy ( valueCompr, values.c_str(), valueComprLen );
1998
		memcpy ( valueCompr, values.c_str(), valueComprLen );
2001
		valueheader = SPKCOMPRESS_NONE;
1999
		valueheader = SPKCOMPRESS_NONE;
2002
	}
2000
	}
2003
 
2001
 
2004
	// write the main header to the file
2002
	// write the main header to the file
2005
	if ( !this->WriteHeader(file, valueheader, valueComprLen) )	return false;
2003
	if ( !this->writeHeader(file, valueheader, valueComprLen) )	return false;
2006
 
2004
 
2007
	// write the compressed data to file
2005
	// write the compressed data to file
2008
	file.put(static_cast<unsigned char>(valueUncomprLen >> 24));
2006
	file.put(static_cast<unsigned char>(valueUncomprLen >> 24));
2009
	file.put(static_cast<unsigned char>(valueUncomprLen >> 16));
2007
	file.put(static_cast<unsigned char>(valueUncomprLen >> 16));
2010
	file.put(static_cast<unsigned char>(valueUncomprLen >> 8));
2008
	file.put(static_cast<unsigned char>(valueUncomprLen >> 8));
Line 2012... Line 2010...
2012
	file.write(valueCompr, valueComprLen);
2010
	file.write(valueCompr, valueComprLen);
2013
	free ( valueCompr );
2011
	free ( valueCompr );
2014
 
2012
 
2015
	// now compress the files header
2013
	// now compress the files header
2016
	// create the files values
2014
	// create the files values
-
 
2015
	SSPKHeader2 header;
2017
	Utils::String files = createFilesLine (true, progress);
2016
	Utils::String files = createFilesLine(&header, progress);
2018
 
2017
	
2019
	// compress the files values
2018
	// compress the files values
2020
	long fileUncomprLen = (long)files.length(), fileComprLen = fileUncomprLen;
2019
	long fileUncomprLen = (long)files.length(), fileComprLen = fileUncomprLen;
2021
	unsigned char *fileCompr = NULL;
2020
	unsigned char *fileCompr = NULL;
2022
 
2021
 
2023
	compressed = false;
2022
	compressed = false;
Line 2044... Line 2043...
2044
		memcpy ( fileCompr, files.c_str(), fileComprLen );
2043
		memcpy ( fileCompr, files.c_str(), fileComprLen );
2045
		fileheader = SPKCOMPRESS_NONE;
2044
		fileheader = SPKCOMPRESS_NONE;
2046
	}
2045
	}
2047
 
2046
 
2048
	// now write the file header
2047
	// now write the file header
2049
	m_SHeader2.lSize = fileComprLen;
2048
	header.lSize = fileComprLen;
2050
	file.write("FileHeader;%d;%ld;%ld;%d;%d\n", m_SHeader2.iNumFiles, m_SHeader2.lSize, m_SHeader2.lFullSize, fileheader, m_SHeader2.iDataCompression);
2049
	file.write("FileHeader;%d;%ld;%ld;%d;%d\n", header.iNumFiles, header.lSize, header.lFullSize, fileheader, header.iDataCompression);
2051
 
2050
 
2052
	file.put(static_cast<unsigned char>(fileUncomprLen >> 24));
2051
	file.put(static_cast<unsigned char>(fileUncomprLen >> 24));
2053
	file.put(static_cast<unsigned char>(fileUncomprLen >> 16));
2052
	file.put(static_cast<unsigned char>(fileUncomprLen >> 16));
2054
	file.put(static_cast<unsigned char>(fileUncomprLen >> 8));
2053
	file.put(static_cast<unsigned char>(fileUncomprLen >> 8));
2055
	file.put(static_cast<unsigned char>(fileUncomprLen));
2054
	file.put(static_cast<unsigned char>(fileUncomprLen));
Line 2093... Line 2092...
2093
			}
2092
			}
2094
 
2093
 
2095
			if ( progress ) progress->IncDone((int)writeSize);
2094
			if ( progress ) progress->IncDone((int)writeSize);
2096
		}
2095
		}
2097
	}
2096
	}
2098
 
-
 
2099
	_changed();
-
 
2100
 
2097
 
2101
	return true;
2098
	return true;
2102
}
2099
}
2103
 
-
 
2104
 
2100
 
2105
bool CBaseFile::ExtractFile(C_File *file, CyString dir, bool includedir, CProgressInfo *progress)
-
 
2106
{
-
 
2107
	return extractFile(file, dir.ToString(), includedir, progress);
-
 
2108
}
-
 
2109
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, bool includedir, CProgressInfo *progress)
2101
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, bool includedir, CProgressInfo *progress)
2110
{
2102
{
2111
	if (ReadFileToMemory(file))
2103
	if (ReadFileToMemory(file))
2112
	{
2104
	{
2113
		// now finally, uncompress the file
2105
		// now finally, uncompress the file
Line 2117... Line 2109...
2117
		{
2109
		{
2118
			// attempt a file decompress
2110
			// attempt a file decompress
2119
			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
2111
			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
2120
			{
2112
			{
2121
				if (file->UncompressToFile(dir, this, includedir, progress))
2113
				if (file->UncompressToFile(dir, this, includedir, progress))
2122
					return true;
2114
					return true;
2123
			}
2115
			}
2124
			return false;
2116
			return false;
2125
		}
2117
		}
2126
 
2118
 
2127
		if (!file->writeToDir(dir, this, includedir, Utils::String::Null(), data, len))
2119
		if (!file->writeToDir(dir, this, includedir, Utils::String::Null(), data, len))
2128
			return false;
2120
			return false;
2129
 
2121
 
2130
		return true;
2122
		return true;
2131
 
2123
 
2132
	}
2124
	}
2133
	else
2125
	else
2134
		return false;
2126
		return false;
2135
}
2127
}
2136
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2128
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2137
{
2129
{
2138
	if (ReadFileToMemory(file))
2130
	if (ReadFileToMemory(file))
Line 2140... Line 2132...
2140
		CDirIO Dir(dir);
2132
		CDirIO Dir(dir);
2141
		Utils::String addonDir;
2133
		Utils::String addonDir;
2142
		if (file->isFileInAddon())
2134
		if (file->isFileInAddon())
2143
		{
2135
		{
2144
			int addonGame = file->getForSingleGame();
2136
			int addonGame = file->getForSingleGame();
2145
			if (!addonGame) addonGame = game;
2137
			if (!addonGame) addonGame = game;
2146
 
2138
 
2147
			if (addonGame > 0)
2139
			if (addonGame > 0)
2148
				addonDir = gameAddons.findString(Utils::String::Number(addonGame));
2140
				addonDir = gameAddons.findString(Utils::String::Number(addonGame));
2149
		}
2141
		}
2150
 
2142
 
2151
		if (!addonDir.empty())
2143
		if (!addonDir.empty())
2152
			Dir.cd(addonDir);
2144
			Dir.cd(addonDir);
2153
 
2145
 
2154
		// create directory first
2146
		// create directory first
2155
		Dir.create(file->getDirectory(this));
2147
		Dir.create(file->getDirectory(this));
2156
 
2148
 
2157
		// now finally, uncompress the file
2149
		// now finally, uncompress the file
2158
		long len = 0;
2150
		long len = 0;
2159
		unsigned char *data = file->UncompressData(&len, progress);
2151
		unsigned char *data = file->UncompressData(&len, progress);
2160
		if (!data)
2152
		if (!data)
2161
		{
2153
		{
Line 2167... Line 2159...
2167
			}
2159
			}
2168
			return false;
2160
			return false;
2169
		}
2161
		}
2170
 
2162
 
2171
		if (!file->writeToDir(Dir.dir(), this, includedir, Utils::String::Null(), data, len))
2163
		if (!file->writeToDir(Dir.dir(), this, includedir, Utils::String::Null(), data, len))
2172
			return false;
2164
			return false;
2173
 
2165
 
2174
		return true;
2166
		return true;
2175
 
2167
 
2176
	}
2168
	}
2177
	else
2169
	else
2178
		return false;
2170
		return false;
2179
}
-
 
2180
 
-
 
2181
bool CBaseFile::ExtractFile(int filenum, CyString dir, bool includedir, CProgressInfo *progress)
-
 
2182
{
-
 
2183
	// invalid valus
-
 
2184
	if (filenum < 0)
-
 
2185
		return false;
-
 
2186
	// out of range
-
 
2187
	if (filenum > m_lFiles.size())
-
 
2188
		return false;
-
 
2189
 
-
 
2190
	// get the file pointer
-
 
2191
	C_File *file = m_lFiles.Get(filenum);
-
 
2192
	return extractFile(file, dir.ToString(), includedir, progress);
-
 
2193
}
2171
}
2194
 
2172
 
2195
bool CBaseFile::extractFile(int filenum, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2173
bool CBaseFile::extractFile(int filenum, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2196
{
2174
{
2197
	// invalid valus
2175
	// invalid valus
Line 2215... Line 2193...
2215
	if (filenum > m_lFiles.size())
2193
	if (filenum > m_lFiles.size())
2216
		return false;
2194
		return false;
2217
 
2195
 
2218
	// get the file pointer
2196
	// get the file pointer
2219
	C_File *file = m_lFiles.Get(filenum);
2197
	C_File *file = m_lFiles.Get(filenum);
2220
	return ExtractFile(file, dir, includedir, progress);
2198
	return extractFile(file, dir, includedir, progress);
2221
}
2199
}
2222
 
2200
 
2223
bool CBaseFile::extractAll(const Utils::String &dir, int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2201
bool CBaseFile::extractAll(const Utils::String &dir, int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2224
{
2202
{
2225
	// no file to read from
2203
	// no file to read from
Line 2280... Line 2258...
2280
	delete File;
2258
	delete File;
2281
	return true;
2259
	return true;
2282
}
2260
}
2283
 
2261
 
2284
 
2262
 
2285
 
-
 
2286
bool CBaseFile::UpdateSigned (bool updateFiles)
2263
bool CBaseFile::computeSigned(bool updateFiles) const
2287
{
2264
{
2288
	m_bSigned = true;
-
 
2289
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
2265
	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
2290
	{
2266
	{
2291
		C_File *file = node->Data();
2267
		C_File* file = node->Data();
2292
		if ( updateFiles )
2268
		if (updateFiles)
2293
			file->UpdateSigned();
2269
			file->UpdateSigned();
2294
		// extra, text, soundtrack, readmes and screen files do not require a modified game directly
2270
		// extra, text, soundtrack, readmes and screen files do not require a modified game directly
2295
		if ( (file->GetFileType() == FILETYPE_EXTRA) || (file->GetFileType() == FILETYPE_TEXT) || (file->GetFileType() == FILETYPE_SOUND) || (file->GetFileType() == FILETYPE_SCREEN) || (file->GetFileType() == FILETYPE_README) )
2271
		if ((file->GetFileType() == FILETYPE_EXTRA) || (file->GetFileType() == FILETYPE_TEXT) || (file->GetFileType() == FILETYPE_SOUND) || (file->GetFileType() == FILETYPE_SCREEN) || (file->GetFileType() == FILETYPE_README))
2296
			continue;
2272
			continue;
2297
		// mods and maps always need modified game
2273
		// mods and maps always need modified game
2298
		else if ( (file->GetFileType() == FILETYPE_MOD) || (file->GetFileType() == FILETYPE_MAP) )
2274
		else if ((file->GetFileType() == FILETYPE_MOD) || (file->GetFileType() == FILETYPE_MAP))
2299
		{
-
 
2300
			m_bSigned = false;
2275
			return false;
2301
			break;
-
 
2302
		}
-
 
2303
 
2276
 
2304
		// else should be a script file, script or uninstall type
2277
		// else should be a script file, script or uninstall type
2305
		// all scripts must be signed, if any are not, then no signed status
2278
		// all scripts must be signed, if any are not, then no signed status
2306
		if ( !file->IsSigned () )
2279
		if (!file->IsSigned())
2307
		{
-
 
2308
			m_bSigned = false;
2280
			return false;
2309
			break;
-
 
2310
		}
-
 
2311
	}
2281
	}
2312
 
2282
 
-
 
2283
	return true;
-
 
2284
}
-
 
2285
 
-
 
2286
bool CBaseFile::updateSigned(bool updateFiles)
-
 
2287
{
-
 
2288
	m_bSigned = computeSigned(updateFiles);
2313
	return m_bSigned;
2289
	return m_bSigned;
2314
}
2290
}
2315
 
-
 
2316
 
2291
 
2317
bool CBaseFile::IsPackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2292
bool CBaseFile::IsPackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2318
{
2293
{
2319
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2294
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2320
	{
2295
	{
Line 2716... Line 2691...
2716
		if ( node->Data()->iGame == 0 )
2691
		if ( node->Data()->iGame == 0 )
2717
			foundAll = true;
2692
			foundAll = true;
2718
		else if ( node->Data()->iGame == game ) { // now check the version
2693
		else if ( node->Data()->iGame == game ) { // now check the version
2719
			if ( node->Data()->sVersion.empty() ) {
2694
			if ( node->Data()->sVersion.empty() ) {
2720
				if (node->Data()->sVersion.compareVersion(sVersion) == COMPARE_OLDER)
2695
				if (node->Data()->sVersion.compareVersion(sVersion) == COMPARE_OLDER)
2721
					return false;
2696
					return false;
2722
				return true;
2697
				return true;
2723
			}
2698
			}
2724
			else {
2699
			else {
2725
				if ( node->Data()->iVersion > iVersion )
2700
				if ( node->Data()->iVersion > iVersion )
2726
					return false;
2701
					return false;
2727
				return true;
2702
				return true;
Line 3087... Line 3062...
3087
Utils::String CBaseFile::fileSizeString() const { return SPK::GetSizeString ( this->fileSize() ); }
3062
Utils::String CBaseFile::fileSizeString() const { return SPK::GetSizeString ( this->fileSize() ); }
3088
 
3063
 
3089
// used for a multiple spk file
3064
// used for a multiple spk file
3090
unsigned char *CBaseFile::CreateData(size_t *size, CProgressInfo *progress)
3065
unsigned char *CBaseFile::CreateData(size_t *size, CProgressInfo *progress)
3091
{
3066
{
3092
	if ( this->WriteFile("temp.dat", progress) ) {
3067
	if ( this->writeFile("temp.dat", progress) ) {
3093
		CFileIO File("temp.dat");
3068
		CFileIO File("temp.dat");
3094
		File.setAutoDelete(true);
3069
		File.setAutoDelete(true);
3095
		return File.readAll(size);
3070
		return File.readAll(size);
3096
	}
3071
	}
3097
	return NULL;
3072
	return NULL;
Line 3282... Line 3257...
3282
	}
3257
	}
3283
 
3258
 
3284
	return Utils::String::Number((long)error);
3259
	return Utils::String::Number((long)error);
3285
}
3260
}
3286
 
3261
 
3287
bool CBaseFile::SaveToArchive(CyString filename, int game, const CGameExe *exes, CProgressInfo *progress)
-
 
3288
{
-
 
3289
	return saveToArchive(filename.ToString(), game, exes, progress);
-
 
3290
}
-
 
3291
bool CBaseFile::saveToArchive(const Utils::String &filename, int game, const CGameExe *exes, CProgressInfo *progress)
3262
bool CBaseFile::saveToArchive(const Utils::String &filename, int game, const CGameExe *exes, CProgressInfo *progress)
3292
{
3263
{
3293
	CDirIO Dir(CFileIO(filename).dir());
3264
	CDirIO Dir(CFileIO(filename).dir());
3294
	if (!Dir.exists())
3265
	if (!Dir.exists())
3295
		Dir.create();
3266
		Dir.create();