Subversion Repositories spk

Rev

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

Rev 6 Rev 7
Line 1... Line 1...
1
 
1
//header
2
#include "SpkFile.h"
2
#include "SpkFile.h"
-
 
3
 
-
 
4
// debug logging
-
 
5
#include "Logging/Log.h"
-
 
6
 
-
 
7
// old style compression (needed to convert old formats)
-
 
8
#include "../../HiP/HiP.h"
-
 
9
 
-
 
10
//TODO: remove this
-
 
11
unsigned char *LineByLineRead ( unsigned char *data, CyString end, CyString *readData )
-
 
12
{
-
 
13
	CyString line;
-
 
14
	while ( true )
-
 
15
	{
-
 
16
		data = line.GetEndOfLine(data);
-
 
17
		//data = ReadNextLine ( data, len, &line );
-
 
18
 
-
 
19
		if ( (*readData).Empty() && line.Empty() ) continue;
-
 
20
		if ( line == end )
-
 
21
			break;
-
 
22
		*readData += (line + "\r\n");
-
 
23
	}
-
 
24
 
-
 
25
	return data;
-
 
26
}
-
 
27
 
3
 
28
 
4
CSpkFile::CSpkFile() : CBaseFile ()
29
CSpkFile::CSpkFile() : CBaseFile ()
5
{
30
{
6
	SetDefaults ();
31
	SetDefaults ();
7
 
32
 
Line 9... Line 34...
9
}
34
}
10
 
35
 
11
CSpkFile::~CSpkFile()
36
CSpkFile::~CSpkFile()
12
{
37
{
13
	Delete ();
38
	Delete ();
14
}
39
}
15
/*
40
/*
16
	Func:   SetDefaults
41
	Func:   SetDefaults
17
	Desc:   Sets the  default values when class is created
42
	Desc:   Sets the  default values when class is created
18
*/
43
*/
19
void CSpkFile::SetDefaults ()
44
void CSpkFile::SetDefaults ()
20
{
45
{
Line 38... Line 63...
38
bool CSpkFile::CheckHeader ( CyString header )
63
bool CSpkFile::CheckHeader ( CyString header )
39
{
64
{
40
	if ( header.Compare("SPKCycrow") )
65
	if ( header.Compare("SPKCycrow") )
41
		return true;
66
		return true;
42
	return false;
67
	return false;
43
}
68
}
44
/*
69
/*
45
	Func:   ParseValueLine
70
	Func:   ParseValueLine
46
	Input:  String - single line from a file to set
71
	Input:  String - single line from a file to set
47
	Return: Boolean - returns true if value exists
72
	Return: Boolean - returns true if value exists
48
	Desc:   Reads the line and assigns the parameters for the file
73
	Desc:   Reads the line and assigns the parameters for the file
49
*/
74
*/
Line 82... Line 107...
82
		SSettingType *t = AddSetting ( rest.GetToken ( 2, '|' ), rest.GetToken ( 1, '|' ).ToInt() );
107
		SSettingType *t = AddSetting ( rest.GetToken ( 2, '|' ), rest.GetToken ( 1, '|' ).ToInt() );
83
		ConvertSetting ( t, rest.GetToken ( 3, -1, '|' ) );
108
		ConvertSetting ( t, rest.GetToken ( 3, -1, '|' ) );
84
	}
109
	}
85
	else
110
	else
86
		return CBaseFile::ParseValueLine ( line );
111
		return CBaseFile::ParseValueLine ( line );
87
 
112
 
88
	return true;
113
	return true;
89
}
114
}
90
 
115
 
