| 7 | cycrow | 1 | //header
 | 
        
           | 1 | cycrow | 2 | #include "SpkFile.h"
 | 
        
           |  |  | 3 |   | 
        
           | 7 | cycrow | 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 | cycrow | 10 | //TODO: remove this
 | 
        
           | 14 | cycrow | 11 | unsigned char *LineByLineRead ( unsigned char *data, const Utils::String &end, Utils::String *readData )
 | 
        
           | 10 | cycrow | 12 | {
 | 
        
           | 14 | cycrow | 13 | 	Utils::String line;
 | 
        
           | 10 | cycrow | 14 | 	while ( true )
 | 
        
           |  |  | 15 | 	{
 | 
        
           | 14 | cycrow | 16 | 		data = line.readToEndOfLine(data);
 | 
        
           | 7 | cycrow | 17 |   | 
        
           | 14 | cycrow | 18 | 		if ( (*readData).empty() && line.empty() ) continue;
 | 
        
           | 10 | cycrow | 19 | 		if ( line == end )
 | 
        
           |  |  | 20 | 			break;
 | 
        
           |  |  | 21 | 		*readData += (line + "\r\n");
 | 
        
           |  |  | 22 | 	}
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | 	return data;
 | 
        
           |  |  | 25 | }
 | 
        
           |  |  | 26 |   | 
        
           |  |  | 27 |   | 
        
           | 1 | cycrow | 28 | CSpkFile::CSpkFile() : CBaseFile ()
 | 
        
           |  |  | 29 | {
 | 
        
           |  |  | 30 | 	SetDefaults ();
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | 	m_iType = TYPE_SPK;
 | 
        
           |  |  | 33 | }
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 | CSpkFile::~CSpkFile()
 | 
        
           |  |  | 36 | {
 | 
        
           |  |  | 37 | 	Delete ();
 | 
        
           |  |  | 38 | }
 | 
        
           |  |  | 39 | /*
 | 
        
           |  |  | 40 | 	Func:   SetDefaults
 | 
        
           |  |  | 41 | 	Desc:   Sets the  default values when class is created
 | 
        
           |  |  | 42 | */
 | 
        
           |  |  | 43 | void CSpkFile::SetDefaults ()
 | 
        
           |  |  | 44 | {
 | 
        
           |  |  | 45 | 	m_pLastWare = NULL;
 | 
        
           |  |  | 46 | 	m_iPackageType = PACKAGETYPE_NORMAL;
 | 
        
           |  |  | 47 | 	m_bForceProfile = false;
 | 
        
           |  |  | 48 | 	m_iScriptType = SCRIPTTYPE_CUSTOM;
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 | 	CBaseFile::SetDefaults ();
 | 
        
           |  |  | 51 | }
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 | void CSpkFile::Delete ()
 | 
        
           |  |  | 54 | {
 | 
        
           |  |  | 55 | 	m_lWares.clear(true);
 | 
        
           |  |  | 56 | 	m_lSettings.clear(true);
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 | 	CBaseFile::Delete ();
 | 
        
           |  |  | 59 | }
 | 
        
           |  |  | 60 |   | 
        
           |  |  | 61 |   | 
        
           | 14 | cycrow | 62 | bool CSpkFile::CheckHeader(const Utils::String header) const
 | 
        
           | 1 | cycrow | 63 | {
 | 
        
           |  |  | 64 | 	if ( header.Compare("SPKCycrow") )
 | 
        
           |  |  | 65 | 		return true;
 | 
        
           |  |  | 66 | 	return false;
 | 
        
           |  |  | 67 | }
 | 
        
           |  |  | 68 | /*
 | 
        
           |  |  | 69 | 	Func:   ParseValueLine
 | 
        
           |  |  | 70 | 	Input:  String - single line from a file to set
 | 
        
           |  |  | 71 | 	Return: Boolean - returns true if value exists
 | 
        
           |  |  | 72 | 	Desc:   Reads the line and assigns the parameters for the file
 | 
        
           |  |  | 73 | */
 | 
        
           | 14 | cycrow | 74 | bool CSpkFile::ParseValueLine(const Utils::String &line)
 | 
        
           | 1 | cycrow | 75 | {
 | 
        
           | 14 | cycrow | 76 | 	Utils::String first = line.token(" ", 1);
 | 
        
           |  |  | 77 | 	Utils::String rest  = line.tokens(" ", 2);
 | 
        
           | 1 | cycrow | 78 |   | 
        
           |  |  | 79 | 	if ( first == "AnotherMod:" )
 | 
        
           |  |  | 80 | 	{
 | 
        
           | 10 | cycrow | 81 | 		m_sOtherAuthor = rest.token("|", 1);
 | 
        
           |  |  | 82 | 		m_sOtherName = rest.tokens("|", 2);
 | 
        
           | 1 | cycrow | 83 | 	}
 | 
        
           |  |  | 84 | 	else if ( line == "CustomStart" )
 | 
        
           |  |  | 85 | 		m_iPackageType = PACKAGETYPE_CUSTOMSTART;
 | 
        
           |  |  | 86 | 	else if ( line == "PackageUpdate" )
 | 
        
           |  |  | 87 | 		m_iPackageType = PACKAGETYPE_UPDATE;
 | 
        
           |  |  | 88 | 	else if ( line == "Patch" )
 | 
        
           |  |  | 89 | 		m_iPackageType = PACKAGETYPE_PATCH;
 | 
        
           |  |  | 90 | 	else if ( line == "ForceProfile" )
 | 
        
           |  |  | 91 | 		m_bForceProfile = true;
 | 
        
           |  |  | 92 | 	else if ( line == "Signed" )
 | 
        
           |  |  | 93 | 		m_bSigned = true;
 | 
        
           |  |  | 94 | 	else if ( first == "ScriptType:" )
 | 
        
           |  |  | 95 | 		m_sScriptType = rest;
 | 
        
           |  |  | 96 | 	else if ( first == "ScriptTypeNew:" )
 | 
        
           | 10 | cycrow | 97 | 		m_iScriptType = rest;
 | 
        
           | 1 | cycrow | 98 | 	else if ( first == "PackageType:" )
 | 
        
           | 10 | cycrow | 99 | 		m_iPackageType = rest;
 | 
        
           | 1 | cycrow | 100 | 	else if ( first == "Ware:" )
 | 
        
           |  |  | 101 | 		AddWare ( rest );
 | 
        
           |  |  | 102 | 	else if ( (first == "WareText:") && (m_pLastWare) )
 | 
        
           |  |  | 103 | 		AddWareText ( rest );
 | 
        
           |  |  | 104 | 	else if ( first == "Setting:" )
 | 
        
           |  |  | 105 | 	{
 | 
        
           | 10 | cycrow | 106 | 		SSettingType *t = AddSetting ( rest.token("|", 2), rest.token("|", 1) );
 | 
        
           |  |  | 107 | 		ConvertSetting ( t, rest.tokens("|", 3));
 | 
        
           | 1 | cycrow | 108 | 	}
 | 
        
           |  |  | 109 | 	else
 | 
        
           |  |  | 110 | 		return CBaseFile::ParseValueLine ( line );
 | 
        
           |  |  | 111 |   | 
        
           |  |  | 112 | 	return true;
 | 
        
           |  |  | 113 | }
 | 
        
           |  |  | 114 |   | 
        
           |  |  | 115 | /*
 | 
        
           |  |  | 116 | 	Func:   CreateValuesLine
 | 
        
           |  |  | 117 | 	Return: String - returns the full string for values
 | 
        
           |  |  | 118 | 	Desc:   Creates a single string for all values, this is used when compressing to write to the spk file
 | 
        
           |  |  | 119 | */
 | 
        
           | 14 | cycrow | 120 | Utils::String CSpkFile::CreateValuesLine () const
 | 
        
           | 1 | cycrow | 121 | {
 | 
        
           | 14 | cycrow | 122 | 	Utils::String values = CBaseFile::CreateValuesLine ();
 | 
        
           | 1 | cycrow | 123 | 	// combine all values together
 | 
        
           | 10 | cycrow | 124 | 	if ( (!m_sOtherAuthor.empty()) && (!m_sOtherName.empty()) )
 | 
        
           | 14 | cycrow | 125 | 		values += "AnotherMod: " + m_sOtherAuthor + "|" + m_sOtherName + "\n";
 | 
        
           | 1 | cycrow | 126 | 	if ( m_bForceProfile )
 | 
        
           |  |  | 127 | 		values += "ForceProfile\n";
 | 
        
           | 10 | cycrow | 128 | 	if ( !m_sScriptType.empty() )
 | 
        
           | 14 | cycrow | 129 | 		values += "ScriptType: " + m_sScriptType + "\n";
 | 
        
           |  |  | 130 | 	values += Utils::String("PackageType: ") + (long)m_iPackageType + "\n";
 | 
        
           |  |  | 131 | 	values += Utils::String("ScriptTypeNew: ") + (long)m_iScriptType + "\n";
 | 
        
           | 1 | cycrow | 132 |   | 
        
           | 14 | cycrow | 133 | 	for ( CListNode<SSettingType> *node = m_lSettings.Front(); node; node = node->next() )
 | 
        
           |  |  | 134 | 		values += Utils::String("Setting: ") + (long)node->Data()->iType + "|" + node->Data()->sKey + "|" + GetSetting(node->Data()) + "\n";
 | 
        
           | 1 | cycrow | 135 |   | 
        
           | 14 | cycrow | 136 | 	for ( CListNode<SWares> *wNode = m_lWares.Front(); wNode; wNode = wNode->next() ) {
 | 
        
           |  |  | 137 | 		SWares *ware = wNode->Data();
 | 
        
           |  |  | 138 | 		if ( wNode->Data()->iTextID > 0 )
 | 
        
           |  |  | 139 | 			values += Utils::String("Ware: ") + ware->cType + ":" + ware->iPrice + ":" + (long)ware->iSize + ":" + (long)ware->iVolumn + ":" + ware->sID + ":" + (long)ware->iNotority + ":" + (long)ware->iTextID + "," + (long)ware->iTextPage + "\n";
 | 
        
           | 1 | cycrow | 140 | 		else
 | 
        
           | 14 | cycrow | 141 | 			values += Utils::String("Ware: ") + ware->cType + ":" + ware->iPrice + ":" + (long)ware->iSize + ":" + (long)ware->iVolumn + ":" + ware->sID + ":" + (long)ware->iNotority + "\n";
 | 
        
           |  |  | 142 | 		for ( CListNode<SWaresText> *wtNode = ware->lText.Front(); wtNode; wtNode = wtNode->next() )
 | 
        
           |  |  | 143 | 			values += Utils::String("WareText: ") + (long)wtNode->Data()->iLang + " " + wtNode->Data()->sName + "|" + wtNode->Data()->sDesc + "\n";
 | 
        
           | 1 | cycrow | 144 | 	}
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 | 	return values;
 | 
        
           |  |  | 147 | }
 | 
        
           |  |  | 148 |   | 
        
           | 13 | cycrow | 149 | Utils::String CSpkFile::GetCustomScriptType (int lang) const
 | 
        
           | 1 | cycrow | 150 | {
 | 
        
           | 10 | cycrow | 151 | 	if ( !m_sScriptType.empty() )
 | 
        
           | 1 | cycrow | 152 | 	{
 | 
        
           |  |  | 153 | 		int max;
 | 
        
           | 10 | cycrow | 154 | 		Utils::String *split = m_sScriptType.tokenise("<br>", &max);
 | 
        
           | 1 | cycrow | 155 | 		if ( max && split )
 | 
        
           |  |  | 156 | 		{
 | 
        
           |  |  | 157 | 			for ( int i = 1; i < max; i++ )
 | 
        
           |  |  | 158 | 			{
 | 
        
           | 10 | cycrow | 159 | 				Utils::String str = split[i];
 | 
        
           |  |  | 160 | 				int num = str.token(":", 1);
 | 
        
           |  |  | 161 | 				Utils::String name = str.tokens(":", 2);
 | 
        
           | 1 | cycrow | 162 |   | 
        
           |  |  | 163 | 				if ( num == lang )
 | 
        
           |  |  | 164 | 				{
 | 
        
           |  |  | 165 | 					CLEANSPLIT(split, max)
 | 
        
           |  |  | 166 | 					return name;
 | 
        
           |  |  | 167 | 				}
 | 
        
           |  |  | 168 | 			}
 | 
        
           |  |  | 169 |   | 
        
           | 10 | cycrow | 170 | 			Utils::String ret = split[0];
 | 
        
           | 1 | cycrow | 171 | 			CLEANSPLIT(split, max)
 | 
        
           |  |  | 172 |   | 
        
           |  |  | 173 | 			return ret;
 | 
        
           |  |  | 174 | 		}
 | 
        
           |  |  | 175 | 		CLEANSPLIT(split, max)
 | 
        
           |  |  | 176 | 	}
 | 
        
           |  |  | 177 | 	return m_sScriptType;
 | 
        
           |  |  | 178 | }
 | 
        
           |  |  | 179 |   | 
        
           |  |  | 180 | bool CSpkFile::WriteHeader(FILE *id, int valueheader, int valueComprLen)
 | 
        
           |  |  | 181 | {
 | 
        
           |  |  | 182 | 	fprintf ( id, "SPKCycrow;%.2f;%d;%d\n", FILEVERSION, valueheader, valueComprLen );
 | 
        
           |  |  | 183 | 	if ( ferror(id) )
 | 
        
           |  |  | 184 | 		return false;
 | 
        
           |  |  | 185 | 	return true;
 | 
        
           |  |  | 186 | }
 | 
        
           |  |  | 187 |   | 
        
           | 10 | cycrow | 188 | void CSpkFile::AddWareText(const Utils::String &sData)
 | 
        
           | 1 | cycrow | 189 | {
 | 
        
           |  |  | 190 | 	if ( !m_pLastWare )
 | 
        
           |  |  | 191 | 		return;
 | 
        
           |  |  | 192 |   | 
        
           |  |  | 193 | 	SWaresText *wt = new SWaresText;
 | 
        
           | 10 | cycrow | 194 | 	wt->iLang = sData.token(" ", 1);
 | 
        
           |  |  | 195 | 	wt->sName = sData.tokens(" ", 2).token("|", 1);
 | 
        
           |  |  | 196 | 	wt->sDesc = sData.tokens(" ", 2).tokens("|", 2);
 | 
        
           | 1 | cycrow | 197 | 	m_pLastWare->lText.push_back ( wt );
 | 
        
           |  |  | 198 |   | 
        
           |  |  | 199 | 	m_bChanged = true;
 | 
        
           |  |  | 200 | }
 | 
        
           |  |  | 201 |   | 
        
           | 10 | cycrow | 202 | void CSpkFile::AddWare(const Utils::String &sData)
 | 
        
           | 1 | cycrow | 203 | {
 | 
        
           |  |  | 204 | 	SWares *ware = new SWares;
 | 
        
           |  |  | 205 | 	ware->iTextID = -1;
 | 
        
           |  |  | 206 | 	ware->iTextPage = 0;
 | 
        
           | 10 | cycrow | 207 | 	ware->cType = sData.token(":", 1)[0];
 | 
        
           |  |  | 208 | 	ware->iPrice = sData.token(":", 2);
 | 
        
           |  |  | 209 | 	ware->iSize = sData.token(":", 3);
 | 
        
           |  |  | 210 | 	ware->iVolumn = sData.token(":", 4);
 | 
        
           |  |  | 211 | 	ware->sID = sData.token(":", 5);
 | 
        
           |  |  | 212 | 	ware->iNotority = sData.token(":", 6);
 | 
        
           |  |  | 213 | 	if ( !sData.token(":", 7).empty() )
 | 
        
           | 1 | cycrow | 214 | 	{
 | 
        
           | 10 | cycrow | 215 | 		Utils::String r = sData.token(":", 7);
 | 
        
           |  |  | 216 | 		ware->iTextID = r.token(",", 1);
 | 
        
           |  |  | 217 | 		ware->iTextPage = r.token(",", 2);
 | 
        
           | 1 | cycrow | 218 | 	}
 | 
        
           |  |  | 219 | 	m_lWares.push_back ( ware );
 | 
        
           |  |  | 220 | 	m_pLastWare = ware;
 | 
        
           |  |  | 221 |   | 
        
           |  |  | 222 | 	m_bChanged = true;
 | 
        
           |  |  | 223 | }
 | 
        
           |  |  | 224 |   | 
        
           |  |  | 225 |   | 
        
           |  |  | 226 |   | 
        
           |  |  | 227 | bool CSpkFile::ReadFileToMemory ( C_File *file )
 | 
        
           |  |  | 228 | {
 | 
        
           |  |  | 229 | 	if ( !file )
 | 
        
           |  |  | 230 | 		return false;
 | 
        
           |  |  | 231 |   | 
        
           |  |  | 232 | 	// check if data is already extracted
 | 
        
           |  |  | 233 | 	if ( (file->GetDataSize ()) && (file->GetData()) )
 | 
        
           |  |  | 234 | 		return true;
 | 
        
           |  |  | 235 |   | 
        
           |  |  | 236 | 	// no file to read from
 | 
        
           |  |  | 237 | 	if ( m_sFilename.Empty() )
 | 
        
           |  |  | 238 | 		return false;
 | 
        
           |  |  | 239 |   | 
        
           |  |  | 240 | 	// now open the file
 | 
        
           |  |  | 241 | 	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
 | 
        
           |  |  | 242 | 	if ( !id )
 | 
        
           |  |  | 243 | 		return false;
 | 
        
           |  |  | 244 |   | 
        
           |  |  | 245 | 	// read the header
 | 
        
           |  |  | 246 | 	GetEndOfLine ( id, NULL, false );
 | 
        
           |  |  | 247 | 	// skip past values
 | 
        
           |  |  | 248 | 	fseek ( id, m_SHeader.lValueCompressSize, SEEK_CUR );
 | 
        
           |  |  | 249 |   | 
        
           |  |  | 250 | 	// read the next header
 | 
        
           |  |  | 251 | 	GetEndOfLine ( id, NULL, false );
 | 
        
           |  |  | 252 | 	// skip past files
 | 
        
           |  |  | 253 | 	fseek ( id, 4, SEEK_CUR );
 | 
        
           |  |  | 254 | 	fseek ( id, m_SHeader2.lSize, SEEK_CUR );
 | 
        
           |  |  | 255 |   | 
        
           |  |  | 256 | 	// skip the icon file
 | 
        
           |  |  | 257 | 	if ( m_pIconFile )
 | 
        
           |  |  | 258 | 	{
 | 
        
           |  |  | 259 | 		fseek ( id, 4, SEEK_CUR );
 | 
        
           |  |  | 260 | 		fseek ( id, m_pIconFile->GetDataSize (), SEEK_CUR );
 | 
        
           |  |  | 261 | 	}
 | 
        
           |  |  | 262 |   | 
        
           |  |  | 263 | 	// now were in the file section
 | 
        
           |  |  | 264 | 	// skip past each one
 | 
        
           |  |  | 265 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 266 | 	{
 | 
        
           |  |  | 267 | 		C_File *fit = node->Data();
 | 
        
           |  |  | 268 | 		if ( fit == file )
 | 
        
           |  |  | 269 | 			break;
 | 
        
           |  |  | 270 |   | 
        
           |  |  | 271 | 		fseek ( id, 4, SEEK_CUR );
 | 
        
           |  |  | 272 | 		fseek ( id, fit->GetDataSize(), SEEK_CUR );
 | 
        
           |  |  | 273 | 	}
 | 
        
           |  |  | 274 |   | 
        
           |  |  | 275 | 	// now we should be at the start of the file
 | 
        
           |  |  | 276 | 	// read the data into memory
 | 
        
           |  |  | 277 | 	if ( !file->ReadFromFile ( id, file->GetDataSize() ) )
 | 
        
           |  |  | 278 | 	{
 | 
        
           |  |  | 279 | 		fclose ( id );
 | 
        
           |  |  | 280 | 		return false;
 | 
        
           |  |  | 281 | 	}
 | 
        
           |  |  | 282 | 	fclose ( id );
 | 
        
           |  |  | 283 |   | 
        
           |  |  | 284 | 	return true;
 | 
        
           |  |  | 285 | }
 | 
        
           |  |  | 286 |   | 
        
           | 13 | cycrow | 287 | bool CSpkFile::CheckValidReadmes () const
 | 
        
           | 1 | cycrow | 288 | {
 | 
        
           |  |  | 289 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 290 | 	{
 | 
        
           |  |  | 291 | 		C_File *file = node->Data();
 | 
        
           |  |  | 292 | 		if ( file->GetFileType() != FILETYPE_README )
 | 
        
           |  |  | 293 | 			continue;
 | 
        
           |  |  | 294 | 		if ( !file->CheckValidFilePointer() )
 | 
        
           |  |  | 295 | 			continue;
 | 
        
           |  |  | 296 | 		return true;
 | 
        
           |  |  | 297 | 	}
 | 
        
           |  |  | 298 |   | 
        
           |  |  | 299 | 	return false;
 | 
        
           |  |  | 300 | }
 | 
        
           |  |  | 301 |   | 
        
           |  |  | 302 |   | 
        
           |  |  | 303 |   | 
        
           |  |  | 304 | void CSpkFile::ClearWares()
 | 
        
           |  |  | 305 | {
 | 
        
           | 10 | cycrow | 306 | 	for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() ) {
 | 
        
           | 1 | cycrow | 307 | 		node->Data()->lText.clear(true);
 | 
        
           |  |  | 308 | 		node->DeleteData();
 | 
        
           |  |  | 309 | 	}
 | 
        
           |  |  | 310 | 	m_bChanged = true;
 | 
        
           |  |  | 311 | 	m_lWares.clear(true);
 | 
        
           |  |  | 312 | }
 | 
        
           |  |  | 313 |   | 
        
           | 10 | cycrow | 314 | SWares *CSpkFile::FindWare(const Utils::String &id) const
 | 
        
           | 1 | cycrow | 315 | {
 | 
        
           | 10 | cycrow | 316 | 	for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 317 | 		SWares *w = node->Data();
 | 
        
           |  |  | 318 | 		if ( w->sID.Compare(id) ) {
 | 
        
           | 1 | cycrow | 319 | 			return w;
 | 
        
           | 10 | cycrow | 320 | 		}
 | 
        
           | 1 | cycrow | 321 | 	}
 | 
        
           |  |  | 322 | 	return NULL;
 | 
        
           |  |  | 323 | }
 | 
        
           |  |  | 324 |   | 
        
           | 10 | cycrow | 325 | void CSpkFile::RemoveWare(const Utils::String &id )
 | 
        
           | 1 | cycrow | 326 | {
 | 
        
           | 10 | cycrow | 327 | 	for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 328 | 		SWares *w = node->Data();
 | 
        
           |  |  | 329 | 		if ( w->sID.Compare(id) ) {
 | 
        
           | 1 | cycrow | 330 | 			m_lWares.RemoveCurrent ();
 | 
        
           |  |  | 331 | 			delete w;
 | 
        
           |  |  | 332 | 			m_bChanged = true;
 | 
        
           |  |  | 333 | 			return;
 | 
        
           |  |  | 334 | 		}
 | 
        
           |  |  | 335 | 	}
 | 
        
           |  |  | 336 | }
 | 
        
           |  |  | 337 |   | 
        
           | 10 | cycrow | 338 | void CSpkFile::AddWare(SWares *ware)
 | 
        
           | 1 | cycrow | 339 | {
 | 
        
           | 10 | cycrow | 340 | 	ware->sID.remove(' ');
 | 
        
           | 1 | cycrow | 341 |   | 
        
           | 10 | cycrow | 342 | 	SWares *newware = this->FindWare(ware->sID);
 | 
        
           |  |  | 343 | 	if ( newware ) {
 | 
        
           |  |  | 344 | 		m_lWares.remove(newware);
 | 
        
           |  |  | 345 | 	}
 | 
        
           | 1 | cycrow | 346 |   | 
        
           | 10 | cycrow | 347 | 	m_lWares.push_back(ware);
 | 
        
           | 1 | cycrow | 348 | 	m_bChanged = true;
 | 
        
           |  |  | 349 | }
 | 
        
           |  |  | 350 |   | 
        
           | 10 | cycrow | 351 | void CSpkFile::AddWareText(SWares *pWare, int iLang, const Utils::String &sName, const Utils::String &sDesc)
 | 
        
           | 1 | cycrow | 352 | {
 | 
        
           |  |  | 353 | 	SWaresText *wt;
 | 
        
           | 10 | cycrow | 354 | 	for ( CListNode<SWaresText> *node = pWare->lText.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 355 | 		wt = node->Data();
 | 
        
           |  |  | 356 | 		if ( wt->iLang == iLang ) {
 | 
        
           |  |  | 357 | 			wt->sDesc = sDesc;
 | 
        
           |  |  | 358 | 			wt->sName = sName;
 | 
        
           | 1 | cycrow | 359 | 			return;
 | 
        
           |  |  | 360 | 		}
 | 
        
           |  |  | 361 | 	}
 | 
        
           |  |  | 362 |   | 
        
           |  |  | 363 | 	wt = new SWaresText;
 | 
        
           | 10 | cycrow | 364 | 	wt->iLang = iLang;
 | 
        
           |  |  | 365 | 	wt->sName = sName;
 | 
        
           |  |  | 366 | 	wt->sDesc = sDesc;
 | 
        
           | 1 | cycrow | 367 |   | 
        
           | 10 | cycrow | 368 | 	pWare->lText.push_back(wt);
 | 
        
           | 1 | cycrow | 369 | 	m_bChanged = true;
 | 
        
           |  |  | 370 | }
 | 
        
           |  |  | 371 |   | 
        
           |  |  | 372 |   | 
        
           | 10 | cycrow | 373 | void CSpkFile::ClearWareText(const Utils::String &id)
 | 
        
           | 1 | cycrow | 374 | {
 | 
        
           | 10 | cycrow | 375 | 	SWares *w = FindWare(id);
 | 
        
           |  |  | 376 | 	ClearWareText(w);
 | 
        
           | 1 | cycrow | 377 | }
 | 
        
           |  |  | 378 |   | 
        
           | 10 | cycrow | 379 | void CSpkFile::ClearWareText(SWares *w)
 | 
        
           | 1 | cycrow | 380 | {
 | 
        
           |  |  | 381 | 	if ( !w ) return;
 | 
        
           |  |  | 382 |   | 
        
           |  |  | 383 | 	w->lText.clear(true);
 | 
        
           |  |  | 384 | 	m_bChanged = true;
 | 
        
           |  |  | 385 | }
 | 
        
           |  |  | 386 |   | 
        
           | 10 | cycrow | 387 | void CSpkFile::RemoveWareText(const Utils::String &wid, int lang)
 | 
        
           | 1 | cycrow | 388 | {
 | 
        
           | 10 | cycrow | 389 | 	SWares *w = FindWare(wid);
 | 
        
           | 1 | cycrow | 390 | 	if ( w )
 | 
        
           |  |  | 391 | 	{
 | 
        
           | 10 | cycrow | 392 | 		for ( CListNode<SWaresText> *node = w->lText.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 393 | 			SWaresText *wt = node->Data();
 | 
        
           |  |  | 394 | 			if ( wt->iLang == lang ) {
 | 
        
           | 1 | cycrow | 395 | 				w->lText.RemoveCurrent();
 | 
        
           |  |  | 396 | 				m_bChanged = true;
 | 
        
           |  |  | 397 | 				delete wt;
 | 
        
           |  |  | 398 | 				break;
 | 
        
           |  |  | 399 | 			}
 | 
        
           |  |  | 400 | 		}
 | 
        
           |  |  | 401 | 	}
 | 
        
           |  |  | 402 | }
 | 
        
           |  |  | 403 |   | 
        
           | 13 | cycrow | 404 | int CSpkFile::CheckValidCustomStart () const
 | 
        
           | 1 | cycrow | 405 | {
 | 
        
           |  |  | 406 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 407 | 	{
 | 
        
           |  |  | 408 | 		C_File *file = node->Data();
 | 
        
           |  |  | 409 | 		if ( file->GetFileType() != FILETYPE_SCRIPT )
 | 
        
           |  |  | 410 | 			continue;
 | 
        
           |  |  | 411 |   | 
        
           | 14 | cycrow | 412 | 		Utils::String basename = file->GetName().GetToken ( 1, file->GetName().NumToken('.') - 1, '.' ).ToString();
 | 
        
           |  |  | 413 | 		if ( basename.right(15).Compare(".initplayership") )
 | 
        
           | 1 | cycrow | 414 | 			return 0;
 | 
        
           |  |  | 415 | 	}
 | 
        
           |  |  | 416 | 	if ( !IsAnotherMod() )
 | 
        
           |  |  | 417 | 		return 1;
 | 
        
           |  |  | 418 | 	else
 | 
        
           |  |  | 419 | 		return 2;
 | 
        
           |  |  | 420 | }
 | 
        
           |  |  | 421 |   | 
        
           |  |  | 422 | bool CSpkFile::UpdateSigned (bool updateFiles)
 | 
        
           |  |  | 423 | {
 | 
        
           |  |  | 424 | 	// check for any custom wares
 | 
        
           |  |  | 425 | 	// patch mods and custom starts are also not signed
 | 
        
           |  |  | 426 | 	if ( (!m_lWares.empty()) || (this->IsPatch()) || (this->IsCustomStart()) )
 | 
        
           |  |  | 427 | 	{
 | 
        
           |  |  | 428 | 		m_bSigned = false;
 | 
        
           |  |  | 429 | 		return false;
 | 
        
           |  |  | 430 | 	}
 | 
        
           |  |  | 431 |   | 
        
           |  |  | 432 | 	return CBaseFile::UpdateSigned(updateFiles);
 | 
        
           |  |  | 433 | }
 | 
        
           |  |  | 434 |   | 
        
           | 14 | cycrow | 435 | SSettingType *CSpkFile::AddSetting(const Utils::String &key, int type )
 | 
        
           | 1 | cycrow | 436 | {
 | 
        
           | 10 | cycrow | 437 | 	Utils::String sKey = key.removeChar('|');
 | 
        
           |  |  | 438 |   | 
        
           | 1 | cycrow | 439 | 	SSettingType *t;
 | 
        
           |  |  | 440 | 	for ( t = m_lSettings.First(); t; t = m_lSettings.Next() )
 | 
        
           |  |  | 441 | 	{
 | 
        
           | 10 | cycrow | 442 | 		if ( t->sKey.Compare(sKey) )
 | 
        
           | 1 | cycrow | 443 | 			return NULL;
 | 
        
           |  |  | 444 | 	}
 | 
        
           |  |  | 445 |   | 
        
           |  |  | 446 | 	switch ( type )
 | 
        
           |  |  | 447 | 	{
 | 
        
           |  |  | 448 | 		case SETTING_STRING:
 | 
        
           |  |  | 449 | 			t = new SSettingString;
 | 
        
           |  |  | 450 | 			break;
 | 
        
           |  |  | 451 | 		case SETTING_INTEGER:
 | 
        
           |  |  | 452 | 			t = new SSettingInteger;
 | 
        
           |  |  | 453 | 			break;
 | 
        
           |  |  | 454 | 		case SETTING_CHECK:
 | 
        
           |  |  | 455 | 			t = new SSettingCheck;
 | 
        
           |  |  | 456 | 			break;
 | 
        
           |  |  | 457 | 	}
 | 
        
           |  |  | 458 |   | 
        
           |  |  | 459 | 	if ( !t )
 | 
        
           |  |  | 460 | 		return NULL;
 | 
        
           |  |  | 461 |   | 
        
           | 10 | cycrow | 462 | 	t->sKey = sKey;
 | 
        
           | 1 | cycrow | 463 | 	t->iType = type;
 | 
        
           |  |  | 464 |   | 
        
           |  |  | 465 | 	m_lSettings.push_back ( t );
 | 
        
           |  |  | 466 | 	m_bChanged = true;
 | 
        
           |  |  | 467 |   | 
        
           |  |  | 468 | 	return t;
 | 
        
           |  |  | 469 | }
 | 
        
           |  |  | 470 |   | 
        
           | 10 | cycrow | 471 | void CSpkFile::ConvertSetting ( SSettingType *t, const Utils::String &set ) const
 | 
        
           | 1 | cycrow | 472 | {
 | 
        
           |  |  | 473 | 	if ( !t )
 | 
        
           |  |  | 474 | 		return;
 | 
        
           |  |  | 475 |   | 
        
           |  |  | 476 | 	switch ( t->iType )
 | 
        
           |  |  | 477 | 	{
 | 
        
           |  |  | 478 | 		case SETTING_STRING:
 | 
        
           |  |  | 479 | 			((SSettingString *)t)->sValue = set;
 | 
        
           |  |  | 480 | 			break;
 | 
        
           |  |  | 481 | 		case SETTING_INTEGER:
 | 
        
           | 10 | cycrow | 482 | 			((SSettingInteger *)t)->iValue = set;
 | 
        
           | 1 | cycrow | 483 | 			break;
 | 
        
           |  |  | 484 | 		case SETTING_CHECK:
 | 
        
           | 10 | cycrow | 485 | 			((SSettingCheck *)t)->bValue = set;
 | 
        
           | 1 | cycrow | 486 | 			break;
 | 
        
           |  |  | 487 | 	}
 | 
        
           |  |  | 488 | }
 | 
        
           | 10 | cycrow | 489 | Utils::String CSpkFile::GetSetting ( SSettingType *t ) const
 | 
        
           | 1 | cycrow | 490 | {
 | 
        
           |  |  | 491 | 	if ( !t )
 | 
        
           |  |  | 492 | 		return "";
 | 
        
           |  |  | 493 |   | 
        
           |  |  | 494 | 	switch ( t->iType )
 | 
        
           |  |  | 495 | 	{
 | 
        
           |  |  | 496 | 		case SETTING_STRING:
 | 
        
           |  |  | 497 | 			return ((SSettingString *)t)->sValue;
 | 
        
           |  |  | 498 | 		case SETTING_INTEGER:
 | 
        
           | 10 | cycrow | 499 | 			return Utils::String::number(((SSettingInteger *)t)->iValue);
 | 
        
           | 1 | cycrow | 500 | 		case SETTING_CHECK:
 | 
        
           |  |  | 501 | 			return (((SSettingInteger *)t)->iValue) ? "1" : "0";
 | 
        
           |  |  | 502 | 	}
 | 
        
           |  |  | 503 |   | 
        
           |  |  | 504 | 	return "";
 | 
        
           |  |  | 505 | }
 | 
        
           |  |  | 506 |   | 
        
           |  |  | 507 | void CSpkFile::ClearSettings ()
 | 
        
           |  |  | 508 | {
 | 
        
           |  |  | 509 | 	m_lSettings.clear(true);
 | 
        
           |  |  | 510 | 	m_bChanged = true;
 | 
        
           |  |  | 511 | }
 | 
        
           |  |  | 512 |   | 
        
           |  |  | 513 |   | 
        
           | 13 | cycrow | 514 | bool CSpkFile::IsMatchingMod(const Utils::String &mod) const
 | 
        
           | 1 | cycrow | 515 | {
 | 
        
           |  |  | 516 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 517 | 	{
 | 
        
           |  |  | 518 | 		C_File *file = node->Data();
 | 
        
           |  |  | 519 | 		if ( file->GetFileType() != FILETYPE_MOD )
 | 
        
           |  |  | 520 | 			continue;
 | 
        
           |  |  | 521 |   | 
        
           |  |  | 522 | 		if ( file->IsFakePatch() )
 | 
        
           |  |  | 523 | 			continue;
 | 
        
           |  |  | 524 |   | 
        
           | 10 | cycrow | 525 | 		Utils::String filename = file->GetBaseName().ToString();
 | 
        
           |  |  | 526 | 		if ( filename.Compare(mod) )
 | 
        
           | 1 | cycrow | 527 | 			return true;
 | 
        
           |  |  | 528 | 	}
 | 
        
           |  |  | 529 | 	return false;
 | 
        
           |  |  | 530 | }
 | 
        
           |  |  | 531 |   | 
        
           | 13 | cycrow | 532 | Utils::String CSpkFile::GetScriptTypeString(int lang) const
 | 
        
           | 1 | cycrow | 533 | {
 | 
        
           |  |  | 534 | 	int iType = m_iScriptType;
 | 
        
           |  |  | 535 |   | 
        
           |  |  | 536 | 	if ( this->IsLibrary() )
 | 
        
           |  |  | 537 | 		return "Library";
 | 
        
           |  |  | 538 | 	else if ( this->IsPackageUpdate() )
 | 
        
           |  |  | 539 | 		return "Package Update";
 | 
        
           |  |  | 540 | 	else if ( this->IsCustomStart() )
 | 
        
           |  |  | 541 | 		return "Custom Start";
 | 
        
           |  |  | 542 | 	else if ( this->IsPatch() )
 | 
        
           |  |  | 543 | 		return "Patch";
 | 
        
           |  |  | 544 | 	else if ( m_iScriptType == SCRIPTTYPE_CUSTOM )
 | 
        
           |  |  | 545 | 	{
 | 
        
           | 10 | cycrow | 546 | 		Utils::String type = this->GetCustomScriptType(lang);
 | 
        
           |  |  | 547 | 		if ( !type.empty() )
 | 
        
           | 1 | cycrow | 548 | 			return type;
 | 
        
           |  |  | 549 | 		iType = -1;
 | 
        
           |  |  | 550 | 	}
 | 
        
           |  |  | 551 |   | 
        
           |  |  | 552 | 	if (iType == -1)  // no script type
 | 
        
           |  |  | 553 | 	{
 | 
        
           |  |  | 554 | 		if ( this->IsFakePatch() )
 | 
        
           |  |  | 555 | 			return "Fake Patch";
 | 
        
           |  |  | 556 | 	}
 | 
        
           |  |  | 557 |   | 
        
           | 10 | cycrow | 558 | 	Utils::String sType = CSpkFile::GetScriptTypeStringStatic(m_iScriptType);
 | 
        
           | 1 | cycrow | 559 |   | 
        
           | 10 | cycrow | 560 | 	if ( sType.empty() )
 | 
        
           | 1 | cycrow | 561 | 		return "Other";
 | 
        
           |  |  | 562 |   | 
        
           |  |  | 563 | 	return sType;	
 | 
        
           |  |  | 564 | }
 | 
        
           |  |  | 565 |   | 
        
           | 10 | cycrow | 566 | int CSpkFile::ConvertScriptType(const Utils::String &sType)
 | 
        
           | 1 | cycrow | 567 | {
 | 
        
           |  |  | 568 | 	for ( int i = 0; i < SCRIPTTYPE_MAX; i++ )
 | 
        
           |  |  | 569 | 	{
 | 
        
           |  |  | 570 | 		if ( sType.Compare(CSpkFile::GetScriptTypeStringStatic(i)) )
 | 
        
           |  |  | 571 | 			return i;
 | 
        
           |  |  | 572 | 	}
 | 
        
           |  |  | 573 |   | 
        
           |  |  | 574 | 	return -1;
 | 
        
           |  |  | 575 | }
 | 
        
           |  |  | 576 |   | 
        
           | 10 | cycrow | 577 | Utils::String CSpkFile::GetScriptTypeStringStatic(int type)
 | 
        
           | 1 | cycrow | 578 | {
 | 
        
           |  |  | 579 | 	switch ( type )
 | 
        
           |  |  | 580 | 	{
 | 
        
           |  |  | 581 | 		case SCRIPTTYPE_CUSTOM:
 | 
        
           |  |  | 582 | 			return "Custom";
 | 
        
           |  |  | 583 | 		case SCRIPTTYPE_NAVIGATION:
 | 
        
           |  |  | 584 | 			return "Navigation";
 | 
        
           |  |  | 585 | 		case SCRIPTTYPE_COMBAT:
 | 
        
           |  |  | 586 | 			return "Combat";
 | 
        
           |  |  | 587 | 		case SCRIPTTYPE_MISSION:
 | 
        
           |  |  | 588 | 			return "Mission";
 | 
        
           |  |  | 589 | 		case SCRIPTTYPE_ALPLUGIN:
 | 
        
           |  |  | 590 | 			return "AL Plugin";
 | 
        
           |  |  | 591 | 		case SCRIPTTYPE_HOTKEY:
 | 
        
           |  |  | 592 | 			return "Hotkey";
 | 
        
           |  |  | 593 | 		case SCRIPTTYPE_SHIPUPGRADE:
 | 
        
           |  |  | 594 | 			return "Ship Upgrade";
 | 
        
           |  |  | 595 | 		case SCRIPTTYPE_SHIPCOMMAND:
 | 
        
           |  |  | 596 | 			return "Ship Command";
 | 
        
           |  |  | 597 | 		case SCRIPTTYPE_STATIONCOMMAND:
 | 
        
           |  |  | 598 | 			return "Station Command";
 | 
        
           |  |  | 599 | 		case SCRIPTTYPE_FLEET:
 | 
        
           |  |  | 600 | 			return "Fleet Management";
 | 
        
           |  |  | 601 | 		case SCRIPTTYPE_TRADE:
 | 
        
           |  |  | 602 | 			return "Trade";
 | 
        
           |  |  | 603 | 		case SCRIPTTYPE_PIRACY:
 | 
        
           |  |  | 604 | 			return "Piracy";
 | 
        
           |  |  | 605 | 		case SCRIPTTYPE_CHEAT:
 | 
        
           |  |  | 606 | 			return "Cheat";
 | 
        
           |  |  | 607 | 		case SCRIPTTYPE_EXTENSION:
 | 
        
           |  |  | 608 | 			return "Extension Mods";
 | 
        
           |  |  | 609 | 		case SCRIPTTYPE_REBALANCE:
 | 
        
           |  |  | 610 | 			return "Rebalance";
 | 
        
           |  |  | 611 | 		case SCRIPTTYPE_FIX:
 | 
        
           |  |  | 612 | 			return "Vanilla Fix";
 | 
        
           |  |  | 613 | 		case SCRIPTTYPE_GENERALMOD:
 | 
        
           |  |  | 614 | 			return "General Mod";
 | 
        
           |  |  | 615 | 		case SCRIPTTYPE_TOTAL:
 | 
        
           |  |  | 616 | 			return "Totel Conversion";
 | 
        
           |  |  | 617 | 		case SCRIPTTYPE_WINGCOMMAND:
 | 
        
           |  |  | 618 | 			return "Wing Command";
 | 
        
           |  |  | 619 | 	}
 | 
        
           |  |  | 620 |   | 
        
           |  |  | 621 | 	return "Other";
 | 
        
           |  |  | 622 | }
 | 
        
           |  |  | 623 |   | 
        
           | 14 | cycrow | 624 | bool CSpkFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest)
 | 
        
           | 1 | cycrow | 625 | {
 | 
        
           | 14 | cycrow | 626 | 	if ( sFirst.Compare("ScriptType") )
 | 
        
           | 1 | cycrow | 627 | 	{
 | 
        
           | 14 | cycrow | 628 | 		if ( sRest.Compare("Library") || sRest.Compare("Library Script") )
 | 
        
           | 1 | cycrow | 629 | 			this->SetLibrary();
 | 
        
           | 14 | cycrow | 630 | 		else if ( sRest.Compare("Update") || sRest.Compare("Package Update") || sRest.Compare("Mod Update") )
 | 
        
           | 1 | cycrow | 631 | 			this->SetPackageUpdate();
 | 
        
           | 14 | cycrow | 632 | 		else if ( sRest.Compare("Start") || sRest.Compare("Custom Start") )
 | 
        
           | 1 | cycrow | 633 | 			this->SetCustomStart();
 | 
        
           | 14 | cycrow | 634 | 		else if ( sRest.Compare("Patch") || sRest.Compare("Patch Mod") )
 | 
        
           | 1 | cycrow | 635 | 			this->SetPatch();
 | 
        
           |  |  | 636 | 		else
 | 
        
           |  |  | 637 | 		{
 | 
        
           | 14 | cycrow | 638 | 			int check = sRest;
 | 
        
           |  |  | 639 | 			if ( check || sRest == "0" )
 | 
        
           | 1 | cycrow | 640 | 				m_iScriptType = check;
 | 
        
           |  |  | 641 | 			else
 | 
        
           |  |  | 642 | 			{
 | 
        
           | 14 | cycrow | 643 | 				m_iScriptType = CSpkFile::ConvertScriptType(sRest);
 | 
        
           | 1 | cycrow | 644 | 				if ( m_iScriptType == -1 )
 | 
        
           | 14 | cycrow | 645 | 					m_sScriptType = sRest;
 | 
        
           | 1 | cycrow | 646 | 			}
 | 
        
           |  |  | 647 | 		}
 | 
        
           |  |  | 648 | 	}
 | 
        
           | 14 | cycrow | 649 | 	else if ( sFirst.Compare("AnotherMod") )
 | 
        
           | 1 | cycrow | 650 | 	{
 | 
        
           | 14 | cycrow | 651 | 		m_sOtherName = sRest.token("|", 1);
 | 
        
           |  |  | 652 | 		m_sOtherAuthor = sRest.tokens("|", 2);
 | 
        
           | 1 | cycrow | 653 | 	}
 | 
        
           | 14 | cycrow | 654 | 	else if ( sFirst.Compare("WareName") || sFirst.Compare("WareDesc") )
 | 
        
           | 1 | cycrow | 655 | 	{
 | 
        
           |  |  | 656 | 		// find the ware to use
 | 
        
           |  |  | 657 | 		SWares *useWare = m_pLastWare;
 | 
        
           | 14 | cycrow | 658 | 		Utils::String id = sRest.token(" ", 1);
 | 
        
           | 1 | cycrow | 659 | 		for ( CListNode<SWares> *wNode = m_lWares.Front(); wNode; wNode = wNode->next() )
 | 
        
           |  |  | 660 | 		{
 | 
        
           | 10 | cycrow | 661 | 			if ( wNode->Data()->sID.Compare(id.c_str()) )
 | 
        
           | 1 | cycrow | 662 | 			{
 | 
        
           |  |  | 663 | 				useWare = wNode->Data();
 | 
        
           |  |  | 664 | 				break;
 | 
        
           |  |  | 665 | 			}
 | 
        
           |  |  | 666 | 		}
 | 
        
           |  |  | 667 |   | 
        
           |  |  | 668 | 		// check if we have the id already
 | 
        
           |  |  | 669 | 		if ( useWare )
 | 
        
           |  |  | 670 | 		{
 | 
        
           | 14 | cycrow | 671 | 			int lang = sRest.token(" ", 2);
 | 
        
           | 1 | cycrow | 672 | 			SWaresText *wt = NULL;
 | 
        
           |  |  | 673 | 			for ( CListNode<SWaresText> *tNode = useWare->lText.Front(); tNode; tNode = tNode->next() )
 | 
        
           |  |  | 674 | 			{
 | 
        
           |  |  | 675 | 				if ( tNode->Data()->iLang == lang )
 | 
        
           |  |  | 676 | 				{
 | 
        
           |  |  | 677 | 					wt = tNode->Data();
 | 
        
           |  |  | 678 | 					break;
 | 
        
           |  |  | 679 | 				}
 | 
        
           |  |  | 680 | 			}
 | 
        
           |  |  | 681 |   | 
        
           |  |  | 682 | 			if ( !wt )
 | 
        
           |  |  | 683 | 			{
 | 
        
           |  |  | 684 | 				wt = new SWaresText;
 | 
        
           |  |  | 685 | 				wt->iLang = lang;
 | 
        
           |  |  | 686 | 				useWare->lText.push_back(wt);
 | 
        
           |  |  | 687 | 			}
 | 
        
           |  |  | 688 |   | 
        
           | 14 | cycrow | 689 | 			if ( sFirst.Compare("WareName") )
 | 
        
           |  |  | 690 | 				wt->sName = sRest.tokens(" ", 3);
 | 
        
           | 1 | cycrow | 691 | 			else
 | 
        
           | 14 | cycrow | 692 | 				wt->sDesc = sRest.tokens(" ", 3);
 | 
        
           | 1 | cycrow | 693 | 		}
 | 
        
           |  |  | 694 | 	}
 | 
        
           | 14 | cycrow | 695 | 	else if ( sFirst.left(4).Compare("Ware") )
 | 
        
           | 1 | cycrow | 696 | 	{
 | 
        
           |  |  | 697 | 		SWares *ware = new SWares;
 | 
        
           |  |  | 698 | 		ware->iTextID = -1;
 | 
        
           |  |  | 699 | 		ware->iTextPage = 0;
 | 
        
           | 14 | cycrow | 700 | 		ware->cType = sFirst[4];
 | 
        
           |  |  | 701 | 		ware->iPrice = sRest.token(" ", 2);
 | 
        
           |  |  | 702 | 		ware->iSize = sRest.token(" ", 3);
 | 
        
           |  |  | 703 | 		ware->iVolumn = sRest.token(" ", 4);
 | 
        
           |  |  | 704 | 		ware->sID = sRest.token(" ", 1);
 | 
        
           |  |  | 705 | 		ware->iNotority = sRest.token(" ", 5);
 | 
        
           |  |  | 706 | 		if ( !sRest.token(" ", 6).empty() )
 | 
        
           | 1 | cycrow | 707 | 		{
 | 
        
           | 14 | cycrow | 708 | 			ware->iTextID = sRest.token(" ", 6).token(",", 2);
 | 
        
           |  |  | 709 | 			ware->iTextPage = sRest.token(" ", 6).token(",", 1);
 | 
        
           | 1 | cycrow | 710 | 		}
 | 
        
           |  |  | 711 | 		m_lWares.push_back ( ware );
 | 
        
           |  |  | 712 | 		m_pLastWare = ware;
 | 
        
           |  |  | 713 | 	}
 | 
        
           |  |  | 714 |   | 
        
           | 14 | cycrow | 715 | 	else if ( CBaseFile::LoadPackageData(sFirst, sRest) )
 | 
        
           | 1 | cycrow | 716 | 		return true;
 | 
        
           |  |  | 717 | 	else
 | 
        
           |  |  | 718 | 		return false;
 | 
        
           |  |  | 719 |   | 
        
           |  |  | 720 | 	return true;
 | 
        
           |  |  | 721 | }
 | 
        
           |  |  | 722 |   | 
        
           |  |  | 723 | bool CSpkFile::GeneratePackagerScript(bool wildcard, CyStringList *list, bool datafile)
 | 
        
           |  |  | 724 | {
 | 
        
           |  |  | 725 | 	if ( !CBaseFile::GeneratePackagerScript(wildcard, list, datafile) )
 | 
        
           |  |  | 726 | 		return false;
 | 
        
           |  |  | 727 |   | 
        
           |  |  | 728 | 	list->PushBack("# Script Type, the type of package file, some are special types, others are just for show");
 | 
        
           |  |  | 729 | 	if ( this->IsLibrary() )
 | 
        
           |  |  | 730 | 		list->PushBack("ScriptType: Library");
 | 
        
           |  |  | 731 | 	else if ( this->IsPackageUpdate() )
 | 
        
           |  |  | 732 | 		list->PushBack("ScriptType: Package Update");
 | 
        
           |  |  | 733 | 	else if ( this->IsCustomStart() )
 | 
        
           |  |  | 734 | 		list->PushBack("ScriptType: Custom Start");
 | 
        
           |  |  | 735 | 	else if ( this->IsPatch() )
 | 
        
           |  |  | 736 | 		list->PushBack("ScriptType: Patch");
 | 
        
           |  |  | 737 | 	else
 | 
        
           |  |  | 738 | 		list->PushBack(CyString("ScriptType: ") + this->GetScriptTypeString(44));
 | 
        
           |  |  | 739 | 	list->PushBack("");
 | 
        
           |  |  | 740 |   | 
        
           |  |  | 741 | 	if ( this->IsAnotherMod() )
 | 
        
           |  |  | 742 | 	{
 | 
        
           |  |  | 743 | 		list->PushBack("# For another mod/package, this is a child package");
 | 
        
           |  |  | 744 | 		list->PushBack(CyString("AnotherMod: ") + m_sOtherName + "|" + m_sOtherAuthor);
 | 
        
           |  |  | 745 | 		list->PushBack("");
 | 
        
           |  |  | 746 | 	}
 | 
        
           |  |  | 747 |   | 
        
           |  |  | 748 | 	if ( !m_lWares.empty() )
 | 
        
           |  |  | 749 | 	{
 | 
        
           |  |  | 750 | 		list->PushBack("# Custom Wares, Ware<type>: <id> <price> <size> <volumn> <notority>");
 | 
        
           |  |  | 751 | 		for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() )
 | 
        
           |  |  | 752 | 		{
 | 
        
           |  |  | 753 | 			SWares *w = node->Data();
 | 
        
           |  |  | 754 | 			if ( w->iTextID > 0 )
 | 
        
           |  |  | 755 | 				list->PushBack(CyString("Ware") + (char)w->cType + ": " + w->sID + " " + (long)w->iPrice + " " + (long)w->iSize + " " + (long)w->iVolumn + " " + (long)w->iNotority + " " + (long)w->iTextPage + "," + (long)w->iTextID);
 | 
        
           |  |  | 756 | 			else
 | 
        
           |  |  | 757 | 				list->PushBack(CyString("Ware") + (char)w->cType + ": " + w->sID + " " + (long)w->iPrice + " " + (long)w->iSize + " " + (long)w->iVolumn + " " + (long)w->iNotority);
 | 
        
           |  |  | 758 | 			for ( CListNode<SWaresText> *wNode = w->lText.Front(); wNode; wNode = wNode->next() )
 | 
        
           |  |  | 759 | 			{
 | 
        
           |  |  | 760 | 				SWaresText *wt = wNode->Data();
 | 
        
           | 10 | cycrow | 761 | 				if ( !wt->sName.empty() )
 | 
        
           | 1 | cycrow | 762 | 					list->PushBack(CyString("WareName: ") + w->sID + " " + (long)wt->iLang + " " + wt->sName);
 | 
        
           | 10 | cycrow | 763 | 				if ( !wt->sDesc.empty() )
 | 
        
           | 1 | cycrow | 764 | 					list->PushBack(CyString("WareDesc: ") + w->sID + " " + (long)wt->iLang + " " + wt->sDesc);
 | 
        
           |  |  | 765 | 			}
 | 
        
           |  |  | 766 | 			list->PushBack("");
 | 
        
           |  |  | 767 | 		}
 | 
        
           |  |  | 768 | 	}
 | 
        
           |  |  | 769 |   | 
        
           |  |  | 770 | 	if ( !datafile )
 | 
        
           |  |  | 771 | 	{
 | 
        
           |  |  | 772 | 		if ( !CBaseFile::GeneratePackagerScriptFile(wildcard, list) )
 | 
        
           |  |  | 773 | 			return false;
 | 
        
           |  |  | 774 | 	}
 | 
        
           |  |  | 775 |   | 
        
           |  |  | 776 | 	return true;
 | 
        
           |  |  | 777 |   | 
        
           |  |  | 778 | }
 | 
        
           |  |  | 779 |   | 
        
           | 10 | cycrow | 780 | Utils::String CSpkFile::GetWareText(SWares *w, int lang)
 | 
        
           | 1 | cycrow | 781 | {
 | 
        
           |  |  | 782 | 	// return the text page if being used
 | 
        
           |  |  | 783 | 	if ( w->iTextID > 0 && w->iTextPage > 0 )
 | 
        
           | 10 | cycrow | 784 | 		return Utils::String("{") + (long)w->iTextPage + "," + (long)w->iTextID + "}";
 | 
        
           | 1 | cycrow | 785 |   | 
        
           | 10 | cycrow | 786 | 	Utils::String name;
 | 
        
           | 1 | cycrow | 787 | 	for ( CListNode<SWaresText> *wt = w->lText.Front(); wt; wt = wt->next() )
 | 
        
           |  |  | 788 | 	{
 | 
        
           | 10 | cycrow | 789 | 		if ( wt->Data()->sName.empty() )
 | 
        
           | 1 | cycrow | 790 | 			continue;
 | 
        
           |  |  | 791 | 		if ( wt->Data()->iLang == lang )
 | 
        
           |  |  | 792 | 			name = wt->Data()->sName;
 | 
        
           | 10 | cycrow | 793 | 		else if ( name.empty() && wt->Data()->iLang == 44 )
 | 
        
           | 1 | cycrow | 794 | 			name = wt->Data()->sName;
 | 
        
           | 10 | cycrow | 795 | 		else if ( name.empty() )
 | 
        
           | 1 | cycrow | 796 | 			name = wt->Data()->sName;
 | 
        
           |  |  | 797 | 	}
 | 
        
           |  |  | 798 |   | 
        
           |  |  | 799 | 	return name;
 | 
        
           |  |  | 800 | }
 | 
        
           | 10 | cycrow | 801 | Utils::String CSpkFile::GetWareDesc(SWares *w, int lang)
 | 
        
           | 1 | cycrow | 802 | {
 | 
        
           |  |  | 803 | 	// return the text page if being used
 | 
        
           |  |  | 804 | 	if ( w->iTextID > 0 && w->iTextPage > 0 )
 | 
        
           | 10 | cycrow | 805 | 		return Utils::String("{") + (long)w->iTextPage + "," + ((long)w->iTextID + 1) + "}";
 | 
        
           | 1 | cycrow | 806 |   | 
        
           | 10 | cycrow | 807 | 	Utils::String name;
 | 
        
           | 1 | cycrow | 808 | 	for ( CListNode<SWaresText> *wt = w->lText.Front(); wt; wt = wt->next() )
 | 
        
           |  |  | 809 | 	{
 | 
        
           | 10 | cycrow | 810 | 		if ( wt->Data()->sDesc.empty() )
 | 
        
           | 1 | cycrow | 811 | 			continue;
 | 
        
           |  |  | 812 |   | 
        
           |  |  | 813 | 		if ( wt->Data()->iLang == lang )
 | 
        
           |  |  | 814 | 			name = wt->Data()->sDesc;
 | 
        
           | 10 | cycrow | 815 | 		else if ( name.empty() && wt->Data()->iLang == 44 )
 | 
        
           | 1 | cycrow | 816 | 			name = wt->Data()->sDesc;
 | 
        
           | 10 | cycrow | 817 | 		else if ( name.empty() )
 | 
        
           | 1 | cycrow | 818 | 			name = wt->Data()->sDesc;
 | 
        
           |  |  | 819 | 	}
 | 
        
           |  |  | 820 |   | 
        
           |  |  | 821 | 	return name;
 | 
        
           |  |  | 822 | }
 | 
        
           |  |  | 823 |   | 
        
           | 13 | cycrow | 824 | Utils::String CSpkFile::GetCustomStartName() const
 | 
        
           | 1 | cycrow | 825 | {
 | 
        
           |  |  | 826 | 	if ( !this->IsCustomStart() )
 | 
        
           | 10 | cycrow | 827 | 		return "";
 | 
        
           | 1 | cycrow | 828 |   | 
        
           |  |  | 829 | 	// else find the custom start script
 | 
        
           |  |  | 830 | 	C_File *file = NULL;
 | 
        
           |  |  | 831 | 	for ( file = this->GetFirstFile(FILETYPE_SCRIPT); file; file = this->GetNextFile(file) )
 | 
        
           |  |  | 832 | 	{
 | 
        
           |  |  | 833 | 		if ( file->GetFilename().IsIn("initplayership")	&& file->GetFilename().GetToken(".", 1, 1).Compare("galaxy") )
 | 
        
           |  |  | 834 | 			break;
 | 
        
           |  |  | 835 | 	}
 | 
        
           |  |  | 836 |   | 
        
           |  |  | 837 | 	if ( !file )
 | 
        
           | 10 | cycrow | 838 | 		return "";
 | 
        
           | 1 | cycrow | 839 |   | 
        
           | 10 | cycrow | 840 | 	return file->GetFilename().GetToken(".", 2, 2).ToString();
 | 
        
           | 1 | cycrow | 841 | }
 | 
        
           |  |  | 842 |   | 
        
           |  |  | 843 | void CSpkFile::MergePackage(CBaseFile *base)
 | 
        
           |  |  | 844 | {
 | 
        
           |  |  | 845 | 	// update version information
 | 
        
           |  |  | 846 | 	m_sVersion = base->GetVersion();
 | 
        
           |  |  | 847 | 	m_sCreationDate = base->GetCreationDate();
 | 
        
           |  |  | 848 | 	m_iPluginType = base->GetPluginType();
 | 
        
           |  |  | 849 |   | 
        
           |  |  | 850 | 	// update possible changes
 | 
        
           |  |  | 851 | 	if ( base->GetType() == TYPE_SPK )
 | 
        
           |  |  | 852 | 	{
 | 
        
           |  |  | 853 | 		CSpkFile *spk = (CSpkFile *)base;
 | 
        
           |  |  | 854 | 		m_bForceProfile = spk->IsForceProfile();
 | 
        
           |  |  | 855 |   | 
        
           |  |  | 856 | 		// add any new wares
 | 
        
           |  |  | 857 | 		if ( spk->AnyWares() )
 | 
        
           |  |  | 858 | 		{
 | 
        
           |  |  | 859 | 			for ( CListNode<SWares> *node = spk->GetWaresList()->Front(); node; node = node->next() )
 | 
        
           |  |  | 860 | 				this->AddWare(node->Data());
 | 
        
           |  |  | 861 | 			spk->GetWaresList()->clear(); // remove wares so they aren't deleted
 | 
        
           |  |  | 862 | 		}
 | 
        
           |  |  | 863 |   | 
        
           |  |  | 864 | 		// add any settings
 | 
        
           |  |  | 865 | 		if ( spk->AnySettings() )
 | 
        
           |  |  | 866 | 		{
 | 
        
           |  |  | 867 | 			for ( CListNode<SSettingType> *node = spk->GetSettingsList()->Front(); node; node = node->next() )
 | 
        
           |  |  | 868 | 				this->AddSetting(node->Data()->sKey, node->Data()->iType);
 | 
        
           |  |  | 869 | 		}
 | 
        
           |  |  | 870 |   | 
        
           | 10 | cycrow | 871 | 		if ( !spk->GetOtherName().empty() )
 | 
        
           | 1 | cycrow | 872 | 		{
 | 
        
           |  |  | 873 | 			m_sOtherName = spk->GetOtherName();
 | 
        
           |  |  | 874 | 			m_sOtherAuthor = spk->GetOtherAuthor();
 | 
        
           |  |  | 875 | 		}
 | 
        
           |  |  | 876 | 	}
 | 
        
           |  |  | 877 |   | 
        
           |  |  | 878 | 	// copy settings from base class
 | 
        
           |  |  | 879 | 	m_iGameChanging = base->GetGameChanging();
 | 
        
           |  |  | 880 | 	m_iRecommended = base->GetRecommended();
 | 
        
           |  |  | 881 | 	m_iEaseOfUse = base->GetEaseOfUse();
 | 
        
           |  |  | 882 |   | 
        
           |  |  | 883 | 	for ( CListNode<SGameCompat> *gNode = base->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
 | 
        
           |  |  | 884 | 		if ( !gNode->Data()->sVersion.Empty() )
 | 
        
           |  |  | 885 | 			this->AddGameCompatability(gNode->Data()->iGame, gNode->Data()->sVersion);
 | 
        
           |  |  | 886 | 		else
 | 
        
           |  |  | 887 | 			this->AddGameCompatability(gNode->Data()->iGame, CyString::Number(gNode->Data()->iVersion));
 | 
        
           |  |  | 888 | 	}
 | 
        
           |  |  | 889 |   | 
        
           |  |  | 890 | 	if ( !base->GetWebAddress().Empty() )
 | 
        
           |  |  | 891 | 		m_sWebAddress = base->GetWebAddress();
 | 
        
           |  |  | 892 | 	if ( !base->GetWebSite().Empty() )
 | 
        
           |  |  | 893 | 		m_sWebSite = base->GetWebSite();
 | 
        
           |  |  | 894 | 	if ( !base->GetEmail().Empty() )
 | 
        
           |  |  | 895 | 		m_sEmail = base->GetEmail();
 | 
        
           |  |  | 896 | 	if ( !base->GetForumLink().Empty() )
 | 
        
           |  |  | 897 | 		m_sForumLink = base->GetForumLink();
 | 
        
           |  |  | 898 |   | 
        
           |  |  | 899 | 	m_sDescription = base->GetDescription();
 | 
        
           |  |  | 900 |   | 
        
           |  |  | 901 | 	// copy over needed librarys
 | 
        
           |  |  | 902 | 	for ( CListNode<SNeededLibrary> *lNode = base->GetNeededLibraries()->Front(); lNode; lNode = lNode->next() )
 | 
        
           |  |  | 903 | 		this->AddNeededLibrary(lNode->Data()->sName, lNode->Data()->sAuthor, lNode->Data()->sMinVersion);
 | 
        
           |  |  | 904 |   | 
        
           |  |  | 905 | 	// web mirror address, add any new ones
 | 
        
           |  |  | 906 | 	for ( SStringList *str = base->GetWebMirrors()->Head(); str; str = str->next )
 | 
        
           |  |  | 907 | 		this->AddWebMirror(str->str);
 | 
        
           |  |  | 908 |   | 
        
           |  |  | 909 | 	// copy over any install text
 | 
        
           |  |  | 910 | 	for ( CListNode<SInstallText> *iNode = base->GetInstallTextList()->Front(); iNode; iNode = iNode->next() )
 | 
        
           |  |  | 911 | 	{
 | 
        
           |  |  | 912 | 		if ( !iNode->Data()->sAfter.Empty() )
 | 
        
           |  |  | 913 | 			this->AddInstallAfterText(iNode->Data()->iLanguage, iNode->Data()->sAfter);
 | 
        
           |  |  | 914 | 		if ( !iNode->Data()->sBefore.Empty() )
 | 
        
           |  |  | 915 | 			this->AddInstallBeforeText(iNode->Data()->iLanguage, iNode->Data()->sBefore);
 | 
        
           |  |  | 916 | 	}
 | 
        
           |  |  | 917 |   | 
        
           |  |  | 918 | 	for ( CListNode<SInstallText> *iNode = base->GetUninstallTextList()->Front(); iNode; iNode = iNode->next() )
 | 
        
           |  |  | 919 | 	{
 | 
        
           |  |  | 920 | 		if ( !iNode->Data()->sAfter.Empty() )
 | 
        
           |  |  | 921 | 			this->AddUninstallAfterText(iNode->Data()->iLanguage, iNode->Data()->sAfter);
 | 
        
           |  |  | 922 | 		if ( !iNode->Data()->sBefore.Empty() )
 | 
        
           |  |  | 923 | 			this->AddUninstallBeforeText(iNode->Data()->iLanguage, iNode->Data()->sBefore);
 | 
        
           |  |  | 924 | 	}
 | 
        
           |  |  | 925 |   | 
        
           |  |  | 926 | 	// copy over package names
 | 
        
           |  |  | 927 | 	for ( CListNode<SNames> *nNode = base->GetNamesList()->Front(); nNode; nNode = nNode->next() )
 | 
        
           |  |  | 928 | 		this->AddLanguageName(nNode->Data()->iLanguage, nNode->Data()->sName);
 | 
        
           |  |  | 929 |   | 
        
           |  |  | 930 | 	// finally do all the files
 | 
        
           |  |  | 931 | 	for ( CListNode<C_File> *node = base->GetFileList()->Front(); node; node = node->next() )
 | 
        
           |  |  | 932 | 	{
 | 
        
           |  |  | 933 | 		C_File *f = node->Data();
 | 
        
           |  |  | 934 | 		// if it exists, remove the old
 | 
        
           |  |  | 935 | 		for ( CListNode<C_File> *thisNode = m_lFiles.Front(); thisNode; thisNode = thisNode->next() )
 | 
        
           |  |  | 936 | 		{
 | 
        
           |  |  | 937 | 			if ( thisNode->Data()->GetFileType() == f->GetFileType() && thisNode->Data()->GetFilename().Compare(f->GetFilename()) && thisNode->Data()->GetDir().Compare(f->GetDir()) )
 | 
        
           |  |  | 938 | 			{
 | 
        
           |  |  | 939 | 				m_lFiles.remove(thisNode);
 | 
        
           |  |  | 940 | 				break;
 | 
        
           |  |  | 941 | 			}
 | 
        
           |  |  | 942 | 		}
 | 
        
           |  |  | 943 |   | 
        
           |  |  | 944 | 		m_lFiles.push_back(f);
 | 
        
           |  |  | 945 | 	}
 | 
        
           |  |  | 946 |   | 
        
           |  |  | 947 | 	// clear the files so we dont delete them later
 | 
        
           |  |  | 948 | 	base->GetFileList()->clear();
 | 
        
           |  |  | 949 | }
 | 
        
           | 7 | cycrow | 950 |   | 
        
           | 8 | cycrow | 951 | unsigned char *CSpkFile::_convert_uncompressFile(const Utils::String &sOldFilename, int *pLen)
 | 
        
           | 7 | cycrow | 952 | {
 | 
        
           | 10 | cycrow | 953 | 	// firstcheck if the file exists
 | 
        
           |  |  | 954 | 	FILE *id = fopen(sOldFilename.c_str(), "rb" );
 | 
        
           |  |  | 955 | 	if ( !id ) {
 | 
        
           |  |  | 956 | 		CLog::logf(CLog::Log_IO, "Unable to open file: %s", sOldFilename.c_str());
 | 
        
           |  |  | 957 | 		return false;
 | 
        
           |  |  | 958 | 	}
 | 
        
           | 7 | cycrow | 959 |   | 
        
           | 10 | cycrow | 960 | 	// read the first 3 charaters to check if its using the original "HiP" compression
 | 
        
           | 14 | cycrow | 961 | 	Utils::String check((char)fgetc(id));
 | 
        
           | 10 | cycrow | 962 | 	check += (char)fgetc ( id );
 | 
        
           |  |  | 963 | 	check += (char)fgetc ( id );
 | 
        
           | 7 | cycrow | 964 |   | 
        
           | 14 | cycrow | 965 | 	Utils::String removeFile;
 | 
        
           | 7 | cycrow | 966 |   | 
        
           | 10 | cycrow | 967 | 	unsigned char *uncomprData = NULL;
 | 
        
           |  |  | 968 | 	unsigned char *data = NULL;
 | 
        
           |  |  | 969 | 	long len = 0, newlen = 0;
 | 
        
           |  |  | 970 |   | 
        
           |  |  | 971 | 	if ( check == "HiP" ) {
 | 
        
           |  |  | 972 | 		fclose ( id );
 | 
        
           |  |  | 973 | 		bool opened = false;
 | 
        
           |  |  | 974 | 		if ( DecompressFile ( (char *)sOldFilename.c_str(), "uncompr.tmp" ) ) {
 | 
        
           |  |  | 975 | 			removeFile = "uncompr.tmp";
 | 
        
           |  |  | 976 | 			id = fopen ( "uncompr.tmp", "r" );
 | 
        
           |  |  | 977 | 			if ( id )
 | 
        
           |  |  | 978 | 				opened = true;
 | 
        
           |  |  | 979 | 		}
 | 
        
           |  |  | 980 |   | 
        
           |  |  | 981 | 		if ( !opened ) {
 | 
        
           |  |  | 982 | 			CLog::log(CLog::Log_IO, "Unable to uncompress file, exiting...");
 | 
        
           |  |  | 983 | 			return false;
 | 
        
           |  |  | 984 | 		}
 | 
        
           |  |  | 985 |   | 
        
           |  |  | 986 | 		CLog::log(CLog::Log_IO, "* Reading file into memory...");
 | 
        
           |  |  | 987 | 		// get file length
 | 
        
           |  |  | 988 | 		fseek ( id, 0, SEEK_END );
 | 
        
           |  |  | 989 | 		len = ftell ( id );
 | 
        
           |  |  | 990 |   | 
        
           |  |  | 991 | 		// move back to beginning
 | 
        
           |  |  | 992 | 		fseek ( id, 0, SEEK_SET );
 | 
        
           |  |  | 993 |   | 
        
           |  |  | 994 | 		// read the data from file into memory
 | 
        
           |  |  | 995 | 		uncomprData = new unsigned char[len + 1];
 | 
        
           |  |  | 996 | 		fread ( uncomprData, sizeof(unsigned char), len, id );
 | 
        
           |  |  | 997 |   | 
        
           |  |  | 998 | 		newlen = len;
 | 
        
           |  |  | 999 | 	}
 | 
        
           |  |  | 1000 | 	else
 | 
        
           |  |  | 1001 | 	{
 | 
        
           |  |  | 1002 | 		CLog::log(CLog::Log_IO, "* Reading file into memory...");
 | 
        
           |  |  | 1003 | 		// get file length
 | 
        
           |  |  | 1004 | 		fseek ( id, 0, SEEK_END );
 | 
        
           |  |  | 1005 | 		len = ftell ( id );
 | 
        
           |  |  | 1006 |   | 
        
           |  |  | 1007 | 		// move back to beginning
 | 
        
           |  |  | 1008 | 		fseek ( id, 0, SEEK_SET );
 | 
        
           |  |  | 1009 |   | 
        
           |  |  | 1010 | 		// read the data from file into memory
 | 
        
           |  |  | 1011 | 		data = new unsigned char[len + 1];
 | 
        
           |  |  | 1012 | 		fread ( data, sizeof(unsigned char), len, id );
 | 
        
           |  |  | 1013 |   | 
        
           |  |  | 1014 | 		// uncompress the file (currently only 7zip compression)
 | 
        
           |  |  | 1015 | 		CLog::log(CLog::Log_IO, "* Uncompressing file...");
 | 
        
           |  |  | 1016 | 		newlen = len;
 | 
        
           |  |  | 1017 | 	#ifdef _INCLUDE7ZIP
 | 
        
           |  |  | 1018 | 		uncomprData = LZMADecodeData ( data, len, newlen, progress );
 | 
        
           |  |  | 1019 | 	#else
 | 
        
           |  |  | 1020 | 		uncomprData = LZMADecode_C ( (unsigned char *)data, len, (size_t*)&newlen, NULL );
 | 
        
           |  |  | 1021 | 	#endif
 | 
        
           |  |  | 1022 | 	}
 | 
        
           |  |  | 1023 |   | 
        
           |  |  | 1024 | 	*pLen = newlen;
 | 
        
           |  |  | 1025 |   | 
        
           | 14 | cycrow | 1026 | 	if ( !removeFile.empty() ) {
 | 
        
           | 10 | cycrow | 1027 | 		CFileIO(removeFile).Remove();
 | 
        
           |  |  | 1028 | 	}
 | 
        
           |  |  | 1029 |   | 
        
           | 7 | cycrow | 1030 | 	return uncomprData;
 | 
        
           |  |  | 1031 | }
 | 
        
           |  |  | 1032 |   | 
        
           | 8 | cycrow | 1033 | Utils::String CSpkFile::_convert_fileEndString(const Utils::String &sFile)
 | 
        
           | 7 | cycrow | 1034 | {
 | 
        
           | 10 | cycrow | 1035 | 	if ( sFile.Compare("Text") )
 | 
        
           |  |  | 1036 | 		return "-- End of Script --";
 | 
        
           |  |  | 1037 | 	else if ( sFile.Compare("Uninstall") )
 | 
        
           |  |  | 1038 | 		return "-- End of Uninstall --";
 | 
        
           |  |  | 1039 | 	else if ( sFile.Compare("Readme") )
 | 
        
           |  |  | 1040 | 		return "-- End of Readme --";
 | 
        
           |  |  | 1041 | 	else if ( sFile.Compare("Map") )
 | 
        
           |  |  | 1042 | 		return "-- End of Map --";
 | 
        
           |  |  | 1043 | 	else if ( sFile.Compare("Mod") || sFile.Compare("Extra") || sFile.Compare("Screen") || sFile.Compare("Sound") )
 | 
        
           |  |  | 1044 | 		return "";
 | 
        
           |  |  | 1045 | 	return "-- End of Script --";
 | 
        
           | 7 | cycrow | 1046 | }
 | 
        
           |  |  | 1047 |   | 
        
           | 8 | cycrow | 1048 | int CSpkFile::_convert_fileType(const Utils::String &sFile)
 | 
        
           | 7 | cycrow | 1049 | {
 | 
        
           | 10 | cycrow | 1050 | 	if ( sFile.Compare("Text") )
 | 
        
           |  |  | 1051 | 		return FILETYPE_TEXT;
 | 
        
           |  |  | 1052 | 	else if ( sFile.Compare("Uninstall") )
 | 
        
           |  |  | 1053 | 		return FILETYPE_UNINSTALL;
 | 
        
           |  |  | 1054 | 	else if ( sFile.Compare("Readme") )
 | 
        
           |  |  | 1055 | 		return FILETYPE_README;
 | 
        
           |  |  | 1056 | 	else if ( sFile.Compare("Map") )
 | 
        
           |  |  | 1057 | 		return FILETYPE_MAP;
 | 
        
           |  |  | 1058 | 	else if ( sFile.Compare("Mod") )
 | 
        
           |  |  | 1059 | 		return FILETYPE_MOD;
 | 
        
           |  |  | 1060 | 	else if ( sFile.Compare("Extra") )
 | 
        
           |  |  | 1061 | 		return FILETYPE_EXTRA;
 | 
        
           |  |  | 1062 | 	else if ( sFile.Compare("Screen") )
 | 
        
           |  |  | 1063 | 		return FILETYPE_SCREEN;
 | 
        
           |  |  | 1064 | 	else if ( sFile.Compare("Sound") )
 | 
        
           |  |  | 1065 | 		return FILETYPE_SOUND;
 | 
        
           |  |  | 1066 |   | 
        
           |  |  | 1067 | 	return FILETYPE_SCRIPT;
 | 
        
           | 7 | cycrow | 1068 | }
 | 
        
           |  |  | 1069 |   | 
        
           | 10 | cycrow | 1070 | void CSpkFile::_convert_parse(const Utils::String &sCmd, const Utils::String &sRest)
 | 
        
           | 7 | cycrow | 1071 | {
 | 
        
           | 10 | cycrow | 1072 | 	if ( sCmd == "Name:" )
 | 
        
           |  |  | 1073 | 	{
 | 
        
           |  |  | 1074 | 		this->SetName ( sRest );
 | 
        
           |  |  | 1075 | 		CLog::logf(CLog::Log_EditPackage, "\tScript Name: %s", sRest.c_str() );
 | 
        
           |  |  | 1076 | 	}
 | 
        
           |  |  | 1077 | 	else if ( sCmd == "Author:" )
 | 
        
           |  |  | 1078 | 	{
 | 
        
           |  |  | 1079 | 		this->SetAuthor ( sRest );
 | 
        
           |  |  | 1080 | 		CLog::logf(CLog::Log_EditPackage, "\tScript Author: %s", sRest.c_str() );
 | 
        
           |  |  | 1081 | 	}
 | 
        
           |  |  | 1082 | 	else if ( sCmd == "CustomStart" )
 | 
        
           |  |  | 1083 | 	{
 | 
        
           |  |  | 1084 | 		this->SetCustomStart();
 | 
        
           |  |  | 1085 | 		CLog::logf(CLog::Log_EditPackage, "\tPackage is a custom start!!" );
 | 
        
           |  |  | 1086 | 	}
 | 
        
           |  |  | 1087 | 	else if ( sCmd == "AnotherMod:" )
 | 
        
           |  |  | 1088 | 	{
 | 
        
           |  |  | 1089 | 		this->SetAnotherMod(sRest.token("|", 1), sRest.tokens("|", 2));
 | 
        
           |  |  | 1090 | 		CLog::logf(CLog::Log_EditPackage, "\tFor another Mod, Name: %s, Author: %s", this->GetOtherName().c_str(), this->GetOtherAuthor().c_str() );
 | 
        
           |  |  | 1091 | 	}
 | 
        
           |  |  | 1092 | 	else if ( sCmd == "PATCH" )
 | 
        
           |  |  | 1093 | 	{
 | 
        
           |  |  | 1094 | 		this->SetPatch();
 | 
        
           |  |  | 1095 | 		CLog::logf(CLog::Log_EditPackage, "\tPackage is a Patch Mod!!" );
 | 
        
           |  |  | 1096 | 	}
 | 
        
           |  |  | 1097 | 	else if ( sCmd == "Version:" )
 | 
        
           |  |  | 1098 | 	{
 | 
        
           |  |  | 1099 | 		this->SetVersion ( sRest );
 | 
        
           |  |  | 1100 | 		CLog::logf(CLog::Log_EditPackage, "\tScript Version: %s", sRest.c_str() );
 | 
        
           |  |  | 1101 | 	}
 | 
        
           |  |  | 1102 | 	else if ( sCmd == "Date:" )
 | 
        
           |  |  | 1103 | 	{
 | 
        
           |  |  | 1104 | 		this->SetCreationDate ( sRest );
 | 
        
           |  |  | 1105 | 		CLog::logf(CLog::Log_EditPackage, "\tScript Creation Date: %s", sRest.c_str() );
 | 
        
           |  |  | 1106 | 	}
 | 
        
           |  |  | 1107 | 	else if ( sCmd == "Desc:" )
 | 
        
           |  |  | 1108 | 	{
 | 
        
           |  |  | 1109 | 		this->SetDescription(sRest.findReplace("<br>", "\n") );
 | 
        
           |  |  | 1110 | 		CLog::logf(CLog::Log_EditPackage, "\tScript Description: %s", this->GetDescription().c_str() );
 | 
        
           |  |  | 1111 | 	}
 | 
        
           |  |  | 1112 | 	else if ( sCmd == "WebAddress:" )
 | 
        
           |  |  | 1113 | 	{
 | 
        
           |  |  | 1114 | 		this->SetWebAddress ( sRest );
 | 
        
           |  |  | 1115 | 		CLog::logf(CLog::Log_EditPackage, "\tWeb Address: %s", sRest.c_str() );
 | 
        
           |  |  | 1116 | 	}
 | 
        
           |  |  | 1117 | 	else if ( sCmd == "WebMirror1:" )
 | 
        
           |  |  | 1118 | 	{
 | 
        
           |  |  | 1119 | 		this->AddWebMirror(sRest);
 | 
        
           |  |  | 1120 | 		CLog::logf(CLog::Log_EditPackage, "\tWeb Mirror Address: %s", sRest.c_str() );
 | 
        
           |  |  | 1121 | 	}
 | 
        
           |  |  | 1122 | 	else if ( sCmd == "WebMirror2:" )
 | 
        
           |  |  | 1123 | 	{
 | 
        
           |  |  | 1124 | 		this->AddWebMirror(sRest);
 | 
        
           |  |  | 1125 | 		CLog::logf(CLog::Log_EditPackage, "\tWeb Mirror Address: %s", sRest.c_str() );
 | 
        
           |  |  | 1126 | 	}
 | 
        
           |  |  | 1127 |   | 
        
           |  |  | 1128 | 	else if ( sCmd == "ScriptType:" )
 | 
        
           |  |  | 1129 | 		this->SetScriptType (sRest);
 | 
        
           |  |  | 1130 | 	else if ( sCmd == "WebSite:" )
 | 
        
           |  |  | 1131 | 	{
 | 
        
           |  |  | 1132 | 		this->SetWebSite ( sRest );
 | 
        
           |  |  | 1133 | 		CLog::logf(CLog::Log_EditPackage, "\tWeb Site: %s", sRest.c_str() );
 | 
        
           |  |  | 1134 | 	}
 | 
        
           |  |  | 1135 | 	else if ( sCmd == "Email:" )
 | 
        
           |  |  | 1136 | 	{
 | 
        
           |  |  | 1137 | 		this->SetEmail ( sRest );
 | 
        
           |  |  | 1138 | 		CLog::logf(CLog::Log_EditPackage, "\tAuthor Email Address: %s", sRest.c_str() );
 | 
        
           |  |  | 1139 | 	}
 | 
        
           |  |  | 1140 | 	else if ( sCmd == "GameVersion:" )
 | 
        
           |  |  | 1141 | 	{
 | 
        
           |  |  | 1142 | 		//TODO: fix this for new game version
 | 
        
           |  |  | 1143 | 		/*
 | 
        
           |  |  | 1144 | 		int version = sRest.ToInt();
 | 
        
           |  |  | 1145 | 		if ( version == 0 )
 | 
        
           |  |  | 1146 | 			this->SetGameVersion ( 1 );
 | 
        
           |  |  | 1147 | 		else if (version == 1 )
 | 
        
           |  |  | 1148 | 			this->SetGameVersion ( 0 );
 | 
        
           |  |  | 1149 | 		else
 | 
        
           |  |  | 1150 | 			this->SetGameVersion ( version );
 | 
        
           |  |  | 1151 | 		CLog::logf(CLog::Log_EditPackage, "\tGame Version: %d", this->GetGameVersion () );
 | 
        
           |  |  | 1152 | 		*/
 | 
        
           |  |  | 1153 | 	}
 | 
        
           |  |  | 1154 |   | 
        
           |  |  | 1155 | 	else if ( sCmd == "Ware:" )
 | 
        
           |  |  | 1156 | 	{
 | 
        
           |  |  | 1157 | 		this->AddWare ( sRest );
 | 
        
           |  |  | 1158 | 		CLog::logf(CLog::Log_EditPackage, "\tAdding Custom Ware" );
 | 
        
           |  |  | 1159 | 	}
 | 
        
           |  |  | 1160 | 	else if ( sCmd == "WareText:" )
 | 
        
           |  |  | 1161 | 		this->AddWareText ( sRest );
 | 
        
           |  |  | 1162 | 	else if ( sCmd == "UninstallAfter:" )
 | 
        
           |  |  | 1163 | 		this->AddUninstallAfterText(sRest.token(" ", 1).toLong(), sRest.tokens(" ", 2));
 | 
        
           |  |  | 1164 | 	else if ( sCmd == "UninstallBefore:" )
 | 
        
           |  |  | 1165 | 		this->AddUninstallBeforeText(sRest.token(" ", 1).toLong(), sRest.tokens(" ", 2));
 | 
        
           |  |  | 1166 | 	else if ( sCmd == "InstallAfter:" )
 | 
        
           |  |  | 1167 | 		this->AddInstallAfterText(sRest.token(" ", 1).toLong(), sRest.tokens(" ", 2));
 | 
        
           |  |  | 1168 | 	else if ( sCmd == "InstallBefore:" )
 | 
        
           |  |  | 1169 | 		this->AddInstallBeforeText(sRest.token(" ", 1).toLong(), sRest.tokens(" ", 2));
 | 
        
           |  |  | 1170 | 	else if ( sCmd == "ScriptName:" )
 | 
        
           |  |  | 1171 | 	{
 | 
        
           |  |  | 1172 | 		Utils::String lang = sRest.token(":", 1);
 | 
        
           |  |  | 1173 | 		Utils::String name = sRest.tokens(":", 2);
 | 
        
           |  |  | 1174 | 		this->AddLanguageName(lang.toLong(), name);
 | 
        
           |  |  | 1175 | 		CLog::logf(CLog::Log_EditPackage, "\tScript Name Language (%s) %s", lang.c_str(), name.c_str() );
 | 
        
           |  |  | 1176 | 	}
 | 
        
           | 7 | cycrow | 1177 | }
 | 
        
           |  |  | 1178 |   | 
        
           | 8 | cycrow | 1179 | Utils::String CSpkFile::_convert_parseFilename(const Utils::String &sRest, float fVersion, Utils::String *pDir)
 | 
        
           | 7 | cycrow | 1180 | {
 | 
        
           | 8 | cycrow | 1181 | 	Utils::String sFilename;
 | 
        
           | 7 | cycrow | 1182 |   | 
        
           | 10 | cycrow | 1183 | 	if ( fVersion >= 3.00f )
 | 
        
           |  |  | 1184 | 		sFilename = sRest.tokens(" ", 3);
 | 
        
           |  |  | 1185 | 	else if ( fVersion >= 2.00f )
 | 
        
           |  |  | 1186 | 		sFilename = sRest.tokens(" ", 2);
 | 
        
           |  |  | 1187 | 	else
 | 
        
           |  |  | 1188 | 		sFilename = sRest;
 | 
        
           |  |  | 1189 |   | 
        
           |  |  | 1190 | 	if ( sFilename.isin("<br>") ) {
 | 
        
           |  |  | 1191 | 		sFilename = sFilename.findReplace("<br>", "|");
 | 
        
           |  |  | 1192 | 		if ( sFilename[0] == '|' ) {
 | 
        
           |  |  | 1193 | 			sFilename = sFilename.token("|", 1);
 | 
        
           |  |  | 1194 | 		}
 | 
        
           |  |  | 1195 | 		else {
 | 
        
           |  |  | 1196 | 			*pDir = sFilename.token("|", 1);
 | 
        
           |  |  | 1197 | 			sFilename = sFilename.tokens("|", 2);
 | 
        
           |  |  | 1198 | 		}
 | 
        
           |  |  | 1199 | 	}
 | 
        
           |  |  | 1200 |   | 
        
           |  |  | 1201 | 	return sFilename;
 | 
        
           | 7 | cycrow | 1202 | }
 | 
        
           |  |  | 1203 |   | 
        
           | 10 | cycrow | 1204 | unsigned char *CSpkFile::_convert_parseFile(const Utils::String &sCmd, const Utils::String &sRest, float fVersion, unsigned char *d)
 | 
        
           | 7 | cycrow | 1205 | {
 | 
        
           | 10 | cycrow | 1206 | 	bool bShared = (sCmd.left(9) == "$$$Shared") ? true : false;
 | 
        
           |  |  | 1207 | 	Utils::String sFile = sCmd.right(-3).left(-1);
 | 
        
           |  |  | 1208 | 	Utils::String sEnd = this->_convert_fileEndString(sFile);
 | 
        
           |  |  | 1209 | 	int iType = this->_convert_fileType(sFile);
 | 
        
           |  |  | 1210 |   | 
        
           |  |  | 1211 | 	// convert the filename and directory
 | 
        
           |  |  | 1212 | 	Utils::String dir, filename = _convert_parseFilename(sRest, fVersion, &dir);
 | 
        
           |  |  | 1213 |   | 
        
           |  |  | 1214 | 	// get the size and time
 | 
        
           |  |  | 1215 | 	long time = 0, size = 0;
 | 
        
           |  |  | 1216 | 	if ( fVersion >= 2.00f ) time = sRest.token(" ", 1).toLong();
 | 
        
           |  |  | 1217 | 	if ( fVersion >= 3.00f ) size = sRest.token(" ", 2).toLong();
 | 
        
           |  |  | 1218 | 	bool binaryRead = (CFileIO(filename).CheckFileExtension("PCK")) ? true : false;
 | 
        
           |  |  | 1219 | 	if ( sEnd.empty() ) binaryRead = true;
 | 
        
           |  |  | 1220 |   | 
        
           |  |  | 1221 | 	C_File *file = new C_File ();
 | 
        
           |  |  | 1222 |   | 
        
           |  |  | 1223 | 	if ( bShared )	CLog::logf(CLog::Log_File, "\tFound %s File (Shared): %s, Reading...", sFile.c_str(), filename.c_str() );
 | 
        
           |  |  | 1224 | 	else			CLog::logf(CLog::Log_File, "\tFound %s File: %s, Reading...", sFile.c_str(), filename.c_str() );
 | 
        
           |  |  | 1225 |   | 
        
           |  |  | 1226 | 	// read the data
 | 
        
           |  |  | 1227 | 	if ( binaryRead )
 | 
        
           |  |  | 1228 | 	{
 | 
        
           |  |  | 1229 | 		file->ReadFromData ( (char *)d, size );
 | 
        
           |  |  | 1230 | 		d += size;
 | 
        
           |  |  | 1231 | 	}
 | 
        
           |  |  | 1232 | 	else
 | 
        
           |  |  | 1233 | 	{
 | 
        
           | 14 | cycrow | 1234 | 		Utils::String readData;
 | 
        
           | 10 | cycrow | 1235 | 		d = LineByLineRead ( d, sEnd, &readData );
 | 
        
           | 14 | cycrow | 1236 | 		file->ReadFromData ( (char *)readData.c_str(), (long)readData.length() );
 | 
        
           | 10 | cycrow | 1237 | 	}
 | 
        
           |  |  | 1238 |   | 
        
           |  |  | 1239 | 	// setup the file
 | 
        
           |  |  | 1240 | 	file->SetName ( filename );
 | 
        
           |  |  | 1241 | 	file->SetFileType ( iType );
 | 
        
           |  |  | 1242 | 	file->SetShared ( bShared );
 | 
        
           |  |  | 1243 | 	file->SetCreationTime ( time );
 | 
        
           |  |  | 1244 | 	if ( !dir.empty() )
 | 
        
           |  |  | 1245 | 		file->SetDir ( dir );
 | 
        
           |  |  | 1246 |   | 
        
           |  |  | 1247 | 	this->AddFile ( file );
 | 
        
           |  |  | 1248 |   | 
        
           |  |  | 1249 | 	CLog::logf(CLog::Log_File, "Size: %s", file->GetDataSizeString().c_str() );
 | 
        
           |  |  | 1250 |   | 
        
           |  |  | 1251 | 	return d;
 | 
        
           | 7 | cycrow | 1252 | }
 | 
        
           |  |  | 1253 |   | 
        
           | 9 | cycrow | 1254 | CSpkFile *CSpkFile::convertFromOld(const Utils::String &sOldFilename)
 | 
        
           |  |  | 1255 | {
 | 
        
           |  |  | 1256 | 	// check if the old file is actually in an old format
 | 
        
           | 10 | cycrow | 1257 | 	int ret = CBaseFile::CheckFile ( sOldFilename );
 | 
        
           |  |  | 1258 | 	if ( ret != SPKFILE_INVALID && ret != SPKFILE_OLD ) {
 | 
        
           |  |  | 1259 | 		return NULL;
 | 
        
           |  |  | 1260 |  	}
 | 
        
           |  |  | 1261 |   | 
        
           |  |  | 1262 | 	CSpkFile *pSpkFile = new CSpkFile();
 | 
        
           |  |  | 1263 | 	if ( !pSpkFile->convertOld(sOldFilename) ) {
 | 
        
           |  |  | 1264 | 		delete pSpkFile;
 | 
        
           |  |  | 1265 | 		return NULL;
 | 
        
           |  |  | 1266 | 	}
 | 
        
           |  |  | 1267 |   | 
        
           |  |  | 1268 | 	return pSpkFile;
 | 
        
           | 9 | cycrow | 1269 | }
 | 
        
           |  |  | 1270 |   | 
        
           | 8 | cycrow | 1271 | bool CSpkFile::convertOld(const Utils::String &sOldFilename)
 | 
        
           | 7 | cycrow | 1272 | {
 | 
        
           |  |  | 1273 | 	// check if the old file is actually in an old format
 | 
        
           | 10 | cycrow | 1274 | 	int ret = CBaseFile::CheckFile ( sOldFilename );
 | 
        
           |  |  | 1275 | 	if ( ret != SPKFILE_INVALID && ret != SPKFILE_OLD ) {
 | 
        
           |  |  | 1276 | 		return false;
 | 
        
           |  |  | 1277 |  	}
 | 
        
           |  |  | 1278 |   | 
        
           |  |  | 1279 | 	//uncomress the data
 | 
        
           |  |  | 1280 | 	int len;
 | 
        
           |  |  | 1281 | 	unsigned char *uncomprData = this->_convert_uncompressFile(sOldFilename, &len);
 | 
        
           |  |  | 1282 |   | 
        
           |  |  | 1283 | 	// uncomressed failed
 | 
        
           |  |  | 1284 | 	if ( !uncomprData ) {
 | 
        
           |  |  | 1285 | 		CLog::log(CLog::Log_IO, "Error: Unable to uncompress the file");
 | 
        
           |  |  | 1286 | 		return false;
 | 
        
           |  |  | 1287 | 	}
 | 
        
           |  |  | 1288 |   | 
        
           |  |  | 1289 | 	// now we can read the data
 | 
        
           |  |  | 1290 | 	unsigned char *d = uncomprData;
 | 
        
           |  |  | 1291 | 	Utils::String str;
 | 
        
           |  |  | 1292 |   | 
        
           |  |  | 1293 | //	CMultiSpkFile *mspk = NULL;
 | 
        
           |  |  | 1294 | 	//SMultiSpkFile *cur_mspk = NULL;
 | 
        
           |  |  | 1295 |   | 
        
           |  |  | 1296 | 	int numscripts = 0, curscript = 0;
 | 
        
           |  |  | 1297 | 	float fVersion = 1;
 | 
        
           |  |  | 1298 |   | 
        
           |  |  | 1299 | 	CLog::log(CLog::Log_IO, "* Reading spk data...");
 | 
        
           |  |  | 1300 | 	while ( d )
 | 
        
           |  |  | 1301 | 	{
 | 
        
           |  |  | 1302 | 		// read the next line
 | 
        
           |  |  | 1303 | 		d = str.readToEndOfLine(d);
 | 
        
           |  |  | 1304 | 		if ( !d || d[0] == 0 ) {
 | 
        
           |  |  | 1305 | 			break;
 | 
        
           |  |  | 1306 | 		}
 | 
        
           |  |  | 1307 | 		if ( str.empty() ) {
 | 
        
           |  |  | 1308 | 			continue;
 | 
        
           |  |  | 1309 | 		}
 | 
        
           |  |  | 1310 |   | 
        
           |  |  | 1311 | 		Utils::String sCmd = str.token(" ", 1);
 | 
        
           |  |  | 1312 |   | 
        
           |  |  | 1313 | 		//TODO: split this into CMultiSpkFile
 | 
        
           |  |  | 1314 | 		/*
 | 
        
           |  |  | 1315 | 		if ( first == "MultiPackage:" )
 | 
        
           |  |  | 1316 | 			mspk = new CMultiSpkFile;
 | 
        
           |  |  | 1317 | 		else if ( (first == "SelectScript:") && (mspk) )
 | 
        
           |  |  | 1318 | 		{
 | 
        
           |  |  | 1319 | 			mspk->AddFileEntry ( rest.GetToken ( 2, -1, ' ' ) + ".spk" );
 | 
        
           |  |  | 1320 | 			++numscripts;
 | 
        
           |  |  | 1321 | 		}
 | 
        
           |  |  | 1322 | 		else if ( (str == "AllowSelection") && (mspk) )
 | 
        
           |  |  | 1323 | 			mspk->SetSelection ( true );
 | 
        
           |  |  | 1324 | 		else if ( str == "-- Start New Script --" )
 | 
        
           |  |  | 1325 | 		{
 | 
        
           |  |  | 1326 | 			if ( !mspk )
 | 
        
           |  |  | 1327 | 			{
 | 
        
           |  |  | 1328 | 				printf ( "Invalid file format, seems to be multi package file but isn't\n" );
 | 
        
           |  |  | 1329 | 				CLEANUP
 | 
        
           |  |  | 1330 | 				exit ( 0 );
 | 
        
           |  |  | 1331 | 			}
 | 
        
           |  |  | 1332 | 			cur_mspk = mspk->GetFileList()->Get ( curscript );
 | 
        
           |  |  | 1333 | 			++curscript;
 | 
        
           |  |  | 1334 | 			cur_mspk->pFile = new CSpkFile;
 | 
        
           |  |  | 1335 | 			spkfile = (CSpkFile *)cur_mspk->pFile;
 | 
        
           |  |  | 1336 | 		}
 | 
        
           |  |  | 1337 | 		*/
 | 
        
           |  |  | 1338 | 		Utils::String sRest = str.tokens(" ", 2);
 | 
        
           |  |  | 1339 | 		if ( sCmd == "Packager:" ) {
 | 
        
           |  |  | 1340 | 			fVersion = sRest;
 | 
        
           |  |  | 1341 | 			CLog::logf(CLog::Log_Read, "\tPackager Version: %.2f", fVersion );
 | 
        
           |  |  | 1342 | 		}
 | 
        
           |  |  | 1343 | 		else if ( sCmd == "Icon:" )
 | 
        
           |  |  | 1344 | 		{
 | 
        
           |  |  | 1345 | 			long size = sRest.token(" ", 1);
 | 
        
           |  |  | 1346 | 			Utils::String ext = sRest.token(" ", 2);
 | 
        
           |  |  | 1347 |   | 
        
           |  |  | 1348 | 			C_File *file = new C_File ();
 | 
        
           |  |  | 1349 | 			file->ReadFromData ( (char *)d, size );
 | 
        
           |  |  | 1350 |   | 
        
           |  |  | 1351 | 			d += size;
 | 
        
           |  |  | 1352 |   | 
        
           |  |  | 1353 | 			this->SetIcon(file, ext);
 | 
        
           |  |  | 1354 |   | 
        
           |  |  | 1355 | 			CLog::logf(CLog::Log_File, "\tIcon (%s) Size: %s", ext.c_str(), file->GetDataSizeString ().c_str() );
 | 
        
           |  |  | 1356 | 		}
 | 
        
           |  |  | 1357 | 		else if ( sCmd.left(3) == "$$$" )
 | 
        
           |  |  | 1358 | 			d = _convert_parseFile(sCmd, sRest, fVersion, d);
 | 
        
           |  |  | 1359 | 		else {
 | 
        
           |  |  | 1360 | 			this->_convert_parse(sCmd, sRest);
 | 
        
           |  |  | 1361 | 		}
 | 
        
           |  |  | 1362 | 	}
 | 
        
           |  |  | 1363 |   | 
        
           |  |  | 1364 | 	CLog::logf(CLog::Log_IO, "* Reading spk data..." );
 | 
        
           |  |  | 1365 |   | 
        
           | 7 | cycrow | 1366 | 	return true;
 | 
        
           |  |  | 1367 | }
 |