Subversion Repositories spk

Rev

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

Rev 298 Rev 329
Line 16... Line 16...
16
#include <direct.h>
16
#include <direct.h>
17
#include <shlobj.h>
17
#include <shlobj.h>
18
#endif
18
#endif
19
 
19
 
20
#include <Package/InstallText.h>
20
#include <Package/InstallText.h>
-
 
21
#include "Utils/CommandLine.h"	
21
 
22
 
22
#define BETA 1
23
#define BETA 1
23
 
24
 
24
class CProgressConsole : public CProgressInfo
25
class CProgressConsole : public CProgressInfo
25
{
26
{
Line 66... Line 67...
66
private:
67
private:
67
	float m_fNextPercent;
68
	float m_fNextPercent;
68
	int   m_iCount;
69
	int   m_iCount;
69
};
70
};
70
 
71
 
71
#define FLAGS L"[-voctm][-d destination][-l langid]"
72
#define FLAGS L"[-voctm][--dir:destination][--lang:langid]"
72
 
73
 
73
Utils::WString	g_dir;
74
Utils::WString	g_dir;
74
bool	g_debug = false;
75
bool	g_debug = false;
75
bool	g_force = false;
76
bool	g_force = false;
76
int		g_indent = 0;
77
int		g_indent = 0;
Line 94... Line 95...
94
	return line;
95
	return line;
95
}
96
}
96
 
97
 