91
/*
116
/*
92
	Func:   CreateValuesLine
117
	Func:   CreateValuesLine
Line 111... Line 136...
111
 
136
 
112
	for ( SWares *ware = m_lWares.First(); ware; ware = m_lWares.Next() )
137
	for ( SWares *ware = m_lWares.First(); ware; ware = m_lWares.Next() )
113
	{
138
	{
114
		if ( ware->iTextID > 0 )
139
		if ( ware->iTextID > 0 )
115
			values += CyString("Ware: ") + ware->cType + ":" + ware->iPrice + ":" + (long)ware->iSize + ":" + (long)ware->iVolumn + ":" + ware->sID + ":" + (long)ware->iNotority + ":" + (long)ware->iTextID + "," + (long)ware->iTextPage + "\n";
140
			values += CyString("Ware: ") + ware->cType + ":" + ware->iPrice + ":" + (long)ware->iSize + ":" + (long)ware->iVolumn + ":" + ware->sID + ":" + (long)ware->iNotority + ":" + (long)ware->iTextID + "," + (long)ware->iTextPage + "\n";
116
		else
141
		else
117
			values += CyString("Ware: ") + ware->cType + ":" + ware->iPrice + ":" + (long)ware->iSize + ":" + (long)ware->iVolumn + ":" + ware->sID + ":" + (long)ware->iNotority + "\n";
142
			values += CyString("Ware: ") + ware->cType + ":" + ware->iPrice + ":" + (long)ware->iSize + ":" + (long)ware->iVolumn + ":" + ware->sID + ":" + (long)ware->iNotority + "\n";
118
		for ( SWaresText *wt = ware->lText.First(); wt; wt = ware->lText.Next() )
143
		for ( SWaresText *wt = ware->lText.First(); wt; wt = ware->lText.Next() )
119
			values += CyString("WareText: ") + (long)wt->iLang + " " + wt->sName + "|" + wt->sDesc + "\n";
144
			values += CyString("WareText: ") + (long)wt->iLang + " " + wt->sName + "|" + wt->sDesc + "\n";
120
	}
145
	}
121
 
146
 
Line 342... Line 367...
342
	wt->iLang = lang;
367
	wt->iLang = lang;
343
	wt->sName = name;
368
	wt->sName = name;
344
	wt->sDesc = desc;
369
	wt->sDesc = desc;
345
 
370
 
346
	w->lText.push_back ( wt );
371
	w->lText.push_back ( wt );
347
	m_bChanged = true;
372
	m_bChanged = true;
348
}
373
}
349
 
374
 
350
 
375
 
351
void CSpkFile::ClearWareText ( CyString id )
376
void CSpkFile::ClearWareText ( CyString id )
352
{
377
{
353
	SWares *w = FindWare ( id );
378
	SWares *w = FindWare ( id );
Line 691... Line 716...
691
		m_pLastWare = ware;
716
		m_pLastWare = ware;
692
	}
717
	}
693
 
718
 
694
	else if ( CBaseFile::LoadPackageData(first, rest) )
719
	else if ( CBaseFile::LoadPackageData(first, rest) )
695
		return true;
720
		return true;
696
	else
721
	else
697
		return false;
722
		return false;
698
 
723
 
699
	return true;
724
	return true;
700
}
725
}
701
 
726
 
Line 923... Line 948...
923
		m_lFiles.push_back(f);
948
		m_lFiles.push_back(f);
924
	}
949
	}
925
 
950
 
926
	// clear the files so we dont delete them later
951
	// clear the files so we dont delete them later
927
	base->GetFileList()->clear();
952
	base->GetFileList()->clear();
-
 
953
}
-
 
954
 
-
 
955
unsigned char *CSpkFile::uncompressOldFile(const CyString &sOldFilename, int *pLen)
-
 
956
{
-
 
957
	// firstcheck if the file exists
-
 
958
	FILE *id = fopen ( ((CyString)sOldFilename).c_str(), "rb" );
-
 
959
	if ( !id ) {
-
 
960
		CLog::logf("Unable to open file: %s\n", ((CyString)sOldFilename).c_str());
-
 
961
		return false;
-
 
962
	}
-
 
963
 
-
 
964
	// read the first 3 charaters to check if its using the original "HiP" compression
-
 
965
	CyString check = (char)fgetc ( id );
-
 
966
	check += (char)fgetc ( id );
-
 
967
	check += (char)fgetc ( id );
-
 
968
 
-
 
969
	CyString removeFile;
-
 
970
 
-
 
971
	unsigned char *uncomprData = NULL;
-
 
972
	unsigned char *data = NULL;
-
 
973
	long len = 0, newlen = 0;
-
 
974
 
-
 
975
	if ( check == "HiP" ) {
-
 
976
		fclose ( id );
-
 
977
		bool opened = false;
-
 
978
		if ( DecompressFile ( (char *)((CyString)sOldFilename).c_str(), "uncompr.tmp" ) ) {
-
 
979
			removeFile = "uncompr.tmp";
-
 
980
			id = fopen ( "uncompr.tmp", "r" );
-
 
981
			if ( id )
-
 
982
				opened = true;
-
 
983
		}
-
 
984
 
-
 
985
		if ( !opened ) {
-
 
986
			CLog::log("Unable to uncompress file, exiting...\n");
-
 
987
			return false;
-
 
988
		}
-
 
989
 
-
 
990
		CLog::log("* Reading file into memory...\n");
-
 
991
		// get file length
-
 
992
		fseek ( id, 0, SEEK_END );
-
 
993
		len = ftell ( id );
-
 
994
		
-
 
995
		// move back to beginning
-
 
996
		fseek ( id, 0, SEEK_SET );
-
 
997
 
-
 
998
		// read the data from file into memory
-
 
999
		uncomprData = new unsigned char[len + 1];
-
 
1000
		fread ( uncomprData, sizeof(unsigned char), len, id );
-
 
1001
 
-
 
1002
		newlen = len;
-
 
1003
	}
-
 
1004
	else
-
 
1005
	{
-
 
1006
		CLog::log("* Reading file into memory...\n");
-
 
1007
		// get file length
-
 
1008
		fseek ( id, 0, SEEK_END );
-
 
1009
		len = ftell ( id );
-
 
1010
		
-
 
1011
		// move back to beginning
-
 
1012
		fseek ( id, 0, SEEK_SET );
-
 
1013
 
-
 
1014
		// read the data from file into memory
-
 
1015
		data = new unsigned char[len + 1];
-
 
1016
		fread ( data, sizeof(unsigned char), len, id );
-
 
1017
 
-
 
1018
		// uncompress the file (currently only 7zip compression)
-
 
1019
		CLog::log("* Uncompressing file...\n");
-
 
1020
		newlen = len;
-
 
1021
	#ifdef _INCLUDE7ZIP
-
 
1022
		uncomprData = LZMADecodeData ( data, len, newlen, progress );
-
 
1023
	#else
-
 
1024
		uncomprData = LZMADecode_C ( (unsigned char *)data, len, (size_t*)&newlen, NULL );
-
 
1025
	#endif
-
 
1026
	}
-
 
1027
 
-
 
1028
	*pLen = newlen;
-
 
1029
 
-
 
1030
	return uncomprData;
-
 
1031
}
-
 
1032
 
-
 
1033
CyString CSpkFile::_convert_fileEndString(const CyString &sFile)
-
 
1034
{
-
 
1035
	CyString temp = sFile;
-
 
1036
	if ( temp.Compare("Text") )
-
 
1037
		return "-- End of Script --";
-
 
1038
	else if ( temp.Compare("Uninstall") )
-
 
1039
		return "-- End of Uninstall --";
-
 
1040
	else if ( temp.Compare("Readme") )
-
 
1041
		return "-- End of Readme --";
-
 
1042
	else if ( temp.Compare("Map") )
-
 
1043
		return "-- End of Map --";
-
 
1044
	else if ( temp.Compare("Mod") || temp.Compare("Extra") || temp.Compare("Screen") || temp.Compare("Sound") )
-
 
1045
		return "";
-
 
1046
	return "-- End of Script --";
-
 
1047
}
-
 
1048
 
-
 
1049
int CSpkFile::_convert_fileType(const CyString &sFile)
-
 
1050
{
-
 
1051
	CyString temp = sFile;
-
 
1052
	if ( temp.Compare("Text") )
-
 
1053
		return FILETYPE_TEXT;
-
 
1054
	else if ( temp.Compare("Uninstall") )
-
 
1055
		return FILETYPE_UNINSTALL;
-
 
1056
	else if ( temp.Compare("Readme") )
-
 
1057
		return FILETYPE_README;
-
 
1058
	else if ( temp.Compare("Map") )
-
 
1059
		return FILETYPE_MAP;
-
 
1060
	else if ( temp.Compare("Mod") )
-
 
1061
		return FILETYPE_MOD;
-
 
1062
	else if ( temp.Compare("Extra") )
-
 
1063
		return FILETYPE_EXTRA;
-
 
1064
	else if ( temp.Compare("Screen") )
-
 
1065
		return FILETYPE_SCREEN;
-
 
1066
	else if ( temp.Compare("Sound") )
-
 
1067
		return FILETYPE_SOUND;
-
 
1068
 
-
 
1069
	return FILETYPE_SCRIPT;
-
 
1070
}
-
 
1071
 
-
 
1072
void CSpkFile::_convert_parse(const CyString &s_Cmd, const CyString &s_Rest, bool bVerbose)
-
 
1073
{
-
 
1074
	CyString sCmd = s_Cmd;
-
 
1075
	CyString sRest = s_Rest;
-
 
1076
	if ( sCmd == "Name:" )
-
 
1077
	{
-
 
1078
		this->SetName ( sRest );
-
 
1079
		if ( bVerbose ) CLog::logf( "\tScript Name: %s\n", sRest.c_str() );
-
 
1080
	}
-
 
1081
	else if ( sCmd == "Author:" )
-
 
1082
	{
-
 
1083
		this->SetAuthor ( sRest );
-
 
1084
		if ( bVerbose ) CLog::logf( "\tScript Author: %s\n", sRest.c_str() );
-
 
1085
	}
-
 
1086
	else if ( sCmd == "CustomStart" )
-
 
1087
	{
-
 
1088
		this->SetCustomStart();
-
 
1089
		if ( bVerbose ) CLog::logf( "\tPackage is a custom start!!\n" );
-
 
1090
	}
-
 
1091
	else if ( sCmd == "AnotherMod:" )
-
 
1092
	{
-
 
1093
		this->SetAnotherMod ( sRest.GetToken ( 1, '|' ), sRest.GetToken ( 2, -1, '|' ) );
-
 
1094
		if ( bVerbose ) CLog::logf( "\tFor another Mod, Name: %s, Author: %s\n", this->GetOtherName().c_str(), this->GetOtherAuthor().c_str() );
-
 
1095
	}
-
 
1096
	else if ( sCmd == "PATCH" )
-
 
1097
	{
-
 
1098
		this->SetPatch();
-
 
1099
		if ( bVerbose ) CLog::logf("\tPackage is a Patch Mod!!\n" );
-
 
1100
	}
-
 
1101
	else if ( sCmd == "Version:" )
-
 
1102
	{
-
 
1103
		this->SetVersion ( sRest );
-
 
1104
		if ( bVerbose ) CLog::logf("\tScript Version: %s\n", sRest.c_str() );
-
 
1105
	}
-
 
1106
	else if ( sCmd == "Date:" )
-
 
1107
	{
-
 
1108
		this->SetCreationDate ( sRest );
-
 
1109
		if ( bVerbose ) CLog::logf("\tScript Creation Date: %s\n", sRest.c_str() );
-
 
1110
	}
-
 
1111
	else if ( sCmd == "Desc:" )
-
 
1112
	{
-
 
1113
		this->SetDescription ( sRest.FindReplace ( "<br>", "\n" ) );
-
 
1114
		if ( bVerbose ) CLog::logf("\tScript Description: %s\n", this->GetDescription().c_str() );
-
 
1115
	}
-
 
1116
	else if ( sCmd == "WebAddress:" )
-
 
1117
	{
-
 
1118
		this->SetWebAddress ( sRest );
-
 
1119
		if ( bVerbose ) CLog::logf("\tWeb Address: %s\n", sRest.c_str() );
-
 
1120
	}
-
 
1121
	else if ( sCmd == "WebMirror1:" )
-
 
1122
	{
-
 
1123
		this->AddWebMirror(sRest);
-
 
1124
		if ( bVerbose ) CLog::logf("\tWeb Mirror Address: %s\n", sRest.c_str() );
-
 
1125
	}
-
 
1126
	else if ( sCmd == "WebMirror2:" )
-
 
1127
	{
-
 
1128
		this->AddWebMirror(sRest);
-
 
1129
		if ( bVerbose ) CLog::logf("\tWeb Mirror Address: %s\n", sRest.c_str() );
-
 
1130
	}
-
 
1131
	
-
 
1132
	else if ( sCmd == "ScriptType:" )
-
 
1133
		this->SetScriptType ( sRest );
-
 
1134
	else if ( sCmd == "WebSite:" )
-
 
1135
	{
-
 
1136
		this->SetWebSite ( sRest );
-
 
1137
		if ( bVerbose ) CLog::logf("\tWeb Site: %s\n", sRest.c_str() );
-
 
1138
	}
-
 
1139
	else if ( sCmd == "Email:" )
-
 
1140
	{
-
 
1141
		this->SetEmail ( sRest );
-
 
1142
		if ( bVerbose ) CLog::logf("\tAuthor Email Address: %s\n", sRest.c_str() );
-
 
1143
	}
-
 
1144
	else if ( sCmd == "GameVersion:" )
-
 
1145
	{
-
 
1146
		//TODO: fix this for new game version
-
 
1147
		/*
-
 
1148
		int version = sRest.ToInt();
-
 
1149
		if ( version == 0 )
-
 
1150
			this->SetGameVersion ( 1 );
-
 
1151
		else if (version == 1 )
-
 
1152
			this->SetGameVersion ( 0 );
-
 
1153
		else
-
 
1154
			this->SetGameVersion ( version );
-
 
1155
		if ( bVerbose ) CLog::logf( "\tGame Version: %d\n", this->GetGameVersion () );
-
 
1156
		*/
