Subversion Repositories spk

Rev

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

Rev 307 Rev 311
Line 38... Line 38...
38
		_display(display),
38
		_display(display),
39
		_packages(packages),
39
		_packages(packages),
40
		_package(package)
40
		_package(package)
41
	{
41
	{
42
 
42
 
-
 
43
	}
-
 
44
 
-
 
45
	void UpdateDisplay(const Utils::WString& display) override
-
 
46
	{
-
 
47
		wprintf(L"%s\n", display.c_str());
43
	}
48
	}
44
 
49
 
45
protected:
50
protected:
46
	void ProgressUpdated(const long cur, const long max)
51
	void ProgressUpdated(const long cur, const long max)
47
	{
52
	{
Line 468... Line 473...
468
		if ( !((CXspFile *)pBaseFile)->convertOld(filename) )
473
		if ( !((CXspFile *)pBaseFile)->convertOld(filename) )
469
		{
474
		{
470
			delete pBaseFile;
475
			delete pBaseFile;
471
			pBaseFile = NULL;
476
			pBaseFile = NULL;
472
			wprintf(L"Failed to convert old xsp file, %s\n", filename.c_str() );
477
			wprintf(L"Failed to convert old xsp file, %s\n", filename.c_str() );
473
			return;
478
			return;
474
		}
479
		}
475
		check = SPKFILE_SINGLESHIP;
480
		check = SPKFILE_SINGLESHIP;
476
		read = true;
481
		read = true;
477
	}
482
	}
478
 
483
 
Line 896... Line 901...
896
		}
901
		}
897
	}
902
	}
898
 
903
 
899
	if ( spkfile.numFiles() < 1 )
904
	if ( spkfile.numFiles() < 1 )
900
		wprintf(L"\nError: You have added no files, you must add at least one file to create a package\n");
905
		wprintf(L"\nError: You have added no files, you must add at least one file to create a package\n");
901
	else
906
	else
902
	{
907
	{
903
		wprintf(L"Writing MultiSpk file... ");
908
		wprintf(L"Writing MultiSpk file... ");
904
		if ( spkfile.writeFile(filename))
909
		if ( spkfile.writeFile(filename))
905
			wprintf(L"(Done)\n" );
910
			wprintf(L"(Done)\n" );
906
		else
911
		else
907
			wprintf(L"(Error)\n" );
912
			wprintf(L"(Error)\n" );
Line 1443... Line 1448...
1443
/*
1448
/*
1444
	Func:	LoadPackagerScript
1449
	Func:	LoadPackagerScript
1445
	Args:	String filename	-	The filename of the packager script to load
1450
	Args:	String filename	-	The filename of the packager script to load
1446
	Desc:	Loads the packager scripts and creates a spk/xsp file from it
1451
	Desc:	Loads the packager scripts and creates a spk/xsp file from it
1447
*/
1452
*/
1448
void LoadPackagerScript(const Utils::WString &filename, bool verify)
1453
void LoadPackagerScript(const Utils::CommandLine &cmd, bool verify)
1449
{
1454
{
-
 
1455
	Utils::WString filename = cmd.arg(1);
-
 
1456
	// check if the file exists in the current directory
-
 
1457
	if (!filename.contains(L":"))
-
 
1458
		filename = CDirIO(g_dir).file(filename);
-
 
1459
 
1450
	if ( !CFileIO::Exists(filename) )
1460
	if (!CFileIO::Exists(filename))
1451
	{
1461
	{
1452
		wprintf(L"Error: The packager script, %s, does not exist", filename.c_str());
1462
		wprintf(L"Error: The packager script, %s, does not exist", filename.c_str());
1453
		return;
1463
		return;
1454
	}
1464
	}
1455
 
1465
 
1456
	Utils::WString myDoc;
1466
	Utils::WString myDoc;
1457
#ifdef _WIN32
1467
#ifdef _WIN32
1458
	TCHAR pszPath[MAX_PATH];
1468
	TCHAR pszPath[MAX_PATH];
1459
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
1469
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
1460
	{
1470
	{
1461
		myDoc = (char *)pszPath;
1471
		myDoc = pszPath;
1462
	}
1472
	}
1463
#endif
1473
#endif
1464
 
1474
 
1465
	if ( verify )
1475
	if ( verify )
1466
		wprintf(L"Verifying Packager Script: %s\n", filename.c_str());
1476
		wprintf(L"Verifying Packager Script: %s\n", filename.c_str());
Line 1473... Line 1483...
1473
	if ( curDir.empty() ) curDir = L"./";
1483
	if ( curDir.empty() ) curDir = L"./";
1474
 
1484
 
1475
	Utils::WStringList variables;
1485
	Utils::WStringList variables;
1476
	variables.pushBack(L"$PATH", curDir);
1486
	variables.pushBack(L"$PATH", curDir);
1477
 
1487
 
1478
	CFileProgress info(&p, NULL, "Adding File");
1488
	CFileProgress info(&p, NULL, "Added File");
1479
	CBaseFile *package = p.loadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables, &info);
1489
	CBaseFile *package = p.loadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables, &info);
1480
 
1490
 
1481
	printf("\n");
1491
	printf("\n");
1482
 
1492
 
1483
	if ( verify )
1493
	if ( verify )
Line 1556... Line 1566...
1556
				else
1566
				else
1557
					printf("Error! There was a problem exporting the package\n");
1567
					printf("Error! There was a problem exporting the package\n");
1558
			}
1568
			}
