Subversion Repositories spk

Rev

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

Rev 297 Rev 298
Line 66... Line 66...
66
private:
66
private:
67
	float m_fNextPercent;
67
	float m_fNextPercent;
68
	int   m_iCount;
68
	int   m_iCount;
69
};
69
};
70
 
70
 
71
#define FLAGS "[-voctm][-d destination][-l langid]"
71
#define FLAGS L"[-voctm][-d destination][-l langid]"
72
 
72
 
73
CyString	g_dir;
73
Utils::WString	g_dir;
74
bool	g_debug = false;
74
bool	g_debug = false;
75
bool	g_force = false;
75
bool	g_force = false;
76
int		g_indent = 0;
76
int		g_indent = 0;
77
/*
77
/*
78
	Func:	GetInput
78
	Func:	GetInput
Line 92... Line 92...
92
	}
92
	}
93
 
93
 
94
	return line;
94
	return line;
95
}
95
}
96
 
96
 
97
void PrintSyntax ( CyString cmd )
97
void PrintSyntax(const Utils::WString &cmd)
98
{
98
{
99
	printf ( "Syntax: %s %s </command> [arguments]\n", cmd.c_str(), FLAGS );
99
	wprintf(L"Syntax: %s %s </command> [arguments]\n", cmd.c_str(), FLAGS );
100
	printf ( "\nCommands:\n" );
100
	wprintf(L"\nCommands:\n" );
101
	printf ( "   /list\n\t- Lists installed packages\n" );
101
	wprintf(L"   /list\n\t- Lists installed packages\n" );
102
	printf ( "   /install <file>\n\t- Installs a package file\n" );
102
	wprintf(L"   /install <file>\n\t- Installs a package file\n" );
103
	printf ( "   /uninstall <package#>\n\t- Uninstalls a package, use id number from list\n" );
103
	wprintf(L"   /uninstall <package#>\n\t- Uninstalls a package, use id number from list\n" );
104
	printf ( "   /enable <package#>\n\t- Enables an installed package\n" );
104
	wprintf(L"   /enable <package#>\n\t- Enables an installed package\n" );
105
	printf ( "   /disable <package#>\n\t- Disables an installed package\n" );
105
	wprintf(L"   /disable <package#>\n\t- Disables an installed package\n" );
106
	printf ( "   /removeuninstall\n\t- Removes uninstall scripts\n" );
106
	wprintf(L"   /removeuninstall\n\t- Removes uninstall scripts\n" );
107
	printf ( "   /removeshared\n\t- Removes unused sharded files\n" );
107
	wprintf(L"   /removeshared\n\t- Removes unused sharded files\n" );
108
	printf ( "\nSwitchs:\n" );
108
	wprintf(L"\nSwitchs:\n" );
109
	printf ( "   -d (--directory) [directory]\n\tChange destination directory, otherwise uses current\n\n" );
109
	wprintf(L"   -d (--directory) [directory]\n\tChange destination directory, otherwise uses current\n\n" );
110
	printf ( "   -v (--verbose)\n\tTurns on verbose mode\n\n" );
110
	wprintf(L"   -v (--verbose)\n\tTurns on verbose mode\n\n" );
111
	printf ( "   -o (--override)\n\tOverride install warnings\n\tIE. allows you to install older scripts\n\n" );
111
	wprintf(L"   -o (--override)\n\tOverride install warnings\n\tIE. allows you to install older scripts\n\n" );
112
	printf ( "   -t (--textrename)\n\tForces text file renaming for installed packages\n\n" );
112
	wprintf(L"   -t (--textrename)\n\tForces text file renaming for installed packages\n\n" );
113
	printf ( "   -l (--language) <language>\n\tSets the language id for text file renaming\n\totheriwse reads game lang.dat\n\n" );
113
	wprintf(L"   -l (--language) <language>\n\tSets the language id for text file renaming\n\totheriwse reads game lang.dat\n\n" );
114
	printf ( "   -c (--enablechild)\n\tAuto Enabled all children when parent is enabled\n\n" );
114
	wprintf(L"   -c (--enablechild)\n\tAuto Enabled all children when parent is enabled\n\n" );
115
	printf ( "   -m (--forcemod)\n\tForces a mod enabled even if theres one already enabled\n\n" );
115
	wprintf(L"   -m (--forcemod)\n\tForces a mod enabled even if theres one already enabled\n\n" );
116
}
116
}
117
 
117
 
118
void DisplayPackage(CBaseFile *p, int indent, int language)
118
void DisplayPackage(CBaseFile *p, int indent, int language)
119
{
119
{
120
	Utils::WString version = p->version();
120
	Utils::WString version = p->version();
Line 576... Line 576...
576
	scanf ( "%s", &pause );
576
	scanf ( "%s", &pause );
577
#endif
577
#endif
578
}
578
}
579
 
579
 
580
 
580
 
581
int ParseCommandSwitchs(char c, Utils::String &destination, CPackages *packages, int start, int *arg, char **argv)
581
int ParseCommandSwitchs(wchar_t c, Utils::WString &destination, CPackages *packages, int start, int *arg, char **argv)
582
{
582
{
583
	switch ( c )
583
	switch ( c )
584
	{
584
	{
585
		case 'o':
585
		case L'o':
586
			g_force = true;
586
			g_force = true;
587
			break;
587
			break;
588
		case 'v':
588
		case L'v':
589
			g_debug = true;
589
			g_debug = true;
590
			break;
590
			break;
591
		case 'd':
591
		case L'd':
592
			destination = argv[*arg];
592
			destination = argv[*arg];
593
			destination = destination.findReplace("\\", "/");
593
			destination = destination.findReplace("\\", "/");
594
			++(*arg);
594
			++(*arg);
595
			++start;
595
			++start;
596
			break;
596
			break;
597
		case 't':
597
		case L't':
598
			packages->SetRenameText(true);
598
			packages->SetRenameText(true);
599
			break;
599
			break;
600
		case 'l':
600
		case L'l':
601
			packages->SetLanguage(CyString(argv[*arg]).ToInt());
601
			packages->SetLanguage(Utils::WString(argv[*arg]).toInt());
602
			++(*arg);
602
			++(*arg);
603
			++start;
603
			++start;
604
			break;
604
			break;
605
		case 'c':
605
		case L'c':
606
			packages->SetAutoEnable(true);
606
			packages->SetAutoEnable(true);
607
			break;
607
			break;
608
		case 'm':
608
		case L'm':
609
			packages->SetForceModInstall(true);
609
			packages->SetForceModInstall(true);
610
			break;
610
			break;
611
	}
611
	}
612
 
612
 
613
	return start;
613
	return start;
Line 627... Line 627...
627
{
627
{
628
 	// display program header to command prompt
628
 	// display program header to command prompt
629
	printf ( "\nSPKInstall V0.90 (SPK Library Version %.2f) 18/10/2009 Created by Cycrow\n\n", GetLibraryVersion() );
629
	printf ( "\nSPKInstall V0.90 (SPK Library Version %.2f) 18/10/2009 Created by Cycrow\n\n", GetLibraryVersion() );
630
 
630
 
631
	// parse the cmd name
631
	// parse the cmd name
632
	CyString cmd (argv[0]);
632
	Utils::WString cmd (argv[0]);
633
 
633
 
634
	cmd = cmd.FindReplace ( ";\\";, "/" );
634
	cmd = cmd.findReplace(L";\\";, L"/");
635
	g_dir = cmd.GetToken ( 0, cmd.NumToken('/') - 1, &apos;/&apos; );
635
	g_dir = cmd.tokens(L"/", 1, cmd.countToken(L";/&quot;) - 1);
636
	cmd = cmd.GetToken ( cmd.NumToken('/'), '/&apos; );
636
	cmd = cmd.token(L"/&quot;, -1);
637
 
637
 
638
	if ( g_dir.Empty() )
638
	if (g_dir.empty())
639
	{
639
	{
640
	    #ifdef _WIN32
640
	    #ifdef _WIN32
641
		g_dir = CyString(_getcwd(NULL, 0));
641
		g_dir = Utils::WString(_getcwd(NULL, 0));
642
		#else
642
		#else
643
		g_dir = CyString(getcwd(NULL, 0));
643
		g_dir = Utils::WString(getcwd(NULL, 0));
644
		#endif
644
		#endif
645
		if ( g_dir.Empty() )
645
		if (g_dir.empty())
646
			g_dir = "./";
646
			g_dir = "./";
647
	}
647
	}
648
 
648
 
649
	// not enough arguments, display the syntax and exit
649
	// not enough arguments, display the syntax and exit
650
	if ( argc < 2 )
650
	if ( argc < 2 )
Line 652... Line 652...
652
		PrintSyntax(cmd);
652
		PrintSyntax(cmd);
653
		Pause();
653
		Pause();
654
		exit ( 1 );
654
		exit ( 1 );
655
	}
655
	}
656
 
656
 
657
	Utils::String destination = g_dir.ToString();
657
	Utils::WString destination = g_dir;
658
	Utils::WStringList lErrors;
658
	Utils::WStringList lErrors;
659
 
659
 
660
	// get the command flag
660
	// get the command flag
661
	CyString command(argv[1]);
661
	Utils::WString command(argv[1]);
662
	command = command.lower();
662
	command = command.lower();
663
 
663
 
664
	CPackages packages;
664
	CPackages packages;
665
	CyString myDoc = g_dir;
665
	Utils::WString myDoc = g_dir;
666
#ifdef _WIN32
666
#ifdef _WIN32
667
	TCHAR pszPath[MAX_PATH];
667
	TCHAR pszPath[MAX_PATH];
668
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
668
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
669
		myDoc = (char *)pszPath;
669
		myDoc = (char *)pszPath;
670
#endif
670
#endif
Line 682... Line 682...
682
		}
682
		}
683
		++start;
683
		++start;
684
 
684
 
685
		// single long commands
685
		// single long commands
686
		int arg = 2;
686
		int arg = 2;
687
		if ( command.Left(2) == "--" )
687
		if ( command.left(2) == L"--" )
688
		{
688
		{
689
			CyString cmd = command.Right(-2);
689
			Utils::WString cmd = command.right(-2);
690
			cmd = cmd.ToLower();
690
			cmd.toLower();
691
 
691
 
692
			char c = 0;
692
			char c = 0;
693
			if ( cmd == "override" )
693
			if ( cmd == L"override" )
694
				c = 'o';
694
				c = 'o';
695
			else if ( cmd == "verbose" )
695
			else if ( cmd == L"verbose" )
696
				c = 'v';
696
				c = 'v';
697
			else if ( cmd == "directory" )
697
			else if ( cmd == L"directory" )
698
				c = 'd';
698
				c = 'd';
699
			else if ( cmd == "textrename" )
699
			else if ( cmd == L"textrename" )
700
				c = 't';
700
				c = 't';
701
			else if ( cmd == "enablechild" )
701
			else if ( cmd == L"enablechild" )
702
				c = 'c';
702
				c = 'c';
703
			else if ( cmd == "language" )
703
			else if ( cmd == L"language" )
704
				c = 'l';
704
				c = 'l';
705
			else if ( cmd == "forcemod" )
705
			else if ( cmd == L"forcemod" )
706
				c = 'm';
706
				c = 'm';
707
 
707
 
708
			if ( c )
708
			if ( c )
709
				start = ParseCommandSwitchs(c, destination, &packages, start, &arg, argv);
709
				start = ParseCommandSwitchs(c, destination, &packages, start, &arg, argv);
710
		}
710
		}
711
		else
711
		else
712
		{
712
		{
713
			// now parse arguments
713
			// now parse arguments
714
			for ( int i = 1; i < (int)command.Length(); i++ )
714
			for ( int i = 1; i < (int)command.length(); i++ )
715
				start = ParseCommandSwitchs(command[i], destination, &packages, start, &arg, argv);
715
				start = ParseCommandSwitchs(command[i], destination, &packages, start, &arg, argv);
716
		}
716
		}
717
 
717
 
718
		if ( argc < start )
718
		if ( argc < start )
719
		{
719
		{
Line 723... Line 723...
723
		command = argv[start - 1];
723
		command = argv[start - 1];
724
	}
724
	}
725
 
725
 
726
	if ( command[0] == '/' )
726
	if ( command[0] == '/' )
727
	{
727
	{
728
		char c = command[1];
728
		wchar_t c = command[1];
729
 
729
 
730
		bool disabled = false;
730
		bool disabled = false;
731
 
731
 
732
		CyString checkCmd = command.ToLower();
732
		Utils::WString checkCmd = command.lower();
733
		if ( checkCmd == "/install" )
733
		if ( checkCmd == L"/install" )
734
			c = 'i';
734
			c = L'i';
735
		else if ( checkCmd == "/installdisable" )
735
		else if ( checkCmd == L"/installdisable" )
736
		{
736
		{
737
			c = 'i';
737
			c = L'i';
738
			disabled = true;
738
			disabled = true;
739
		}
739
		}
740
		else if ( checkCmd == "/uninstall" )
740
		else if ( checkCmd == L"/uninstall" )
741
			c = 'u';
741
			c = L'u';
742
		else if ( checkCmd == "/enable" )
742
		else if ( checkCmd == L"/enable" )
743
			c = 'e';
743
			c = L'e';
744
		else if ( checkCmd == "/disable" )
744
		else if ( checkCmd == L"/disable" )
745
			c = 'd';
745
			c = L'd';
746
		else if ( checkCmd == "/list" )
746
		else if ( checkCmd == L"/list" )
747
			c = 'l';
747
			c = L'l';
748
		else if ( checkCmd == "/removeshared" )
748
		else if ( checkCmd == L"/removeshared" )
749
			c = 's';
749
			c = L's';
750
		else if ( checkCmd == "/removeunisntall" )
750
		else if ( checkCmd == L"/removeunisntall" )
751
			c = 'r';
751
			c = L'r';
752
 
752
 
753
		if ( c == 'i' || c == 'l' || c == 'u' || c == 'e' || c == 'd' || c == 'r' || c == 's' )
753
		if ( c == L'i' || c == L'l' || c == L'u' || c == L'e' || c == L'd' || c == L'r' || c == L's' )
754
		{
754
		{
755
			Utils::WString endMessage;
755
			Utils::WString endMessage;
756
 
756
 
757
			printf ( "                                   |0              100|\n\n");
757
			wprintf(L"                                   |0              100|\n\n");
758
			printf ( "  - Reading game directory         " );
758
			wprintf(L"  - Reading game directory         ");
759
 
759
 
760
			CProgressConsole progress;
760
			CProgressConsole progress;
761
 
761
 
762
			if ( packages.read(destination, &progress) )
762
			if ( packages.read(destination, &progress) )
763
			{
763
			{
Line 791... Line 791...
791
 
791
 
792
			switch ( c )
792
			switch ( c )
793
			{
793
			{
794
				case 'i':
794
				case 'i':
795
					if ( argc <= start )
795
					if ( argc <= start )
796
						printf ( "Syntax: %s [flags] /i <file>\n\tInstalls a package to the destination\n", cmd.c_str() );
796
						wprintf(L"Syntax: %s [flags] /i <file>\n\tInstalls a package to the destination\n", cmd.c_str() );
797
					else
797
					else
798
					{
798
					{
799
						Utils::WString aftertext = InstallPackage(lArguments, &lErrors, &packages, disabled);
799
						Utils::WString aftertext = InstallPackage(lArguments, &lErrors, &packages, disabled);
800
						if(!aftertext.empty())
800
						if(!aftertext.empty())
801
						{
801
						{
Line 806... Line 806...
806
					}
806
					}
807
					break;
807
					break;
808
 
808
 
809
				case 'u':
809
				case 'u':
810
					if ( argc <= start )
810
					if ( argc <= start )
811
						printf ( "Syntax: %s [flags] /u <package#>\n\tUninstalls a package, package# is from the /l list command\n", cmd.c_str() );
811
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tUninstalls a package, package# is from the /l list command\n", cmd.c_str() );
812
					else
812
					else
813
					{
813
					{
814
						prepare = UninstallPackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
814
						prepare = UninstallPackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
815
						PrintDebug(&lErrors);
815
						PrintDebug(&lErrors);
816
					}
816
					}
817
					break;
817
					break;
818
 
818
 
819
				case 'e':
819
				case 'e':
820
					if ( argc <= start )
820
					if ( argc <= start )
821
						printf ( "Syntax: %s [flags] /u <package#>\n\tEnabled an installed package thats been disabled\n", cmd.c_str() );
821
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tEnabled an installed package thats been disabled\n", cmd.c_str() );
822
					else
822
					else
823
					{
823
					{
824
						prepare = EnablePackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
824
						prepare = EnablePackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
825
						PrintDebug(&lErrors);
825
						PrintDebug(&lErrors);
826
					}
826
					}
827
					break;
827
					break;
828
 
828
 
829
				case 'd':
829
				case 'd':
830
					if ( argc <= start )
830
					if ( argc <= start )
831
						printf ( "Syntax: %s [flags] /u <package#>\n\tDisabled an installed package\n", cmd.c_str() );
831
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tDisabled an installed package\n", cmd.c_str() );
832
					else
832
					else
833
					{
833
					{
834
						prepare = DisablePackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
834
						prepare = DisablePackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
835
						PrintDebug(&lErrors);
835
						PrintDebug(&lErrors);
836
					}
836
					}
837
					break;
837
					break;
838
 
838
 
839
				case 'l':
839
				case 'l':