Subversion Repositories spk

Rev

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

Rev 116 Rev 126
Line 70... Line 70...
70
	printf ( "\t--createscript <packagescript>\n\t\tCreates a spk file from a packager script\n\n");
70
	printf ( "\t--createscript <packagescript>\n\t\tCreates a spk file from a packager script\n\n");
71
	printf ( "\t--verifyscript <packagescript>\n\t\tChecks a packager script is valid without creating the resulting file\n\n");
71
	printf ( "\t--verifyscript <packagescript>\n\t\tChecks a packager script is valid without creating the resulting file\n\n");
72
	printf ( "\t--generatescript <package> [packagescript]\n\t\tCreates a packager script (.sps) from a spk file\n\n");
72
	printf ( "\t--generatescript <package> [packagescript]\n\t\tCreates a packager script (.sps) from a spk file\n\n");
73
	printf ( "\t--extractship <modfile> <xspfile> [shipid]\n\t\tCreates an XSP ship file from a mod package\n\n");
73
	printf ( "\t--extractship <modfile> <xspfile> [shipid]\n\t\tCreates an XSP ship file from a mod package\n\n");
74
	printf ( "\t--generateupdatefile <package>\n\t\tCreates an update file for the spk/xsp file\n\n");
74
	printf ( "\t--generateupdatefile <package>\n\t\tCreates an update file for the spk/xsp file\n\n");
-
 
75
	printf ( "\t--packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n\n");
75
//	printf ( "\t--convertxspwizard <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
76
	//	printf ( "\t--convertxspwizard <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
76
}
77
}
77
 
78
 
78
void Settings(CyString filename, CyString settings, int argc, char **argv, CyString cmd)
79
void Settings(CyString filename, CyString settings, int argc, char **argv, CyString cmd)
79
{
80
{
80
	if ( settings.Compare("author") )
81
	if ( settings.Compare("author") )
Line 349... Line 350...
349
			return "X3: Reunion";
350
			return "X3: Reunion";
350
		case GAME_X3TC:
351
		case GAME_X3TC:
351
			return "X3: Terran Conflict";
352
			return "X3: Terran Conflict";
352
		case GAME_X3AP:
353
		case GAME_X3AP:
353
			return "X3: Albion Prelude";
354
			return "X3: Albion Prelude";
-
 
355
		case GAME_X3FL:
-
 
356
			return "X3: Farnham's Legacy";
354
		case GAME_XREBIRTH:
357
		case GAME_XREBIRTH:
355
			return "X: Rebirth";
358
			return "X: Rebirth";
356
	}
359
	}
357
	return "Unknown";
360
	return "Unknown";
358
}
361
}
Line 1146... Line 1149...
1146
 
1149
 
