Subversion Repositories spk

Rev

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

Rev 130 Rev 131
Line 7507... Line 7507...
7507
	}
7507
	}
7508
 
7508
 
7509
	return baseFile->GeneratePackagerScript(wildcard, list, game, gameAddons, datafile);
7509
	return baseFile->GeneratePackagerScript(wildcard, list, game, gameAddons, datafile);
7510
}
7510
}
7511
 
7511
 
7512
CBaseFile *CPackages::LoadPackagerScript(CyString filename, int compression, Utils::String (*askFunc)(const Utils::String &), CyStringList *malformedLines, CyStringList *unknownCommands, CyStringList *variables)
7512
CBaseFile *CPackages::LoadPackagerScript(const Utils::String &filename, int compression, Utils::String (*askFunc)(const Utils::String &), Utils::CStringList *malformedLines, Utils::CStringList *unknownCommands, Utils::CStringList *variables)
7513
{
7513
{
7514
	// check the file exists
7514
	// check the file exists
7515
	if ( !CFileIO::Exists(filename.ToString()) )
7515
	if ( !CFileIO::Exists(filename) )
7516
		return NULL;
7516
		return NULL;
7517
 
7517
 
7518
	// read all the lines
7518
	// read all the lines
7519
	CFileIO File(filename);
7519
	CFileIO File(filename);
7520
	if ( !File.startRead() ) 
7520
	if ( !File.startRead() ) 
Line 7540... Line 7540...
7540
		if ( line.left(2).Compare("//") || line[0] == '#' ) continue;
7540
		if ( line.left(2).Compare("//") || line[0] == '#' ) continue;
7541
 
7541
 
7542
		++iLine;
7542
		++iLine;
7543
 
7543
 
7544
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7544
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7545
		if ( !line.isin(':') )
7545
		if ( !line.contains(':') )
7546
		{
7546
		{
7547
			// there are some exeptions, and these are one word entrys only
7547
			// there are some exeptions, and these are one word entrys only
7548
			line.removeEndSpace();
7548
			line.removeEndSpace();
7549
			if ( line.isin(" ") )
7549
			if ( line.contains(" ") )
7550
			{
7550
			{
7551
				if ( malformedLines )
7551
				if ( malformedLines )
7552
					malformedLines->PushBack(CyString(line), CyString::Number(iLine));
7552
					malformedLines->pushBack(line, Utils::String::Number(iLine));
7553
				continue;
7553
				continue;
7554
			}
7554
			}
7555
		}
7555
		}
7556
 
7556
 
7557
		// check for the type line
7557
		// check for the type line
Line 7590... Line 7590...
7590
		if (!exe->sAddon.empty())
7590
		if (!exe->sAddon.empty())
7591
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon);
7591
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon);
7592
	}
7592
	}
7593
 
7593
 
7594
	// now lets read the rest of the day
7594
	// now lets read the rest of the day
7595
	CyStringList listVaribles;
7595
	Utils::CStringList listVaribles;
7596
	for ( Utils::SStringList *line = fileData.first(); line; line = fileData.next() )
7596
	for (Utils::SStringList *line = fileData.first(); line; line = fileData.next())
