Subversion Repositories spk

Rev

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

Rev 7 Rev 8
Line 950... Line 950...
950
 
950
 
951
	// clear the files so we dont delete them later
951
	// clear the files so we dont delete them later
952
	base->GetFileList()->clear();
952
	base->GetFileList()->clear();
953
}
953
}
954
 
954
 
955
unsigned char *CSpkFile::uncompressOldFile(const CyString &sOldFilename, int *pLen)
955
unsigned char *CSpkFile::_convert_uncompressFile(const Utils::String &sOldFilename, int *pLen)
956
{
956
{
957
	// firstcheck if the file exists
957
	// firstcheck if the file exists
958
	FILE *id = fopen ( ((CyString)sOldFilename).c_str(), "rb" );
958
	FILE *id = fopen(sOldFilename.c_str(), "rb" );
959
	if ( !id ) {
959
	if ( !id ) {
960
		CLog::logf("Unable to open file: %s\n", ((CyString)sOldFilename).c_str());
960
		CLog::logf("Unable to open file: %s", ((CyString)sOldFilename).c_str());
961
		return false;
961
		return false;
962
	}
962
	}
963
 
963
 
964
	// read the first 3 charaters to check if its using the original "HiP" compression
964
	// read the first 3 charaters to check if its using the original "HiP" compression
965
	CyString check = (char)fgetc ( id );
965
	CyString check = (char)fgetc ( id );
Line 981... Line 981...
981
			if ( id )
981
			if ( id )
982
				opened = true;
982
				opened = true;
983
		}
983
		}
984
 
984
 
985
		if ( !opened ) {
985
		if ( !opened ) {
986
			CLog::log("Unable to uncompress file, exiting...\n");
986
			CLog::log("Unable to uncompress file, exiting...");
987
			return false;
987
			return false;
988
		}
988
		}
989
 
989
 
990
		CLog::log("* Reading file into memory...\n");
990
		CLog::log("* Reading file into memory...");
991
		// get file length
991
		// get file length
992
		fseek ( id, 0, SEEK_END );
992
		fseek ( id, 0, SEEK_END );
993
		len = ftell ( id );
993
		len = ftell ( id );
994
		
994
		
995
		// move back to beginning
995
		// move back to beginning
Line 1001... Line 1001...
1001
 
1001
 
1002
		newlen = len;
1002
		newlen = len;
1003
	}
1003
	}
1004
	else
1004
	else
1005
	{
1005
	{
1006
		CLog::log("* Reading file into memory...\n");
1006
		CLog::log("* Reading file into memory...");
1007
		// get file length
1007
		// get file length
1008
		fseek ( id, 0, SEEK_END );
1008
		fseek ( id, 0, SEEK_END );
1009
		len = ftell ( id );
1009
		len = ftell ( id );
1010
		
1010
		
1011
		// move back to beginning
1011
		// move back to beginning
Line 1014... Line 1014...
1014
		// read the data from file into memory
1014
		// read the data from file into memory
1015
		data = new unsigned char[len + 1];
1015
		data = new unsigned char[len + 1];
1016
		fread ( data, sizeof(unsigned char), len, id );
1016
		fread ( data, sizeof(unsigned char), len, id );
1017
 
1017
 
1018
		// uncompress the file (currently only 7zip compression)
1018
		// uncompress the file (currently only 7zip compression)
1019
		CLog::log("* Uncompressing file...\n");
1019
		CLog::log("* Uncompressing file...");
1020
		newlen = len;
1020
		newlen = len;
1021
	#ifdef _INCLUDE7ZIP
1021
	#ifdef _INCLUDE7ZIP
1022
		uncomprData = LZMADecodeData ( data, len, newlen, progress );
1022
		uncomprData = LZMADecodeData ( data, len, newlen, progress );
1023
	#else
1023
	#else
1024
		uncomprData = LZMADecode_C ( (unsigned char *)data, len, (size_t*)&newlen, NULL );
1024
		uncomprData = LZMADecode_C ( (unsigned char *)data, len, (size_t*)&newlen, NULL );
1025
	#endif
1025
	#endif
1026
	}
1026
	}
