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 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 <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> <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
	{