-
 
1157
	}
-
 
1158
	
-
 
1159
	else if ( sCmd == "Ware:" )
-
 
1160
	{
-
 
1161
		this->AddWare ( sRest );
-
 
1162
		if ( bVerbose ) CLog::logf( "\tAdding Custom Ware\n" );
-
 
1163
	}
-
 
1164
	else if ( sCmd == "WareText:" )
-
 
1165
		this->AddWareText ( sRest );
-
 
1166
	else if ( sCmd == "UninstallAfter:" )
-
 
1167
		this->AddUninstallAfterText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, ' ' ) );
-
 
1168
	else if ( sCmd == "UninstallBefore:" )
-
 
1169
		this->AddUninstallBeforeText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, ' ' ) );
-
 
1170
	else if ( sCmd == "InstallAfter:" )
-
 
1171
		this->AddInstallAfterText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, ' ' ) );
-
 
1172
	else if ( sCmd == "InstallBefore:" )
-
 
1173
		this->AddInstallBeforeText ( sRest.GetToken ( 1, ' ' ).ToInt(), sRest.GetToken ( 2, -1, ' ' ) );
-
 
1174
	else if ( sCmd == "ScriptName:" )
-
 
1175
	{
-
 
1176
		CyString lang = sRest.GetToken ( 1, ':' );
-
 
1177
		CyString name = sRest.GetToken ( 2, -1, ':' );
-
 
1178
		this->AddLanguageName ( lang.ToInt(), name );
-
 
1179
		if ( bVerbose ) CLog::logf( "\tScript Name Language (%s) %s\n", lang.c_str(), name.c_str() );
-
 
1180
	}
