Subversion Repositories spk

Rev

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

Rev 96 Rev 98
Line 3... Line 3...
3
 
3
 
4
#include <time.h>
4
#include <time.h>
5
#include <vector>
5
#include <vector>
6
 
6
 
7
#include "OriginalFiles.h"
7
#include "OriginalFiles.h"
-
 
8
#include "spkdef.h"
8
 
9
 
9
#ifdef _RAR
10
#ifdef _RAR
10
#include <unrar.h>
11
#include <unrar.h>
11
#endif
12
#endif
12
 
13
 
Line 1678... Line 1679...
1678
	if ( !dontAdd )
1679
	if ( !dontAdd )
1679
	{
1680
	{
1680
		CLog::log(CLog::Log_Install, 1, "Adding package into main list");
1681
		CLog::log(CLog::Log_Install, 1, "Adding package into main list");
1681
		if ( oldPackage )
1682
		if ( oldPackage )
1682
		{
1683
		{
-
 
1684
			// find all other packages that has the old package as parent and switch to new
-
 
1685
			for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
-
 
1686
				if ( node->Data()->GetParent() == oldPackage ) {
-
 
1687
					node->Data()->SetParent(package);
-
 
1688
				}
-
 
1689
			}
-
 
1690
 
-
 
1691
			// remove olld package from list, and replace it with the new one
1683
			m_lPackages.insert(oldPackage, package);
1692
			m_lPackages.insert(oldPackage, package);
1684
			m_lPackages.remove(oldPackage, false);
1693
			m_lPackages.remove(oldPackage, false);
1685
		}
1694
		}
1686
		else
1695
		else
1687
			m_lPackages.push_back (package);
1696
			m_lPackages.push_back (package);
Line 4860... Line 4869...
4860
CyString CPackages::GetGameTypesString(CBaseFile *package, bool includeVersion)
4869
CyString CPackages::GetGameTypesString(CBaseFile *package, bool includeVersion)
4861
{
4870
{
4862
	if ( !package->AnyGameCompatability() )
4871
	if ( !package->AnyGameCompatability() )
4863
		return NullString;
4872
		return NullString;
4864
 
4873
 
4865
	CyString sGames;
4874
	Utils::String sGames;
4866
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
4875
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
4867
		if ( !sGames.Empty() )
4876
		if ( !sGames.empty() )
4868
			sGames += ", ";
4877
			sGames += ", ";
4869
		sGames += m_gameExe.GetGameNameFromType(gNode->Data()->iGame - 1);
4878
		sGames += m_gameExe.GetGameNameFromType(gNode->Data()->iGame - 1);
4870
		if ( includeVersion ) {
4879
		if ( includeVersion ) {
-
 
4880
			Utils::String version = m_gameExe.GetGameVersionFromType(gNode->Data()->iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
-
 
4881
			if ( !version.empty() ) {
4871
			sGames += " (";
4882
				sGames += " (";
4872
			sGames += m_gameExe.GetGameVersionFromType(gNode->Data()->iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
4883
				sGames += version;
4873
			sGames += ")";
4884
				sGames += ")";
-
 
4885
			}
4874
		}
4886
		}
4875
	}
4887
	}
4876
	return sGames;
4888
	return sGames;
4877
}
4889
}
4878
 
4890
 
Line 7380... Line 7392...
7380
}
7392
}
7381
 
7393
 
