Subversion Repositories spk

Rev

Rev 341 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 341 Rev 346
Line 1579... Line 1579...
1579
		}
1579
		}
1580
	}
1580
	}
1581
	return fileTypes;
1581
	return fileTypes;
1582
}
1582
}
1583
 
1583
 
1584
/*
-
 
1585
	Main entry point to program
-
 
1586
*/
-
 
1587
int main ( int argc, char **argv )
1584
int doMain(Utils::CommandLine& cmd)
1588
{
1585
{
1589
	// display program header to command prompt
1586
	// display program header to command prompt
1590
	wprintf(L"\nSPKTool V1.51 (SPK File Version %.2f) 17/05/2025 Created by Cycrow\n\n", (float)FILEVERSION );
1587
	wprintf(L"\nSPKTool V1.51 (SPK File Version %.2f) 17/05/2025 Created by Cycrow\n\n", (float)FILEVERSION );
1591
 
1588
 
1592
	Utils::CommandLine cmd(argc, argv);
-
 
1593
	g_dir = cmd.cmdDir();
1589
	g_dir = cmd.cmdDir();
1594
	g_read = false;
1590
	g_read = false;
1595
 
1591
 
1596
	// not enough arguments, display the syntax and exit
1592
	// not enough arguments, display the syntax and exit
1597
	if (cmd.argCount() < 1)
1593
	if (cmd.argCount() < 1)
Line 1604... Line 1600...
1604
	Utils::WString command(cmd.arg(0));
1600
	Utils::WString command(cmd.arg(0));
1605
 
1601
 
1606
	// display the contents of the spk file
1602
	// display the contents of the spk file
1607
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1603
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1608
	{
1604
	{
1609
		if ( argc < 3 )
1605
		if (cmd.argCount() < 2)
1610
			wprintf(L"Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.cmdName().c_str());
1606
			wprintf(L"Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.cmdName().c_str());
1611
		else
1607
		else
1612
			DisplayVersion(cmd);
1608
			DisplayVersion(cmd);
1613
	}
1609
	}
1614
 
1610
 
1615
	// creates a new spk file
1611
	// creates a new spk file
1616
	else if ( command == L"-c" || command == L"-create" )
1612
	else if ( command == L"-c" || command == L"-create" )
1617
	{
1613
	{
1618
		if ( argc < 3 )
1614
		if (cmd.argCount() < 2)
1619
			wprintf(L"Syntax:\n\t%s -c <spkfile>\n\t%s -create <spkfile>\n\t\tThis will create a new SPK file and allow you to set some basic settings for the file\n", cmd.cmdName().c_str(), cmd.cmdName().c_str() );
1615
			wprintf(L"Syntax:\n\t%s -c <spkfile>\n\t%s -create <spkfile>\n\t\tThis will create a new SPK file and allow you to set some basic settings for the file\n", cmd.cmdName().c_str(), cmd.cmdName().c_str() );
1620
		else
1616
		else
1621
			CreateFile ( argv[2] );
1617
			CreateFile(cmd.arg(1));
1622
	}
1618
	}
1623
 
1619
 
1624
	// appends a file onto the spk archive
1620
	// appends a file onto the spk archive
1625
	else if ( command == L"-a" || command == L"-append" )
1621
	else if ( command == L"-a" || command == L"-append" )
1626
	{
1622
	{
1627
		if ( argc < 4 )
1623
		if (cmd.argCount() < 3)
1628
			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
			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() );
1629
		else
1625
		else
1630
		{
1626
		{
1631
			Utils::WString arg4;
1627
			Utils::WString arg4;
1632
			if ( argc > 4 )
1628
			if (cmd.argCount() > 3)
1633
				arg4 = argv[4];
1629
				arg4 = cmd.arg(3);
1634
			AppendFile ( argv[2], argv[3], arg4 );
1630
			AppendFile(cmd.arg(1), cmd.arg(2), arg4);
1635
		}
1631
		}
1636
	}
1632
	}
1637
 
1633
 
1638
	// removes a file from the spk archive
1634
	// removes a file from the spk archive
1639
	else if ( command == L"-r" || command == L"-remove" || command == L"-removespk" )
1635
	else if ( command == L"-r" || command == L"-remove" || command == L"-removespk" )
1640
	{
1636
	{
1641
		if ( argc < 4 )
1637
		if (cmd.argCount() < 3)
1642
		{
1638
		{
1643
			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"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() );
1644
			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
			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() );
1645
		}
1641
		}
1646
		else
1642
		else
1647
		{
1643
		{
1648
			Utils::WString arg4;
1644
			Utils::WString arg4;
1649
			if ( argc > 4 )
1645
			if (cmd.argCount() > 3)
1650
				arg4 = argv[4];
1646
				arg4 = cmd.arg(3);
1651
			RemoveFile ( argv[2], argv[3], arg4 );
1647
			RemoveFile(cmd.arg(1), cmd.arg(2), arg4 );
1652
		}
1648
		}
1653
	}
1649
	}
1654
 
1650
 
1655
	// extracts a file from a spk file
1651
	// extracts a file from a spk file
1656
	else if ( command == L"-extractspk" )
1652
	else if ( command == L"-extractspk" )
1657
	{
1653
	{
1658
		if ( argc < 4 )
1654
		if (cmd.argCount() < 3)
1659
			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
			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() );
1660
		else
1656
		else
1661
		{
1657
		{
1662
			Utils::WString arg4;
1658
			Utils::WString arg4;
1663
			if ( argc > 4 )
1659
			if (cmd.argCount() > 3)
1664
				arg4 = argv[3];
1660
				arg4 = cmd.arg(2);
1665
			ExtractFile(argv[2], argv[3], arg4, Utils::WString::Null());
1661
			ExtractFile(cmd.arg(1), cmd.arg(2), arg4, Utils::WString::Null());
1666
		}
1662
		}
1667
	}
1663
	}
1668
	else if ( command == L"-x" || command == L"-extract")
1664
	else if ( command == L"-x" || command == L"-extract")
1669
	{
1665
	{
1670
		if ( argc < 4 )
1666
		if (cmd.argCount() < 3)
1671
		{
1667
		{
1672
			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"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() );
1673
			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
			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() );
1674
		}
1670
		}
1675
		else
1671
		else
1676
		{
1672
		{
1677
			Utils::WString arg5, arg4;
1673
			Utils::WString arg5, arg4;
1678
			if ( argc > 5 )
1674
			if (cmd.argCount() > 4)
1679
				arg5 = argv[5];
1675
				arg5 = cmd.arg(4);
1680
			if ( argc > 4 )
1676
			if (cmd.argCount() > 3)
1681
				arg4 = argv[4];
1677
				arg4 = cmd.arg(3);
1682
			ExtractFile(argv[2], argv[3], arg4, arg5);
1678
			ExtractFile(cmd.arg(1), cmd.arg(2), arg4, arg5);
1683
		}
1679
		}
1684
	}
1680
	}