-
 
1181
}
-
 
1182
 
-
 
1183
CyString CSpkFile::_convert_parseFilename(const CyString &s_Rest, float fVersion, CyString *pDir)
-
 
1184
{
-
 
1185
	CyString sFilename;
-
 
1186
	CyString sRest = s_Rest;
-
 
1187
 
-
 
1188
	if ( fVersion >= 3.00f )
-
 
1189
		sFilename = sRest.GetToken ( 3, -1, ' ' );
-
 
1190
	else if ( fVersion >= 2.00f )
-
 
1191
		sFilename = sRest.GetToken ( 2, -1, ' ' );
-
 
1192
	else
-
 
1193
		sFilename = sRest;
-
 
1194
 
-
 
1195
	if ( sFilename.IsIn ( "<br>" ) )
-
 
1196
	{
-
 
1197
		sFilename = sFilename.FindReplace ( "<br>", "|" );
-
 
1198
		if ( sFilename[0] == '|' ) {
-
 
1199
			sFilename = sFilename.GetToken ( 1, '|' );
-
 
1200
		}
-
 
1201
		else {
-
 
1202
			*pDir = sFilename.GetToken ( 1, '|' );
-
 
1203
			sFilename = sFilename.GetToken ( 2, -1, '|' );
-
 
1204
		}
-
 
1205
	}
-
 
1206
 
-
 
1207
	return sFilename;
-
 
1208
}
-
 
