Subversion Repositories spk

Rev

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

Rev 311 Rev 315
Line 959... Line 959...
959
 
959
 
960
	spkfile.writeFile(filename, NULL);
960
	spkfile.writeFile(filename, NULL);
961
	wprintf(L"SPK file has been written to disk: %s\n", filename.c_str() );
961
	wprintf(L"SPK file has been written to disk: %s\n", filename.c_str() );
962
}
962
}
963
 
963
 
964
void ExtractFiles (const Utils::WString &sfile, const Utils::WString &dir, int game )
964
void ExtractFiles (const Utils::CommandLine &cmd)
965
{
965
{
-
 
966
	const Utils::WString& sfile = cmd.arg(1);
-
 
967
	const Utils::WString & dir = cmd.arg(2);
-
 
968
	int game = (cmd.hasSwitch(L"game")) ? CBaseFile::GetGameFromString(cmd.switchData(L"game")) : 0;
-
 
969
 
966
	// First checks if the file exists by opening it
970
	// First checks if the file exists by opening it
-
 
971
	CFileIO File(sfile);
-
 
972
	if (!File.exists())
967
	FILE *id = _wfopen(sfile.c_str(), L"rb+");
973
		File.open(CDirIO(g_dir).file(sfile));
968
	if ( !id )
974
	if (!File.exists())
969
	{
975
	{
970
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
976
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
971
		return;
977
		return;
972
	}
978
	}
973
	fclose ( id );
-
 
974
 
979
 
975
	CPackages packages;
980
	CPackages packages;
976
	packages.startup(L".", L".", L".");
981
	packages.startup(L".", L".", L".");
977
 
982
 
978
	int check = CSpkFile::CheckFile ( sfile );
983
	int check = CSpkFile::CheckFile(File.fullFilename());
979
 
984
 
980
	// extracts a file from single packages file
985
	// extracts a file from single packages file
981
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
986
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
982
	{
987
	{
983
		// creates the spkfile object
988
		// creates the spkfile object
Line 990... Line 995...
990
			pBaseFile = new CBaseFile();
995
			pBaseFile = new CBaseFile();
991
 
996
 
992
		wprintf(L"Opening File, %s... ", sfile.c_str());
997
		wprintf(L"Opening File, %s... ", sfile.c_str());
993
		// reads the file into memory
998
		// reads the file into memory
994
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
999
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
995
		if ( !pBaseFile->readFile(sfile, SPKREAD_NODATA))
1000
		if ( !pBaseFile->readFile(File.fullFilename(), SPKREAD_NODATA))
996
		{
1001
		{
997
			wprintf(L"(Error)\nUnable to open the file, %s\n", sfile.c_str() );
1002
			wprintf(L"(Error)\nUnable to open the file, %s\n", sfile.c_str() );
998
			return;
1003
			return;
999
		}
1004
		}
1000
		wprintf(L"(Done)\n");
1005
		wprintf(L"(Done)\n");
Line 1003... Line 1008...
1003
			wprintf(L"Extracting all files from archive...\n\n");
1008
			wprintf(L"Extracting all files from archive...\n\n");
1004
		else
1009
		else
1005
			wprintf(L"Extracting %s files from archive...\n\n", packages.GetGameExe()->gameNameFromType(game - 1).c_str());
1010
			wprintf(L"Extracting %s files from archive...\n\n", packages.GetGameExe()->gameNameFromType(game - 1).c_str());
1006
 
1011
 
1007
		CFileProgress info(&packages, pBaseFile, "Extracting");
1012
		CFileProgress info(&packages, pBaseFile, "Extracting");
1008
		if (packages.extractAll(pBaseFile, dir, game, true, &info) )
1013
		if (packages.extractAll(pBaseFile, File.dirIO().dir(dir), game, true, &info) )
1009
			wprintf(L"\n(Done)\nFiles have been extracted successfully\n");
1014
			wprintf(L"\n(Done)\nFiles have been extracted successfully\n");
1010
		else
1015
		else
1011
			wprintf(L"\n(Error)\nThere was a problem extracting the files\n");
1016
			wprintf(L"\n(Error)\nThere was a problem extracting the files\n");
1012
	}
1017
	}
1013
	else
1018
	else
Line 1148... Line 1153...
1148
		// creates the directory so it can be extracted
1153
		// creates the directory so it can be extracted
1149
		CDirIO Dir(dir);
1154
		CDirIO Dir(dir);
1150
		if ( !Dir.create(f->getDirectory(pBaseFile)) )
1155
		if ( !Dir.create(f->getDirectory(pBaseFile)) )
1151
		{
1156
		{
1152
			wprintf(L"Unable to create the directory \"%s\" to extract into\n", dir.c_str());
1157
			wprintf(L"Unable to create the directory \"%s\" to extract into\n", dir.c_str());
1153
			return;
1158
			return;
1154
		}
1159
		}
1155
 
1160
 
1156
		// sets up the progress pointer
1161
		// sets up the progress pointer
1157
		// if it uses 7zip, the progress will be displayed in the command prompt
1162
		// if it uses 7zip, the progress will be displayed in the command prompt
1158
		MyProgress progress(0);
1163
		MyProgress progress(0);
Line 1329... Line 1334...
1329
				if(!p->description().empty())
1334
				if(!p->description().empty())
1330
					wprintf(L"\t\t%s\n", p->description().c_str());
1335
					wprintf(L"\t\t%s\n", p->description().c_str());
1331
 
1336
 
1332
				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
1337
				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
1333
				delete p;
1338
				delete p;
1334
			}
1339
			}