1685
 
1681
 
1686
	// extracts all the files from an archive
1682
	// extracts all the files from an archive
1687
	else if ( command == L"-e" || command == L"-extractall" )
1683
	else if ( command == L"-e" || command == L"-extractall" )
1688
	{
1684
	{
1689
		if ( argc < 3 )
1685
		if (cmd.argCount() < 2)
1690
			wprintf(L"Syntax:\n\t%s -e <spkfile> [destination]\n\t-extractall --game:<game> <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() );
1686
			wprintf(L"Syntax:\n\t%s -e <spkfile> [destination]\n\t-extractall --game:<game> <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() );
1691
		else
1687
		else
1692
			ExtractFiles(cmd);
1688
			ExtractFiles(cmd);
1693
	}
1689
	}
1694
 
1690
 
1695
	// creates a multispk archive
1691
	// creates a multispk archive
1696
	else if ( command == L"-n" || command == L"-createmulti" )
1692
	else if ( command == L"-n" || command == L"-createmulti" )
1697
	{
1693
	{
1698
		if ( argc < 3 )
1694
		if (cmd.argCount() < 2)
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() );
1695
			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
1696
		else
1701
			CreateMultiFile ( argv[2] );
1697
			CreateMultiFile(cmd.arg(1));
1702
	}
1698
	}
1703
 
1699
 
1704
	// merges 2 multi-spk archives together, or appends a single spk file into a multi-spk file
1700
	// merges 2 multi-spk archives together, or appends a single spk file into a multi-spk file
1705
	else if ( command == L"-m" || command == L"-mergemulti" )
1701
	else if ( command == L"-m" || command == L"-mergemulti" )
1706
	{
1702
	{
1707
		if ( argc < 4 )
1703
		if (cmd.argCount() < 3)
1708
			wprintf(L"Syntax:\n\t%s -m <spkfile1> <spkfile2>\n\t%s -mergemulti <spkfile1> <spkfile2>\n\t\tThis will add spkfile2 into spkfile1, if spkfile1 is a normal SPK file, it will be saved into a Multi-Spk file\nspkfile2 can also be a Multi-Spk file, all files within it will be added\n", cmd.cmdName().c_str(), cmd.cmdName().c_str() );
1704
			wprintf(L"Syntax:\n\t%s -m <spkfile1> <spkfile2>\n\t%s -mergemulti <spkfile1> <spkfile2>\n\t\tThis will add spkfile2 into spkfile1, if spkfile1 is a normal SPK file, it will be saved into a Multi-Spk file\nspkfile2 can also be a Multi-Spk file, all files within it will be added\n", cmd.cmdName().c_str(), cmd.cmdName().c_str() );
1709
		else
1705
		else
1710
			AppendMultiFile ( argv[2], argv[3] );
1706
			AppendMultiFile(cmd.arg(1), cmd.arg(2));
1711
	}
1707
	}
1712
 
1708
 
1713
	// splits the multi-spk file, exracts all spk files
1709
	// splits the multi-spk file, exracts all spk files
1714
	else if ( command == L"-s" || command == L"-splitmulti" )
1710
	else if ( command == L"-s" || command == L"-splitmulti" )
1715
	{
1711
	{
1716
		if ( argc < 3 )
1712
		if (cmd.argCount() < 2)
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() );
1713
			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
1714
		else
1719
		{
1715
		{
1720
			Utils::WString arg3;
1716
			Utils::WString arg3;
1721
			if ( argc > 3 )
1717
			if (cmd.argCount() > 2)
1722
				arg3 = argv[3];
1718
				arg3 = cmd.arg(2);
1723
			SplitMulti ( argv[2], arg3 );
1719
			SplitMulti(cmd.arg(1), arg3);
1724
		}
1720
		}
1725
	}
1721
	}
