Subversion Repositories spk

Rev

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

Rev 127 Rev 129
Line 880... Line 880...
880
 
880
 
881
	spkfile.WriteFile ( filename, NULL );
881
	spkfile.WriteFile ( filename, NULL );
882
	printf ( "SPK file has been written to disk: %s\n", filename.c_str() );
882
	printf ( "SPK file has been written to disk: %s\n", filename.c_str() );
883
}
883
}
884
 
884
 
885
void ExtractFiles ( CyString sfile, CyString dir, int game )
885
void ExtractFiles (const Utils::String &sfile, const Utils::String &dir, int game )
886
{
886
{
887
	// First checks if the file exists by opening it
887
	// First checks if the file exists by opening it
888
	FILE *id = fopen ( sfile.c_str(), "rb+" );
888
	FILE *id = fopen ( sfile.c_str(), "rb+" );
889
	if ( !id )
889
	if ( !id )
890
	{
890
	{
891
		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
891
		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
892
		return;
892
		return;
893
	}
893
	}
894
	fclose ( id );
894
	fclose ( id );
-
 
895
 
-
 
896
	CPackages packages;
-
 
897
	packages.startup(".", ".", ".");
895
 
898
 
896
	int check = CSpkFile::CheckFile ( sfile );
899
	int check = CSpkFile::CheckFile ( sfile );
897
 
900
 
898
	// extracts a file from single packages file
901
	// extracts a file from single packages file
899
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
902
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
Line 911... Line 914...
911
		// reads the file into memory
914
		// reads the file into memory
912
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
915
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
913
		if ( !pBaseFile->ReadFile ( sfile, SPKREAD_NODATA ) )
916
		if ( !pBaseFile->ReadFile ( sfile, SPKREAD_NODATA ) )
914
		{
917
		{
915
			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
918
			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
916
			return;
919
			return;
917
		}
920
		}
918
		printf ( "(Done)\n" );
921
		printf ( "(Done)\n" );
919
 
922
 
920
		printf ( "Extracting all files from archive..." );
923
		printf ( "Extracting all files from archive..." );
921
		if ( pBaseFile->ExtractAll ( dir, game ) )
924
		if (packages.extractAll(pBaseFile, dir, game) )
922
			printf ( "(Done)\nFiles have been extracted successfully\n" );
925
			printf ( "(Done)\nFiles have been extracted successfully\n" );
923
		else
926
		else
924
			printf ( "(Error)\nThere was a problem extracting the files\n" );
927
			printf ( "(Error)\nThere was a problem extracting the files\n" );
925
	}
928
	}
926
	else
929
	else
927
		printf("Invalid package file, %s\n", sfile.c_str());
930
		printf("Invalid package file, %s\n", sfile.c_str());
928
}
931
}
929
 
932
 
930
 
933
 