97
void PrintSyntax(const Utils::WString &cmd)
98
void PrintSyntax(const Utils::WString &cmd)
98
{
99
{
99
	wprintf(L"Syntax: %s %s </command> [arguments]\n", cmd.c_str(), FLAGS );
100
	wprintf(L"Syntax: %s %s <command> [arguments]\n", cmd.c_str(), FLAGS );
100
	wprintf(L"\nCommands:\n" );
101
	wprintf(L"\nCommands:\n" );
101
	wprintf(L"   /list\n\t- Lists installed packages\n" );
102
	wprintf(L"   list\n\t- Lists installed packages\n");
-
 
103
	wprintf(L"   info <package#>\n\t- Info about an installed package, use id number from list\n");
102
	wprintf(L"   /install <file>\n\t- Installs a package file\n" );
104
	wprintf(L"   install <file>\n\t- Installs a package file\n" );
103
	wprintf(L"   /uninstall <package#>\n\t- Uninstalls a package, use id number from list\n" );
105
	wprintf(L"   uninstall <package#>\n\t- Uninstalls a package, use id number from list\n" );
104
	wprintf(L"   /enable <package#>\n\t- Enables an installed package\n" );
106
	wprintf(L"   enable <package#>\n\t- Enables an installed package\n" );
105
	wprintf(L"   /disable <package#>\n\t- Disables an installed package\n" );
107
	wprintf(L"   disable <package#>\n\t- Disables an installed package\n" );
106
	wprintf(L"   /removeuninstall\n\t- Removes uninstall scripts\n" );
108
	wprintf(L"   removeuninstall\n\t- Removes uninstall scripts\n" );
107
	wprintf(L"   /removeshared\n\t- Removes unused sharded files\n" );
109
	wprintf(L"   removeshared\n\t- Removes unused sharded files\n" );
108
	wprintf(L"\nSwitchs:\n" );
110
	wprintf(L"\nSwitchs:\n");
109
	wprintf(L"   -d (--directory) [directory]\n\tChange destination directory, otherwise uses current\n\n" );
111
	wprintf(L"   --dir:<directory>\n\tChange destination directory, otherwise uses current\n\n" );
-
 
112
	wprintf(L"   --lang:<language>\n\tSets the language id for text file renaming\n\totheriwse reads game lang.dat\n\n");
-
 
113
	wprintf(L"\nFlags:\n");
110
	wprintf(L"   -v (--verbose)\n\tTurns on verbose mode\n\n" );
114
	wprintf(L"   -v (--verbose)\n\tTurns on verbose mode\n\n");
111
	wprintf(L"   -o (--override)\n\tOverride install warnings\n\tIE. allows you to install older scripts\n\n" );
115
	wprintf(L"   -o (--override)\n\tOverride install warnings\n\tIE. allows you to install older scripts\n\n");
112
	wprintf(L"   -t (--textrename)\n\tForces text file renaming for installed packages\n\n" );
116
	wprintf(L"   -t (--textrename)\n\tForces text file renaming for installed packages\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
	wprintf(L"   -c (--enablechild)\n\tAuto Enabled all children when parent is enabled\n\n" );
117
	wprintf(L"   -c (enablechild)\n\tAuto Enabled all children when parent is enabled\n\n");
115
	wprintf(L"   -m (--forcemod)\n\tForces a mod enabled even if theres one already enabled\n\n" );
118
	wprintf(L"   -m (forcemod)\n\tForces a mod enabled even if theres one already enabled\n\n");
116
}
119
}
117
 
120
 
118
void DisplayPackage(CBaseFile *p, int indent, int language)
121
void DisplayPackage(CBaseFile *p, int indent, int language)
119
{
122
{
120
	Utils::WString version = p->version();
123
	Utils::WString version = p->version();
Line 133... Line 136...
133
	g_indent = indent;
136
	g_indent = indent;
134
 
137
 
135
	if ( !p->IsEnabled() )
138
	if ( !p->IsEnabled() )
136
		printf("[D] ");
139
		printf("[D] ");
137
 
140
 
138
	wprintf(L"%s %s by %s\n", p->name(language).c_str(), version.c_str(), p->author().c_str() );
141
	wprintf(L"%s %s by %s", p->name(language).c_str(), version.c_str(), p->author().c_str());
-
 
142
 
-
 
143
	switch (p->GetType())
-
 
144
	{
-
 
145
	case TYPE_XSP:
-
 
146
		wprintf(L" (Ship)");
-
 
147
		break;
-
 
148
	case TYPE_SPK:
-
 
149
	{
-
 
150
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
-
 
151
		wprintf(L" (%s)", spk->scriptTypeString(language).c_str());
-
 
152
		break;
-
 
153
	}
-
 
154
	}
-
 
155
 
-
 
156
	wprintf(L"\n");
139
}
157
}
140
 
158
 
141
void DoAllChildren(CPackages *packages, CBaseFile *p, CLinkList<CBaseFile> *doneList, int indent)
159
void DoAllChildren(CPackages *packages, CBaseFile *p, CLinkList<CBaseFile> *doneList, int indent)
142
{
160
{
143
	CLinkList<CBaseFile> children;
161
	CLinkList<CBaseFile> children;
Line 158... Line 176...
158
	CProgressConsole progress;
176
	CProgressConsole progress;
159
 
177
 
160
	CLinkList<CBaseFile> doneList;
178
	CLinkList<CBaseFile> doneList;
161
 
179
 
162
	g_indent = 0;
180
	g_indent = 0;
163
	printf ( "\nPackages:\n" );
181
	wprintf(L"\nPackages:\n");
164
	for ( CBaseFile *p = packages->PackageList()->First(); p; p = packages->PackageList()->Next() )
182
	for ( CBaseFile *p = packages->PackageList()->First(); p; p = packages->PackageList()->Next() )
165
	{
183
	{
166
		// already done?
184
		// already done?
167
		if ( doneList.FindData(p) )
185
		if ( doneList.FindData(p) )
168
			continue;
186
			continue;
Line 174... Line 192...
174
		doneList.push_back(p);
192
		doneList.push_back(p);
175
 
193
 
176
		// find all children
194
		// find all children
177
		DoAllChildren(packages, p, &doneList, 1);
195
		DoAllChildren(packages, p, &doneList, 1);
178
	}
196
	}
-
 
197
	wprintf(L"\n");
179
}
198
}
180
 
199
 
181
size_t SplitArguments(char **argv, int argc, int start, Utils::WStringList *argList)
200
size_t SplitArguments(char **argv, int argc, int start, Utils::WStringList *argList)
182
{
201
{
183
	for ( int i = start; i < argc; i++ )
202
	for ( int i = start; i < argc; i++ )
Line 611... Line 630...
611
	}
630
	}
612
 
631
 
613
	return start;
632
	return start;
614
}
633
}
615
 
634
 
-
 
635
 
-
 
636
bool OpenDestination(Utils::CommandLine &cmd, const Utils::WString& destination)
-
 
637
{
-
 
638
	Utils::WString endMessage;
-
 
639
 
-
 
640
	wprintf(L"                                   |0              100|\n\n");
-
 
641
	wprintf(L"  - Reading game directory         ");
-
 
642
 
-
 
643
	CProgressConsole progress;
-
 
644
 
-
 
645
	auto& packages = cmd.packages();
-
 
646
	if (packages.read(destination, &progress))
-
 
647
	{
-
 
648
		packages.UpdatePackages();
-
 
649
		packages.ReadGameLanguage(false);
-
 
650
		progress.Finish(false);
-
 
651
 
-
 
652
		Utils::WString gameName = packages.getGameName();
-
 
653
		if (packages.GetLanguage() || !gameName.empty())
-
 
654
		{
-
 
655
			wprintf(L"\n\t");
-
 
656
			if (!gameName.empty())
-
 
657
				wprintf(L"Game: %s ", gameName.c_str());
-
 
658
			if (packages.GetLanguage())
-
 
659
				wprintf(L"(Language: %d)", packages.GetLanguage());
-
 
660
		}
-
 
661
		wprintf(L"\n");
-
 
662
		packages.AssignPackageNumbers();
-
 
663
		return true;
-
 
664
	}
-
 
665
	else
-
 
666
	{
-
 
667
		wprintf(L"ERROR!\n");
-
 
668
		wprintf(L"\nFailed to open destination directory: %s\n", destination.c_str());
-
 
669
		exit(1);
-
 
670
	}
-
 
671
 
-
 
672
	return false;
-
 
673
}
-
 