1027
 
1027
 
1028
	*pLen = newlen;
1028
	*pLen = newlen;
-
 
1029
 
-
 
1030
	if ( removeFile.Empty() ) {
-
 
1031
		CFileIO(removeFile).Remove();
-
 
1032
	}
1029
 
1033
 
1030
	return uncomprData;
1034
	return uncomprData;
1031
}
1035
}
1032
 
1036
 
1033
CyString CSpkFile::_convert_fileEndString(const CyString &sFile)
1037
Utils::String CSpkFile::_convert_fileEndString(const Utils::String &sFile)
1034
{
1038
{
1035
	CyString temp = sFile;
-
 
1036
	if ( temp.Compare("Text") )
1039
	if ( sFile.Compare("Text") )
1037
		return "-- End of Script --";
1040
		return "-- End of Script --";
1038
	else if ( temp.Compare("Uninstall") )
1041
	else if ( sFile.Compare("Uninstall") )
1039
		return "-- End of Uninstall --";
1042
		return "-- End of Uninstall --";
1040
	else if ( temp.Compare("Readme") )
1043
	else if ( sFile.Compare("Readme") )
1041
		return "-- End of Readme --";
1044
		return "-- End of Readme --";
1042
	else if ( temp.Compare("Map") )
1045
	else if ( sFile.Compare("Map") )
1043
		return "-- End of Map --";
1046
		return "-- End of Map --";
1044
	else if ( temp.Compare("Mod") || temp.Compare("Extra") || temp.Compare("Screen") || temp.Compare("Sound") )
1047
	else if ( sFile.Compare("Mod") || sFile.Compare("Extra") || sFile.Compare("Screen") || sFile.Compare("Sound") )
1045
		return "";
1048
		return "";
1046
	return "-- End of Script --";
1049
	return "-- End of Script --";
1047
}
1050
}
1048
 
1051
 
1049
int CSpkFile::_convert_fileType(const CyString &sFile)
1052
int CSpkFile::_convert_fileType(const Utils::String &sFile)
1050
{
1053
{
1051
	CyString temp = sFile;
-
 
1052
	if ( temp.Compare("Text") )
1054
	if ( sFile.Compare("Text") )
1053
		return FILETYPE_TEXT;
1055
		return FILETYPE_TEXT;
1054
	else if ( temp.Compare("Uninstall") )
1056
	else if ( sFile.Compare("Uninstall") )
1055
		return FILETYPE_UNINSTALL;
1057
		return FILETYPE_UNINSTALL;
1056
	else if ( temp.Compare("Readme") )
1058
	else if ( sFile.Compare("Readme") )
1057
		return FILETYPE_README;
1059
		return FILETYPE_README;
1058
	else if ( temp.Compare("Map") )
1060
	else if ( sFile.Compare("Map") )
1059
		return FILETYPE_MAP;
1061
		return FILETYPE_MAP;
1060
	else if ( temp.Compare("Mod") )
1062
	else if ( sFile.Compare("Mod") )
1061
		return FILETYPE_MOD;
1063
		return FILETYPE_MOD;
1062
	else if ( temp.Compare("Extra") )
1064
	else if ( sFile.Compare("Extra") )
1063
		return FILETYPE_EXTRA;
1065
		return FILETYPE_EXTRA;
1064
	else if ( temp.Compare("Screen") )
1066
	else if ( sFile.Compare("Screen") )
1065
		return FILETYPE_SCREEN;
1067
		return FILETYPE_SCREEN;
1066
	else if ( temp.Compare("Sound") )
1068
	else if ( sFile.Compare("Sound") )
1067
		return FILETYPE_SOUND;
1069
		return FILETYPE_SOUND;
1068
 
1070
 
1069
	return FILETYPE_SCRIPT;
1071
	return FILETYPE_SCRIPT;
1070
}
1072
}
1071
 