1209
 
-
 
1210
unsigned char *CSpkFile::_convert_parseFile(const CyString &s_Cmd, const CyString &s_Rest, float fVersion, unsigned char *d, bool bVerbose )
-
 
1211
{
-
 
1212
	CyString sCmd = s_Cmd;
-
 
1213
	CyString sRest = s_Rest;
-
 
1214
 
-
 
1215
	bool bShared = (sCmd.Left (9) == "$$$Shared") ? true : false;
-
 
1216
	CyString sFile = sCmd.Right(-3).Left(-1);
-
 
1217
	CyString sEnd = this->_convert_fileEndString(sFile);
-
 
1218
	int iType = this->_convert_fileType(sFile);
-
 
1219
 
-
 
1220
	// convert the filename and directory
-
 
1221
	CyString dir, filename = _convert_parseFilename(sRest, fVersion, &dir);
-
 
1222
 
-
 
1223
	// get the size and time
-
 
1224
	long time = 0, size = 0;
-
 
1225
	if ( fVersion >= 2.00f ) time = sRest.GetToken ( 1, ' ' ).ToLong();
-
 
1226
	if ( fVersion >= 3.00f ) size = sRest.GetToken ( 2, ' ' ).ToLong();
-
 
1227
	bool binaryRead = (CFileIO(filename).CheckFileExtension("PCK")) ? true : false;
-
 
1228
	if ( sEnd.Empty() ) binaryRead = true;
-
 
1229
	
-
 
1230
	C_File *file = new C_File ();
-
 
1231
 
-
 
1232
	if ( bVerbose )
-
 
1233
	{
-
 
1234
		if ( bShared )
-
 
1235
			CLog::logf( "\tFound %s File (Shared): %s, Reading...", sFile.c_str(), filename.c_str() );
-
 
1236
		else
-
 
1237
			CLog::logf( "\tFound %s File: %s, Reading...", sFile.c_str(), filename.c_str() );
-
 
1238
	}
-
 
1239
 
-
 
1240
	// read the data
-
 
1241
	if ( binaryRead )
-
 
1242
	{
-
 
1243
		file->ReadFromData ( (char *)d, size );
-
 
1244
		d += size;
-
 
1245
	}
-
 
1246
	else
-
 
1247
	{
-
 
1248
		CyString readData;
-
 
1249
		d = LineByLineRead ( d, sEnd, &readData );
-
 
1250
		file->ReadFromData ( (char *)readData.c_str(), (long)readData.Length() );
-
 
1251
	}
-
 
1252
 
-
 
1253
	// setup the file
-
 
1254
	file->SetName ( filename );
-
 
1255
	file->SetFileType ( iType );
-
 
1256
	file->SetShared ( bShared );
-
 
1257
	file->SetCreationTime ( time );
-
 
1258
	if ( !dir.Empty() )
-
 
1259
		file->SetDir ( dir );
-
 
1260
	
-
 
1261
	this->AddFile ( file );
-
 
1262
 
-
 
1263
	CLog::logf( "(Done) Size: %s\n", file->GetDataSizeString().c_str() );
-
 
1264
 
-
 
1265
	return d;
-
 
1266
}
-
 