7382
CBaseFile *CPackages::LoadPackagerScript(CyString filename, int compression, CyString (*askFunc)(CyString), CyStringList *malformedLines, CyStringList *unknownCommands, CyStringList *variables)
7394
CBaseFile *CPackages::LoadPackagerScript(CyString filename, int compression, CyString (*askFunc)(CyString), CyStringList *malformedLines, CyStringList *unknownCommands, CyStringList *variables)
7383
{
7395
{
7384
	// check the file exists
7396
	// check the file exists
7385
	if ( !CFileIO(filename).ExistsOld() )
7397
	if ( !CFileIO::Exists(filename.ToString()) )
7386
		return NULL;
7398
		return NULL;
7387
 
7399
 
7388
	// read all the lines
7400
	// read all the lines
7389
	CFileIO File(filename);
7401
	CFileIO File(filename);
7390
	std::vector<CyString> *lines = File.ReadLines();
-
 
7391
 
-
 
7392
	if ( !lines )
7402
	if ( !File.startRead() ) 
7393
		return NULL;
7403
		return NULL;
7394
 
7404
 
-
 
7405
	Utils::CStringList fileData;
-
 
7406
 
-
 
7407
	int iLine = 0;
-
 
7408
 
7395
	CBaseFile *package = NULL;
7409
	CBaseFile *package = NULL;
7396
 
7410
 
7397
	// filter out blank lines and comments
-
 
7398
	CyStringList fileData;
7411
	while(!File.atEnd()) {
7399
	for ( int i = 0; i < (int)lines->size(); i++ )
7412
		// read the next line in the file
7400
	{
-
 
7401
		CyString line(lines->at(i));
7413
		Utils::String line = File.readEndOfLine();
7402
 
7414
 
7403
		// dont include empty lines (whitespace)
7415
		// filter out any characters we dont really want
7404
		if ( line.Empty() )
7416
		line.removeChar("\t\r");
7405
			continue;
7417
		line.removeFirstSpace();
7406
 
7418
 
7407
		// filter out any spaces, tabs in front
-
 
7408
		line.RemoveChar('\t');
-
 
7409
		line.RemoveChar('\r');
-
 
7410
		CyString linenospace = line;
-
 
7411
		linenospace.RemoveFirstSpace();
-
 
7412
		if ( linenospace.Empty() )
7419
		if ( line.empty() ) continue;
7413
			continue;
-
 
7414
 
7420
 
7415
		// check for any comments
7421
		// check for any comments (so we can ignore them)
7416
		if ( linenospace.Left(2) == "//" )
7422
		if ( line.left(2).Compare("//") || line[0] == '#' ) continue;
7417
			continue;
7423
 
7418
		if ( linenospace[0] == '#' )
-
 
7419
			continue;
7424
		++iLine;
7420
 
7425
 
7421
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7426
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7422
		if ( !line.IsIn(':') )
7427
		if ( !line.isin(':') )
7423
		{
7428
		{
7424
			// there are some exeptions, and these are one word entrys only
7429
			// there are some exeptions, and these are one word entrys only
7425
			line.RemoveEndSpace();
7430
			line.removeEndSpace();
7426
			if ( line.IsIn(" ") )
7431
			if ( line.isin(" ") )
7427
			{
7432
			{
7428
				if ( malformedLines )
7433
				if ( malformedLines )
7429
					malformedLines->PushBack(line, CyString::Number(i));
7434
					malformedLines->PushBack(CyString(line), CyString::Number(iLine));
7430
				continue;
7435
				continue;
7431
			}
7436
			}
7432
		}
7437
		}
7433
 
7438
 
7434
		// check for the type line
7439
		// check for the type line
7435
		if ( !package && line.GetToken(":", 1, 1).Compare("FileType") )
7440
		if ( !package && line.token(":", 1).Compare("FileType") )
7436
		{
7441
		{
7437
			CyString sFileType = line.GetToken(":", 2).RemoveFirstSpace();
7442
			Utils::String sFileType = line.tokens(":", 2).removeFirstSpace();
7438
			if ( sFileType.Compare("Ship") )
7443
			if ( sFileType.Compare("Ship") )
7439
				package = new CXspFile();
7444
				package = new CXspFile();
7440
			else if ( sFileType.Compare("Script") )
7445
			else if ( sFileType.Compare("Script") )
7441
				package = new CSpkFile();
7446
				package = new CSpkFile();
7442
			else if ( sFileType.Compare("Base") )
7447
			else if ( sFileType.Compare("Base") )
7443
				package = new CBaseFile();
7448
				package = new CBaseFile();
-
 
7449
			continue;
7444
		}
7450
		}
7445
 
7451
 
7446
		fileData.PushBack(line, CyString::Number(i));
7452
		fileData.pushBack(line, Utils::String::Number(iLine));
7447
	}
7453
	}
7448
 
7454
 
7449
	delete lines;
-
 
7450
 
-
 
7451
	// assume its a script if no type is set (all old versions are scripts)
7455
	// assume its a script if no type is set (all old versions are scripts)
7452
	if ( !package )
7456
	if ( !package )
7453
		package = new CSpkFile();
7457
		package = new CSpkFile();
7454
 
7458
 
7455
	if ( compression != -1 )
7459
	if ( compression != -1 )
Line 7457... Line 7461...
7457
 
7461
 
7458
	CyString ftpaddr;
7462
	CyString ftpaddr;
7459
	CyString ftpuser;
7463
	CyString ftpuser;
7460
	CyString ftppass;
7464
	CyString ftppass;
7461
	CyString ftpdir;
7465
	CyString ftpdir;
-
 
7466
	Utils::String sMainGame;
-
 
7467
	Utils::CStringList otherGames;
-
 
7468
 
7462
	// now lets read the rest of the day
7469
	// now lets read the rest of the day
7463
	CyStringList listVaribles;
7470
	CyStringList listVaribles;
7464
	for ( SStringList *strNode = fileData.Head(); strNode; strNode = strNode->next )
7471
	for ( Utils::SStringList *line = fileData.First(); line; line = fileData.Next() )
7465
	{
7472
	{
7466
		CyString first = strNode->str.GetToken(":", 1, 1);
7473
		Utils::String cmd = line->str.token(":", 1);
7467
		CyString rest = strNode->str.GetToken(":", 2).RemoveFirstSpace();
7474
		Utils::String rest = line->str.tokens(":", 2).removeFirstSpace();
7468
 
7475
 
7469
		if ( first.Compare("Varible") || first.Compare("Variable") )
7476
		if ( cmd.Compare("Varible") || cmd.Compare("Variable") )
7470
			listVaribles.PushBack(rest.GetToken(" ", 1, 1), rest.GetToken(" ", 2), true);
7477
			listVaribles.PushBack(CyString(rest.token(" ", 1)), CyString(rest.tokens(" ", 2)), true);
7471
		else
7478
		else
7472
		{
7479
		{
7473
			// replace variables
7480
			// replace variables
7474
			if ( rest.IsIn("$") )
7481
			if ( rest.isin("$") )
7475
			{
7482
			{
7476
				for ( SStringList *strVar = listVaribles.Head(); strVar; strVar = strVar->next )
7483
				for ( SStringList *strVar = listVaribles.Head(); strVar; strVar = strVar->next )
7477
				{
7484
				{
7478
					if ( rest.IsIn(strVar->str) )
7485
					if ( rest.isin(strVar->str.ToString()) )
7479
						rest.FindReplace(strVar->str, strVar->data);
7486
						rest = rest.findReplace(strVar->str.ToString(), strVar->data.ToString());
7480
				}
7487
				}
7481
 
7488
 
7482
				if ( variables )
7489
				if ( variables )
7483
				{
7490
				{
7484
					for ( SStringList *strVar = variables->Head(); strVar; strVar = strVar->next )
7491
					for ( SStringList *strVar = variables->Head(); strVar; strVar = strVar->next )
7485
					{
7492
					{
7486
						if ( rest.IsIn(strVar->str) )
7493
						if ( rest.isin(strVar->str.ToString()) )
7487
							rest.FindReplace(strVar->str, strVar->data);
7494
							rest = rest.findReplace(strVar->str.ToString(), strVar->data.ToString());
7488
					}
7495
					}
7489
				}
7496
				}
7490
			}
7497
			}
7491
 
7498
 
7492
			//check for the built in varibles
7499
			//check for the built in varibles
7493
			if ( rest.IsIn("$ASK") )
7500
			if ( rest.isin("$ASK") )
7494
			{
7501
			{
7495
				CyString replace = "$ASK";
7502
				Utils::String replace = "$ASK";
7496
				CyString result;
7503
				Utils::String result;
7497
 
7504
 
7498
				if ( askFunc )
7505
				if ( askFunc )
7499
					result = askFunc(first);
7506
					result = askFunc(CyString(cmd)).ToString();
7500
 
7507
 
7501
				if ( rest.IsIn("$ASK(") )
7508
				if ( rest.isin("$ASK(") )
7502
				{
7509
				{
7503
					replace = rest.GetToken("$ASK(", 2).GetToken(")", 1, 1);
7510
					replace = rest.tokens("$ASK(", 2).token(")", 1);
7504
					if ( result.Empty() )
7511
					if ( result.empty() )
7505
						result = replace;
7512
						result = replace;
7506
					replace = CyString("$ASK(") + replace + ")";
7513
					replace = "$ASK(" + replace + ")";
7507
				}
7514
				}
7508
 
7515
 
7509
 
-
 
7510
				if ( !result.Empty() )
7516
				if ( !result.empty() )
7511
					rest.FindReplace(replace, result);
7517
					rest = rest.findReplace(replace, result);
7512
			}
7518
			}
7513
			// todays date
7519
			// todays date
7514
			if ( rest.IsIn("$DATE") )
7520
			if ( rest.isin("$DATE") )
7515
			{
7521
			{
7516
				time_t now;
7522
				time_t now;
7517
				time(&now);
7523
				time(&now);
7518
				struct tm *timeinfo = localtime(&now);
7524
				struct tm *timeinfo = localtime(&now);
7519
				CyString result = CyString::Number(timeinfo->tm_mday) + "." + CyString::Number(timeinfo->tm_mon + 1) + "." + CyString::Number(timeinfo->tm_year + 1900);
7525
				Utils::String result = Utils::String::Number(timeinfo->tm_mday) + "." + Utils::String::Number(timeinfo->tm_mon + 1) + "." + Utils::String::Number(timeinfo->tm_year + 1900);
7520
				if ( !result.Empty() )
7526
				if ( !result.empty() )
7521
					rest.FindReplace("$DATE", result);
7527
					rest = rest.findReplace("$DATE", result);
7522
			}
7528
			}
7523
			// mydocuments
7529
			// mydocuments
7524
			if ( rest.IsIn("$MYDOCUMENTS") )
7530
			if ( rest.isin("$MYDOCUMENTS") )
7525
			{
7531
			{
7526
				if ( !m_sMyDoc.Empty() )
7532
				if ( !m_sMyDoc.Empty() )
7527
					rest.FindReplace("$MYDOCUMENTS", m_sMyDoc);
7533
					rest = rest.findReplace("$MYDOCUMENTS", m_sMyDoc.ToString());
7528
			}
7534
			}
7529
 
7535
 
7530
			// current path
7536
			// current path
7531
			if ( rest.IsIn("$PATH") )
7537
			if ( rest.isin("$PATH") )
7532
			{
7538
			{
7533
				CyString currentDir = CFileIO(filename).GetDir();
7539
				Utils::String currentDir = CFileIO(filename).GetDir().ToString();
7534
				if ( !currentDir.Empty() )
7540
				if ( !currentDir.empty() )
7535
					rest.FindReplace("$PATH", currentDir);
7541
					rest = rest.findReplace("$PATH", currentDir);
7536
			}
7542
			}
7537
 
7543
 
7538
			// now parse the rest of the values
7544
			// now parse the rest of the values
7539
			if ( first.Compare("FtpUpload") )
7545
			if ( cmd.Compare("FtpUpload") )
7540
				ftpaddr = rest.GetToken(" ", 1, 1) + ":" + rest.GetToken(" ", 2, 2);
7546
				ftpaddr = rest.token(" ", 1) + ":" + rest.token(" ", 2);
7541
			else if ( first.Compare("FtpUser") )
7547
			else if ( cmd.Compare("FtpUser") )
7542
				ftpuser = rest;
7548
				ftpuser = rest;
7543
			else if ( first.Compare("FtpPass") )
7549
			else if ( cmd.Compare("FtpPass") )
7544
				ftppass = rest;
7550
				ftppass = rest;
7545
			else if ( first.Compare("FtpDir") )
7551
			else if ( cmd.Compare("FtpDir") )
7546
				ftpdir = rest;
7552
				ftpdir = rest;
-
 
7553
			else if ( cmd.Compare("MultiGames") ) {
-
 
7554
				sMainGame = rest.token(" ", 1);
-
 
7555
				otherGames.tokenise(rest.tokens(" ", 2), " ");
-
 
7556
			}
7547
			else if ( !package->LoadPackageData(first.ToString(), rest.ToString()) )
7557
			else if ( !package->LoadPackageData(cmd, rest, sMainGame, otherGames) )
7548
			{
7558
			{
7549
				if ( unknownCommands )
7559
				if ( unknownCommands )
7550
					unknownCommands->PushBack(first, rest);
7560
					unknownCommands->PushBack(CyString(cmd), CyString(rest));
7551
			}
7561
			}
7552
		}
7562
		}
7553
	}
7563
	}
7554
 
7564
 
7555
	if ( package->filename().empty() )
7565
	if ( package->filename().empty() )
7556
		package->LoadPackageData("AutoSave", "$AUTOSAVE");
7566
		package->LoadPackageData("AutoSave", "$AUTOSAVE", sMainGame, otherGames);
7557
 
7567
 
7558
	if ( !ftpaddr.Empty() )
7568
	if ( !ftpaddr.Empty() )
7559
	{
7569
	{
7560
		if ( !ftpuser.Empty() )
7570
		if ( !ftpuser.Empty() )
7561
		{
7571
		{
Line 8528... Line 8538...
8528
		ReadArchiveData(data, size, archive);
8538
		ReadArchiveData(data, size, archive);
8529
}
8539
}
8530
 
8540
 
8531
void CPackages::ReadArchiveData(const char *buf, size_t len, CBaseFile *archive)
8541
void CPackages::ReadArchiveData(const char *buf, size_t len, CBaseFile *archive)
8532
{
8542
{
-
 
8543
	Utils::CStringList otherGames;
-
 
8544
 
8533
	CyString data(buf);
8545
	CyString data(buf);
8534
	int max;
8546
	int max;
8535
	CyString *str = data.SplitToken("\n", &max);
8547
	CyString *str = data.SplitToken("\n", &max);
8536
	if ( str && max )
8548
	if ( str && max )
8537
	{
8549
	{
Line 8571... Line 8583...
8571
			}
8583
			}
8572
 
8584
 
8573
			// now check type name
8585
			// now check type name
8574
			int filetype = GetFileTypeFromString(checkType);
8586
			int filetype = GetFileTypeFromString(checkType);
8575
			if ( filetype == -1 )
8587
			if ( filetype == -1 )
8576
				archive->LoadPackageData(first.ToString(), rest.ToString());
8588
				archive->LoadPackageData(first.ToString(), rest.ToString(), Utils::String::Null(), otherGames);
8577
		}
8589
		}
8578
	}
8590
	}
8579
 
8591
 
8580
	CLEANSPLIT(str, max)
8592
	CLEANSPLIT(str, max)
8581
}
8593
}