Subversion Repositories spk

Rev

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

Rev 315 Rev 321
Line 13... Line 13...
13
#include "../spk/spkcmdprogress.h"
13
#include "../spk/spkcmdprogress.h"
14
#endif
14
#endif
15
// Multi Spk File format, required if using Multi Spk files
15
// Multi Spk File format, required if using Multi Spk files
16
// Displays 7Zip compression progress to the command line
16
// Displays 7Zip compression progress to the command line
17
#include <time.h>
17
#include <time.h>
18
#ifdef _WIN32
-
 
19
#include <windows.h>
-
 
20
#include <direct.h>
-
 
21
#include <shlobj.h>
-
 
22
#endif
-
 
23
 
18
 
24
#include "Utils/CommandLine.h"
19
#include "Utils/CommandLine.h"
25
 
20
 
26
Utils::WString g_dir;
21
Utils::WString g_dir;
27
bool g_read;
22
bool g_read;
Line 29... Line 24...
29
class CFileProgress : public CProgressInfo
24
class CFileProgress : public CProgressInfo
30
{
25
{
31
private:
26
private:
32
	Utils::WString _display;
27
	Utils::WString _display;
33
	CBaseFile *_package;
28
	CBaseFile *_package;
34
	CPackages *_packages;
29
	const CPackages *_packages;
35
 
30
 
36
public:
31
public:
37
	CFileProgress(CPackages *packages, CBaseFile *package, const Utils::WString &display) : 
32
	CFileProgress(const CPackages *packages, CBaseFile *package, const Utils::WString &display) : 
38
		_display(display),
33
		_display(display),
39
		_packages(packages),
34
		_packages(packages),
40
		_package(package)
35
		_package(package)
41
	{
36
	{
42
 
37
 
Line 61... Line 56...
61
		{
56
		{
62
			for (unsigned int i = 0; i < 31; ++i)
57
			for (unsigned int i = 0; i < 31; ++i)
63
			{
58
			{
64
				if (file->game() & (1 << i))
59
				if (file->game() & (1 << i))
65
				{
60
				{
66
					Utils::WString g = _packages->GetGameExe()->gameNameFromType(i - 1);
61
					Utils::WString g = _packages->gameExe()->gameNameFromType(i - 1);
67
					if (!g.empty())
62
					if (!g.empty())
68
					{
63
					{
69
						if (game.empty())
64
						if (game.empty())
70
							game = g;
65
							game = g;
71
						else
66
						else
Line 338... Line 333...
338
		}
333
		}
339
		if ( i == 1 )
334
		if ( i == 1 )
340
			wprintf(L"[%3d][%30s]\n", id, ids[0].c_str());
335
			wprintf(L"[%3d][%30s]\n", id, ids[0].c_str());
341
		printf("Enter ID to use > ");
336
		printf("Enter ID to use > ");
342
		shipid = GetInput();
337
		shipid = GetInput();
343
 
338
 
344
		if ( shipid.isNumber() )
339
		if ( shipid.isNumber() )
345
			tShipsLine = ships->get(shipid.toInt())->str;
340
			tShipsLine = ships->get(shipid.toInt())->str;
346
		else
341
		else
347
			tShipsLine = ships->findData(shipid, true);
342
			tShipsLine = ships->findData(shipid, true);
348
	}
343
	}
349
	else
344
	else
350
		ships->findData(shipid, true);
345
		ships->findData(shipid, true);
351
 
346
 
352
	if ( tShipsLine.empty() )
347
	if ( tShipsLine.empty() )
353
	{
348
	{
354
		wprintf(L"Error, %s is not a valid ship id to use\n", shipid.c_str());
349
		wprintf(L"Error, %s is not a valid ship id to use\n", shipid.c_str());
355
		delete pVfs;
350
		delete pVfs;
356
		return;
351
		return;
357
	}
352
	}
358
 
353
 
359
	// now we have the tships to use, lets start to extract the ship
354
	// now we have the tships to use, lets start to extract the ship
360
	wprintf(L"Extracting ship from %s, Ship=%s\n", catfile.c_str(), tShipsLine.token(L";", -2).c_str());
355
	wprintf(L"Extracting ship from %s, Ship=%s\n", catfile.c_str(), tShipsLine.token(L";", -2).c_str());
361
 
356
 
362
	CXspFile ship;
357
	CXspFile ship;
363
	if ( ship.extractShip(pVfs, tShipsLine.token(L";", -2).toString(), 0))
358
	if ( ship.extractShip(pVfs, tShipsLine.token(L";", -2).toString(), 0))
364
	{
359
	{
365
		printf ( "Ship has been successfully extracted\n" );
360
		printf ( "Ship has been successfully extracted\n" );
366
 
361
 
Line 415... Line 410...
415
		case GAME_X3FL:
410
		case GAME_X3FL:
416
			return L"X3: Farnham's Legacy";
411
			return L"X3: Farnham's Legacy";
417
	}
412
	}
418
	return L"Unknown";
413
	return L"Unknown";
419
}
414
}
420
void DisplayVersion(const Utils::WString &filename)
415
void DisplayVersion(const Utils::CommandLine &cmd)
421
{
416
{
-
 
417
	const Utils::WString& filename = cmd.arg(1);
-
 
418
 
422
	// first chekc if file even exists
419
	// first chekc if file even exists
423
	FILE *id = _wfopen(filename.c_str(), L"rb+");
420
	FILE *id = _wfopen(filename.c_str(), L"rb+");
424
	if ( !id )
421
	if ( !id )
425
	{
422
	{
426
		wprintf(L"Error: File, %s, doesn't exist\n", filename.c_str());
423
		wprintf(L"Error: File, %s, doesn't exist\n", filename.c_str());
Line 445... Line 442...
445
	}
442
	}
446
	else if ( check == SPKFILE_SINGLE )
443
	else if ( check == SPKFILE_SINGLE )
447
	{
444
	{
448
		pBaseFile = (CBaseFile *)new CSpkFile();
445
		pBaseFile = (CBaseFile *)new CSpkFile();
449
		wprintf(L"* Opening SPK File, %s...\n", filename.c_str() );
446
		wprintf(L"* Opening SPK File, %s...\n", filename.c_str() );
450
		if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
447
		if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
451
		{
448
		{
452
			wprintf(L"Failed to open the spk files, %s\n", filename.c_str() );
449
			wprintf(L"Failed to open the spk files, %s\n", filename.c_str() );
453
			return;
450
			return;
454
		}
451
		}
455
		read = true;
452
		read = true;
Line 481... Line 478...
481
		read = true;
478
		read = true;
482
	}
479
	}
483
 
480
 
484
	if ( pBaseFile && read)
481
	if ( pBaseFile && read)
485
	{
482
	{
486
		CPackages p;
-
 
487
		p.startup(L".", L".", L".");
-
 
488
 
-
 
489
		CSpkFile *pSpkFile = NULL;
483
		CSpkFile *pSpkFile = NULL;
490
		CXspFile *pXspFile = NULL;
484
		CXspFile *pXspFile = NULL;
491
		if ( check == SPKFILE_SINGLE )
485
		if ( check == SPKFILE_SINGLE )
492
			pSpkFile = (CSpkFile *)pBaseFile;
486
			pSpkFile = (CSpkFile *)pBaseFile;
493
		else
487
		else
Line 511... Line 505...
511
		//for game
505
		//for game
512
		printf("For Games: ");
506
		printf("For Games: ");
513
		if ( !pBaseFile->AnyGameCompatability() )
507
		if ( !pBaseFile->AnyGameCompatability() )
514
			printf("All");
508
			printf("All");
515
		else
509
		else
516
			wprintf(L"%s", p.getGameTypesString(pBaseFile, true).c_str());
510
			wprintf(L"%s", cmd.packages().getGameTypesString(pBaseFile, true).c_str());
517
		printf("\n");
511
		printf("\n");
518
 
512
 
519
		if ( pXspFile )
513
		if ( pXspFile )
520
		{
514
		{
521
			wprintf(L"Ship Display Name: %s\n", pXspFile->shipName(44).c_str());
515
			wprintf(L"Ship Display Name: %s\n", pXspFile->shipName(44).c_str());
Line 653... Line 647...
653
 
647
 
654
					if (display)
648
					if (display)
655
					{
649
					{
656
						if (heading)
650
						if (heading)
657
						{
651
						{
658
							Utils::WString sGame = p.GetGameExe()->gameNameFromType(game - 1);
652
							Utils::WString sGame = cmd.packages().gameExe()->gameNameFromType(game - 1);
659
							wprintf(L"\tGame: %s\n", sGame.c_str());
653
							wprintf(L"\tGame: %s\n", sGame.c_str());
660
							heading = false;
654
							heading = false;
661
						}
655
						}
662
						wprintf(L"\t\t%s (%s) Size: %s\n", file->getNameDirectory(pBaseFile).c_str(), file->fileTypeString().c_str(), file->dataSizeString().c_str());
656
						wprintf(L"\t\t%s (%s) Size: %s\n", file->getNameDirectory(pBaseFile).c_str(), file->fileTypeString().c_str(), file->dataSizeString().c_str());
663
 
657
 
664
					}
658
					}
665
				}
659
				}
666
			}
660
			}
667
 
661
 
668
		}
662
		}
669
		else
663
		else
670
			printf ( "\nThere are currently no files in the package\n" );
664
			printf ( "\nThere are currently no files in the package\n" );
671
	}
665
	}
Line 674... Line 668...
674
		CMultiSpkFile spkfile;
668
		CMultiSpkFile spkfile;
675
		wprintf(L"* Opening Multi-SPK file, %s...\n", filename.c_str() );
669
		wprintf(L"* Opening Multi-SPK file, %s...\n", filename.c_str() );
676
		if ( !pBaseFile->readFile(filename, false))
670
		if ( !pBaseFile->readFile(filename, false))
677
		{
671
		{
678
			wprintf(L"Error: Failed to open the Multi-SPK file, %s\n", filename.c_str() );
672
			wprintf(L"Error: Failed to open the Multi-SPK file, %s\n", filename.c_str() );
679
			return;
673
			return;
680
		}
674
		}
681
 
675
 
682
		wprintf(L"Multi Package Name: %s\n", spkfile.name().c_str() );
676
		wprintf(L"Multi Package Name: %s\n", spkfile.name().c_str() );
683
		wprintf(L"Selection Mode: " );
677
		wprintf(L"Selection Mode: " );
684
		if (spkfile.isSelection ())
678
		if (spkfile.isSelection ())
685
			wprintf(L"On\n" );
679
			wprintf(L"On\n" );
686
		else
680
		else
Line 711... Line 705...
711
{
705
{
712
	int t = GetFileTypeFromString(type);
706
	int t = GetFileTypeFromString(type);
713
	if ( t == -1 )
707
	if ( t == -1 )
714
	{
708
	{
715
		wprintf(L"The file type \"%s\" is invalid\n", type.c_str());
709
		wprintf(L"The file type \"%s\" is invalid\n", type.c_str());
716
		return;
710
		return;
717
	}
711
	}
718
 
712
 
719
	int check = CSpkFile::CheckFile(sfile);
713
	int check = CSpkFile::CheckFile(sfile);
720
	CBaseFile *pBaseFile = 0;
714
	CBaseFile *pBaseFile = 0;
721
	if ( check == SPKFILE_SINGLE )
715
	if ( check == SPKFILE_SINGLE )
722
		pBaseFile = new CSpkFile();
716
		pBaseFile = new CSpkFile();
Line 748... Line 742...
748
		progress.PrintDone();
742
		progress.PrintDone();
749
		wprintf(L"< (Done)\n");
743
		wprintf(L"< (Done)\n");
750
 
744
 
751
		pBaseFile->writeFile(sfile);
745
		pBaseFile->writeFile(sfile);
752
		wprintf(L"\nFile has been written sucessfully\n");
746
		wprintf(L"\nFile has been written sucessfully\n");
753
	}
747
	}
754
	else
748
	else
755
		wprintf(L"< (Error)\n");
749
		wprintf(L"< (Error)\n");
756
}
750
}
757
 
751
 
758
void RemoveFile(const Utils::WString &sfile, const Utils::WString &type, const Utils::WString &addfile)
752
void RemoveFile(const Utils::WString &sfile, const Utils::WString &type, const Utils::WString &addfile)
759
{
753
{
760
	FILE *id = _wfopen(sfile.c_str(), L"rb+");
754
	FILE *id = _wfopen(sfile.c_str(), L"rb+");
761
	if ( !id )
755
	if ( !id )
762
	{
756
	{
763
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
757
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
764
		return;
758
		return;
765
	}
759
	}
766
 
760
 
767
	if ( addfile.empty() )
761
	if ( addfile.empty() )
768
	{
762
	{
769
		wprintf(L"Error: Remove filename is invalid\n" );
763
		wprintf(L"Error: Remove filename is invalid\n" );
770
		return;
764
		return;
771
	}
765
	}
772
	FileType t = GetFileTypeFromString(type);
766
	FileType t = GetFileTypeFromString(type);
773
	if (t == FileType::FILETYPE_UNKNOWN)
767
	if (t == FileType::FILETYPE_UNKNOWN)
774
	{
768
	{
775
		wprintf(L"The file type \"%s\" is invalid\n", type.c_str() );
769
		wprintf(L"The file type \"%s\" is invalid\n", type.c_str() );
776
		return;
770
		return;
777
	}
771
	}
778
 
772
 
779
	int check = CSpkFile::CheckFile(sfile);
773
	int check = CSpkFile::CheckFile(sfile);
780
	CBaseFile *pBaseFile = 0;
774
	CBaseFile *pBaseFile = 0;
781
	if ( check == SPKFILE_SINGLE )
775
	if ( check == SPKFILE_SINGLE )
782
		pBaseFile = new CSpkFile();
776
		pBaseFile = new CSpkFile();
783
	else if ( check == SPKFILE_SINGLESHIP )
777
	else if ( check == SPKFILE_SINGLESHIP )
784
		pBaseFile = new CXspFile();
778
		pBaseFile = new CXspFile();
785
	else if ( check == SPKFILE_BASE )
779
	else if ( check == SPKFILE_BASE )
786
		pBaseFile = new CBaseFile();
780
		pBaseFile = new CBaseFile();
787
 
781
 
788
	if ( pBaseFile )
782
	if ( pBaseFile )
789
	{
783
	{
790
		wprintf(L"Opening File, %s... ", sfile.c_str());
784
		wprintf(L"Opening File, %s... ", sfile.c_str());
791
		if ( !pBaseFile->readFile(sfile))
785
		if ( !pBaseFile->readFile(sfile))
792
		{
786
		{
793
			wprintf(L"(Error)\nUnable to open the file, %s\n", sfile.c_str());
787
			wprintf(L"(Error)\nUnable to open the file, %s\n", sfile.c_str());
794
			return;
788
			return;
795
		}
789
		}
796
		wprintf(L"(Done)\n");
790
		wprintf(L"(Done)\n");
797
 
791
 
798
		wprintf(L"Removing file, %s, from Package\n", addfile.c_str());
792
		wprintf(L"Removing file, %s, from Package\n", addfile.c_str());
799
 
793
 
800
		if(pBaseFile->removeFile(addfile, t))
794
		if(pBaseFile->removeFile(addfile, t))
801
		{
795
		{
802
			wprintf(L"File, %s, has been remove from package\n", addfile.c_str() );
796
			wprintf(L"File, %s, has been remove from package\n", addfile.c_str() );
803
			pBaseFile->writeFile(sfile);
797
			pBaseFile->writeFile(sfile);
804
			wprintf(L"File has been written to disk successfully\n" );
798
			wprintf(L"File has been written to disk successfully\n" );
805
		}
799
		}
806
		else
800
		else
807
			wprintf(L"Unable to remove the file, %s, from the package\n", addfile.c_str());
801
			wprintf(L"Unable to remove the file, %s, from the package\n", addfile.c_str());
808
	}
802
	}
809
	else if ( check == SPKFILE_MULTI )
803
	else if ( check == SPKFILE_MULTI )
810
	{
804
	{
811
		CMultiSpkFile spkfile;
805
		CMultiSpkFile spkfile;
812
		wprintf(L"Opening Multi-SPK file, %s...", sfile.c_str());
806
		wprintf(L"Opening Multi-SPK file, %s...", sfile.c_str());
813
		if ( !spkfile.readFile(sfile))
807
		if ( !spkfile.readFile(sfile))
814
		{
808
		{
815
			wprintf(L"(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str());
809
			wprintf(L"(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str());
816
			return;
810
			return;
817
		}
811
		}
818
		wprintf(L"(Done)\n");
812
		wprintf(L"(Done)\n");
819
 
813
 
820
		const SMultiSpkFile *ms = spkfile.findFile(type);
814
		const SMultiSpkFile *ms = spkfile.findFile(type);
821
		if ( !ms )
815
		if ( !ms )
822
		{
816
		{
823
			wprintf(L"Unable to find the file \"%s\" in the package\n", type.c_str());
817
			wprintf(L"Unable to find the file \"%s\" in the package\n", type.c_str());
824
			return;
818
			return;
825
		}
819
		}
826
 
820
 
827
		wprintf(L"Removing file, %s, from Package\n", addfile.c_str());
821
		wprintf(L"Removing file, %s, from Package\n", addfile.c_str());
828
		if (!spkfile.removeFile(ms))
822
		if (!spkfile.removeFile(ms))
829
		{
823
		{
Line 837... Line 831...
837
		else
831
		else
838
			wprintf(L"(Error)\n");
832
			wprintf(L"(Error)\n");
839
	}
833
	}
840
	else
834
	else
841
		wprintf(L"Error: Invalid file format, unable to open\n");
835
		wprintf(L"Error: Invalid file format, unable to open\n");
842
}
836
}
843
 
837
 
844
 
838
 
845
void CreateMultiFile (const Utils::WString &filename)
839
void CreateMultiFile (const Utils::WString &filename)
846
{
840
{
847
	wprintf(L"* Creating new Multi-SPK File, %s\n\n", filename.c_str());
841
	wprintf(L"* Creating new Multi-SPK File, %s\n\n", filename.c_str());
848
 
842
 
849
	FILE *id = _wfopen(filename.c_str(), L"rb+");
843
	FILE *id = _wfopen(filename.c_str(), L"rb+");
850
	if ( id )
844
	if ( id )
851
	{
845
	{
852
		fclose ( id );
846
		fclose ( id );
853
		wprintf(L"* File already exists, unable to create\n");
847
		wprintf(L"* File already exists, unable to create\n");
854
		return;
848
		return;
855
	}
849
	}
856
 
850
 
857
	id = _wfopen(filename.c_str(), L"wb");
851
	id = _wfopen(filename.c_str(), L"wb");
858
	if ( !id )
852
	if ( !id )
859
	{
853
	{
860
		wprintf(L"* Unable to open file for writing\n");
854
		wprintf(L"* Unable to open file for writing\n");
861
		return;
855
		return;
862
	}
856
	}
863
	fclose(id);
857
	fclose(id);
864
	_wremove(filename.c_str());
858
	_wremove(filename.c_str());
865
 
859
 
866
	CMultiSpkFile spkfile;
860
	CMultiSpkFile spkfile;
867
 
861
 
868
	Utils::WString sInput;
862
	Utils::WString sInput;
869
	wprintf(L"Enter Multi-Spk Package Name: ");
863
	wprintf(L"Enter Multi-Spk Package Name: ");
870
	spkfile.setName(GetInput());
864
	spkfile.setName(GetInput());
871
 
865
 
872
	while ( true )
866
	while ( true )
Line 875... Line 869...
875
		Utils::WString i = GetInput();
869
		Utils::WString i = GetInput();
876
		i = i.upper();
870
		i = i.upper();
877
		if ( i == L"Y" )
871
		if ( i == L"Y" )
878
			spkfile.setSelection(true);
872
			spkfile.setSelection(true);
879
		if ( (i == L"Y") || (i == L"N") )
873
		if ( (i == L"Y") || (i == L"N") )
880
			break;
874
			break;
881
	}
875
	}
882
 
876
 
883
	while ( true )
877
	while ( true )
884
	{
878
	{
885
		wprintf(L"\nEnter Spk File to add (Enter \"0\" to finish): " );
879
		wprintf(L"\nEnter Spk File to add (Enter \"0\" to finish): " );
886
		sInput = GetInput();
880
		sInput = GetInput();
887
		if ( sInput == L"0" )
881
		if ( sInput == L"0" )
888
			break;
882
			break;
889
 
883
 
Line 897... Line 891...
897
			if ( !spkfile.addFile(sInput))
891
			if ( !spkfile.addFile(sInput))
898
				wprintf(L"Error: Unable to add SPK file to package\n");
892
				wprintf(L"Error: Unable to add SPK file to package\n");
899
			else
893
			else
900
				wprintf(L"File Added to package (%s)\n", sInput.c_str());
894
				wprintf(L"File Added to package (%s)\n", sInput.c_str());
901
		}
895
		}
902
	}
896
	}
903
 
897
 
904
	if ( spkfile.numFiles() < 1 )
898
	if ( spkfile.numFiles() < 1 )
905
		wprintf(L"\nError: You have added no files, you must add at least one file to create a package\n");
899
		wprintf(L"\nError: You have added no files, you must add at least one file to create a package\n");
906
	else
900
	else
907
	{
901
	{
908
		wprintf(L"Writing MultiSpk file... ");
902
		wprintf(L"Writing MultiSpk file... ");
Line 911... Line 905...
911
		else
905
		else
912
			wprintf(L"(Error)\n" );
906
			wprintf(L"(Error)\n" );
913
	}
907
	}
914
 
908
 
915
}
909
}
916
 
910
 
917
void CreateFile(const Utils::WString &filename)
911
void CreateFile(const Utils::WString &filename)
918
{
912
{
919
	wprintf(L"* Creating new SPK File, %s\n\n", filename.c_str());
913
	wprintf(L"* Creating new SPK File, %s\n\n", filename.c_str());
920
 
914
 
921
	FILE *id = _wfopen(filename.c_str(), L"rb+");
915
	FILE *id = _wfopen(filename.c_str(), L"rb+");
922
	if ( id )
916
	if ( id )
923
	{
917
	{
924
		fclose(id);
918
		fclose(id);
925
		wprintf(L"* File already exists, unable to create\n");
919
		wprintf(L"* File already exists, unable to create\n");
926
		return;
920
		return;
927
	}
921
	}
928
 
922
 
Line 958... Line 952...
958
	spkfile.setCreationDate(Utils::WString::FromString(dateString));
952
	spkfile.setCreationDate(Utils::WString::FromString(dateString));
959
 
953
 
960
	spkfile.writeFile(filename, NULL);
954
	spkfile.writeFile(filename, NULL);
961
	wprintf(L"SPK file has been written to disk: %s\n", filename.c_str() );
955
	wprintf(L"SPK file has been written to disk: %s\n", filename.c_str() );
962
}
956
}
963
 
957
 
964
void ExtractFiles (const Utils::CommandLine &cmd)
958
void ExtractFiles (const Utils::CommandLine &cmd)
965
{
959
{
966
	const Utils::WString& sfile = cmd.arg(1);
960
	const Utils::WString& sfile = cmd.arg(1);
967
	const Utils::WString & dir = cmd.arg(2);
961
	const Utils::WString & dir = cmd.arg(2);
968
	int game = (cmd.hasSwitch(L"game")) ? CBaseFile::GetGameFromString(cmd.switchData(L"game")) : 0;
962
	int game = (cmd.hasSwitch(L"game")) ? CBaseFile::GetGameFromString(cmd.switchData(L"game")) : 0;
969
 
963
 
970
	// First checks if the file exists by opening it
964
	// First checks if the file exists by opening it
971
	CFileIO File(sfile);
965
	CFileIO File(sfile);
972
	if (!File.exists())
966
	if (!File.exists())
973
		File.open(CDirIO(g_dir).file(sfile));
967
		File.open(CDirIO(g_dir).file(sfile));
974
	if (!File.exists())
968
	if (!File.exists())
975
	{
969
	{
976
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
970
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
977
		return;
971
		return;
978
	}
972
	}
979
 
-
 
980
	CPackages packages;
-
 
981
	packages.startup(L".", L".", L".");
-
 
982
 
973
 
983
	int check = CSpkFile::CheckFile(File.fullFilename());
974
	int check = CSpkFile::CheckFile(File.fullFilename());
984
 
975
 
985
	// extracts a file from single packages file
976
	// extracts a file from single packages file
986
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
977
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
987
	{
978
	{
988
		// creates the spkfile object
979
		// creates the spkfile object
989
		CBaseFile *pBaseFile = 0;
980
		CBaseFile *pBaseFile = 0;
990
		if ( check == SPKFILE_SINGLE )
981
		if ( check == SPKFILE_SINGLE )
Line 1005... Line 996...
1005
		wprintf(L"(Done)\n");
996
		wprintf(L"(Done)\n");
1006
 
997
 
1007
		if(game == 0)
998
		if(game == 0)
1008
			wprintf(L"Extracting all files from archive...\n\n");
999
			wprintf(L"Extracting all files from archive...\n\n");
1009
		else
1000
		else
1010
			wprintf(L"Extracting %s files from archive...\n\n", packages.GetGameExe()->gameNameFromType(game - 1).c_str());
1001
			wprintf(L"Extracting %s files from archive...\n\n", cmd.packages().gameExe()->gameNameFromType(game - 1).c_str());
1011
 
1002
 
1012
		CFileProgress info(&packages, pBaseFile, "Extracting");
1003
		CFileProgress info(&cmd.packages(), pBaseFile, "Extracting");
1013
		if (packages.extractAll(pBaseFile, File.dirIO().dir(dir), game, true, &info) )
1004
		if (cmd.packages().extractAll(pBaseFile, File.dirIO().dir(dir), game, true, &info))
1014
			wprintf(L"\n(Done)\nFiles have been extracted successfully\n");
1005
			wprintf(L"\n(Done)\nFiles have been extracted successfully\n");
1015
		else
1006
		else
1016
			wprintf(L"\n(Error)\nThere was a problem extracting the files\n");
1007
			wprintf(L"\n(Error)\nThere was a problem extracting the files\n");
1017
	}
1008
	}
1018
	else
1009
	else
Line 1241... Line 1232...
1241
{
1232
{
1242
	wprintf(L"(ASK) Enter the value for, %s: ", command.c_str());
1233
	wprintf(L"(ASK) Enter the value for, %s: ", command.c_str());
1243
	return GetInput();
1234
	return GetInput();
1244
}
1235
}
1245
 
1236
 
1246
void GenerateUpdateList(int argc, char **argv)
1237
void GenerateUpdateList(const Utils::CommandLine &cmd)
1247
{
1238
{
1248
	Utils::WString currentDir = CFileIO(Utils::WString::FromString(argv[0])).dir();
-
 
1249
	CDirIO Dir(currentDir);
-
 
1250
 
-
 
1251
	Utils::WStringList list;
1239
	Utils::WStringList list;
1252
	for (int i = 2; i < argc; ++i)
1240
	for (int i = 1; i < cmd.argCount(); ++i)
1253
	{
1241
	{
1254
		Utils::WString file(argv[i]);
1242
		Utils::WString file(cmd.arg(i));
1255
		if (CFileIO::Exists(file))
1243
		if (CFileIO::Exists(file))
1256
			list.pushBack(file, L"file");
1244
			list.pushBack(file, L"file");
1257
		else if (CFileIO::Exists(Dir.file(file)))
1245
		else if (CFileIO::Exists(cmd.dirIO().file(file)))
1258
			list.pushBack(Dir.file(file), L"file");
1246
			list.pushBack(cmd.dirIO().file(file), L"file");
1259
		else if (CDirIO::Exists(file))
1247
		else if (CDirIO::Exists(file))
1260
			list.pushBack(file, L"dir");
1248
			list.pushBack(file, L"dir");
1261
		else if (CDirIO::Exists(Dir.dir(file)))
1249
		else if (CDirIO::Exists(cmd.dirIO().dir(file)))
1262
			list.pushBack(Dir.dir(file), L"dir");
1250
			list.pushBack(cmd.dirIO().dir(file), L"dir");
1263
		else
1251
		else
1264
			list.pushBack(file, L"pattern");
1252
			list.pushBack(file, L"pattern");
1265
	}
1253
	}
1266
 
1254
 
1267
	if (list.empty())
1255
	if (list.empty())
Line 1278... Line 1266...
1278
			else if (data == L"dir")
1266
			else if (data == L"dir")
1279
			{
1267
			{
1280
				CDirIO dir(file);
1268
				CDirIO dir(file);
1281
				Utils::WStringList d;
1269
				Utils::WStringList d;
1282
				if (dir.dirList(d))
1270
				if (dir.dirList(d))
1283
				{
1271
				{
1284
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1272
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1285
					{
1273
					{
1286
						Utils::WString ext = CFileIO((*itr2)->str).extension().lower();
1274
						Utils::WString ext = CFileIO((*itr2)->str).extension().lower();
1287
						if(ext == L"xsp" || ext == L"spk")
1275
						if(ext == L"xsp" || ext == L"spk")
1288
							fileList.pushBack(dir.file((*itr2)->str));
1276
							fileList.pushBack(dir.file((*itr2)->str));
1289
					}
1277
					}
1290
				}
1278
				}
1291
			}
1279
			}
Line 1293... Line 1281...
1293
			{				
1281
			{				
1294
				CFileIO f(file);
1282
				CFileIO f(file);
1295
				CDirIO dir(f.dir());
1283
				CDirIO dir(f.dir());
1296
 
1284
 
1297
				if (!dir.exists())
1285
				if (!dir.exists())
1298
					dir = CDirIO(Dir.dir(dir.dir()));
1286
					dir = CDirIO(cmd.dirIO().dir(dir.dir()));
1299
 
1287
 
1300
				Utils::WStringList d;
1288
				Utils::WStringList d;
1301
				if (dir.dirList(d, Utils::WString::Null(), f.filename()))
1289
				if (dir.dirList(d, Utils::WString::Null(), f.filename()))
1302
				{
1290
				{
1303
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1291
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
Line 1312... Line 1300...
1312
 
1300
 
1313
		if (fileList.empty())
1301
		if (fileList.empty())
1314
			wprintf(L"unable to find any packages");
1302
			wprintf(L"unable to find any packages");
1315
		else
1303
		else
1316
		{
1304
		{
1317
			CPackages packages;
-
 
1318
 
-
 
1319
			Utils::WStringList filedata;
1305
			Utils::WStringList filedata;
1320
			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
1306
			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
1321
			{
1307
			{
1322
				wprintf(L"Reading file: %s\n", (*itr)->str.c_str());
1308
				wprintf(L"Reading file: %s\n", (*itr)->str.c_str());
1323
 
1309
 
1324
				int error = 0;
1310
				int error = 0;
1325
				CBaseFile *p = packages.openPackage((*itr)->str.toString(), &error, 0, SPKREAD_NODATA);
1311
				CBaseFile *p = cmd.packages().openPackage((*itr)->str.toString(), &error, 0, SPKREAD_NODATA);
1326
				if (!p)
1312
				if (!p)
1327
				{
1313
				{
1328
					printf("\tERROR!\n");
1314
					printf("\tERROR!\n");
1329
					continue;
1315
					continue;
1330
				}
1316
				}
Line 1340... Line 1326...
1340
 
1326
 
1341
			if (filedata.empty())
1327
			if (filedata.empty())
1342
				wprintf(L"unable to find any packages");
1328
				wprintf(L"unable to find any packages");
1343
			else				
1329
			else				
1344
			{
1330
			{
1345
				Utils::WString dest = Dir.file(L"xpackagedata.dat");
1331
				Utils::WString dest = cmd.dirIO().file(L"xpackagedata.dat");
1346
				if (CFileIO(dest).writeFile(&filedata))
1332
				if (CFileIO(dest).writeFile(&filedata))
1347
					wprintf(L"web update file, xpackagedata.dat, generated");
1333
					wprintf(L"web update file, xpackagedata.dat, generated");
1348
				else
1334
				else
1349
					wprintf(L"unable to write update file");
1335
					wprintf(L"unable to write update file");
1350
			}
1336
			}
Line 1479... Line 1465...
1479
 
1465
 
1480
	if ( verify )
1466
	if ( verify )
1481
		wprintf(L"Verifying Packager Script: %s\n", filename.c_str());
1467
		wprintf(L"Verifying Packager Script: %s\n", filename.c_str());
1482
 
1468
 
1483
	CPackages p;
1469
	CPackages p;
1484
	p.startup(L".", L".", myDoc);
1470
	p.startup(L".", cmd.tempDir(), cmd.myDoc());
1485
	Utils::WStringList malformed, unknown;
1471
	Utils::WStringList malformed, unknown;
1486
 
1472
 
1487
	Utils::WString curDir = CFileIO(filename).dir();
1473
	Utils::WString curDir = CFileIO(filename).dir();
1488
	if ( curDir.empty() ) curDir = L"./";
1474
	if ( curDir.empty() ) curDir = L"./";
1489
 
1475
 
Line 1621... Line 1607...
1621
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1607
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1622
	{
1608
	{
1623
		if ( argc < 3 )
1609
		if ( argc < 3 )
1624
			wprintf(L"Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.cmdName().c_str());
1610
			wprintf(L"Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.cmdName().c_str());
1625
		else
1611
		else
1626
			DisplayVersion(argv[2]);
1612
			DisplayVersion(cmd);
1627
	}
1613
	}
1628
 
1614
 
1629
	// creates a new spk file
1615
	// creates a new spk file
1630
	else if ( command == L"-c" || command == L"-create" )
1616
	else if ( command == L"-c" || command == L"-create" )
1631
	{
1617
	{
Line 1812... Line 1798...
1812
	else if (command == L"-packagelist")
1798
	else if (command == L"-packagelist")
1813
	{
1799
	{
1814
		if (argc < 3)
1800
		if (argc < 3)
1815
			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());
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());
1816
		else
1802
		else
1817
			GenerateUpdateList(argc, argv);
1803
			GenerateUpdateList(cmd);
1818
	}
1804
	}
1819
 
1805
 
1820
	// not a valid switch, display syntax
1806
	// not a valid switch, display syntax
1821
	else
1807
	else
1822
		PrintSyntax(cmd.cmdName());
1808
		PrintSyntax(cmd.cmdName());