1147
CyString GetAsk(CyString command)
1150
CyString GetAsk(CyString command)
1148
{
1151
{
1149
	printf("(ASK) Enter the value for, %s: ", command.c_str());
1152
	printf("(ASK) Enter the value for, %s: ", command.c_str());
1150
	return GetInput();
1153
	return GetInput();
-
 
1154
}
-
 
1155
 
-
 
1156
void GenerateUpdateList(int argc, char **argv)
-
 
1157
{
-
 
1158
	Utils::String currentDir = CFileIO(argv[0]).dir();
-
 
1159
	CDirIO Dir(currentDir);
-
 
1160
 
-
 
1161
	Utils::CStringList list;
-
 
1162
	for (int i = 2; i < argc; ++i)
-
 
1163
	{
-
 
1164
		Utils::String file(argv[i]);
-
 
1165
		if (CFileIO::Exists(file))
-
 
1166
			list.pushBack(file, "file");
-
 
1167
		else if (CFileIO::Exists(Dir.file(file)))
-
 
1168
			list.pushBack(Dir.file(file), "file");
-
 
1169
		else if (CDirIO::Exists(file))
-
 
1170
			list.pushBack(file, "dir");
-
 
1171
		else if (CDirIO::Exists(Dir.dir(file)))
-
 
1172
			list.pushBack(Dir.dir(file), "dir");
-
 
1173
		else
-
 
1174
			list.pushBack(file, "pattern");
-
 
1175
	}
-
 
1176
 
-
 
1177
	if (list.empty())
-
 
1178
		printf("unable to find any packages");
-
 
1179
	else
-
 
1180
	{
-
 
1181
		Utils::CStringList fileList;
-
 
1182
		for (auto itr = list.begin(); itr != list.end(); itr++)
-
 
1183
		{
-
 
1184
			Utils::String file = (*itr)->str;
-
 
1185
			Utils::String data = (*itr)->data;
-
 
1186
			if (data == "file")
-
 
1187
				fileList.pushBack(file);
-
 
1188
			else if (data == "dir")
-
 
1189
			{
-
 
1190
				CDirIO dir(file);
-
 
1191
				Utils::CStringList d;
-
 
1192
				if (dir.dirList(d))
-
 
1193
				{
-
 
1194
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
-
 
1195
					{
-
 
1196
						Utils::String ext = CFileIO((*itr2)->str).extension().lower();
-
 
1197
						if(ext == "xsp" || ext == "spk")
-
 
1198
							fileList.pushBack(dir.file((*itr2)->str));
-
 
1199
					}
-
 
1200
				}
-
 
1201
			}
-
 
1202
			else if (data == "pattern")
-
 
1203
			{				
-
 
1204
				CFileIO f(file);
-
 
1205
				CDirIO dir(f.dir());
-
 
1206
 
-
 
1207
				if (!dir.exists())
-
 
1208
					dir = CDirIO(Dir.dir(dir.dir()));
-
 
1209
 
-
 
1210
				Utils::CStringList d;
-
 
1211
				if (dir.dirList(d, Utils::String::Null(), f.filename()))
-
 
1212
				{
-
 
1213
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
-
 
1214
					{
-
 
1215
						Utils::String ext = CFileIO((*itr2)->str).extension().lower();
-
 
1216
						if (ext == "xsp" || ext == "spk")
-
 
1217
							fileList.pushBack(dir.file((*itr2)->str));
-
 
1218
					}
-
 
1219
				}
-
 
1220
			}
-
 
1221
		}
-
 
1222
 
-
 
1223
		if (fileList.empty())
-
 
1224
			printf("unable to find any packages");
-
 
1225
		else
-
 
1226
		{
-
 
1227
			CPackages packages;
-
 
1228
 
-
 
1229
			Utils::CStringList filedata;
-
 
1230
			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
-
 
1231
			{
-
 
1232
				printf("Reading file: %s\n", (*itr)->str.c_str());
-
 
1233
 
-
 
1234
				int error = 0;
-
 
1235
				CBaseFile *p = packages.OpenPackage((*itr)->str, &error, 0, SPKREAD_NODATA);
-
 
1236
				if (!p)
-
 
1237
				{
-
 
1238
					printf("\tERROR!\n");
-
 
1239
					continue;
-
 
1240
				}
-
 
1241
				printf("\tData extracted: %s %s by %s\n", p->name().c_str(), p->version().c_str(), p->author().c_str());
-
 
1242
				if (!p->creationDate().empty())
-
 
1243
					printf("\t\tCreated: %s\n", p->creationDate().c_str());
-
 
1244
				if(!p->description().empty())
-
 
1245
					printf("\t\t%s\n", p->description().c_str());
-
 
1246
 
-
 
1247
				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
-
 
1248
				delete p;
-
 
1249
			}
-
 
1250
 
-
 
1251
			if (filedata.empty())
-
 
1252
				printf("unable to find any packages");
-
 
1253
			else				
-
 
1254
			{
-
 
1255
				Utils::String dest = Dir.file("xpackagedata.dat");
-
 
1256
				if (CFileIO(dest).writeFile(&filedata))
-
 
1257
					printf("web update file, xpackagedata.dat, generated");
-
 
1258
				else
-
 
1259
					printf("unable to write update file");
-
 
1260
			}
-
 
1261
		}
-
 
1262
	}
1151
}
1263
}
1152
 
1264
 