1073
 
1072
void CSpkFile::_convert_parse(const CyString &s_Cmd, const CyString &s_Rest, bool bVerbose)
1074
void CSpkFile::_convert_parse(const Utils::String &sCmd, const Utils::String &sRest, bool bVerbose)
1073
{
1075
{
1074
	CyString sCmd = s_Cmd;
-
 
1075
	CyString sRest = s_Rest;
-
 
1076
	if ( sCmd == "Name:" )
1076
	if ( sCmd == "Name:" )
1077
	{
1077
	{
1078
		this->SetName ( sRest );
1078
		this->SetName ( sRest );
1079
		if ( bVerbose ) CLog::logf( "\tScript Name: %s\n", sRest.c_str() );
1079
		if ( bVerbose ) CLog::logf( "\tScript Name: %s", sRest.c_str() );
1080
	}
1080
	}
1081
	else if ( sCmd == "Author:" )
1081
	else if ( sCmd == "Author:" )
1082
	{
1082
	{
1083
		this->SetAuthor ( sRest );
1083
		this->SetAuthor ( sRest );
1084
		if ( bVerbose ) CLog::logf( "\tScript Author: %s\n", sRest.c_str() );
1084
		if ( bVerbose ) CLog::logf( "\tScript Author: %s", sRest.c_str() );
1085
	}
1085
	}
1086
	else if ( sCmd == "CustomStart" )
1086
	else if ( sCmd == "CustomStart" )
1087
	{
1087
	{
1088
		this->SetCustomStart();
1088
		this->SetCustomStart();
1089
		if ( bVerbose ) CLog::logf( "\tPackage is a custom start!!\n" );
1089
		if ( bVerbose ) CLog::logf( "\tPackage is a custom start!!" );
1090
	}
1090
	}
1091
	else if ( sCmd == "AnotherMod:" )
1091
	else if ( sCmd == "AnotherMod:" )
1092
	{
1092
	{
1093
		this->SetAnotherMod ( sRest.GetToken ( 1, '|' ), sRest.GetToken ( 2, -1, '|' ) );
1093
		this->SetAnotherMod(sRest.token("|", 1), sRest.tokens("|", 2));
1094
		if ( bVerbose ) CLog::logf( "\tFor another Mod, Name: %s, Author: %s\n", this->GetOtherName().c_str(), this->GetOtherAuthor().c_str() );
1094
		if ( bVerbose ) CLog::logf( "\tFor another Mod, Name: %s, Author: %s", this->GetOtherName().c_str(), this->GetOtherAuthor().c_str() );
1095
	}
1095
	}
1096
	else if ( sCmd == "PATCH" )
1096
	else if ( sCmd == "PATCH" )
1097
	{
1097
	{
1098
		this->SetPatch();
1098
		this->SetPatch();
1099
		if ( bVerbose ) CLog::logf("\tPackage is a Patch Mod!!\n" );
1099
		if ( bVerbose ) CLog::logf("\tPackage is a Patch Mod!!" );
1100
	}
1100
	}
1101
	else if ( sCmd == "Version:" )
1101
	else if ( sCmd == "Version:" )
1102
	{
1102
	{
1103
		this->SetVersion ( sRest );
1103
		this->SetVersion ( sRest );
1104
		if ( bVerbose ) CLog::logf("\tScript Version: %s\n", sRest.c_str() );
1104
		if ( bVerbose ) CLog::logf("\tScript Version: %s", sRest.c_str() );
1105
	}
1105
	}
1106
	else if ( sCmd == "Date:" )
1106
	else if ( sCmd == "Date:" )
1107
	{
1107
	{
1108
		this->SetCreationDate ( sRest );
1108
		this->SetCreationDate ( sRest );
1109
		if ( bVerbose ) CLog::logf("\tScript Creation Date: %s\n", sRest.c_str() );
1109
		if ( bVerbose ) CLog::logf("\tScript Creation Date: %s", sRest.c_str() );
1110
	}
1110
	}
1111
	else if ( sCmd == "Desc:" )
1111
	else if ( sCmd == "Desc:" )
1112
	{
1112
	{
1113
		this->SetDescription ( sRest.FindReplace ( "<br>;", "\n" ) );
1113
		this->SetDescription(sRest.findReplace("<br>;", "\n") );
1114
		if ( bVerbose ) CLog::logf("\tScript Description: %s\n", this->GetDescription().c_str() );
1114
		if ( bVerbose ) CLog::logf("\tScript Description: %s", this->GetDescription().c_str() );
1115
	}
1115
	}
1116
	else if ( sCmd == "WebAddress:" )
1116
	else if ( sCmd == "WebAddress:" )
1117
	{
1117
	{
1118
		this->SetWebAddress ( sRest );
1118
		this->SetWebAddress ( sRest );
1119
		if ( bVerbose ) CLog::logf("\tWeb Address: %s\n", sRest.c_str() );
1119
		if ( bVerbose ) CLog::logf("\tWeb Address: %s", sRest.c_str() );
1120
	}
1120
	}
1121
	else if ( sCmd == "WebMirror1:" )
1121
	else if ( sCmd == "WebMirror1:" )
1122
	{
1122
	{
1123
		this->AddWebMirror(sRest);
1123
		this->AddWebMirror(sRest);
1124
		if ( bVerbose ) CLog::logf("\tWeb Mirror Address: %s\n", sRest.c_str() );
1124
		if ( bVerbose ) CLog::logf("\tWeb Mirror Address: %s", sRest.c_str() );
1125
	}
1125
	}
1126
	else if ( sCmd == "WebMirror2:" )
1126
	else if ( sCmd == "WebMirror2:" )
1127
	{
1127
	{
1128
		this->AddWebMirror(sRest);
1128
		this->AddWebMirror(sRest);
1129
		if ( bVerbose ) CLog::logf("\tWeb Mirror Address: %s\n", sRest.c_str() );
1129
		if ( bVerbose ) CLog::logf("\tWeb Mirror Address: %s", sRest.c_str() );
1130
	}
1130
	}
1131
	
1131
	
1132
	else if ( sCmd == "ScriptType:" )
1132
	else if ( sCmd == "ScriptType:" )
1133
		this->SetScriptType ( sRest );
1133
		this->SetScriptType ( CyString(sRest) );
1134
	else if ( sCmd == "WebSite:" )
1134
	else if ( sCmd == "WebSite:" )
1135
	{
1135
	{
1136
		this->SetWebSite ( sRest );
1136
		this->SetWebSite ( sRest );
1137
		if ( bVerbose ) CLog::logf("\tWeb Site: %s\n", sRest.c_str() );
1137
		if ( bVerbose ) CLog::logf("\tWeb Site: %s", sRest.c_str() );
1138
	}
1138
	}
1139
	else if ( sCmd == "Email:" )
1139
	else if ( sCmd == "Email:" )
1140
	{
1140
	{
1141
		this->SetEmail ( sRest );
1141
		this->SetEmail ( sRest );
1142
		if ( bVerbose ) CLog::logf("\tAuthor Email Address: %s\n", sRest.c_str() );
1142
		if ( bVerbose ) CLog::logf("\tAuthor Email Address: %s", sRest.c_str() );
1143
	}
1143
	}
1144
	else if ( sCmd == "GameVersion:" )
1144
	else if ( sCmd == "GameVersion:" )
1145
	{
1145
	{
1146
		//TODO: fix this for new game version
1146
		//TODO: fix this for new game version
1147
		/*
1147
		/*
Line 1150... Line 1150...
1150
			this->SetGameVersion ( 1 );
1150
			this->SetGameVersion ( 1 );
1151
		else if (version == 1 )
1151
		else if (version == 1 )
1152
			this->SetGameVersion ( 0 );
1152
			this->SetGameVersion ( 0 );
1153
		else
1153
		else
1154
			this->SetGameVersion ( version );
1154
			this->SetGameVersion ( version );
1155
		if ( bVerbose ) CLog::logf( "\tGame Version: %d\n", this->GetGameVersion () );
1155
		if ( bVerbose ) CLog::logf( "\tGame Version: %d", this->GetGameVersion () );
1156
		*/
1156
		*/
1157
	}
1157
	}
1158
	
1158
	
1159
	else if ( sCmd == "Ware:" )
1159
	else if ( sCmd == "Ware:" )
1160
	{
1160
	{
1161
		this->AddWare ( sRest );
1161
		this->AddWare ( sRest );
1162
		if ( bVerbose ) CLog::logf( "\tAdding Custom Ware\n" );
1162
		if ( bVerbose ) CLog::logf( "\tAdding Custom Ware" );
1163
	}
1163
	}
1164
	else if ( sCmd == "WareText:" )
1164
	else if ( sCmd == "WareText:" )
1165
		this->AddWareText ( sRest );
1165
		this->AddWareText ( sRest );
1166
	else if ( sCmd == "UninstallAfter:" )
1166
	else if ( sCmd == "UninstallAfter:" )
1167
		this->AddUninstallAfterText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, &apos; &apos; ) );