7597
	{
7597
	{
7598
		Utils::String cmd = line->str.token(":", 1);
7598
		Utils::String cmd = line->str.token(":", 1);
7599
		Utils::String rest = line->str.tokens(":", 2).removeFirstSpace();
7599
		Utils::String rest = line->str.tokens(":", 2).removeFirstSpace();
7600
 
7600
 
7601
		if ( cmd.Compare("Varible") || cmd.Compare("Variable") )
7601
		if (cmd.Compare("Varible") || cmd.Compare("Variable"))
-
 
7602
		{
-
 
7603
			Utils::String s1 = rest.token(" ", 1);
7602
			listVaribles.PushBack(CyString(rest.token(" ", 1)), CyString(rest.tokens(" ", 2)), true);
7604
			Utils::String s2 = rest.tokens(" ", 2);
-
 
7605
			if(!listVaribles.changeData(s1, s2))
-
 
7606
				listVaribles.pushBack(s1, s2);
-
 
7607
		}
7603
		else
7608
		else
7604
		{
7609
		{
7605
			// replace variables
7610
			// replace variables
7606
			if ( rest.isin("$") )
7611
			if ( rest.isin("$") )
7607
			{
7612
			{
7608
				for ( SStringList *strVar = listVaribles.Head(); strVar; strVar = strVar->next )
7613
				for (Utils::SStringList *strVar = listVaribles.first(); strVar; strVar = listVaribles.next())
7609
				{
7614
				{
7610
					if ( rest.isin(strVar->str.ToString()) )
7615
					if ( rest.contains(strVar->str) )
7611
						rest = rest.findReplace(strVar->str.ToString(), strVar->data.ToString());
7616
						rest = rest.findReplace(strVar->str, strVar->data);
7612
				}
7617
				}
7613
 
7618
 
7614
				if ( variables )
7619
				if ( variables )
7615
				{
7620
				{
7616
					for ( SStringList *strVar = variables->Head(); strVar; strVar = strVar->next )
7621
					for (Utils::SStringList *strVar = variables->first(); strVar; strVar = variables->next())
7617
					{
7622
					{
7618
						if ( rest.isin(strVar->str.ToString()) )
7623
						if ( rest.contains(strVar->str) )
7619
							rest = rest.findReplace(strVar->str.ToString(), strVar->data.ToString());
7624
							rest = rest.findReplace(strVar->str, strVar->data);
7620
					}
7625
					}
7621
				}
7626
				}
7622
			}
7627
			}
7623
 
7628
 
7624
			//check for the built in varibles
7629
			//check for the built in varibles
Line 7680... Line 7685...
7680
				otherGames.tokenise(rest.tokens(" ", 2), " ");
7685
				otherGames.tokenise(rest.tokens(" ", 2), " ");
7681
			}
7686
			}
7682
			else if ( !package->LoadPackageData(cmd, rest, sMainGame, otherGames, gameAddons) )
7687
			else if ( !package->LoadPackageData(cmd, rest, sMainGame, otherGames, gameAddons) )
7683
			{
7688
			{
7684
				if ( unknownCommands )
7689
				if ( unknownCommands )
7685
					unknownCommands->PushBack(CyString(cmd), CyString(rest));
7690
					unknownCommands->pushBack(cmd, rest);
7686
			}
7691
			}
7687
		}
7692
		}
7688
	}
7693
	}
7689
 
7694
 
7690
	if ( package->filename().empty() )
7695
	if ( package->filename().empty() )
7691
		package->LoadPackageData("AutoSave", "$AUTOSAVE", sMainGame, otherGames, gameAddons);
7696
		package->LoadPackageData("AutoSave", "$AUTOSAVE", sMainGame, otherGames, gameAddons);
7692
 
7697
 
-
 
7698
	if (package->autoExtraction())
-
 
7699
	{
-
 
7700
		for (auto itr = package->autoExtraction()->begin(); itr != package->autoExtraction()->end(); itr++)
-
 
7701
		{
-
 
7702
			unsigned int game = itr->first;
-
 
7703
			for (auto node = package->fileList()->Front(); node; node = node->next())
-
 
7704
			{
-
 
7705
				C_File *f = node->Data();
-
 
7706
				if (f->game() && f->game() != GAME_ALLNEW && !(f->game() & (1 << game)))
-
 
7707
					continue;
-
 
7708
				package->extractFile(f, itr->second, game, gameAddons);
-
 
7709
			}
-
 
7710
		}
-
 
7711
	}
-
 
7712
 
-
 
7713
	if (package->autoExporter())
-
 