1153
void GenerateUpdateFile(CyString spkfile)
1265
void GenerateUpdateFile(CyString spkfile)
1154
{
1266
{
1155
	if ( !CFileIO(spkfile).ExistsOld() )
1267
	if ( !CFileIO(spkfile).ExistsOld() )
1156
	{
1268
	{
1157
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1269
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1158
		return;
1270
		return;
1159
	}
1271
	}
1160
 
1272
 
1161
	int check = CSpkFile::CheckFile(spkfile);
1273
	int check = CSpkFile::CheckFile(spkfile);
1162
	if ( check == SPKFILE_MULTI )
1274
	if ( check == SPKFILE_MULTI )
1163
	{
1275
	{
Line 1165... Line 1277...
1165
		return;
1277
		return;
1166
	}
1278
	}
1167
	else if ( check == SPKFILE_OLD )
1279
	else if ( check == SPKFILE_OLD )
1168
	{
1280
	{
1169
		printf("Error: unable to read old format spk file, try spkconvert first\n");
1281
		printf("Error: unable to read old format spk file, try spkconvert first\n");
1170
		return;
1282
		return;
1171
	}
1283
	}
1172
	else if ( check == SPKFILE_INVALID )
1284
	else if ( check == SPKFILE_INVALID )
1173
	{
1285
	{
1174
		printf("Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
1286
		printf("Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
1175
		return;
1287
		return;
1176
	}
1288
	}
1177
 
1289
 
1178
	CPackages p;
1290
	CPackages p;
1179
	int error;
1291
	int error;
1180
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1292
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
Line 1192... Line 1304...
1192
 
1304
 
1193
	delete package;
1305
	delete package;
1194
 
1306
 
1195
}
1307
}
1196
 
1308
 
1197
void GeneratePackagerScript(CyString spkfile, CyString toFile)
1309
void GeneratePackagerScript(const Utils::String &spkfile, CyString toFile, int game)
1198
{
1310
{
1199
	if ( !CFileIO(spkfile).ExistsOld() )
1311
	if (!CFileIO::Exists(spkfile))
1200
	{
1312
	{
1201
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1313
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1202
		return;
1314
		return;
1203
	}
1315
	}
1204
 
1316
 
Line 1226... Line 1338...
1226
	{
1338
	{
1227
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1339
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1228
		return;
1340
		return;
1229
	}
1341
	}
1230
 
1342
 
1231
	CyStringList list;
1343
	Utils::CStringList list;
1232
	if ( !package->GeneratePackagerScript(true, &list) )
1344
	if ( !package->GeneratePackagerScript(true, &list, game) )
1233
	{
1345
	{
1234
		printf("Error: Unable to generate packager script\n");
1346
		printf("Error: Unable to generate packager script\n");
1235
		return;
1347
		return;
1236
	}
1348
	}
1237
 
1349
 
1238
	if ( toFile.Empty() )
1350
	if ( toFile.Empty() )
1239
		toFile = CFileIO(spkfile).GetDirIO().File(package->name() + "_" + package->author() + ".sps");
1351
		toFile = CFileIO(spkfile).GetDirIO().File(package->name() + "_" + package->author() + ".sps");
1240
 
1352
 
1241
	// save package file
1353
	// save package file
1242
	if ( CFileIO(toFile).WriteFile(&list) )
1354
	if ( CFileIO(toFile).writeFile(&list) )
1243
		printf("Packager script, %s, has been geenrated\n", toFile.c_str());
1355
		printf("Packager script, %s, has been geenrated\n", toFile.c_str());
1244
	else
1356
	else
1245
		printf("Error: unable to write packager script, %s\n", toFile.c_str());
1357
		printf("Error: unable to write packager script, %s\n", toFile.c_str());
1246
 
1358
 
1247
	delete package;
1359
	delete package;
Line 1344... Line 1456...
1344
			if ( verify )
1456
			if ( verify )
1345
				printf("Package can be exported from this script\n");
1457
				printf("Package can be exported from this script\n");
1346
			else
1458
			else
1347
			{
1459
			{
1348
				// export
1460
				// export
1349
				if ( package->SaveToArchive(saveto, 0) ) {
1461
				if ( package->SaveToArchive(saveto, 0, p.GetGameExe()) ) {
1350
					if ( package->IsAnyGameInPackage() ) {
1462
					if ( package->IsAnyGameInPackage() ) {
1351
						for ( int i = 0; i < p.GetGameExe()->GetNumGames(); i++ ) {
1463
						for ( int i = 0; i < p.GetGameExe()->GetNumGames(); i++ ) {
1352
							if ( package->IsGameInPackage(i + 1) ) {								
1464
							if ( package->IsGameInPackage(i + 1) ) {								
1353
								Utils::String exportFile = CFileIO(saveto).dir() + "/" + CFileIO(saveto).baseName() + "_" + CBaseFile::ConvertGameToString(i + 1) + "." + CFileIO(saveto).extension();
1465
								Utils::String exportFile = CFileIO(saveto).dir() + "/" + CFileIO(saveto).baseName() + "_" + CBaseFile::ConvertGameToString(i + 1) + "." + CFileIO(saveto).extension();
1354
								package->SaveToArchive(exportFile, i + 1);
1466
								package->SaveToArchive(exportFile, i + 1, p.GetGameExe());
1355
							}
1467
							}
1356
						}
1468
						}
1357
					}
1469
					}
1358
					printf("Package: %s was exported\n", saveto.c_str());
1470
					printf("Package: %s was exported\n", saveto.c_str());
1359
				}
1471
				}
Line 1368... Line 1480...
1368
	Main entry point to program
1480
	Main entry point to program
1369
*/
1481
*/
1370
int main ( int argc, char **argv )
1482
int main ( int argc, char **argv )
1371
{
1483
{
1372
	// display program header to command prompt
1484
	// display program header to command prompt
1373
	printf ( "\nSPKTool V1.42 (SPK File Version %.2f) 03/01/2012 Created by Cycrow\n\n", (float)FILEVERSION );
1485
	printf ( "\nSPKTool V1.50 (SPK File Version %.2f) 14/02/2021 Created by Cycrow\n\n", (float)FILEVERSION );
1374
 
-
 
1375
	//TEST: test new string library
-
 
1376
	CyString a = "a";
-
 
1377
	printf("Test: %s\n", a.c_str());
-
 
1378
	char pause2;
-
 
1379
	scanf ( "%s", &pause2 );
-
 
1380
 
-
 
1381
 
1486
 
1382
	// parse the cmd name
1487
	// parse the cmd name
1383
	CyString cmd (argv[0]);
1488
	CyString cmd (argv[0]);
1384
	cmd = cmd.FindReplace ( "\\", "/" );
1489
	cmd = cmd.FindReplace ( "\\", "/" );
1385
	g_dir = cmd.GetToken ( 0, cmd.NumToken('/') - 1, '/' );
1490
	g_dir = cmd.GetToken ( 0, cmd.NumToken('/') - 1, '/' );
Line 1434... Line 1539...
1434
	// appends a file onto the spk archive
1539
	// appends a file onto the spk archive
1435
	else if ( command == "-a" || command == "--append" )
1540
	else if ( command == "-a" || command == "--append" )
1436
	{
1541
	{
1437
		if ( argc < 4 )
1542
		if ( argc < 4 )
1438
			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
			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() );
1439
		else
1544
		else
1440
		{
1545
		{
1441
			CyString arg4;
1546
			CyString arg4;
1442
			if ( argc > 4 )
1547
			if ( argc > 4 )
1443
				arg4 = argv[4];
1548
				arg4 = argv[4];
1444
			AppendFile ( argv[2], argv[3], arg4 );
1549
			AppendFile ( argv[2], argv[3], arg4 );
1445
		}
1550
		}
1446
	}
1551
	}
1447
 
1552
 
1448
	// removes a file from the spk archive
1553
	// removes a file from the spk archive
1449
	else if ( command == "-r" || command == "--remove" || command == "--removespk" )
1554
	else if ( command == "-r" || command == "--remove" || command == "--removespk" )
1450
	{
1555
	{
1451
		if ( argc < 4 )
1556
		if ( argc < 4 )
1452
		{
1557
		{
1453
			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 ( "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() );
1454
			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
			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() );
1455
		}
1560
		}
1456
		else
1561
		else
1457
		{
1562
		{
1458
			CyString arg4;
1563
			CyString arg4;
1459
			if ( argc > 4 )
1564
			if ( argc > 4 )
1460
				arg4 = argv[4];
1565
				arg4 = argv[4];
1461
			RemoveFile ( argv[2], argv[3], arg4 );
1566
			RemoveFile ( argv[2], argv[3], arg4 );
1462
		}
1567
		}
1463
	}
1568
	}
1464
 
1569
 
Line 1488... Line 1593...
1488
			if ( argc > 5 )
1593
			if ( argc > 5 )
1489
				arg5 = argv[5];
1594
				arg5 = argv[5];
1490
			if ( argc > 4 )
1595
			if ( argc > 4 )
1491
				arg4 = argv[4];
1596
				arg4 = argv[4];
1492
			ExtractFile ( argv[2], argv[3], arg4, arg5 );
1597
			ExtractFile ( argv[2], argv[3], arg4, arg5 );
1493
		}
1598
		}
1494
	}
1599
	}
1495
 
1600
 
1496
	// extracts all the files from an archive
1601
	// extracts all the files from an archive
1497
	else if ( command == "-e" || command == "--extractall" )
1602
	else if ( command == "-e" || command == "--extractall" )
1498
	{
1603
	{
1499
		if ( argc < 3 )
1604
		if ( argc < 3 )
Line 1573... Line 1678...
1573
			LoadPackagerScript ( argv[2], false );
1678
			LoadPackagerScript ( argv[2], false );
1574
	}
1679
	}
1575
	else if ( command == "--generatescript" )
1680
	else if ( command == "--generatescript" )
1576
	{
1681
	{
1577
		if ( argc < 3 )
1682
		if ( argc < 3 )
1578
			printf ( "Syntax:\n\t%s --generatescript <package> [packagerscript]\n\t\tThis will create a spk/xsp file from a packager script\n", cmd.c_str() );
1683
			printf ( "Syntax:\n\t%s --generatescript <package> [packagerscript]\n\t\tThis will generate a packager script file from a spk/xsp file.\n", cmd.c_str() );
1579
		else
1684
		else
1580
		{
1685
		{
1581
			if ( argc < 4 )
1686
			if ( argc < 4 )
1582
				GeneratePackagerScript ( argv[2], "" );
1687
				GeneratePackagerScript ( argv[2], "", 0);
1583
			else
1688
			else
1584
				GeneratePackagerScript ( argv[2], argv[3] );
1689
				GeneratePackagerScript ( argv[2], argv[3], 0);
1585
		}
1690
		}
1586
	}
1691
	}
1587
	else if ( command == "--verifyscript" )
1692
	else if ( command == "--verifyscript" )
1588
	{
1693
	{
1589
		if ( argc < 3 )
1694
		if ( argc < 3 )
Line 1601... Line 1706...
1601
				ExtractShip ( argv[2], argv[3], "" );
1706
				ExtractShip ( argv[2], argv[3], "" );
1602
			else
1707
			else
1603
				ExtractShip ( argv[2], argv[3], argv[4] );
1708
				ExtractShip ( argv[2], argv[3], argv[4] );
1604
		}
1709
		}
1605
	}
1710
	}
1606
	else if ( command == "--generateupdatefile" )
1711
	else if (command == "--generateupdatefile")
1607
	{
1712
	{
1608
		if ( argc < 3 )
1713
	if (argc < 3)
1609
			printf ( "Syntax:\n\t%s --generateupdatefile <package>\n\t\tThis will generate the update file to allow auto updates for a package\n", cmd.c_str() );
1714
		printf("Syntax:\n\t%s --generateupdatefile <package>\n\t\tThis will generate the update file to allow auto updates for a package\n", cmd.c_str());
-
 
1715
	else
-
 
1716
		GenerateUpdateFile(argv[2]);
-
 
1717
	}
-
 
1718
	else if (command == "--packagelist")
-
 
1719
	{
-
 
1720
		if (argc < 3)
-
 
1721
			printf("Syntax:\n\t%s --packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.c_str());
1610
		else
1722
		else
1611
			GenerateUpdateFile(argv[2]);
1723
			GenerateUpdateList(argc, argv);
1612
	}
1724
	}
1613
 
1725
 
1614
	// not a valid switch, display syntax
1726
	// not a valid switch, display syntax
1615
	else
1727
	else
1616
		PrintSyntax ( cmd );
1728
		PrintSyntax ( cmd );