1167
		this->AddUninstallAfterText(sRest.token(" ", 1).toLong(), sRest.tokens("; &quot;, 2));
1168
	else if ( sCmd == "UninstallBefore:" )
1168
	else if ( sCmd == "UninstallBefore:" )
1169
		this->AddUninstallBeforeText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, &apos; &apos; ) );
1169
		this->AddUninstallBeforeText(sRest.token(" ", 1).toLong(), sRest.tokens("; &quot;, 2));
1170
	else if ( sCmd == "InstallAfter:" )
1170
	else if ( sCmd == "InstallAfter:" )
1171
		this->AddInstallAfterText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, &apos; &apos; ) );
1171
		this->AddInstallAfterText(sRest.token(" ", 1).toLong(), sRest.tokens("; &quot;, 2));
1172
	else if ( sCmd == "InstallBefore:" )
1172
	else if ( sCmd == "InstallBefore:" )
1173
		this->AddInstallBeforeText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, &apos; &apos; ) );
1173
		this->AddInstallBeforeText(sRest.token(" ", 1).toLong(), sRest.tokens("; &quot;, 2));
1174
	else if ( sCmd == "ScriptName:" )
1174
	else if ( sCmd == "ScriptName:" )
1175
	{
1175
	{
1176
		CyString lang = sRest.GetToken ( 1, &apos;:&apos; );
1176
		Utils::String lang = sRest.token(&quot;:&quot;, 1);
1177
		CyString name = sRest.GetToken ( 2, -1, &apos;:&apos; );
1177
		Utils::String name = sRest.tokens(&quot;:&quot;, 2);
1178
		this->AddLanguageName ( lang.ToInt(), name );
1178
		this->AddLanguageName(lang.toLong(), name);
1179
		if ( bVerbose ) CLog::logf( "\tScript Name Language (%s) %s\n", lang.c_str(), name.c_str() );
1179
		if ( bVerbose ) CLog::logf( "\tScript Name Language (%s) %s", lang.c_str(), name.c_str() );
1180
	}
1180
	}
1181
}
1181
}
1182
 