1267
 
-
 
1268
bool CSpkFile::convertOld(CyString &sOldFilename)
-
 
1269
{
-
 
1270
	// check if the old file is actually in an old format
-
 
1271
	int ret = CBaseFile::CheckFile ( sOldFilename );
-
 
1272
	if ( ret != SPKFILE_INVALID && ret != SPKFILE_OLD ) {
-
 
1273
		return false;
-
 
1274
 	}
-
 
1275
 
-
 
1276
	//uncomress the data
-
 
1277
	int len;
-
 
1278
	unsigned char *uncomprData = this->uncompressOldFile(sOldFilename, &len);
-
 
1279
 
-
 
1280
	// uncomressed failed
-
 
1281
	if ( !uncomprData ) {
-
 
1282
		CLog::log("Error: Unable to uncompress the file\n");
-
 
1283
		return false;
-
 
1284
	}
-
 
1285
 
-
 
1286
	// now we can read the data
-
 
1287
	unsigned char *d = uncomprData;
-
 
1288
	CyString str;
-
 
1289
 
-
 
1290
//	CMultiSpkFile *mspk = NULL;
-
 
1291
	//SMultiSpkFile *cur_mspk = NULL;
-
 
1292
 
-
 
1293
	int numscripts = 0, curscript = 0;
-
 
1294
	bool bVerbose = true;
-
 
1295
	float fVersion = 1;
-
 
1296
 
-
 
1297
	CLog::log("* Reading spk data...\n");
-
 
1298
	while ( d )
-
 
1299
	{
-
 
1300
		// read the next line
-
 
1301
		d = str.GetEndOfLine(d);
-
 
1302
		if ( !d || d[0] == 0 ) {
-
 
1303
			break;
-
 
1304
		}
-
 
1305
		if ( str.Empty() ) {
-
 
1306
			continue;
-
 
1307
		}
-
 
1308
 
-
 
1309
		CyString sCmd = str.GetToken ( 1, ' ' );
-
 
1310
 
-
 
1311
		//TODO: split this into CMultiSpkFile
-
 
1312
		/*
-
 
1313
		if ( first == "MultiPackage:" )
-
 
1314
			mspk = new CMultiSpkFile;
-
 
1315
		else if ( (first == "SelectScript:") && (mspk) )
-
 
1316
		{
-
 
1317
			mspk->AddFileEntry ( rest.GetToken ( 2, -1, ' ' ) + ".spk" );
-
 
1318
			++numscripts;
-
 
1319
		}
-
 
1320
		else if ( (str == "AllowSelection") && (mspk) )
-
 
1321
			mspk->SetSelection ( true );
-
 
1322
		else if ( str == "-- Start New Script --" )
-
 
1323
		{
-
 
1324
			if ( !mspk )
-
 
1325
			{
-
 
1326
				printf ( "Invalid file format, seems to be multi package file but isn't\n" );
-
 
1327
				CLEANUP
-
 
1328
				exit ( 0 );
-
 
1329
			}
-
 
1330
			cur_mspk = mspk->GetFileList()->Get ( curscript );
-
 
1331
			++curscript;
-
 
1332
			cur_mspk->pFile = new CSpkFile;
-
 
1333
			spkfile = (CSpkFile *)cur_mspk->pFile;
-
 
1334
		}
-
 
1335
		*/
-
 
1336
		CyString sRest = str.GetToken ( 2, -1, ' ' );
-
 
1337
		if ( sCmd == "Packager:" ) {
-
 
1338
			fVersion = sRest.ToFloat ();
-
 
1339
			if ( bVerbose ) CLog::logf( "\tPackager Version: %.2f\n", fVersion );
-
 
1340
		}
-
 
1341
		else if ( sCmd == "Icon:" )
-
 
1342
		{
-
 
1343
			long size = sRest.GetToken ( 1, ' ' ).ToLong ();
-
 
1344
			
-
 
1345
			C_File *file = new C_File ();
-
 
1346
			file->ReadFromData ( (char *)d, size );
-
 
1347
 
-
 
1348
			d += size;
-
 
1349
 
-
 
1350
			this->SetIcon(file, sRest.GetToken ( 2, ' ' ));
-
 
1351
 
-
 
1352
			if ( bVerbose ) CLog::logf( "\tIcon (%s) Size: %s\n", ext.c_str(), file->GetDataSizeString ().c_str() );
-
 
1353
		}
-
 
1354
		else if ( sCmd.Left(3) == "$$$" )
-
 
1355
			d = _convert_parseFile(sCmd, sRest, fVersion, d, bVerbose);
-
 
1356
		else {
-
 
1357
			this->_convert_parse(sCmd, sRest, bVerbose);
-
 
1358
		}
-
 
1359
	}
-
 
1360
 
-
 
1361
	if ( bVerbose ) CLog::logf( "* Reading spk data...\n" );
-
 
1362
 
-
 
1363
	return true;
928
}
1364
}