Subversion Repositories spk

Rev

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

Rev 218 Rev 222
Line 176... Line 176...
176
		// find all children
176
		// find all children
177
		DoAllChildren(packages, p, &doneList, 1);
177
		DoAllChildren(packages, p, &doneList, 1);
178
	}
178
	}
179
}
179
}
180
 
180
 
181
int SplitArguments(char **argv, int argc, int start, CyStringList *argList)
181
size_t SplitArguments(char **argv, int argc, int start, Utils::WStringList *argList)
182
{
182
{
183
	for ( int i = start; i < argc; i++ )
183
	for ( int i = start; i < argc; i++ )
184
	{
184
	{
185
		CyString arg = argv[i];
185
		Utils::WString arg = argv[i];
186
		if ( !arg.Empty() )
186
		if (!arg.empty())
187
			argList->PushBack(arg);
187
			argList->pushBack(arg);
188
	}
188
	}
189
 
189
 
190
	return argList->Count();
190
	return argList->size();
191
}
191
}
192
 
192
 
193
Utils::WString InstallPackage(CyStringList *lArguments, Utils::WStringList *errors, CPackages *packages, bool disabled)
193
Utils::WString InstallPackage(const Utils::WStringList &lArguments, Utils::WStringList *errors, CPackages *packages, bool disabled)
194
{
194
{
195
	CProgressConsole progress;
195
	CProgressConsole progress;
196
 
196
 
197
	int error;
197
	int error;
198
 
198
 
199
	if ( !lArguments || !lArguments->Count() )
199
	if (lArguments.empty())
200
		return Utils::WString::Null();
200
		return Utils::WString::Null();
201
 
201
 
202
	// append spk on the end
202
	// append spk on the end
203
	for ( SStringList *node = lArguments->Head(); node; node = node->;next )
203
	for (auto itr = lArguments.begin(); itr != lArguments.end(); itr++)
204
	{
204
	{
205
		if (!CFileIO::Exists(node->str.ToString()))
205
		if (!CFileIO::Exists((*itr)->str))
206
		{
206
		{
207
			if (CFileIO(node->str.ToString()).extension().lower() != L"spk")
207
			if (CFileIO((*itr)->str).extension().lower() != L"spk")
208
				node->str += ".spk";
208
				(*itr)->str += ".spk";
209
		}
209
		}
210
	}
210
	}
211
 
211
 
212
	CLinkList<CBaseFile> lPackages;
212
	CLinkList<CBaseFile> lPackages;
213
 
213
 
214
	// open the package file
214
	// open the package file
215
	printf ( "  - Opening Package                \n" );
215
	printf ( "  - Opening Package                \n" );
216
	for ( SStringList *node = lArguments->Head(); node; node = node->;next )
216
	for (auto itr = lArguments.begin(); itr != lArguments.end(); itr++)
217
	{
217
	{
218
		Utils::String spkFilename = node->str.ToString();
218
		Utils::WString spkFilename = (*itr)->str;
219
 
219
 
220
		if ( spkFilename.length() > 30 )
220
		if ( spkFilename.length() > 30 )
221
			printf ( "    ..%28s ", spkFilename.right(28).c_str() );
221
			wprintf(L"    ..%28s ", spkFilename.right(28).c_str() );
222
		else
222
		else
223
			printf ( "    %30s ", spkFilename.right(30).c_str() );
223
			wprintf(L"    %30s ", spkFilename.right(30).c_str() );
224
 
224
 
225
		CLinkList<CBaseFile> lPackageList;
225
		CLinkList<CBaseFile> lPackageList;
226
		CBaseFile *package = packages->openPackage(spkFilename, &error, &progress);
226
		CBaseFile *package = packages->openPackage(spkFilename, &error, &progress);
227
 
227
 
228
		// multi packages
228
		// multi packages
Line 543... Line 543...
543
	packages->removeUnusedSharedFiles(errors, &progress);
543
	packages->removeUnusedSharedFiles(errors, &progress);
544
	progress.Finish();
544
	progress.Finish();
545
}
545
}
546
 
546
 
547
 
547
 
548
void PrintDebug(CyStringList *errors)
548
void PrintDebug(Utils::WStringList *errors)
549
{
549
{
550
	if ( !g_debug )
550
	if ( !g_debug )
551
		return;
551
		return;
552
 
552
 
553
	if ( errors &;& errors->Count() )
553
	if (errors &;& errors->size())
554
		printf ( "\n");
554
		printf ( "\n");
555
 
555
 
556
	for ( SStringList *str = errors->;Head(); str; str = str->next )
556
	for(auto itr = errors->;begin(); itr != errors->end(); itr++)
557
	{
557
	{
558
		int errornum = str->str.ToInt();
558
		int errornum = (*itr)->data.toInt();
559
		CyString rest = str->str.GetToken(" ", 2);
559
		Utils::WString rest = (*itr)->str.tokens(L" ", 2);
560
 
560
 
561
		Utils::WString err = FormatErrorString(errornum, rest.ToString());
561
		Utils::WString err = FormatErrorString(errornum, rest);
562
		wprintf(L"  * %s\n", err.c_str());
562
		wprintf(L"  * %s\n", err.c_str());
563
	}
563
	}
564
 
564
 
565
	if ( errors &;& errors->Count() )
565
	if (errors &;& errors->size())
566
		printf ( "\n");
566
		printf ( "\n");
567
}
567
}
568
 
568
 
569
 
569
 
570
 
570
 
Line 653... Line 653...
653
		Pause();
653
		Pause();
654
		exit ( 1 );
654
		exit ( 1 );
655
	}
655
	}