1182
 
1183
CyString CSpkFile::_convert_parseFilename(const CyString &s_Rest, float fVersion, CyString *pDir)
1183
Utils::String CSpkFile::_convert_parseFilename(const Utils::String &sRest, float fVersion, Utils::String *pDir)
1184
{
1184
{
1185
	CyString sFilename;
1185
	Utils::String sFilename;
1186
	CyString sRest = s_Rest;
-
 
1187
 
1186
 
1188
	if ( fVersion >= 3.00f )
1187
	if ( fVersion >= 3.00f )
1189
		sFilename = sRest.GetToken ( 3, -1, &apos; &apos; );
1188
		sFilename = sRest.tokens(&quot; &quot;, 3);
1190
	else if ( fVersion >= 2.00f )
1189
	else if ( fVersion >= 2.00f )
1191
		sFilename = sRest.GetToken ( 2, -1, &apos; &apos; );
1190
		sFilename = sRest.tokens(&quot; &quot;, 2);
1192
	else
1191
	else
1193
		sFilename = sRest;
1192
		sFilename = sRest;
1194
 
1193
 
1195
	if ( sFilename.IsIn ( "<br>" ) )
1194
	if ( sFilename.isin("<br>") ) {
1196
	{
-
 
1197
		sFilename = sFilename.FindReplace ( "<;br&gt;&quot;, ";|" );
1195
		sFilename = sFilename.findReplace("<;br&gt;&quot;, ";|");
1198
		if ( sFilename[0] == '|' ) {
1196
		if ( sFilename[0] == '|' ) {
1199
			sFilename = sFilename.GetToken ( 1, &apos;|&apos; );
1197
			sFilename = sFilename.token(&quot;|&quot;, 1);
1200
		}
1198
		}
1201
		else {
1199
		else {
1202
			*pDir = sFilename.GetToken ( 1, &apos;|&apos; );
1200
			*pDir = sFilename.token(&quot;|&quot;, 1);
1203
			sFilename = sFilename.GetToken ( 2, -1, &apos;|&apos; );
1201
			sFilename = sFilename.tokens(&quot;|&quot;, 2);
1204
		}
1202
		}
1205
	}
1203
	}
1206
 
1204
 
1207
	return sFilename;
1205
	return sFilename;
1208
}
1206
}
1209
 
1207
 
1210
unsigned char *CSpkFile::_convert_parseFile(const CyString &s_Cmd, const CyString &s_Rest, float fVersion, unsigned char *d, bool bVerbose )
1208
unsigned char *CSpkFile::_convert_parseFile(const Utils::String &sCmd, const Utils::String &sRest, float fVersion, unsigned char *d, bool bVerbose )
1211
{
1209
{
1212
	CyString sCmd = s_Cmd;
-
 
1213
	CyString sRest = s_Rest;
-
 
1214
 
-
 
1215
	bool bShared = (sCmd.Left (9) == "$$$Shared") ? true : false;
1210
	bool bShared = (sCmd.left(9) == "$$$Shared") ? true : false;
1216
	CyString sFile = sCmd.Right(-3).Left(-1);
1211
	Utils::String sFile = sCmd.right(-3).left(-1);
1217
	CyString sEnd = this->_convert_fileEndString(sFile);
1212
	Utils::String sEnd = this->_convert_fileEndString(sFile);
1218
	int iType = this->_convert_fileType(sFile);
1213
	int iType = this->_convert_fileType(sFile);
1219
 
1214
 
1220
	// convert the filename and directory
1215
	// convert the filename and directory
1221
	CyString dir, filename = _convert_parseFilename(sRest, fVersion, &dir);
1216
	Utils::String dir, filename = _convert_parseFilename(sRest, fVersion, &dir);
1222
 
1217
 
1223
	// get the size and time
1218
	// get the size and time
1224
	long time = 0, size = 0;
1219
	long time = 0, size = 0;
1225
	if ( fVersion >= 2.00f ) time = sRest.GetToken ( 1, &apos; &apos; ).ToLong();
1220
	if ( fVersion >= 2.00f ) time = sRest.token(&quot; &quot;, 1).toLong();
1226
	if ( fVersion >= 3.00f ) size = sRest.GetToken ( 2, &apos; &apos; ).ToLong();
1221
	if ( fVersion >= 3.00f ) size = sRest.token(&quot; &quot;, 2).toLong();
1227
	bool binaryRead = (CFileIO(filename).CheckFileExtension("PCK")) ? true : false;
1222
	bool binaryRead = (CFileIO(filename).CheckFileExtension("PCK")) ? true : false;
1228
	if ( sEnd.Empty() ) binaryRead = true;
1223
	if ( sEnd.empty() ) binaryRead = true;
1229
	
1224
	
1230
	C_File *file = new C_File ();
1225
	C_File *file = new C_File ();
1231
 
1226
 
1232
	if ( bVerbose )
1227
	if ( bVerbose )
1233
	{
1228
	{
Line 1253... Line 1248...
1253
	// setup the file
1248
	// setup the file
1254
	file->SetName ( filename );
1249
	file->SetName ( filename );
1255
	file->SetFileType ( iType );
1250
	file->SetFileType ( iType );
1256
	file->SetShared ( bShared );
1251
	file->SetShared ( bShared );
1257
	file->SetCreationTime ( time );
1252
	file->SetCreationTime ( time );
1258
	if ( !dir.Empty() )
1253
	if ( !dir.empty() )
1259
		file->SetDir ( dir );
1254
		file->SetDir ( dir );
1260
	
1255
	
1261
	this->AddFile ( file );
1256
	this->AddFile ( file );
1262
 
1257
 
1263
	CLog::logf( "(Done) Size: %s\n", file->GetDataSizeString().c_str() );
1258
	CLog::logf( "Size: %s", file->GetDataSizeString().c_str() );
1264
 
1259
 
1265
	return d;
1260
	return d;
1266
}
1261
}
1267
 
1262
 
1268
bool CSpkFile::convertOld(CyString &sOldFilename)
1263
bool CSpkFile::convertOld(const Utils::String &sOldFilename)
1269
{
1264
{
1270
	// check if the old file is actually in an old format
1265
	// check if the old file is actually in an old format
1271
	int ret = CBaseFile::CheckFile ( sOldFilename );
1266
	int ret = CBaseFile::CheckFile ( sOldFilename );
1272
	if ( ret != SPKFILE_INVALID && ret != SPKFILE_OLD ) {
1267
	if ( ret != SPKFILE_INVALID && ret != SPKFILE_OLD ) {
1273
		return false;
1268
		return false;
1274
 	}
1269
 	}
1275
 
1270
 
1276
	//uncomress the data
1271
	//uncomress the data
1277
	int len;
1272
	int len;
1278
	unsigned char *uncomprData = this->uncompressOldFile(sOldFilename, &len);
1273
	unsigned char *uncomprData = this->_convert_uncompressFile(sOldFilename, &len);
1279
 
1274
 
1280
	// uncomressed failed
1275
	// uncomressed failed
1281
	if ( !uncomprData ) {
1276
	if ( !uncomprData ) {
1282
		CLog::log("Error: Unable to uncompress the file\n");
1277
		CLog::log("Error: Unable to uncompress the file");
1283
		return false;
1278
		return false;
1284
	}
1279
	}
1285
 
1280
 
1286
	// now we can read the data
1281
	// now we can read the data
1287
	unsigned char *d = uncomprData;
1282
	unsigned char *d = uncomprData;
1288
	CyString str;
1283
	Utils::String str;
1289
 
1284
 
1290
//	CMultiSpkFile *mspk = NULL;
1285
//	CMultiSpkFile *mspk = NULL;
1291
	//SMultiSpkFile *cur_mspk = NULL;
1286
	//SMultiSpkFile *cur_mspk = NULL;
1292
 
1287
 
1293
	int numscripts = 0, curscript = 0;
1288
	int numscripts = 0, curscript = 0;
1294
	bool bVerbose = true;
1289
	bool bVerbose = true;
1295
	float fVersion = 1;
1290
	float fVersion = 1;
1296
 
1291
 
1297
	CLog::log("* Reading spk data...\n");
1292
	CLog::log("* Reading spk data...");
1298
	while ( d )
1293
	while ( d )
1299
	{
1294
	{
1300
		// read the next line
1295
		// read the next line
1301
		d = str.GetEndOfLine(d);
1296
		d = str.readToEndOfLine(d);
1302
		if ( !d || d[0] == 0 ) {
1297
		if ( !d || d[0] == 0 ) {
1303
			break;
1298
			break;
1304
		}
1299
		}
1305
		if ( str.Empty() ) {
1300
		if ( str.empty() ) {
1306
			continue;
1301
			continue;
1307
		}
1302
		}
1308
 
1303
 
1309
		CyString sCmd = str.GetToken ( 1, &apos; &apos; );
1304
		Utils::String sCmd = str.token(&quot; &quot;, 1);
1310
 
1305
 
1311
		//TODO: split this into CMultiSpkFile
1306
		//TODO: split this into CMultiSpkFile
1312
		/*
1307
		/*
1313
		if ( first == "MultiPackage:" )
1308
		if ( first == "MultiPackage:" )
1314
			mspk = new CMultiSpkFile;
1309
			mspk = new CMultiSpkFile;
Line 1331... Line 1326...
1331
			++curscript;
1326
			++curscript;
1332
			cur_mspk->pFile = new CSpkFile;
1327
			cur_mspk->pFile = new CSpkFile;
1333
			spkfile = (CSpkFile *)cur_mspk->pFile;
1328
			spkfile = (CSpkFile *)cur_mspk->pFile;
1334
		}
1329
		}
1335
		*/
1330
		*/
1336
		CyString sRest = str.GetToken ( 2, -1, &apos; &apos; );
1331
		Utils::String sRest = str.tokens(&quot; &quot;, 2);
1337
		if ( sCmd == "Packager:" ) {
1332
		if ( sCmd == "Packager:" ) {
1338
			fVersion = sRest.ToFloat ();
1333
			fVersion = sRest;
1339
			if ( bVerbose ) CLog::logf( "\tPackager Version: %.2f\n", fVersion );
1334
			if ( bVerbose ) CLog::logf( "\tPackager Version: %.2f", fVersion );
1340
		}
1335
		}
1341
		else if ( sCmd == "Icon:" )
1336
		else if ( sCmd == "Icon:" )
1342
		{
1337
		{
1343
			long size = sRest.GetToken ( 1, ' &apos; ).ToLong ();
1338
			long size = sRest.token(&quot; ", 1);
-
 
1339
			Utils::String ext = sRest.token(" ", 2);
1344
			
1340
			
1345
			C_File *file = new C_File ();
1341
			C_File *file = new C_File ();
1346
			file->ReadFromData ( (char *)d, size );
1342
			file->ReadFromData ( (char *)d, size );
1347
 
1343
 
1348
			d += size;
1344
			d += size;
1349
 
1345
 
1350
			this->SetIcon(file, sRest.GetToken ( 2, ' ' ));
1346
			this->SetIcon(file, ext);
1351
 
1347
 
1352
			if ( bVerbose ) CLog::logf( "\tIcon (%s) Size: %s\n", ext.c_str(), file->GetDataSizeString ().c_str() );
1348
			if ( bVerbose ) CLog::logf( "\tIcon (%s) Size: %s", ext.c_str(), file->GetDataSizeString ().c_str() );
1353
		}
1349
		}
1354
		else if ( sCmd.Left(3) == "$$$" )
1350
		else if ( sCmd.left(3) == "$$$" )
1355
			d = _convert_parseFile(sCmd, sRest, fVersion, d, bVerbose);
1351
			d = _convert_parseFile(sCmd, sRest, fVersion, d, bVerbose);
1356
		else {
1352
		else {
1357
			this->_convert_parse(sCmd, sRest, bVerbose);
1353
			this->_convert_parse(sCmd, sRest, bVerbose);
1358
		}
1354
		}
1359
	}
1355
	}
1360
 
1356
 
1361
	if ( bVerbose ) CLog::logf( "* Reading spk data...\n" );
1357
	if ( bVerbose ) CLog::logf( "* Reading spk data..." );
1362
 
1358
 
1363
	return true;
1359
	return true;
1364
}
1360
}