1559
		}
1569
		}
1560
	}
1570
	}
-
 
1571
}
-
 
1572
 
-
 
1573
Utils::WString GetFileTypes()
-
 
1574
{
-
 
1575
	Utils::WString fileTypes;
-
 
1576
	for (int i = 0; i < FILETYPE_MAX; i++)
-
 
1577
	{
-
 
1578
		Utils::WString sT = GetFileTypeString(i);
-
 
1579
		if (!sT.empty())
-
 
1580
		{
-
 
1581
			if (fileTypes.empty())
-
 
1582
				fileTypes = sT;
-
 
1583
			else
-
 
1584
			{
-
 
1585
				fileTypes += L", ";
-
 
1586
				fileTypes += sT;
-
 
1587
			}
-
 
1588
		}
-
 
1589
	}
-
 
1590
	return fileTypes;
1561
}
1591
}
1562
 
1592
 
1563
/*
1593
/*
1564
	Main entry point to program
1594
	Main entry point to program
1565
*/
1595
*/
1566
int main ( int argc, char **argv )
1596
int main ( int argc, char **argv )
1567
{
1597
{
1568
	// display program header to command prompt
1598
	// display program header to command prompt
1569
	printf ( "\nSPKTool V1.50 (SPK File Version %.2f) 14/02/2021 Created by Cycrow\n\n", (float)FILEVERSION );
1599
	printf ( "\nSPKTool V1.51 (SPK File Version %.2f) 17/05/2025 Created by Cycrow\n\n", (float)FILEVERSION );
1570
 
1600
 
1571
	Utils::CommandLine cmd(argc, argv);
1601
	Utils::CommandLine cmd(argc, argv);
1572
	g_dir = cmd.cmdDir();
1602
	g_dir = cmd.cmdDir();
1573
	g_read = false;
1603
	g_read = false;
1574
 
1604
 
1575
	// not enough arguments, display the syntax and exit
1605
	// not enough arguments, display the syntax and exit
1576
	if ( argc < 2 )
1606
	if (cmd.argCount() < 1)
1577
	{
1607
	{
1578
		PrintSyntax(cmd.cmdName());
1608
		PrintSyntax(cmd.cmdName());
1579
		exit ( 1 );
1609
		exit ( 1 );
1580
	}
-
 
1581
 
-
 
1582
	Utils::WString fileTypes;
-
 
1583
	for ( int i = 0; i < FILETYPE_MAX; i++ )
-
 
1584
	{
-
 
1585
		Utils::WString sT = GetFileTypeString(i);
-
 
1586
		if ( !sT.empty() )
-
 
1587
		{
-
 
1588
			if ( fileTypes.empty() )
-
 
1589
				fileTypes = sT;
-
 
1590
			else
-
 
1591
			{
-
 
1592
				fileTypes += L", ";
-
 
1593
				fileTypes += sT;
-
 
1594
			}
-
 
1595
		}
-
 
1596
	}
1610
	}
1597
 
1611
 
1598
	// get the command flag
1612
	// get the command flag
1599
	Utils::WString command(argv[1]);
1613
	Utils::WString command(cmd.arg(0));
1600
 
1614
 
1601
	// display the contents of the spk file
1615
	// display the contents of the spk file
1602
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1616
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1603
	{
1617
	{
1604
		if ( argc < 3 )
1618
		if ( argc < 3 )
Line 1618... Line 1632...
1618
 
1632
 
1619
	// appends a file onto the spk archive
1633
	// appends a file onto the spk archive
1620
	else if ( command == L"-a" || command == L"-append" )
1634
	else if ( command == L"-a" || command == L"-append" )
1621
	{
1635
	{
1622
		if ( argc < 4 )
1636
		if ( argc < 4 )
1623
			wprintf(L"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.cmdName().c_str(), cmd.cmdName().c_str(), fileTypes.c_str() );
1637
			wprintf(L"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.cmdName().c_str(), cmd.cmdName().c_str(), GetFileTypes().c_str() );
1624
		else
1638
		else
1625
		{
1639
		{
1626
			Utils::WString arg4;
1640
			Utils::WString arg4;
1627
			if ( argc > 4 )
1641
			if ( argc > 4 )
1628
				arg4 = argv[4];
1642
				arg4 = argv[4];
Line 1633... Line 1647...
1633
	// removes a file from the spk archive
1647
	// removes a file from the spk archive
1634
	else if ( command == L"-r" || command == L"-remove" || command == L"-removespk" )
1648
	else if ( command == L"-r" || command == L"-remove" || command == L"-removespk" )
1635
	{
1649
	{
1636
		if ( argc < 4 )
1650
		if ( argc < 4 )
1637
		{
1651
		{
1638
			wprintf(L"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.cmdName().c_str(), cmd.cmdName().c_str(), fileTypes.c_str() );
1652
			wprintf(L"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.cmdName().c_str(), cmd.cmdName().c_str(), GetFileTypes().c_str() );
1639
			wprintf(L"\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.cmdName().c_str(), cmd.cmdName().c_str() );
1653
			wprintf(L"\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.cmdName().c_str(), cmd.cmdName().c_str() );
1640
		}
1654
		}
1641
		else
1655
		else
1642
		{
1656
		{
1643
			Utils::WString arg4;
1657
			Utils::WString arg4;
1644
			if ( argc > 4 )
1658
			if ( argc > 4 )
1645
				arg4 = argv[4];
1659
				arg4 = argv[4];
1646
			RemoveFile ( argv[2], argv[3], arg4 );
1660
			RemoveFile ( argv[2], argv[3], arg4 );
1647
		}
1661
		}
1648
	}
1662
	}
1649
 
1663
 
1650
	// extracts a file from a spk file
1664
	// extracts a file from a spk file
1651
	else if ( command == L"-extractspk" )
1665
	else if ( command == L"-extractspk" )
1652
	{
1666
	{
1653
		if ( argc < 4 )
1667
		if ( argc < 4 )
1654
			wprintf(L"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.cmdName().c_str() );
1668
			wprintf(L"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.cmdName().c_str() );
1655
		else
1669
		else
1656
		{
1670
		{
1657
			Utils::WString arg4;
1671
			Utils::WString arg4;
1658
			if ( argc > 4 )
1672
			if ( argc > 4 )
1659
				arg4 = argv[3];
1673
				arg4 = argv[3];
1660
			ExtractFile(argv[2], argv[3], arg4, Utils::WString::Null());
1674
			ExtractFile(argv[2], argv[3], arg4, Utils::WString::Null());
1661
		}
1675
		}
1662
	}
1676
	}
1663
	else if ( command == L"-x" || command == L"-extract")
1677
	else if ( command == L"-x" || command == L"-extract")
1664
	{
1678
	{
1665
		if ( argc < 4 )
1679
		if ( argc < 4 )
1666
		{
1680
		{
1667
			wprintf(L"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.cmdName().c_str(), fileTypes.c_str() );
1681
			wprintf(L"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.cmdName().c_str(), GetFileTypes().c_str() );
1668
			wprintf(L"\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.cmdName().c_str() );
1682
			wprintf(L"\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.cmdName().c_str() );
1669
		}
1683
		}
1670
		else
1684
		else
1671
		{
1685
		{
1672
			Utils::WString arg5, arg4;
1686
			Utils::WString arg5, arg4;
1673
			if ( argc > 5 )
1687
			if ( argc > 5 )
1674
				arg5 = argv[5];
1688
				arg5 = argv[5];
1675
			if ( argc > 4 )
1689
			if ( argc > 4 )
1676
				arg4 = argv[4];
1690
				arg4 = argv[4];
1677
			ExtractFile(argv[2], argv[3], arg4, arg5);
1691
			ExtractFile(argv[2], argv[3], arg4, arg5);
1678
		}
1692
		}
1679
	}
1693
	}
1680
 
1694
 
1681
	// extracts all the files from an archive
1695
	// extracts all the files from an archive
1682
	else if ( command == L"-e" || command == L"-extractall" )
1696
	else if ( command == L"-e" || command == L"-extractall" )
1683
	{
1697
	{
1684
		if ( argc < 3 )
1698
		if ( argc < 3 )
1685
			wprintf(L"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.cmdName().c_str() );
1699
			wprintf(L"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.cmdName().c_str() );
Line 1687... Line 1701...
1687
		{
1701
		{
1688
			Utils::WString arg4;
1702
			Utils::WString arg4;
1689
			if ( argc > 4 )
1703
			if ( argc > 4 )
1690
				arg4 = argv[4];
1704
				arg4 = argv[4];
1691
			ExtractFiles(argv[2], arg4, CBaseFile::GetGameFromString(argv[3]));
1705
			ExtractFiles(argv[2], arg4, CBaseFile::GetGameFromString(argv[3]));
1692
		}
1706
		}
1693
	}
1707
	}
1694
 
1708
 
1695
	// creates a multispk archive
1709
	// creates a multispk archive
1696
	else if ( command == L"-n" || command == L"-createmulti" )
1710
	else if ( command == L"-n" || command == L"-createmulti" )
1697
	{
1711
	{
1698
		if ( argc < 3 )
1712
		if ( argc < 3 )
1699
			wprintf(L"Syntax:\n\t%s -n <multispkfile>\n\t%s -createmulti <multispkfile>\n\t\tThis will create a multispk file and allow you to add spk files to it\n", cmd.cmdName().c_str(), cmd.cmdName().c_str() );
1713
			wprintf(L"Syntax:\n\t%s -n <multispkfile>\n\t%s -createmulti <multispkfile>\n\t\tThis will create a multispk file and allow you to add spk files to it\n", cmd.cmdName().c_str(), cmd.cmdName().c_str() );
1700
		else
1714
		else
1701
			CreateMultiFile ( argv[2] );
1715
			CreateMultiFile ( argv[2] );
1702
	}
1716
	}
1703
 
1717
 
Line 1713... Line 1727...
1713
	// splits the multi-spk file, exracts all spk files
1727
	// splits the multi-spk file, exracts all spk files
1714
	else if ( command == L"-s" || command == L"-splitmulti" )
1728
	else if ( command == L"-s" || command == L"-splitmulti" )
1715
	{
1729
	{
1716
		if ( argc < 3 )
1730
		if ( argc < 3 )
1717
			wprintf(L"Syntax: %s -s <multispkfile> [destination]\n\tSplits the Multi-SPK file and saves each spk file to the destiantion directory\n", cmd.cmdName().c_str() );
1731
			wprintf(L"Syntax: %s -s <multispkfile> [destination]\n\tSplits the Multi-SPK file and saves each spk file to the destiantion directory\n", cmd.cmdName().c_str() );
1718
		else
1732
		else
1719
		{
1733
		{
1720
			Utils::WString arg3;
1734
			Utils::WString arg3;
1721
			if ( argc > 3 )
1735
			if ( argc > 3 )
1722
				arg3 = argv[3];
1736
				arg3 = argv[3];
1723
			SplitMulti ( argv[2], arg3 );
1737
			SplitMulti ( argv[2], arg3 );
1724
		}
1738
		}
Line 1750... Line 1764...
1750
			ConvertXsp(Utils::WString::FromString(argv[2]), arg3, (command == L"-convertxspwizard") ? true : false);
1764
			ConvertXsp(Utils::WString::FromString(argv[2]), arg3, (command == L"-convertxspwizard") ? true : false);
1751
		}
1765
		}
1752
	}
1766
	}
1753
	else if ( command == L"-createscript" )
1767
	else if ( command == L"-createscript" )
1754
	{
1768
	{
1755
		if ( argc < 3 )
1769
		if (cmd.argCount() < 2)
1756
			wprintf(L"Syntax:\n\t%s -createscript <packagerscript>\n\t\tThis will create a spk/xsp file from a packager script\n", cmd.cmdName().c_str() );
1770
			wprintf(L"Syntax:\n\t%s -createscript <packagerscript>\n\t\tThis will create a spk/xsp file from a packager script\n", cmd.cmdName().c_str() );
1757
		else
1771
		else
1758
			LoadPackagerScript ( argv[2], false );
1772
			LoadPackagerScript(cmd, false);
1759
	}
1773
	}
1760
	else if ( command == L"-generatescript" )
1774
	else if ( command == L"-generatescript" )
1761
	{
1775
	{
1762
		if ( argc < 3 )
1776
		if (cmd.argCount() < 2)
1763
			wprintf(L"Syntax:\n\t%s -generatescript <package> [packagerscript]\n\t\tThis will generate a packager script file from a spk/xsp file.\n", cmd.cmdName().c_str() );
1777
			wprintf(L"Syntax:\n\t%s -generatescript <package> [packagerscript]\n\t\tThis will generate a packager script file from a spk/xsp file.\n", cmd.cmdName().c_str() );
1764
		else
1778
		else
1765
		{
1779
		{
1766
			if ( argc < 4 )
1780
			if (cmd.argCount() < 3)
1767
				GeneratePackagerScript ( argv[2], "", 0);
1781
				GeneratePackagerScript ( argv[2], "", 0);
1768
			else
1782
			else
1769
				GeneratePackagerScript ( argv[2], argv[3], 0);
1783
				GeneratePackagerScript ( argv[2], argv[3], 0);
1770
		}
1784
		}
1771
	}
1785
	}
1772
	else if ( command == L"-verifyscript" )
1786
	else if ( command == L"-verifyscript" )
1773
	{
1787
	{
1774
		if ( argc < 3 )
1788
		if (cmd.argCount() < 2)
1775
			wprintf(L"Syntax:\n\t%s -verifyscript <packagerscript>\n\t\tThis will read a packager script and check its correct without creating the resulting spk/xsp file\n", cmd.cmdName().c_str() );
1789
			wprintf(L"Syntax:\n\t%s -verifyscript <packagerscript>\n\t\tThis will read a packager script and check its correct without creating the resulting spk/xsp file\n", cmd.cmdName().c_str() );
1776
		else
1790
		else
1777
			LoadPackagerScript ( argv[2], true );
1791
			LoadPackagerScript(cmd, true);
1778
	}
1792
	}
1779
	else if ( command == L"-extractship" )
1793
	else if ( command == L"-extractship" )
1780
	{
1794
	{
1781
		if ( argc < 4 )
1795
		if ( argc < 4 )
1782
			wprintf(L"Syntax:\n\t%s -extractship <modfile> <xspfile> [shipid]\n\t\tThis will create an xsp ship file by extracting from a mod file\n", cmd.cmdName().c_str() );
1796
			wprintf(L"Syntax:\n\t%s -extractship <modfile> <xspfile> [shipid]\n\t\tThis will create an xsp ship file by extracting from a mod file\n", cmd.cmdName().c_str() );