931
/*
934
/*
932
	Func:	AppendMultiFile
935
	Func:	AppendMultiFile
933
	Args:	String toFile	- The spk file to append onto
936
	Args:	String toFile	- The spk file to append onto
Line 979... Line 982...
979
		else
982
		else
980
			printf ( "(Error)\n" );
983
			printf ( "(Error)\n" );
981
	}
984
	}
982
	else
985
	else
983
		printf ( "Error: Unable to add files, %s, to Multi-Spk Package\n", addfile.c_str() );
986
		printf ( "Error: Unable to add files, %s, to Multi-Spk Package\n", addfile.c_str() );
984
}
987
}
985
 
988
 
986
/*
989
/*
987
	Func:	ExtractFile
990
	Func:	ExtractFile
988
	Args:	String sfile	- the spk file to read from
991
	Args:	String sfile	- the spk file to read from
989
			String type		- the type of the file to find
992
			String type		- the type of the file to find
990
			String addfile	- The filename to extract
993
			String addfile	- The filename to extract
Line 1247... Line 1250...
1247
			}
1250
			}
1248
 
1251
 
1249
			if (filedata.empty())
1252
			if (filedata.empty())
1250
				printf("unable to find any packages");
1253
				printf("unable to find any packages");
1251
			else				
1254
			else				
1252
			{
1255
			{
1253
				Utils::String dest = Dir.file("xpackagedata.dat");
1256
				Utils::String dest = Dir.file("xpackagedata.dat");
1254
				if (CFileIO(dest).writeFile(&filedata))
1257
				if (CFileIO(dest).writeFile(&filedata))
1255
					printf("web update file, xpackagedata.dat, generated");
1258
					printf("web update file, xpackagedata.dat, generated");
1256
				else
1259
				else
1257
					printf("unable to write update file");
1260
					printf("unable to write update file");
1258
			}
1261
			}
1259
		}
1262
		}
1260
	}
1263
	}
1261
}
1264
}
1262
 
1265
 
1263
void GenerateUpdateFile(CyString spkfile)
1266
void GenerateUpdateFile(CyString spkfile)
1264
{
1267
{
1265
	if ( !CFileIO(spkfile).ExistsOld() )
1268
	if ( !CFileIO(spkfile).ExistsOld() )
1266
	{
1269
	{
1267
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1270
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1268
		return;
1271
		return;
1269
	}
1272
	}
1270
 
1273
 
1271
	int check = CSpkFile::CheckFile(spkfile);
1274
	int check = CSpkFile::CheckFile(spkfile);
1272
	if ( check == SPKFILE_MULTI )
1275
	if ( check == SPKFILE_MULTI )
1273
	{
1276
	{
1274
		printf("Error: Multi-Package files currently not supported\n");
1277
		printf("Error: Multi-Package files currently not supported\n");
1275
		return;
1278
		return;
1276
	}
1279
	}
1277
	else if ( check == SPKFILE_OLD )
1280
	else if ( check == SPKFILE_OLD )
1278
	{
1281
	{
Line 1289... Line 1292...
1289
	int error;
1292
	int error;
1290
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1293
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1291
	if ( !package )
1294
	if ( !package )
1292
	{
1295
	{
1293
		printf("Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
1296
		printf("Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
1294
		return;
1297
		return;
1295
	}
1298
	}
1296
 
1299
 
1297
	Utils::String file = package->CreateUpdateFile(CFileIO(spkfile).dir()).ToString();
1300
	Utils::String file = package->CreateUpdateFile(CFileIO(spkfile).dir()).ToString();
1298
	if ( file.empty() )
1301
	if ( file.empty() )
1299
		printf("Error: unable to create update file for: %s, Directory=%s\n", spkfile.c_str(), CFileIO(spkfile).dir().c_str());
1302
		printf("Error: unable to create update file for: %s, Directory=%s\n", spkfile.c_str(), CFileIO(spkfile).dir().c_str());
1300
	else
1303
	else
1301
		printf("Update file: %s has been created for package, %s\n", file.c_str(), spkfile.c_str());
1304
		printf("Update file: %s has been created for package, %s\n", file.c_str(), spkfile.c_str());
1302
 
1305
 
1303
	delete package;
1306
	delete package;
1304
 
1307
 
1305
}
1308
}
1306
 
1309
 
1307
void GeneratePackagerScript(const Utils::String &spkfile, CyString toFile, int game)
1310
void GeneratePackagerScript(const Utils::String &spkfile, CyString toFile, int game)
1308
{
1311
{
1309
	if (!CFileIO::Exists(spkfile))
1312
	if (!CFileIO::Exists(spkfile))
1310
	{
1313
	{
1311
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1314
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1312
		return;
1315
		return;
1313
	}
1316
	}
1314
 
1317
 
1315
	int check = CSpkFile::CheckFile(spkfile);
1318
	int check = CSpkFile::CheckFile(spkfile);
1316
	if ( check == SPKFILE_MULTI )
1319
	if ( check == SPKFILE_MULTI )
1317
	{
1320
	{
1318
		printf("Error: Cant generate a script from a multi-spk file\n");
1321
		printf("Error: Cant generate a script from a multi-spk file\n");
1319
		return;
1322
		return;
1320
	}
1323
	}
1321
	else if ( check == SPKFILE_OLD )
1324
	else if ( check == SPKFILE_OLD )
1322
	{
1325
	{
Line 1334... Line 1337...
1334
	int error;
1337
	int error;
1335
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1338
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1336
	if ( !package )
1339
	if ( !package )
1337
	{
1340
	{
1338
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1341
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1339
		return;
1342
		return;
1340
	}
1343
	}
1341
 
1344
 
1342
	Utils::CStringList list;
1345
	Utils::CStringList list;
1343
	if ( !p.generatePackagerScript(package, true, &list, game) )
1346
	if ( !p.generatePackagerScript(package, true, &list, game) )
1344
	{
1347
	{
1345
		printf("Error: Unable to generate packager script\n");
1348
		printf("Error: Unable to generate packager script\n");
1346
		return;
1349
		return;
Line 1513... Line 1516...
1513
			}
1516
			}
1514
		}
1517
		}
1515
	}
1518
	}
1516
 
1519
 
1517
	// get the command flag
1520
	// get the command flag
1518
	CyString command(argv[1]);
1521
	CyString command(argv[1]);
1519
 
1522
 
1520
	// display the contents of the spk file
1523
	// display the contents of the spk file
1521
	if ( command == "-v" || command == "--version" )
1524
	if ( command == "-v" || command == "--version" )
1522
	{
1525
	{
1523
		if ( argc < 3 )
1526
		if ( argc < 3 )
1524
			printf ( "Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.c_str() );
1527
			printf ( "Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.c_str() );
Line 1535... Line 1538...
1535
			CreateFile ( argv[2] );
1538
			CreateFile ( argv[2] );
1536
	}
1539
	}
1537
 
1540
 
1538
	// appends a file onto the spk archive
1541
	// appends a file onto the spk archive
1539
	else if ( command == "-a" || command == "--append" )
1542
	else if ( command == "-a" || command == "--append" )
1540
	{
1543
	{
1541
		if ( argc < 4 )
1544
		if ( argc < 4 )
1542
			printf ( "Syntax:\n\t%s -a <spkfile> <type> <filename>\n\t%s --append <spkfile> <type> <filename>\n\t\tThis will append the file into the archive and compress it according to the files default compression\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
1545
			printf ( "Syntax:\n\t%s -a <spkfile> <type> <filename>\n\t%s --append <spkfile> <type> <filename>\n\t\tThis will append the file into the archive and compress it according to the files default compression\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
1543
		else
1546
		else
1544
		{
1547
		{
1545
			CyString arg4;
1548
			CyString arg4;
1546
			if ( argc > 4 )
1549
			if ( argc > 4 )
Line 1554... Line 1557...
1554
	{
1557
	{
1555
		if ( argc < 4 )
1558
		if ( argc < 4 )
1556
		{
1559
		{
1557
			printf ( "Syntax:\n\t%s -r <spkfile> <type> <filename>\n\t%s --remove <spkfile> <type> <filename\n\t\tThis will remove a file from the archive\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
1560
			printf ( "Syntax:\n\t%s -r <spkfile> <type> <filename>\n\t%s --remove <spkfile> <type> <filename\n\t\tThis will remove a file from the archive\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
1558
			printf ( "\t%s -r <multispkfile> <filename>\n\t%s --removespk <multispkfile> <filename>\n\t\tThis will remove a spk file from the Multi-SPK package\n", cmd.c_str(), cmd.c_str() );
1561
			printf ( "\t%s -r <multispkfile> <filename>\n\t%s --removespk <multispkfile> <filename>\n\t\tThis will remove a spk file from the Multi-SPK package\n", cmd.c_str(), cmd.c_str() );
1559
		}
1562
		}
1560
		else
1563
		else
1561
		{
1564
		{
1562
			CyString arg4;
1565
			CyString arg4;
1563
			if ( argc > 4 )
1566
			if ( argc > 4 )
1564
				arg4 = argv[4];
1567
				arg4 = argv[4];
1565
			RemoveFile ( argv[2], argv[3], arg4 );
1568
			RemoveFile ( argv[2], argv[3], arg4 );
1566
		}
1569
		}
1567
	}
1570
	}
1568
 
1571
 
1569
	// extracts a file from a spk file
1572
	// extracts a file from a spk file
1570
	else if ( command == "--extractspk" )
1573
	else if ( command == "--extractspk" )
1571
	{
1574
	{
1572
		if ( argc < 4 )
1575
		if ( argc < 4 )
1573
			printf ( "Syntax:\n\t%s --extractspk <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
1576
			printf ( "Syntax:\n\t%s --extractspk <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
1574
		else
1577
		else
1575
		{
1578
		{
1576
			CyString arg4;
1579
			CyString arg4;
1577
			if ( argc > 4 )
1580
			if ( argc > 4 )
1578
				arg4 = argv[3];
1581
				arg4 = argv[3];
1579
			ExtractFile ( argv[2], argv[3], arg4, NullString );
1582
			ExtractFile ( argv[2], argv[3], arg4, NullString );
1580
		}
1583
		}
1581
	}
1584
	}
1582
	else if ( command == "-x" || command == "--extract")
1585
	else if ( command == "-x" || command == "--extract")
1583
	{
1586
	{
1584
		if ( argc < 4 )
1587
		if ( argc < 4 )
1585
		{
1588
		{
1586
			printf ( "Syntax:\n\t%s -x <spkfile> <type> <filename> [destination]\n\tThis will extract a file from the package and save it to the corect path in <directory>\n\t<type> = %s\n", cmd.c_str(), fileTypes.c_str() );
1589
			printf ( "Syntax:\n\t%s -x <spkfile> <type> <filename> [destination]\n\tThis will extract a file from the package and save it to the corect path in <directory>\n\t<type> = %s\n", cmd.c_str(), fileTypes.c_str() );
1587
			printf ( "\t%s -x <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
1590
			printf ( "\t%s -x <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
1588
		}
1591
		}
1589
		else
1592
		else
1590
		{
1593
		{
Line 1602... Line 1605...
1602
	{
1605
	{
1603
		if ( argc < 3 )
1606
		if ( argc < 3 )
1604
			printf ( "Syntax:\n\t%s -e <spkfile> [destination]\n\t--extractall <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.c_str() );
1607
			printf ( "Syntax:\n\t%s -e <spkfile> [destination]\n\t--extractall <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.c_str() );
1605
		else
1608
		else
1606
		{
1609
		{
1607
			CyString arg4;
1610
			Utils::String arg4;
1608
			if ( argc > 4 )
1611
			if ( argc > 4 )
1609
				arg4 = argv[4];
1612
				arg4 = argv[4];
1610
			ExtractFiles ( argv[2], arg4, atoi(argv[3]) );
1613
			ExtractFiles(argv[2], arg4, atoi(argv[3]) );
1611
		}
1614
		}
1612
	}
1615
	}
1613
 
1616
 
1614
	// creates a multispk archive
1617
	// creates a multispk archive
1615
	else if ( command == "-n" || command == "--createmulti" )
1618
	else if ( command == "-n" || command == "--createmulti" )