7714
	{
-
 
7715
		for (auto itr = package->autoExporter()->begin(); itr != package->autoExporter()->end(); itr++)
-
 
7716
			package->saveToArchive(itr->second, itr->first, &m_gameExe);
-
 
7717
	}
-
 
7718
 
7693
	if ( !ftpaddr.Empty() )
7719
	if ( !ftpaddr.Empty() )
7694
	{
7720
	{
7695
		if ( !ftpuser.Empty() )
7721
		if ( !ftpuser.Empty() )
7696
		{
7722
		{
7697
			if ( !ftppass.Empty() )
7723
			if ( !ftppass.Empty() )
Line 8951... Line 8977...
8951
	}
8977
	}
8952
 
8978
 
8953
	return archive;
8979
	return archive;
8954
}
8980
}
8955
 
8981
 
8956
CyString CPackages::CreateFromPackagerScript(CyString filename)
8982
Utils::String CPackages::CreateFromPackagerScript(CPackages *packages, const Utils::String &filename)
8957
{
8983
{
8958
	CyString curDir = CFileIO(filename).dir();
8984
	Utils::String curDir = CFileIO(filename).dir();
8959
	CyStringList variables;
8985
	Utils::CStringList variables;
8960
	variables.PushBack("$PATH", curDir);
8986
	variables.pushBack("$PATH", curDir);
8961
	CPackages p;
-
 
8962
	CBaseFile *package = p.LoadPackagerScript(filename, NULL, NULL, NULL, &variables);
8987
	CBaseFile *package = packages->LoadPackagerScript(filename, NULL, NULL, NULL, &variables);
8963
 
8988
 
8964
	if ( !package )
8989
	if ( !package )
8965
		return NullString;
8990
		return Utils::String::Null();
8966
 
8991
 
8967
	CyString saveto = package->filename();
8992
	Utils::String saveto = package->filename();
8968
	saveto = saveto.FindReplace("$DEFAULTDIR", curDir + "/");
8993
	saveto = saveto.findReplace("$DEFAULTDIR", curDir + "/");
8969
	saveto = saveto.FindReplace("$PATH", curDir);
8994
	saveto = saveto.findReplace("$PATH", curDir);
8970
	saveto = saveto.FindReplace("\\", "/");
8995
	saveto = saveto.findReplace("\\", "/");
8971
	saveto = saveto.FindReplace("//", "/");
8996
	saveto = saveto.findReplace("//", "/");
8972
	if ( !saveto.Right(4).Compare(".spk") && package->GetType() != TYPE_XSP )
8997
	if ( !saveto.right(4).Compare(".spk") && package->GetType() != TYPE_XSP )
8973
		saveto += ".spk";
8998
		saveto += ".spk";
8974
	else if ( !saveto.Right(4).Compare(".xsp") && package->GetType() == TYPE_XSP )
8999
	else if ( !saveto.right(4).Compare(".xsp") && package->GetType() == TYPE_XSP )
8975
		saveto += ".xsp";
9000
		saveto += ".xsp";
8976
 
9001
 
8977
	// write script
9002
	// write script
8978
	if ( package->WriteFile(saveto) )
9003
	if ( package->WriteFile(saveto) )
8979
	{
9004
	{
8980
		if ( package->AutoGenerateUpdateFile() )
9005
		if ( package->AutoGenerateUpdateFile() )
8981
			package->CreateUpdateFile(CFileIO(saveto).dir());
9006
			package->CreateUpdateFile(CFileIO(saveto).dir());
8982
		return saveto;
9007
		return saveto;
8983
	}
9008
	}
8984
 
9009
 
8985
	return NullString;
9010
	return Utils::String::Null();
8986
}
9011
}
8987
 
9012
 
8988
int CPackages::GeneratePackageUpdateData(CyString dir, bool includeSingle)
9013
int CPackages::GeneratePackageUpdateData(CyString dir, bool includeSingle)
8989
{
9014
{
8990
	Utils::CStringList filedata;
9015
	Utils::CStringList filedata;