1726
 
1722
 
1727
	else if ( command == L"-set" )
1723
	else if ( command == L"-set" )
1728
	{
1724
	{
1729
		if ( argc < 4 )
1725
		if (cmd.argCount() < 3)
1730
			wprintf(L"Syntax: %s -set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.cmdName().c_str() );
1726
			wprintf(L"Syntax: %s -set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.cmdName().c_str() );
1731
		else
1727
		else
1732
			Settings(cmd);
1728
			Settings(cmd);
1733
	}
1729
	}
1734
	else if ( command == L"-setrating" )
1730
	else if ( command == L"-setrating" )
1735
	{
1731
	{
1736
		if ( argc < 6 )
1732
		if (cmd.argCount() < 5)
1737
			wprintf(L"Syntax: %s -setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.cmdName().c_str() );
1733
			wprintf(L"Syntax: %s -setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.cmdName().c_str() );
1738
		else
1734
		else
1739
			SetRating(argv[2], Utils::WString(argv[3]).toInt(), Utils::WString(argv[4]).toInt(), Utils::WString(argv[5]).toInt());
1735
			SetRating(cmd.arg(1), cmd.arg(2).toInt(), cmd.arg(3).toInt(), cmd.arg(4).toInt());
1740
	}
1736
	}
1741
	else if ( command == L"-convertxsp" || command == L"-convertxspwizard" )
1737
	else if ( command == L"-convertxsp" || command == L"-convertxspwizard" )
1742
	{
1738
	{
1743
		if ( argc < 3 )
1739
		if (cmd.argCount() < 2)
1744
			wprintf(L"Syntax: %s %s <xspfile> [newxspfile]\n\tConverts an old format xsp file to work with the new format\n", cmd.cmdName().c_str(), command.c_str());
1740
			wprintf(L"Syntax: %s %s <xspfile> [newxspfile]\n\tConverts an old format xsp file to work with the new format\n", cmd.cmdName().c_str(), command.c_str());
1745
		else
1741
		else
1746
		{
1742
		{
1747
			Utils::WString arg3;
1743
			Utils::WString arg3;
1748
			if ( argc > 3 )
1744
			if (cmd.argCount() > 2)
1749
				arg3 = argv[3];
1745
				arg3 = cmd.arg(2);
1750
			ConvertXsp(Utils::WString::FromString(argv[2]), arg3, (command == L"-convertxspwizard") ? true : false);
1746
			ConvertXsp(cmd.arg(1), arg3, (command == L"-convertxspwizard") ? true : false);
1751
		}
1747
		}
1752
	}
1748
	}
1753
	else if ( command == L"-createscript" )
1749
	else if ( command == L"-createscript" )
1754
	{
1750
	{
1755
		if (cmd.argCount() < 2)
1751
		if (cmd.argCount() < 2)
Line 1762... Line 1758...
1762
		if (cmd.argCount() < 2)
1758
		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() );
1759
			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
1760
		else
1765
		{
1761
		{
1766
			if (cmd.argCount() < 3)
1762
			if (cmd.argCount() < 3)
1767
				GeneratePackagerScript ( argv[2], "", 0);
1763
				GeneratePackagerScript(cmd.arg(1), "", 0);
1768
			else
1764
			else
1769
				GeneratePackagerScript ( argv[2], argv[3], 0);
1765
				GeneratePackagerScript(cmd.arg(1), cmd.arg(2), 0);
1770
		}
1766
		}
1771
	}
1767
	}
1772
	else if ( command == L"-verifyscript" )
1768
	else if ( command == L"-verifyscript" )
1773
	{
1769
	{
1774
		if (cmd.argCount() < 2)
1770
		if (cmd.argCount() < 2)
Line 1776... Line 1772...
1776
		else
1772
		else
1777
			LoadPackagerScript(cmd, true);
1773
			LoadPackagerScript(cmd, true);
1778
	}
1774
	}
1779
	else if ( command == L"-extractship" )
1775
	else if ( command == L"-extractship" )
1780
	{
1776
	{
1781
		if ( argc < 4 )
1777
		if (cmd.argCount() < 3)
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() );
1778
			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() );
1783
		else
1779
		else
1784
		{
1780
		{
1785
			if ( argc < 5 )
1781
			if (cmd.argCount() < 4)
1786
				ExtractShip ( argv[2], argv[3], L"" );
1782
				ExtractShip(cmd.arg(1), cmd.arg(2), L"");
1787
			else
1783
			else
1788
				ExtractShip ( argv[2], argv[3], argv[4] );
1784
				ExtractShip(cmd.arg(1), cmd.arg(2), cmd.arg(3));
1789
		}
1785
		}
1790
	}
1786
	}
1791
	else if (command == L"-generateupdatefile")
1787
	else if (command == L"-generateupdatefile")
1792
	{
1788
	{
1793
		if (argc < 3)
1789
		if (cmd.argCount() < 2)
1794
			wprintf(L"Syntax:\n\t%s -generateupdatefile <package>\n\t\tThis will generate the update file to allow auto updates for a package\n", cmd.cmdName().c_str());
1790
			wprintf(L"Syntax:\n\t%s -generateupdatefile <package>\n\t\tThis will generate the update file to allow auto updates for a package\n", cmd.cmdName().c_str());
1795
		else
1791
		else
1796
			GenerateUpdateFile(argv[2]);
1792
			GenerateUpdateFile(cmd.arg(1));
1797
	}
1793
	}
1798
	else if (command == L"-packagelist")
1794
	else if (command == L"-packagelist")
1799
	{
1795
	{
1800
		if (argc < 3)
1796
		if (cmd.argCount() < 2)
1801
			wprintf(L"Syntax:\n\t%s -packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.cmdName().c_str());
1797
			wprintf(L"Syntax:\n\t%s -packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.cmdName().c_str());
1802
		else
1798
		else
1803
			GenerateUpdateList(cmd);
1799
			GenerateUpdateList(cmd);
1804
	}
1800
	}
1805
 
1801
 
Line 1812... Line 1808...
1812
	scanf ( "%s", &pause );
1808
	scanf ( "%s", &pause );
1813
#endif
1809
#endif
1814
 
1810
 
1815
	return 0;
1811
	return 0;
1816
}
1812
}
-
 
1813
 
-
 
1814
/*
-
 
1815
	Main entry point to program
-
 
1816
*/
-
 
1817
#ifdef _WIN32
-
 
1818
int wmain(int argc, wchar_t** argv)
-
 
1819
{
-
 
1820
	Utils::CommandLine cmd(argc, argv);
-
 
1821
	return doMain(cmd);
-
 
1822
}
-
 
1823
#else
-
 
1824
int main(int argc, char** argv)
-
 
1825
{
-
 
1826
	Utils::CommandLine cmd(argc, argv);
-
 
1827
	return doMain(cmd);
-
 
1828
}
-
 
1829
#endif