Subversion Repositories spk

Rev

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

Rev 82 Rev 83
Line 138... Line 138...
138
	}
138
	}
139
	else
139
	else
140
		m_pGameVFS.LoadFilesystem(m_sCurrentDir.ToString(), 0);
140
		m_pGameVFS.LoadFilesystem(m_sCurrentDir.ToString(), 0);
141
}
141
}
142
 
142
 
143
bool CPackages::IsOldDir(CyString dir)
143
bool CPackages::isOldDir(const Utils::String &dir)
144
{
144
{
145
	bool oldPlugin = false;
145
	bool oldPlugin = false;
146
 
146
 
147
	dir = dir.FindReplace("\\", "/");
-
 
148
	CFileIO datFile(dir + "/PluginManager/pluginmanager.dat");
147
	CFileIO datFile(dir + "/PluginManager/pluginmanager.dat");
149
	if ( datFile.exists() )
148
	if ( datFile.exists() )
150
	{
149
	{
151
		std::vector<CyString> *readFile = datFile.ReadLines();
150
		std::vector<Utils::String> *readFile = datFile.readLines();
152
		if ( readFile )
151
		if ( readFile )
153
		{
152
		{
154
			for ( int i = 0; i < (int)readFile->size(); i++ )
153
			for ( int i = 0; i < (int)readFile->size(); i++ )
155
			{
154
			{
156
				CyString line(readFile->at(i));
155
				Utils::String line(readFile->at(i));
157
				CyString cmd = line.GetToken(":", 1, 1).lower();
156
				Utils::String cmd = line.token(":", 1);
158
				if ( cmd == "<script>" || cmd == "</scripts>" )
157
				if ( cmd.Compare("<script>") || cmd.Compare("</scripts>") )
159
					break;
158
					break;
160
				else if ( cmd == "spkinstaller" || cmd == "globalfiles" )
159
				else if ( cmd.Compare("spkinstaller") || cmd.Compare("globalfiles") )
161
					break;
160
					break;
162
				else if ( cmd == "pluginmanager" )
161
				else if ( cmd.Compare("pluginmanager") )
163
				{
162
				{
164
					oldPlugin = true;
163
					oldPlugin = true;
165
					break;
164
					break;
166
				}
165
				}
167
			}
166
			}
Line 191... Line 190...
191
 
190
 
192
	// check the pluginmanager data file exists
191
	// check the pluginmanager data file exists
193
	CFileIO datFile(m_sCurrentDir + "/PluginManager/pluginmanager.dat");
192
	CFileIO datFile(m_sCurrentDir + "/PluginManager/pluginmanager.dat");
194
	if ( datFile.exists() )
193
	if ( datFile.exists() )
195
	{
194
	{
196
		std::vector<CyString> *readFile = datFile.ReadLines();
195
		std::vector<Utils::String> *readFile = datFile.readLines();
197
		if ( readFile )
196
		if ( readFile )
198
		{
197
		{
199
			float fVersion = 0;
198
			float fVersion = 0;
200
			bool spkinstaller = false;
199
			bool spkinstaller = false;
201
			float fBeta = 0;
200
			float fBeta = 0;
Line 207... Line 206...
207
 
206
 
208
			CBaseFile *packageFile = 0;
207
			CBaseFile *packageFile = 0;
209
 
208
 
210
			for ( int i = 0; i < (int)readFile->size(); i++ )
209
			for ( int i = 0; i < (int)readFile->size(); i++ )
211
			{
210
			{
212
				CyString line(readFile->at(i));
211
				Utils::String line(readFile->at(i));
213
 
212
 
214
				CyString cmd = line.GetToken(":", 1, 1).lower();
213
				Utils::String cmd = line.token(":", 1).lower();
215
				CyString rest = line.GetToken(":", 2).RemoveFirstSpace();
214
				Utils::String rest = line.tokens(":", 2).removeFirstSpace();
216
 
215
 
217
				if ( iStatus == READ_GLOBAL )
216
				if ( iStatus == READ_GLOBAL )
218
				{
217
				{
219
					if ( cmd == "<script>" )
218
					if ( cmd == "<script>" )
220
					{
219
					{
Line 238... Line 237...
238
					}
237
					}
239
					else if ( cmd != "</scripts>" )
238
					else if ( cmd != "</scripts>" )
240
					{
239
					{
241
						int game = 0;
240
						int game = 0;
242
						bool disabled = false;
241
						bool disabled = false;
243
						CyString fileName = line.GetToken(":", 5);
242
						Utils::String fileName = line.tokens(":", 5);
244
						CyString origName;
243
						Utils::String origName;
245
						if ( fileName.Left(2) == "D#" )
244
						if ( fileName.left(2) == "D#" )
246
						{
245
						{
247
							fileName.Erase(0, 2);
246
							fileName.erase(0, 2);
248
							disabled = true;
247
							disabled = true;
249
						}
248
						}
250
						if ( fileName.Left(2) == "G#" ) {
249
						if ( fileName.left(2) == "G#" ) {
251
							fileName.Erase(0, 2);
250
							fileName.erase(0, 2);
252
							game = fileName.GetToken("#", 1, 1).ToInt();
251
							game = fileName.token("#", 1).toLong();
253
							fileName = fileName.GetToken("#", 2);
252
							fileName = fileName.tokens("#", 2);
254
						}
253
						}
255
						if ( fileName.IsIn("O#") )
254
						if ( fileName.isin("O#") )
256
						{
255
						{
257
							origName = fileName.GetToken("O#", 2, 2);
256
							origName = fileName.token("O#", 2);
258
							fileName = fileName.GetToken("O#", 1, 1);
257
							fileName = fileName.token("O#", 1);
259
						}
258
						}
260
 
259
 
261
						C_File *newFile = new C_File( m_sCurrentDir + fileName );
260
						C_File *newFile = new C_File( m_sCurrentDir + fileName );
262
						newFile->SetGame(game);
261
						newFile->SetGame(game);
263
						newFile->SetOriginalName(origName);
262
						newFile->SetOriginalName(origName);
264
						newFile->SetDisabled(disabled);
263
						newFile->SetDisabled(disabled);
265
						newFile->SetFileType(line.GetToken(":", 1, 1).ToInt());
264
						newFile->SetFileType(line.token(":", 1).toLong());
266
						newFile->SetCreationTime((time_t)line.GetToken(":", 2, 2).ToInt());
265
						newFile->SetCreationTime((time_t)line.token(":", 2).toLong());
267
						newFile->SetDir(line.GetToken(":", 3, 3));
266
						newFile->SetDir(line.token(":", 3));
268
						if ( line.GetToken(":", 4, 4).ToInt() )
267
						if ( line.token(":", 4).toLong() )
269
							newFile->SetShared(true);
268
							newFile->SetShared(true);
270
						newFile->UpdateSigned();
269
						newFile->UpdateSigned();
271
 
270
 
272
						m_lFiles.push_back(newFile);
271
						m_lFiles.push_back(newFile);
273
					}
272
					}
274
				}
273
				}
275
				else if ( iStatus == READ_SCRIPT )
274
				else if ( iStatus == READ_SCRIPT )
276
				{
275
				{
277
					if ( cmd == "installspk" )
276
					if ( cmd == "installspk" )
278
						packageFile->setFilename(rest.ToString());
277
						packageFile->setFilename(rest);
279
					else if ( cmd == "files" )
278
					else if ( cmd == "files" )
280
					{
279
					{
281
						iStatus = READ_SCRIPTFILE;
280
						iStatus = READ_SCRIPTFILE;
282
						if ( spkinstaller )
281
						if ( spkinstaller )
283
						{
282
						{
284
							int max;
283
							int max;
285
							CyString *files = rest.SplitToken(' ', &max);
284
							Utils::String *files = rest.tokenise(" ", &max);
286
 
285
 
287
							for ( int i = 0; i < max; i++ )
286
							for ( int i = 0; i < max; i++ )
288
							{
287
							{
289
								int fileNum = files[i].ToInt();
288
								int fileNum = files[i].toLong();
290
								if ( fileNum >= 0 && fileNum < m_lFiles.size() )
289
								if ( fileNum >= 0 && fileNum < m_lFiles.size() )
291
									packageFile->AddFile(m_lFiles[fileNum]);
290
									packageFile->AddFile(m_lFiles[fileNum]);
292
							}
291
							}
293
 
292
 
294
							CLEANSPLIT(files, max);
293
							CLEANSPLIT(files, max);
Line 298... Line 297...
298
						packageFile->SetEnabled(false);
297
						packageFile->SetEnabled(false);
299
					else if ( cmd == "modifieddisabled" )
298
					else if ( cmd == "modifieddisabled" )
300
						packageFile->SetModifiedEnabled(false);
299
						packageFile->SetModifiedEnabled(false);
301
					else if ( cmd == "icon" )
300
					else if ( cmd == "icon" )
302
					{
301
					{
303
						C_File *icon = new C_File(rest.GetToken(" ", 2));
302
						C_File *icon = new C_File(CyString(rest.tokens(" ", 2)));
304
						packageFile->SetIcon(icon, rest.GetToken(" ", 1, 1));
303
						packageFile->SetIcon(icon, rest.token(" ", 1));
305
					}
304
					}
306
					else
305
					else
307
						packageFile->ParseValueLine(line.ToString());
306
						packageFile->ParseValueLine(line);
308
				}
307
				}
309
				else if ( iStatus == READ_SCRIPTFILE )
308
				else if ( iStatus == READ_SCRIPTFILE )
310
				{
309
				{
311
					if ( cmd == "<script>" )
310
					if ( cmd == "<script>" )
312
					{
311
					{
Line 348... Line 347...
348
						m_lPackages.push_back(packageFile);
347
						m_lPackages.push_back(packageFile);
349
						this->ConvertOldPackage(packageFile);
348
						this->ConvertOldPackage(packageFile);
350
					}
349
					}
351
					else
350
					else
352
					{
351
					{
353
						int fileNum = line.GetToken("::", 1, 1).ToInt();
352
						int fileNum = line.token("::", 1).toLong();
354
						if ( fileNum >= 0 && fileNum < m_lFiles.size() )
353
						if ( fileNum >= 0 && fileNum < m_lFiles.size() )
355
							packageFile->AddFile(m_lFiles[fileNum]);
354
							packageFile->AddFile(m_lFiles[fileNum]);
356
					}
355
					}
357
				}
356
				}
358
				else if ( iWare != -1 )
357
				else if ( iWare != -1 )
359
				{
358
				{
360
					--iCount;
359
					--iCount;
361
 
360
 
362
					SGameWare *gm = new SGameWare;
361
					SGameWare *gm = new SGameWare;
363
					gm->iPos = line.GetToken(" ", 1, 1).ToInt();
362
					gm->iPos = line.token(" ", 1).toLong();
364
					gm->iType = line.GetToken(" ", 2, 2).ToInt();
363
					gm->iType = line.token(" ", 2).toLong();
365
					gm->cType = line.GetToken(" ", 3, 3)[0];
364
					gm->cType = line.token(" ", 3)[0];
366
					gm->pWare = NULL;
365
					gm->pWare = NULL;
367
					gm->sWareName = line.GetToken(" ", 4);
366
					gm->sWareName = line.tokens(" ", 4);
368
					m_lGameWares[iWare].push_back(gm);
367
					m_lGameWares[iWare].push_back(gm);
369
					if ( iCount <= 0 )
368
					if ( iCount <= 0 )
370
						iWare = -1;
369
						iWare = -1;
371
				}
370
				}
372
				else if ( iShip != -1 )
371
				else if ( iShip != -1 )
373
				{
372
				{
374
					--iCount;
373
					--iCount;
375
 
374
 
376
					SGameShip *gm = new SGameShip;
375
					SGameShip *gm = new SGameShip;
377
					gm->iType = line.GetToken(" ", 1, 1).ToInt();
376
					gm->iType = line.token(" ", 1).toLong();
378
					if ( line.GetToken(" ", 2, 2).Left(4) == "$#C:" )
377
					if ( line.token(" ", 2).left(4) == "$#C:" )
379
					{
378
					{
380
						gm->sShipClass = line.GetToken(" ", 2, 2).Right(-4);
379
						gm->sShipClass = line.token(" ", 2).right(-4);
381
						gm->sShipID = line.GetToken(" ", 3);
380
						gm->sShipID = line.tokens(" ", 3);
382
					}
381
					}
383
					else
382
					else
384
					{
383
					{
385
						gm->sShipID = line.GetToken(" ", 2);
384
						gm->sShipID = line.tokens(" ", 2);
386
						gm->sShipClass = "OBJ_SHIP_M5";
385
						gm->sShipClass = "OBJ_SHIP_M5";
387
					}
386
					}
388
					gm->pPackage = NULL;
387
					gm->pPackage = NULL;
389
					m_lGameShips.push_back(gm);
388
					m_lGameShips.push_back(gm);
390
					if ( iCount <= 0 )
389
					if ( iCount <= 0 )
391
						iShip = -1;
390
						iShip = -1;
392
				}
391
				}
393
				else if ( cmd.Compare("savegamemanager") )
392
				else if ( cmd.Compare("savegamemanager") )
394
					m_iSaveGameManager = rest.ToInt();
393
					m_iSaveGameManager = rest.toLong();
395
				else if ( cmd.Compare("savegame") )
394
				else if ( cmd.Compare("savegame") )
396
					m_iSaveGame = rest.ToInt();
395
					m_iSaveGame = rest.toLong();
397
				else if ( cmd == "fakepatch" )
396
				else if ( cmd == "fakepatch" )
398
					m_iFakePatch = rest.ToInt();
397
					m_iFakePatch = rest.toLong();
399
				else if ( cmd == "updatetime" )
398
				else if ( cmd == "updatetime" )
400
					m_iLastUpdated = rest.ToInt();
399
					m_iLastUpdated = rest.toLong();
401
				else if ( cmd == "surpressprotectedwarning" )
400
				else if ( cmd == "surpressprotectedwarning" )
402
					m_bSurpressProtectedWarning = true;
401
					m_bSurpressProtectedWarning = true;
403
				else if ( cmd == "pluginmanager" )
402
				else if ( cmd == "pluginmanager" )
404
				{
403
				{
405
					fVersion = rest.ToFloat();
404
					fVersion = rest.toFloat();
406
					m_bOldPlugin = true;
405
					m_bOldPlugin = true;
407
				}
406
				}
408
				else if ( cmd == "setmod" )
407
				else if ( cmd == "setmod" )
409
					m_sSetMod = rest;
408
					m_sSetMod = rest;
410
				else if ( cmd == "shipbuffer" )
409
				else if ( cmd == "shipbuffer" )
411
					m_iShipBuffer = rest.ToInt();
410
					m_iShipBuffer = rest.toLong();
412
				else if ( cmd == "warebuffers" )
411
				else if ( cmd == "warebuffers" )
413
				{
412
				{
414
					int max = rest.NumToken(" ");
413
					int max = rest.countToken(" ");
415
					for ( int i = 0; i < WAREBUFFERS; i++ )
414
					for ( int i = 0; i < WAREBUFFERS; i++ )
416
					{
415
					{
417
						if ( i > max )
416
						if ( i > max )
418
							m_iWareBuffer[i] = 0;
417
							m_iWareBuffer[i] = 0;
419
						else
418
						else
420
							m_iWareBuffer[i] = rest.GetToken(" ", i + 1, i + 1).ToInt();
419
							m_iWareBuffer[i] = rest.token(" ", i + 1).toLong();
421
					}
420
					}
422
				}
421
				}
423
				else if ( cmd == "createdfile" )
422
				else if ( cmd == "createdfile" )
424
					m_lCreatedFiles.PushBack(rest);
423
					m_lCreatedFiles.PushBack(CyString(rest));
425
				else if ( cmd == "wares" )
424
				else if ( cmd == "wares" )
426
				{
425
				{
427
					iWare = rest.GetToken(" ", 1, 1).ToInt();
426
					iWare = rest.token(" ", 1).toLong();
428
					iCount = rest.GetToken(" ", 2, 2).ToInt();
427
					iCount = rest.token(" ", 2).toLong();
429
				}
428
				}
430
				else if ( cmd == "ships" )
429
				else if ( cmd == "ships" )
431
				{
430
				{
432
					iShip = 1;
431
					iShip = 1;
433
					iCount = rest.GetToken(" ", 1, 1).ToInt();
432
					iCount = rest.token(" ", 1).toLong();
434
				}
433
				}
435
				else if ( cmd == "modified" )
434
				else if ( cmd == "modified" )
436
					m_bVanilla = false;
435
					m_bVanilla = false;
437
				else if ( cmd == "spkinstaller" )
436
				else if ( cmd == "spkinstaller" )
438
				{
437
				{
439
					fVersion = rest.ToFloat();
438
					fVersion = rest.toFloat();
440
					spkinstaller = true;
439
					spkinstaller = true;
441
				}
440
				}
442
				else if ( cmd == "BetaVersion" )
441
				else if ( cmd == "BetaVersion" )
443
					fBeta = rest.ToFloat();
442
					fBeta = rest.toFloat();
444
				else if ( cmd == "Uninstall" )
443
				else if ( cmd == "Uninstall" )
445
				{
444
				{
446
					C_File *uf = new C_File();
445
					C_File *uf = new C_File();
447
					uf->SetFileType(FILETYPE_SCRIPT);
446
					uf->SetFileType(FILETYPE_SCRIPT);
448
					uf->SetCreationTime(rest.GetToken(" ", 1, 1).ToInt());
447
					uf->SetCreationTime(rest.token(" ", 1).toLong());
449
					uf->SetFilename(m_sCurrentDir + "/Scripts/" + rest.GetToken(" ", 2));
448
					uf->SetFilename(m_sCurrentDir + "/Scripts/" + rest.tokens(" ", 2));
450
					m_lUninstallFiles.push_back(uf);
449
					m_lUninstallFiles.push_back(uf);
451
				}
450
				}
452
				else if ( cmd == "NonRemovedFile" )
451
				else if ( cmd == "NonRemovedFile" )
453
				{
452
				{
454
					if ( !CFileIO::Remove(rest.ToString()) )
453
					if ( !CFileIO::Remove(rest) )
455
						m_lNonRemovedFiles.PushBack(rest);
454
						m_lNonRemovedFiles.PushBack(CyString(rest));
456
				}
455
				}
457
				else if ( cmd == "Original" )
456
				else if ( cmd == "Original" )
458
				{
457
				{
459
					C_File *uf = new C_File();
458
					C_File *uf = new C_File();
460
					uf->SetFileType(rest.GetToken(" ", 1, 1).ToInt());
459
					uf->SetFileType(rest.token(" ", 1).toLong());
461
					if ( uf->GetFileType() == FILETYPE_EXTRA )
460
					if ( uf->GetFileType() == FILETYPE_EXTRA )
462
					{
461
					{
463
						uf->SetDir(rest.GetToken(" ", 2).GetToken(":", 2));
462
						uf->SetDir(rest.tokens(" ", 2).tokens(":", 2));
464
						uf->SetFilename(rest.GetToken(" ", 2).GetToken(":", 1, 1));
463
						uf->SetFilename(rest.tokens(" ", 2).token(":", 1));
465
					}
464
					}
466
					else
465
					else
467
						uf->SetFilename(rest.GetToken(" ", 2));
466
						uf->SetFilename(rest.tokens(" ", 2));
468
					uf->SetFilename(m_sCurrentDir + "/" + uf->GetNameDirectory(NULL));
467
					uf->SetFilename(m_sCurrentDir + "/" + uf->GetNameDirectory(NULL));
469
					m_lOriginalFiles.push_back(uf);
468
					m_lOriginalFiles.push_back(uf);
470
				}
469
				}
471
				else if ( cmd.Compare("GlobalSetting") )
470
				else if ( cmd.Compare("GlobalSetting") )
472
					m_lGlobals.PushBack(rest.GetToken(":", 1, 1), rest.GetToken(":", 2));
471
					m_lGlobals.PushBack(CyString(rest.token(":", 1)), CyString(rest.tokens(":", 2)));
473
				else if ( cmd.Compare("FakePatchOrder") )
472
				else if ( cmd.Compare("FakePatchOrder") )
474
					m_lFakePatchOrder.PushBack(rest.GetToken(":", 1, 1), rest.GetToken(":", 2));
473
					m_lFakePatchOrder.PushBack(CyString(rest.token(":", 1)), CyString(rest.tokens(":", 2)));
475
				else if ( cmd == "globalfiles" )
474
				else if ( cmd == "globalfiles" )
476
					iStatus = READ_GLOBAL;
475
					iStatus = READ_GLOBAL;
477
 
476
 
478
				if ( progress )
477
				if ( progress )
479
				{
478
				{