656
 
656
 
657
	Utils::String destination = g_dir.ToString();
657
	Utils::String destination = g_dir.ToString();
658
	CyStringList errors;
-
 
659
	Utils::WStringList lErrors;
658
	Utils::WStringList lErrors;
660
 
659
 
661
	// get the command flag
660
	// get the command flag
662
	CyString command(argv[1]);
661
	CyString command(argv[1]);
663
	command = command.lower();
662
	command = command.lower();
Line 785... Line 784...
785
 
784
 
786
			bool prepare = false;
785
			bool prepare = false;
787
 
786
 
788
			packages.AssignPackageNumbers();
787
			packages.AssignPackageNumbers();
789
 
788
 
790
			CyStringList lArguments;
789
			Utils::WStringList lArguments;
791
			SplitArguments(argv, argc, start, &lArguments);
790
			SplitArguments(argv, argc, start, &lArguments);
792
 
791
 
793
			switch ( c )
792
			switch ( c )
794
			{
793
			{
795
				case 'i':
794
				case 'i':
796
					if ( argc <= start )
795
					if ( argc <= start )
797
						printf ( "Syntax: %s [flags] /i <file>\n\tInstalls a package to the destination\n", cmd.c_str() );
796
						printf ( "Syntax: %s [flags] /i <file>\n\tInstalls a package to the destination\n", cmd.c_str() );
798
					else
797
					else
799
					{
798
					{
800
						Utils::WString aftertext = InstallPackage(&lArguments, &lErrors, &packages, disabled);
799
						Utils::WString aftertext = InstallPackage(lArguments, &lErrors, &packages, disabled);
801
						if(!aftertext.empty())
800
						if(!aftertext.empty())
802
						{
801
						{
803
							prepare = true;
802
							prepare = true;
804
							endMessage = aftertext;
803
							endMessage = aftertext;
805
						}
804
						}
806
						PrintDebug(&errors);
805
						PrintDebug(&lErrors);
807
					}
806
					}
808
					break;
807
					break;
809
 
808
 
810
				case 'u':
809
				case 'u':
811
					if ( argc <= start )
810
					if ( argc <= start )
812
						printf ( "Syntax: %s [flags] /u <package#\n\tUninstalls a package, package# is from the /l list command\n", cmd.c_str() );
811
						printf ( "Syntax: %s [flags] /u <package#\n\tUninstalls a package, package# is from the /l list command\n", cmd.c_str() );
813
					else
812
					else
814
					{
813
					{
815
						prepare = UninstallPackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
814
						prepare = UninstallPackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
816
						PrintDebug(&errors);
815
						PrintDebug(&lErrors);
817
					}
816
					}
818
					break;
817
					break;
819
 
818
 
820
				case 'e':
819
				case 'e':
821
					if ( argc <= start )
820
					if ( argc <= start )
822
						printf ( "Syntax: %s [flags] /u <package#\n\tEnabled an installed package thats been disabled\n", cmd.c_str() );
821
						printf ( "Syntax: %s [flags] /u <package#\n\tEnabled an installed package thats been disabled\n", cmd.c_str() );
823
					else
822
					else
824
					{
823
					{
825
						prepare = EnablePackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
824
						prepare = EnablePackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
826
						PrintDebug(&errors);
825
						PrintDebug(&lErrors);
827
					}
826
					}
828
					break;
827
					break;
829
 
828
 
830
				case 'd':
829
				case 'd':
831
					if ( argc <= start )
830
					if ( argc <= start )
832
						printf ( "Syntax: %s [flags] /u <package#\n\tDisabled an installed package\n", cmd.c_str() );
831
						printf ( "Syntax: %s [flags] /u <package#\n\tDisabled an installed package\n", cmd.c_str() );
833
					else
832
					else
834
					{
833
					{
835
						prepare = DisablePackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
834
						prepare = DisablePackage(CyString(argv[start]).ToInt(), &lErrors, &packages, endMessage);
836
						PrintDebug(&errors);
835
						PrintDebug(&lErrors);
837
					}
836
					}
838
					break;
837
					break;
839
 
838
 
840
				case 'l':
839
				case 'l':
841
					ListPackages(&packages);
840
					ListPackages(&packages);
Line 852... Line 851...
852
					break;
851
					break;
853
			}
852
			}
854
 
853
 
855
			if ( prepare )
854
			if ( prepare )
856
			{
855
			{
857
				errors.Clear();
-
 
858
				lErrors.clear();
856
				lErrors.clear();
859
				printf ( "  - Preparing game directory       " );
857
				printf ( "  - Preparing game directory       " );
860
				if ( packages.closeDir(&lErrors, &progress, true) )
858
				if ( packages.closeDir(&lErrors, &progress, true) )
861
					progress.Finish();
859
					progress.Finish();
862
				else
860
				else
Line 864... Line 862...
864
					printf ( "ERROR!\n" );
862
					printf ( "ERROR!\n" );
865
					Pause();
863
					Pause();
866
					exit(1);
864
					exit(1);
867
				}
865
				}
868
 
866
 
869
				PrintDebug(&errors);
867
				PrintDebug(&lErrors);
870
			}
868
			}
871
			else
869
			else
872
				packages.RestoreFakePatch();
870
				packages.RestoreFakePatch();
873
 
871
 
874
			printf ( "\nDone!\n" );
872
			printf ( "\nDone!\n" );