674
 
-
 
675
bool CloseDestination(Utils::CommandLine& cmd, bool isPrepare)
-
 
676
{
-
 
677
	CProgressConsole progress;
-
 
678
	Utils::WStringList lErrors;
-
 
679
 
-
 
680
	if (isPrepare)
-
 
681
		wprintf(L"  - Preparing game directory       ");
-
 
682
	else
-
 
683
		wprintf(L"  - Closing game directory         ");
-
 
684
 
-
 
685
	if (cmd.packages().closeDir(&lErrors, &progress, true))
-
 
686
		progress.Finish();
-
 
687
	else
-
 
688
	{
-
 
689
		wprintf(L"ERROR!\n");
-
 
690
		exit(1);
-
 
691
	}
-
 
692
 
-
 
693
	cmd.packages().RestoreFakePatch();
-
 
694
 
-
 
695
	wprintf(L"\nDone!\n");
-
 
696
 
-
 
697
	return true;
-
 
698
}
-
 
699
 
616
/*
700
/*
617
TODO:
701
TODO:
618
Additional Features
702
Additional Features
619
	Patch Mods
703
	Patch Mods
620
	Update Packages
704
	Update Packages
Line 624... Line 708...
624
	Main entry point to program
708
	Main entry point to program
625
*/
709
*/
626
int main ( int argc, char **argv )
710
int main ( int argc, char **argv )
627
{
711
{
628
 	// display program header to command prompt
712
 	// display program header to command prompt
629
	printf ( "\nSPKInstall V0.90 (SPK Library Version %.2f) 18/10/2009 Created by Cycrow\n\n", GetLibraryVersion() );
713
	printf ( "\nSPKInstall V1.00 (SPK Library Version %.2f) 31/05/2025 Created by Cycrow\n\n", GetLibraryVersion() );
630
 
714
 
631
	// parse the cmd name
-
 
632
	Utils::WString cmd (argv[0]);
715
	Utils::CommandLine cmd(argc, argv, true);
633
 
-
 
634
	cmd = cmd.findReplace(L"\\", L"/");
-
 
635
	g_dir = cmd.tokens(L"/", 1, cmd.countToken(L"/") - 1);
-
 
636
	cmd = cmd.token(L"/", -1);
-
 
637
 
-
 
638
	if (g_dir.empty())
-
 
639
	{
-
 
640
	    #ifdef _WIN32
-
 
641
		g_dir = Utils::WString(_getcwd(NULL, 0));
-
 
642
		#else
-
 
643
		g_dir = Utils::WString(getcwd(NULL, 0));
-
 
644
		#endif
-
 
645
		if (g_dir.empty())
-
 
646
			g_dir = "./";
-
 
647
	}
-
 
648
 
716
 
649
	// not enough arguments, display the syntax and exit
717
	// not enough arguments, display the syntax and exit
650
	if ( argc < 2 )
718
	if (cmd.argCount() < 1 )
651
	{
719
	{
652
		PrintSyntax(cmd);
720
		PrintSyntax(cmd.cmdName());
653
		Pause();
721
		Pause();
654
		exit ( 1 );
722
		exit ( 1 );
655
	}
723
	}
656
 
724
 
657
	Utils::WString destination = g_dir;
725
	Utils::WString destination = cmd.cmdDir();
658
	Utils::WStringList lErrors;
726
	Utils::WStringList lErrors;
659
 
727
 
660
	// get the command flag
728
	// do the flags and switchs
661
	Utils::WString command(argv[1]);
729
	// get the destination directory
662
	command = command.lower();
730
	if(cmd.hasSwitch(L"dir"))
-
 
731
		destination = cmd.switchData(L"dir").findReplace("\\", "/");
-
 
732
	else if (cmd.hasSwitch(L"directory"))
-
 
733
		destination = cmd.switchData(L"directory").findReplace("\\", "/");
-
 
734
	else if (cmd.hasSwitch(L"destination"))
-
 
735
		destination = cmd.switchData(L"destination").findReplace("\\", "/");
663
 
736
 
664
	CPackages packages;
737
	// get the game language
665
	Utils::WString myDoc = g_dir;
738
	auto& packages = cmd.packages();
666
#ifdef _WIN32
739
	if (cmd.hasSwitch(L"lang"))
-
 
740
		packages.SetLanguage(cmd.switchData(L"lang").toInt());
667
	TCHAR pszPath[MAX_PATH];
741
	else if (cmd.hasSwitch(L"language"))
668
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
742
		packages.SetLanguage(cmd.switchData(L"language").toInt());
-
 
743
 
669
		myDoc = (char *)pszPath;
744
	// check for verbose mode
-
 
745
	if (cmd.hasSwitch(L"verbose"))
670
#endif
746
		g_debug = true;
671
	packages.startup(g_dir.c_str(), g_dir.c_str(), myDoc.c_str());
747
	else if (cmd.hasFlag('v'))
-
 
748
		g_debug = true;
672
 
749
 
673
	int start = 2;
750
	int start = 2;
-
 
751
	/*
674
	// check for switchs
752
	// check for switchs
675
	while ( command[0] == '-' )
753
	while ( command[0] == '-' )
676
	{
754
	{
677
		if ( argc < (start + 1) )
755
		if ( argc < (start + 1) )
678
		{
756
		{
Line 720... Line 798...
720
			PrintSyntax(cmd);
798
			PrintSyntax(cmd);
721
			exit( 1 );
799
			exit( 1 );
722
		}
800
		}
723
		command = argv[start - 1];
801
		command = argv[start - 1];
724
	}
802
	}
-
 
803
	*/
-
 
804
 
-
 
805
	// check for valid command
-
 
806
	Utils::WString command = cmd.arg(0).toLower();
-
 
807
	if (command.Compare(L"list"))
-
 
808
	{
-
 
809
		if (OpenDestination(cmd, destination))
-
 
810
		{
-
 
811
			ListPackages(&packages);
-
 
812
			CloseDestination(cmd, false);
-
 
813
		}
-
 
814
	}
725
 
815
 
726
	if ( command[0] == '/' )
816
	if ( command[0] == '/' )
727
	{
817
	{
728
		wchar_t c = command[1];
818
		wchar_t c = command[1];
729
 
819
 
Line 791... Line 881...
791
 
881
 
792
			switch ( c )
882
			switch ( c )
793
			{
883
			{
794
				case 'i':
884
				case 'i':
795
					if ( argc <= start )
885
					if ( argc <= start )
796
						wprintf(L"Syntax: %s [flags] /i <file>\n\tInstalls a package to the destination\n", cmd.c_str() );
886
						wprintf(L"Syntax: %s [flags] /i <file>\n\tInstalls a package to the destination\n", cmd.cmdName().c_str() );
797
					else
887
					else
798
					{
888
					{
799
						Utils::WString aftertext = InstallPackage(lArguments, &lErrors, &packages, disabled);
889
						Utils::WString aftertext = InstallPackage(lArguments, &lErrors, &packages, disabled);
800
						if(!aftertext.empty())
890
						if(!aftertext.empty())
801
						{
891
						{
Line 806... Line 896...
806
					}
896
					}
807
					break;
897
					break;
808
 
898
 
809
				case 'u':
899
				case 'u':
810
					if ( argc <= start )
900
					if ( argc <= start )
811
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tUninstalls a package, package# is from the /l list command\n", cmd.c_str() );
901
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tUninstalls a package, package# is from the /l list command\n", cmd.cmdName().c_str() );
812
					else
902
					else
813
					{
903
					{
814
						prepare = UninstallPackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
904
						prepare = UninstallPackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
815
						PrintDebug(&lErrors);
905
						PrintDebug(&lErrors);
816
					}
906
					}
817
					break;
907
					break;
818
 
908
 
819
				case 'e':
909
				case 'e':
820
					if ( argc <= start )
910
					if ( argc <= start )
821
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tEnabled an installed package thats been disabled\n", cmd.c_str() );
911
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tEnabled an installed package thats been disabled\n", cmd.cmdName().c_str() );
822
					else
912
					else
823
					{
913
					{
824
						prepare = EnablePackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
914
						prepare = EnablePackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
825
						PrintDebug(&lErrors);
915
						PrintDebug(&lErrors);
826
					}
916
					}
827
					break;
917
					break;
828
 
918
 
829
				case 'd':
919
				case 'd':
830
					if ( argc <= start )
920
					if ( argc <= start )
831
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tDisabled an installed package\n", cmd.c_str() );
921
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tDisabled an installed package\n", cmd.cmdName().c_str() );
832
					else
922
					else
833
					{
923
					{
834
						prepare = DisablePackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
924
						prepare = DisablePackage(Utils::WString(argv[start]).toInt(), &lErrors, &packages, endMessage);
835
						PrintDebug(&lErrors);
925
						PrintDebug(&lErrors);
836
					}
926
					}