1335
 
1340
 
1336
			if (filedata.empty())
1341
			if (filedata.empty())
1337
				wprintf(L"unable to find any packages");
1342
				wprintf(L"unable to find any packages");
1338
			else				
1343
			else				
1339
			{
1344
			{
1340
				Utils::WString dest = Dir.file(L"xpackagedata.dat");
1345
				Utils::WString dest = Dir.file(L"xpackagedata.dat");
Line 1342... Line 1347...
1342
					wprintf(L"web update file, xpackagedata.dat, generated");
1347
					wprintf(L"web update file, xpackagedata.dat, generated");
1343
				else
1348
				else
1344
					wprintf(L"unable to write update file");
1349
					wprintf(L"unable to write update file");
1345
			}
1350
			}
1346
		}
1351
		}
1347
	}
1352
	}
1348
}
1353
}
1349
 
1354
 
1350
void GenerateUpdateFile(const Utils::WString &spkfile)
1355
void GenerateUpdateFile(const Utils::WString &spkfile)
1351
{
1356
{
1352
	if (!CFileIO::Exists(spkfile))
1357
	if (!CFileIO::Exists(spkfile))
1353
	{
1358
	{
1354
		wprintf(L"Error: The package file, %s, does not exist", spkfile.c_str());
1359
		wprintf(L"Error: The package file, %s, does not exist", spkfile.c_str());
-
 
1360
		return;
-
 
1361
	}
-
 
1362
 
-
 
1363
	int check = CSpkFile::CheckFile(spkfile);
-
 
1364
	if ( check == SPKFILE_MULTI )
-
 
1365
	{
-
 
1366
		wprintf(L"Error: Multi-Package files currently not supported\n");
-
 
1367
		return;
-
 
1368
	}
-
 
1369
	else if ( check == SPKFILE_OLD )
-
 
1370
	{
-
 
1371
		wprintf(L"Error: unable to read old format spk file, try spkconvert first\n");
1355
		return;
1372
		return;
1356
	}
1373
	}
1357
 
-
 
1358
	int check = CSpkFile::CheckFile(spkfile);
-
 
1359
	if ( check == SPKFILE_MULTI )
1374
	else if ( check == SPKFILE_INVALID )
1360
	{
1375
	{
1361
		wprintf(L"Error: Multi-Package files currently not supported\n");
1376
		wprintf(L"Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
1362
		return;
1377
		return;
1363
	}
1378
	}
-
 
1379
 
-
 
1380
	CPackages p;
-
 
1381
	int error;
-
 
1382
	CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
1364
	else if ( check == SPKFILE_OLD )
1383
	if ( !package )
1365
	{
1384
	{
1366
		wprintf(L"Error: unable to read old format spk file, try spkconvert first\n");
-
 
1367
		return;
-
 
1368
	}
-
 
1369
	else if ( check == SPKFILE_INVALID )
-
 
1370
	{
-
 
1371
		wprintf(L"Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
-
 
1372
		return;
-
 
1373
	}
-
 
1374
 
-
 
1375
	CPackages p;
-
 
1376
	int error;
-
 
1377
	CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
-
 
1378
	if ( !package )
-
 
1379
	{
-
 
1380
		wprintf(L"Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
1385
		wprintf(L"Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
1381
		return;
1386
		return;
1382
	}
1387
	}
1383
 
1388
 
1384
	Utils::WString file = package->createUpdateFile(CFileIO(spkfile).dir());
1389
	Utils::WString file = package->createUpdateFile(CFileIO(spkfile).dir());
1385
	if ( file.empty() )
1390
	if ( file.empty() )
Line 1399... Line 1404...
1399
		return;
1404
		return;
1400
	}
1405
	}
1401
 
1406
 
1402
	int check = CSpkFile::CheckFile(spkfile);
1407
	int check = CSpkFile::CheckFile(spkfile);
1403
	if ( check == SPKFILE_MULTI )
1408
	if ( check == SPKFILE_MULTI )
1404
	{
1409
	{
1405
		wprintf(L"Error: Cant generate a script from a multi-spk file\n");
1410
		wprintf(L"Error: Cant generate a script from a multi-spk file\n");
1406
		return;
1411
		return;
1407
	}
1412
	}
1408
	else if ( check == SPKFILE_OLD )
1413
	else if ( check == SPKFILE_OLD )
1409
	{
1414
	{
Line 1421... Line 1426...
1421
	int error;
1426
	int error;
1422
	CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
1427
	CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
1423
	if ( !package )
1428
	if ( !package )
1424
	{
1429
	{
1425
		wprintf(L"Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1430
		wprintf(L"Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1426
		return;
1431
		return;
1427
	}
1432
	}
1428
 
1433
 
1429
	Utils::WStringList list;
1434
	Utils::WStringList list;
1430
	if ( !p.generatePackagerScript(package, true, &list, game) )
1435
	if ( !p.generatePackagerScript(package, true, &list, game) )
1431
	{
1436
	{
Line 1489... Line 1494...
1489
	CBaseFile *package = p.loadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables, &info);
1494
	CBaseFile *package = p.loadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables, &info);
1490
 
1495
 
1491
	printf("\n");
1496
	printf("\n");
1492
 
1497
 
1493
	if ( verify )
1498
	if ( verify )
1494
	{
1499
	{
1495
		if ( !malformed.empty() )
1500
		if ( !malformed.empty() )
1496
		{
1501
		{
1497
			printf("Malformed Lines (%lu):\n", static_cast<unsigned long>(malformed.size()));
1502
			printf("Malformed Lines (%lu):\n", static_cast<unsigned long>(malformed.size()));
1498
			for(auto itr = malformed.begin(); itr != malformed.end(); itr++)				
1503
			for(auto itr = malformed.begin(); itr != malformed.end(); itr++)				
1499
				wprintf(L"\t(Line %3d) %s\n", (*itr)->data.toInt(), (*itr)->str.c_str());
1504
				wprintf(L"\t(Line %3d) %s\n", (*itr)->data.toInt(), (*itr)->str.c_str());
Line 1512... Line 1517...
1512
			printf("Error: There are errors in the packager script which prevents it from being created\n");
1517
			printf("Error: There are errors in the packager script which prevents it from being created\n");
1513
		else
1518
		else
1514
			wprintf(L"Error: Unable to create package, from script: %s\n", filename.c_str());
1519
			wprintf(L"Error: Unable to create package, from script: %s\n", filename.c_str());
1515
	}
1520
	}
1516
	else
1521
	else
1517
	{
1522
	{
1518
		Utils::WString saveto = package->filename();
1523
		Utils::WString saveto = package->filename();
1519
		saveto = saveto.findReplace(L"$DEFAULTDIR", curDir + L"/");
1524
		saveto = saveto.findReplace(L"$DEFAULTDIR", curDir + L"/");
1520
		saveto = saveto.findReplace(L"$PATH", curDir);
1525
		saveto = saveto.findReplace(L"$PATH", curDir);
1521
		saveto = saveto.findReplace(L"\\", L"/");
1526
		saveto = saveto.findReplace(L"\\", L"/");
1522
		saveto = saveto.findReplace(L"//", L"/");
1527
		saveto = saveto.findReplace(L"//", L"/");
Line 1694... Line 1699...
1694
 
1699
 
1695
	// extracts all the files from an archive
1700
	// extracts all the files from an archive
1696
	else if ( command == L"-e" || command == L"-extractall" )
1701
	else if ( command == L"-e" || command == L"-extractall" )
1697
	{
1702
	{
1698
		if ( argc < 3 )
1703
		if ( argc < 3 )
1699
			wprintf(L"Syntax:\n\t%s -e <spkfile> [destination]\n\t-extractall &lt;spkfile>; <game> [destination]\n\t\tThis will extract all files of a set game into the destination directory\n\n\t\tGame = 0 will extract all files", cmd.cmdName().c_str() );
1704
			wprintf(L"Syntax:\n\t%s -e <spkfile> [destination]\n\t-extractall --game:<game&gt; <spkfile> [destination]\n\t\tThis will extract all files of a set game into the destination directory\n\n\t\tGame = 0 will extract all files", cmd.cmdName().c_str() );
1700
		else
1705
		else
1701
		{
-
 
1702
			Utils::WString arg4;
-
 
1703
			if ( argc > 4 )
-
 
1704
				arg4 = argv[4];
1706
			ExtractFiles(cmd);
1705
			ExtractFiles(argv[2], arg4, CBaseFile::GetGameFromString(argv[3]));
-
 
1706
		}
-
 
1707
	}
1707
	}
1708
 
1708
 
1709
	// creates a multispk archive
1709
	// creates a multispk archive
1710
	else if ( command == L"-n" || command == L"-createmulti" )
1710
	else if ( command == L"-n" || command == L"-createmulti" )
1711
	{
1711
	{