Subversion Repositories spk

Rev

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

Rev 329 Rev 331
Line 92... Line 92...
92
		c = getchar();
92
		c = getchar();
93
	}
93
	}
94
 
94
 
95
	return line;
95
	return line;
96
}
96
}
-
 
97
 
-
 
98
bool OpenDestination(Utils::CommandLine& cmd, const Utils::WString& destination)
-
 
99
{
-
 
100
	Utils::WString endMessage;
-
 
101
 
-
 
102
	wprintf(L"                                   |0              100|\n\n");
-
 
103
	wprintf(L"  - Reading game directory         ");
-
 
104
 
-
 
105
	CProgressConsole progress;
-
 
106
 
-
 
107
	auto& packages = cmd.packages();
-
 
108
	if (packages.read(destination, &progress))
-
 
109
	{
-
 
110
		packages.UpdatePackages();
-
 
111
		packages.ReadGameLanguage(false);
-
 
112
		progress.Finish(false);
-
 
113
 
-
 
114
		Utils::WString gameName = packages.getGameName();
-
 
115
		if (packages.GetLanguage() || !gameName.empty())
-
 
116
		{
-
 
117
			wprintf(L"\n\t");
-
 
118
			if (!gameName.empty())
-
 
119
				wprintf(L"Game: %s ", gameName.c_str());
-
 
120
			if (packages.GetLanguage())
-
 
121
				wprintf(L"(Language: %d)", packages.GetLanguage());
-
 
122
		}
-
 
123
		wprintf(L"\n");
-
 
124
		packages.AssignPackageNumbers();
-
 
125
		return true;
-
 
126
	}
-
 
127
	else
-
 
128
	{
-
 
129
		wprintf(L"ERROR!\n");
-
 
130
		wprintf(L"\nFailed to open destination directory: %s\n", destination.c_str());
-
 
131
		exit(1);
-
 
132
	}
-
 
133
 
-
 
134
	return false;
-
 
135
}
-
 
136
 
-
 
137
bool CloseDestination(Utils::CommandLine& cmd, bool isPrepare)
-
 
138
{
-
 
139
	CProgressConsole progress;
-
 
140
	Utils::WStringList lErrors;
-
 
141
 
-
 
142
	if (isPrepare)
-
 
143
		wprintf(L"  - Preparing game directory       ");
-
 
144
	else
-
 
145
		wprintf(L"  - Closing game directory         ");
-
 
146
 
-
 
147
	if (cmd.packages().closeDir(&lErrors, &progress, true))
-
 
148
		progress.Finish();
-
 
149
	else
-
 
150
	{
-
 
151
		wprintf(L"ERROR!\n");
-
 
152
		exit(1);
-
 
153
	}
-
 
154
 
-
 
155
	cmd.packages().RestoreFakePatch();
-
 
156
 
-
 
157
	wprintf(L"\nDone!\n");
-
 
158
 
-
 
159
	return true;
-
 
160
}
-
 
161
 
97
 
162
 
98
void PrintSyntax(const Utils::WString &cmd)
163
void PrintSyntax(const Utils::WString &cmd)
99
{
164
{
100
	wprintf(L"Syntax: %s %s <command> [arguments]\n", cmd.c_str(), FLAGS );
165
	wprintf(L"Syntax: %s %s <command> [arguments]\n", cmd.c_str(), FLAGS );
101
	wprintf(L"\nCommands:\n" );
166
	wprintf(L"\nCommands:\n" );
Line 152... Line 217...
152
		break;
217
		break;
153
	}
218
	}
154
	}
219
	}
155
 
220
 
156
	wprintf(L"\n");
221
	wprintf(L"\n");
157
}
222
}
158
 
223
 
159
void DoAllChildren(CPackages *packages, CBaseFile *p, CLinkList<CBaseFile> *doneList, int indent)
224
void DoAllChildren(CPackages *packages, CBaseFile *p, CLinkList<CBaseFile> *doneList, int indent)
160
{
225
{
161
	CLinkList<CBaseFile> children;
226
	CLinkList<CBaseFile> children;
162
	if ( packages->GetChildPackages(p, &children) )
227
	if ( packages->GetChildPackages(p, &children) )
Line 188... Line 253...
188
		if ( p->GetType() != TYPE_SPK )
253
		if ( p->GetType() != TYPE_SPK )
189
			continue;
254
			continue;
190
 
255
 
191
		DisplayPackage(p, 0, packages->GetLanguage());
256
		DisplayPackage(p, 0, packages->GetLanguage());
192
		doneList.push_back(p);
257
		doneList.push_back(p);
193
 
258
 
194
		// find all children
259
		// find all children
195
		DoAllChildren(packages, p, &doneList, 1);
260
		DoAllChildren(packages, p, &doneList, 1);
196
	}
261
	}
197
	wprintf(L"\n");
262
	wprintf(L"\n");
198
}
263
}
Line 207... Line 272...
207
	}
272
	}
208
 
273
 
209
	return argList->size();
274
	return argList->size();
210
}
275
}
211
 
276
 
212
Utils::WString InstallPackage(const Utils::WStringList &lArguments, Utils::WStringList *errors, CPackages *packages, bool disabled)
277
bool GetAllFiles(const Utils::CommandLine& cmd, int start, Utils::WStringList &files, const Utils::WString &ext, bool showError)
213
{
278
{
-
 
279
	for (int i = start; i < cmd.argCount(); i++)
-
 
280
	{
-
 
281
		if (cmd.arg(i).containsAny(L"?*"))
-
 
282
		{
-
 
283
			CFileIO File(cmd.fullFilename(cmd.arg(i)));
-
 
284
			if (File.dirIO().exists())
-
 
285
			{
-
 
286
				Utils::WStringList fileList;
-
 
287
				if (File.dirIO().dirList(fileList, Utils::WString::Null(), File.filename(), true))
-
 
288
				{
-
 
289
					for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
-
 
290
					{
-
 
291
						// check if the file exists
-
 
292
						if (CFileIO::Exists((*itr)->str))						
-
 
293
							files.pushBack((*itr)->str);
-
 
294
					}
-
 
295
				}
-
 
296
			}
-
 
297
		}
-
 
298
		else
-
 
299
		{
-
 
300
			// check if the file exists
-
 
301
			if (CFileIO::Exists(cmd.fullFilename(cmd.arg(i))))
-
 
302
			{
-
 
303
				files.pushBack(cmd.fullFilename(cmd.arg(i)));
-
 
304
				continue;
-
 
305
			}
-
 
306
 
-
 
307
			// otherwise, try to append extension to the filename
-
 
308
			if (!ext.empty())
-
 
309
			{
-
 
310
				if (CFileIO(cmd.fullFilename(cmd.arg(i))).extension().lower() != ext.lower())
-
 
311
				{
-
 
312
					Utils::WString filename = cmd.fullFilename(cmd.arg(i)) + L"." + ext;
-
 
313
					if (CFileIO::Exists(filename))
-
 
314
					{
-
 
315
						files.pushBack(filename);
-
 
316
						continue;
-
 
317
					}
-
 
318
				}
-
 
319
			}
-
 
320
 
-
 
321
			if (showError)
-
 
322
				wprintf(L"Error: Unable to find package file %s\n", cmd.arg(i).c_str());
-
 
323
		}
-
 
324
 
-
 
325
	}
-
 
326
 
-
 
327
	return !files.empty();
-
 
328
}
-
 
329
 
-
 
330
Utils::WString InstallPackage(Utils::CommandLine &cmd, const Utils::WString &destination, Utils::WStringList *errors, CPackages *packages, bool disabled)
-
 
331
{
-
 
332
	if (cmd.argCount() < 2)
-
 
333
	{
-
 
334
		wprintf(L"Syntax: %s [flags] install <file>\n\tInstalls a package to the destination\n", cmd.cmdName().c_str());
-
 
335
		return Utils::WString::Null();
-
 
336
	}
-
 
337
 
214
	CProgressConsole progress;
338
	CProgressConsole progress;
215
 
339
 
216
	int error;
340
	int error;
217
 
341
 
218
	if (lArguments.empty())
-
 
219
		return Utils::WString::Null();
342
	Utils::WStringList files;
220
 
-
 
221
	// append spk on the end
-
 
222
	for (auto itr = lArguments.begin(); itr != lArguments.end(); itr++)
343
	if(!GetAllFiles(cmd, 1, files, L";spk", true))
223
	{
344
	{
224
		if (!CFileIO::Exists((*itr)->str))
-
 
225
		{
-
 
226
			if (CFileIO((*itr)->str).extension().lower() != L"spk")
345
		wprintf(L"Error: No package files specified to install\n");
227
				(*itr)->str += L".spk";
346
		return Utils::WString::Null();
228
		}
-
 
229
	}
347
	}
230
 
348
 
-
 
349
	if (!OpenDestination(cmd, destination))
-
 
350
		return Utils::WString::Null();
-
 
351
 
231
	CLinkList<CBaseFile> lPackages;
352
	CLinkList<CBaseFile> lPackages;
232
 
353
 
233
	// open the package file
354
	// open the package file
234
	printf ( "  - Opening Package                \n" );
355
	printf ( "  - Opening Package                \n" );
235
	for (auto itr = lArguments.begin(); itr != lArguments.end(); itr++)
356
	for (auto itr = files.begin(); itr != files.end(); itr++)
236
	{
357
	{
237
		Utils::WString spkFilename = (*itr)->str;
358
		CFileIO spkFile((*itr)->str);
238
 
359
 
239
		if ( spkFilename.length() > 30 )
360
		if(spkFile.filename().length() > 30 )
240
			wprintf(L"    ..%28s ", spkFilename.right(28).c_str() );
361
			wprintf(L"    %28s.. ", spkFile.filename().left(28).c_str() );
241
		else
362
		else
242
			wprintf(L"    %30s ", spkFilename.right(30).c_str() );
363
			wprintf(L"    %30s ", spkFile.filename().c_str() );
243
 
364
 
244
		CLinkList<CBaseFile> lPackageList;
365
		CLinkList<CBaseFile> lPackageList;
245
		CBaseFile *package = packages->openPackage(spkFilename, &error, &progress);
366
		CBaseFile *package = packages->openPackage(spkFile.fullFilename(), &error, &progress);
246
 
367
 
247
		// multi packages
368
		// multi packages
248
		if ( !package && error == INSTALLERR_NOMULTI )
369
		if ( !package && error == INSTALLERR_NOMULTI )
249
		{
370
		{
250
			if ( !packages->openMultiPackage(spkFilename, &;lPackageList, &error, &progress) )
371
			if ( !packages->openMultiPackage(spkFile.fullFilename(), &;lPackageList, &error, &progress))
251
			{
372
			{
252
				printf ( "Error!\n");
373
				printf ( "Error!\n");
253
				continue;
374
				continue;
254
			}
375
			}
255
			progress.Finish();
376
			progress.Finish();
256
		}
377
		}
257
 
-
 
258
		else if ( package )
378
		else if ( package )
259
		{
379
		{
260
			progress.Finish();
380
			progress.Finish();
261
			lPackageList.push_back(package);
381
			lPackageList.push_back(package);
262
		}
382
		}
263
		else
383
		else
264
		{
384
		{
265
			printf ( "ERROR!  " );
385
			printf ( "ERROR!  " );
266
			switch ( error )
386
			switch ( error )
267
			{
387
			{
268
				case INSTALLERR_OLD:
388
				case INSTALLERR_OLD:
269
					printf ( "File is in old format no longer supported" );
389
					printf ( "File is in old format no longer supported" );
270
					break;
390
					break;
271
				case INSTALLERR_NOEXIST:
391
				case INSTALLERR_NOEXIST:
272
					printf ( "file doesn't exist" );
392
					printf ( "file doesn't exist" );
273
					break;
393
					break;
274
				case INSTALLERR_INVALID:
394
				case INSTALLERR_INVALID:
275
					printf ( "Invalid package file" );
395
					printf ( "Invalid package file" );
276
					break;
396
					break;
277
				case INSTALLERR_NOSHIP:
397
				case INSTALLERR_NOSHIP:
278
					printf ( "Ship Packages are currently not supported" );
398
					printf ( "Ship Packages are currently not supported" );
279
					break;
399
					break;
280
				case INSTALLERR_VERSION:
400
				case INSTALLERR_VERSION:
281
					printf ( "Package file was created in a newer version, unable to open" );
401
					printf ( "Package file was created in a newer version, unable to open" );
282
					break;
402
					break;
283
			}
403
			}
284
			printf ( "\n");
404
			printf ( "\n");
Line 286... Line 406...
286
		}
406
		}
287
 
407
 
288
		for ( CListNode<CBaseFile> *pNode = lPackageList.Front(); pNode; pNode = pNode->next() )
408
		for ( CListNode<CBaseFile> *pNode = lPackageList.Front(); pNode; pNode = pNode->next() )
289
		{
409
		{
290
			CBaseFile *package = pNode->Data();
410
			CBaseFile *package = pNode->Data();
291
 
411
 
292
			// compare versions
412
			// compare versions
293
			Utils::WString packageName = package->getFullPackageName(packages->GetLanguage());
413
			Utils::WString packageName = package->getFullPackageName(packages->GetLanguage());
294
 
414
 
295
			int checkFlags = IC_ALL;
415
			int checkFlags = IC_ALL;
296
			int check = packages->PrepareInstallPackage(package, (disabled) ? true : !package->IsEnabled(), false, checkFlags);
416
			int check = packages->PrepareInstallPackage(package, (disabled) ? true : !package->IsEnabled(), false, checkFlags);
297
 
417
 
298
			switch (check)
418
			switch (check)
299
			{
419
			{
300
				case INSTALLCHECK_OLDVERSION:
420
				case INSTALLCHECK_OLDVERSION:
301
					wprintf(L"Newer version of \"%s\" already installed", packageName.c_str() );
421
					wprintf(L"Newer version of \"%s\" already installed", packageName.c_str() );
302
					if ( !g_force )
422
					if ( !g_force )
303
					{
423
					{
304
						printf ( ", Unable to install older, use -o to force installation\n" );
424
						printf ( ", Unable to install older, use -o to force installation\n" );
305
						continue;
425
						continue;
306
					}
426
					}
307
					else
427
					else
308
					{
428
					{
Line 379... Line 499...
379
	{
499
	{
380
		printf ( "\nError! Some packages are missing dependacies:\n" );
500
		printf ( "\nError! Some packages are missing dependacies:\n" );
381
		for ( CListNode<CBaseFile> *pNode = lCheckPackages.Front(); pNode; pNode = pNode->next() )
501
		for ( CListNode<CBaseFile> *pNode = lCheckPackages.Front(); pNode; pNode = pNode->next() )
382
		{
502
		{
383
			CSpkFile *spk = (CSpkFile *)pNode->Data();
503
			CSpkFile *spk = (CSpkFile *)pNode->Data();
384
			wprintf(L"\t%s V%s by %s (Requires: %s by %s)\n";, spk->;name(packages->GetLanguage()).c_str(), spk->version().c_str(), spk->author().c_str(), spk->otherName().c_str(), spk->otherAuthor().c_str());
504
			wprintf(L"\t%s V%s by %s, Requires:\n";, spk->name(packages->;GetLanguage()).c_str(), spk->version().c_str(), spk->author().c_str());
-
 
505
			if(!spk->otherName().empty())
-
 
506
				wprintf(L"\t\t%s by %s\n", spk->otherName().c_str(), spk->otherAuthor().c_str());
-
 
507
			for (auto lNode = spk->GetNeededLibraries()->Front(); lNode; lNode = lNode->next())
-
 
508
				wprintf(L"\t\t%s by %s (Minimum Version: %s)\n", lNode->Data()->sName.c_str(), lNode->Data()->sAuthor.c_str(), lNode->Data()->sMinVersion.c_str());
385
		}
509
		}
386
	}
510
	}
387
 
511
 
388
	// no packages will be installed
512
	// no packages will be installed
389
	if ( packages->GetNumPackagesInQueue() < 1 )
513
	if ( packages->GetNumPackagesInQueue() < 1 )
Line 395... Line 519...
395
	if ( packages->installPreparedPackages(errors, &progress, &erroredPackages) )
519
	if ( packages->installPreparedPackages(errors, &progress, &erroredPackages) )
396
		progress.Finish();
520
		progress.Finish();
397
	else
521
	else
398
	{
522
	{
399
		printf ( "ERROR!\n" );
523
		printf ( "ERROR!\n" );
-
 
524
		CloseDestination(cmd, false);
400
		return Utils::WString::Null();
525
		return Utils::WString::Null();
401
	}
526
	}
402
 
527
 
403
	// delete any errored packages
528
	// delete any errored packages
404
	for ( CListNode<CBaseFile> *pNode = erroredPackages.Front(); pNode; pNode = pNode->next() )
529
	for ( CListNode<CBaseFile> *pNode = erroredPackages.Front(); pNode; pNode = pNode->next() )
405
	{
530
	{
406
		lPackages.remove(pNode->Data());
531
		lPackages.remove(pNode->Data());
407
		pNode->DeleteData();
532
		pNode->DeleteData();
408
	}
533
	}
-
 
534
 
-
 
535
	CloseDestination(cmd, true);
409
 
536
 
410
	// now display the packages
537
	// now display the packages
411
	Utils::WString retStr = L"Packages Installed:\n";
538
	Utils::WString retStr = L"Packages Installed:\n";
412
	for ( CListNode<CBaseFile> *pNode = lPackages.Front(); pNode; pNode = pNode->next() )
539
	for ( CListNode<CBaseFile> *pNode = lPackages.Front(); pNode; pNode = pNode->next() )
413
	{
540
	{
414
		CBaseFile *package = pNode->Data();
541
		CBaseFile *package = pNode->Data();
415
 
542
 
416
		retStr += L"  <> ";
543
		retStr += L"  <> ";
417
		retStr += package->getFullPackageName(packages->GetLanguage());
544
		retStr += package->getFullPackageName(packages->GetLanguage());
418
		retStr += L"\n";
545
		retStr += L"\n";
419
 
546
 
420
		if ( !packages->getInstallAfterText(package).empty() )
547
		if ( !packages->getInstallAfterText(package).empty() )
421
		{
548
		{
422
			Utils::WString afterText = packages->getInstallAfterText(package).stripHtml();
549
			Utils::WString afterText = packages->getInstallAfterText(package).stripHtml();
423
			afterText = afterText.findReplace(L"\n", L"\n\t");
550
			afterText = afterText.findReplace(L"\n", L"\n\t");
424
			retStr += L"\t";
551
			retStr += L"\t";
Line 428... Line 555...
428
	}
555
	}
429
 
556
 
430
	return retStr;
557
	return retStr;
431
}
558
}
432
 
559
 
433
CBaseFile *FindPackage(int packageNum, CPackages *packages)
560
CBaseFile *FindPackage(int packageNum, const CPackages *packages)
434
{
561
{
435
	for ( CBaseFile *p = packages->PackageList()->First(); p; p = packages->PackageList()->Next() )
562
	for(auto node = packages->packageList()->Front(); node; node = node->next())
436
	{
563
	{
437
		if ( p->GetNum() == (packageNum - 1) )
564
		if (node->Data() && node->Data()->GetNum() == (packageNum - 1))
438
			return p;
565
			return node->Data();
439
	}
566
	}
440
 
567
 
441
	return 0;
568
	return nullptr;
442
}
569
}
443
 
570
 
444
bool UninstallPackage(int uninstallNum, Utils::WStringList *errors, CPackages *packages, Utils::WString &endMessage)
571
bool UninstallPackage(int uninstallNum, Utils::WStringList *errors, CPackages *packages, Utils::WString &endMessage)
445
{
572
{
446
	CBaseFile *p = FindPackage(uninstallNum, packages);
573
	CBaseFile *p = FindPackage(uninstallNum, packages);
447
	if ( !p )
574
	if ( !p )
448
		return false;
575
		return false;
449
 
576
 
450
	// lets check for the uninstall text
577
	// lets check for the uninstall text
Line 462... Line 589...
462
			{
589
			{
463
				printf ( "\nUninstallation has been aborted!!\n" );
590
				printf ( "\nUninstallation has been aborted!!\n" );
464
				return false;
591
				return false;
465
			}
592
			}
466
		}
593
		}
467
	}
594
	}
468
 
595
 
469
	CProgressConsole progress;
596
	CProgressConsole progress;
470
 
597
 
471
	endMessage = L"Uninstalled: " + p->getFullPackageName(packages->GetLanguage());
598
	endMessage = L"Uninstalled: " + p->getFullPackageName(packages->GetLanguage());
472
	// add the uninstall after text
599
	// add the uninstall after text
Line 494... Line 621...
494
 
621
 
495
	return true;
622
	return true;
496
}
623
}
497
 
624
 
498
bool EnablePackage(int uninstallNum, Utils::WStringList *errors, CPackages *packages, Utils::WString &endMessage)
625
bool EnablePackage(int uninstallNum, Utils::WStringList *errors, CPackages *packages, Utils::WString &endMessage)
499
{
626
{
500
	CBaseFile *p = FindPackage(uninstallNum, packages);
627
	CBaseFile *p = FindPackage(uninstallNum, packages);
501
	if ( !p )
628
	if ( !p )
502
		return false;
629
		return false;
503
 
630
 
504
	CProgressConsole progress;
631
	CProgressConsole progress;
505
 
632
 
506
	endMessage = L"Enabled: " + p->getFullPackageName(packages->GetLanguage());
633
	endMessage = L"Enabled: " + p->getFullPackageName(packages->GetLanguage());
507
 
634
 
508
	printf ( "  - Enabling                       " );
635
	printf ( "  - Enabling                       " );
509
	if ( packages->enablePackage(p, errors, &progress) )
636
	if ( packages->enablePackage(p, errors, &progress) )
510
	{
637
	{
511
		progress.Finish();
638
		progress.Finish();
512
	}
639
	}
513
	else
640
	else
514
	{
641
	{
515
		int error = packages->GetError();
642
		int error = packages->GetError();
516
		endMessage = "";
643
		endMessage = "";
517
		printf ( "ERROR! " );
644
		printf ( "ERROR! " );
518
		if ( error == PKERR_NOPARENT )
645
		if ( error == PKERR_NOPARENT )
519
			printf ( "Parent package is disabled" );
646
			printf ( "Parent package is disabled" );
520
		printf ( "\n" );
647
		printf ( "\n" );
521
		return false;
648
		return false;
522
	}
649
	}
523
	return true;
650
	return true;
524
}
651
}
525
 
652
 
526
bool DisablePackage(int uninstallNum, Utils::WStringList *errors, CPackages *packages, Utils::WString &endMessage)
653
bool DisablePackage(int uninstallNum, Utils::WStringList *errors, CPackages *packages, Utils::WString &endMessage)
527
{
654
{
528
	CBaseFile *p = FindPackage(uninstallNum, packages);
655
	CBaseFile *p = FindPackage(uninstallNum, packages);
529
	if ( !p )
656
	if ( !p )
Line 543... Line 670...
543
		endMessage = L"";
670
		endMessage = L"";
544
		printf ( "ERROR!\n" );
671
		printf ( "ERROR!\n" );
545
		return false;
672
		return false;
546
	}
673
	}
547
	return true;
674
	return true;
548
}
675
}
549
 
676
 
550
void RemoveUninstallScripts(CPackages *packages, Utils::WStringList *errors)
677
void RemoveUninstallScripts(CPackages *packages, Utils::WStringList *errors)
551
{
678
{
552
	CProgressConsole progress;
679
	CProgressConsole progress;
553
	printf ( "  - Removing uninstall scripts     " );
680
	printf ( "  - Removing uninstall scripts     " );
Line 565... Line 692...
565
 
692
 
566
 
693
 
567
void PrintDebug(Utils::WStringList *errors)
694
void PrintDebug(Utils::WStringList *errors)
568
{
695
{
569
	if ( !g_debug )
696
	if ( !g_debug )
570
		return;
697
		return;
571
 
698
 
572
	if (errors && errors->size())
699
	if (errors && errors->size())
573
		printf ( "\n");
700
		printf ( "\n");
574
 
701
 
575
	for(auto itr = errors->begin(); itr != errors->end(); itr++)
702
	for(auto itr = errors->begin(); itr != errors->end(); itr++)
576
	{
703
	{
577
		int errornum = (*itr)->data.toInt();
704
		int errornum = (*itr)->data.toInt();
-
 
705
		//Check this?
578
		Utils::WString rest = (*itr)->str.tokens(L" ", 2);
706
		//Utils::WString rest = (*itr)->str.tokens(L" ", 2);
-
 
707
		Utils::WString rest = (*itr)->str;
579
 
708
 
580
		Utils::WString err = FormatErrorString(errornum, rest);
709
		Utils::WString err = FormatErrorString(errornum, rest);
581
		wprintf(L"  * %s\n", err.c_str());
710
		wprintf(L"  * %s\n", err.c_str());
582
	}
711
	}
583
 
712
 
584
	if (errors && errors->size())
713
	if (errors && errors->size())
585
		printf ( "\n");
714
		printf ( "\n");
586
}
715
}
587
 
716
 
-
 
717
void ShowInfo(const Utils::CommandLine& cmd)
-
 
718
{
-
 
719
	int package = Utils::WString(cmd.arg(1)).toInt();
-
 
720
	CBaseFile* p = FindPackage(package, &cmd.packages());
-
 
721
	if (!p)
-
 
722
	{
-
 
723
		wprintf(L"Error: Unable to find package #%d\n", package);
-
 
724
		return;
-
 
725
	}
-
 
726
	wprintf(L"\n============================\n");
-
 
727
	wprintf(L"Package #%d: %s\n", package, p->name(cmd.packages().language()).c_str());
-
 
728
	wprintf(L"\t%15s: %s\n", L"Author", p->author().c_str());
-
 
729
	wprintf(L"\t%15s: %s\n", L"Version", p->version().c_str());
-
 
730
	wprintf(L"\t%15s: %s\n", L"Description", p->description().c_str());
-
 
731
	if (p->GetType() == TYPE_SPK)
-
 
732
	{
-
 
733
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
-
 
734
		wprintf(L"\t%15s: %s\n", L"Type", spk->scriptTypeString(cmd.packages().language()).c_str());
-
 
735
	}
-
 
736
	else if (p->GetType() == TYPE_XSP)
-
 
737
		wprintf(L"\t%15s: %s\n", L"Type", L"Ship");
-
 
738
 
-
 
739
	wprintf(L"\t%15s: %s\n", L"Status", p->isEnabled() ? L"Enabled" : L"Disabled");
-
 
740
 
-
 
741
	if (p->anyDependacies())
-
 
742
	{
-
 
743
		wprintf(L"\t%15s:\n", L"Dependancies");
-
 
744
		for (auto needed = p->GetNeededLibraries()->First(); needed; needed = p->GetNeededLibraries()->Next())
-
 
745
			wprintf(L"\t\t%s by %s (Min Version: %s)", needed->sName.c_str(), needed->sAuthor.c_str(), needed->sMinVersion.c_str());
-
 
746
	}
588
 
747
 
-
 
748
	wprintf(L"\n============================\n\b");
-
 
749
}
589
 
750
 
590
 
751
 
591
void Pause()
752
void Pause()
592
{
753
{
593
#ifdef _DEBUG
754
#ifdef _DEBUG
594
	char pause;
755
	char pause;
595
	scanf ( "%s", &pause );
756
	scanf ( "%s", &pause );
596
#endif
757
#endif
597
}
758
}
598
 
759
 
599
 
760
 
600
int ParseCommandSwitchs(wchar_t c, Utils::WString &destination, CPackages *packages, int start, int *arg, char **argv)
761
int ParseCommandSwitchs(wchar_t c, Utils::WString &destination, CPackages *packages, int start, int *arg, char **argv)
601
{
762
{
602
	switch ( c )
763
	switch ( c )
603
	{
764
	{
604
		case L'o':
765
		case L'o':
605
			g_force = true;
766
			g_force = true;
606
			break;
767
			break;
Line 608... Line 769...
608
			g_debug = true;
769
			g_debug = true;
609
			break;
770
			break;
610
		case L'd':
771
		case L'd':
611
			destination = argv[*arg];
772
			destination = argv[*arg];
612
			destination = destination.findReplace("\\", "/");
773
			destination = destination.findReplace("\\", "/");
613
			++(*arg);
774
			++(*arg);
614
			++start;
775
			++start;
615
			break;
776
			break;
616
		case L't':
777
		case L't':
617
			packages->SetRenameText(true);
778
			packages->SetRenameText(true);
618
			break;
779
			break;
619
		case L'l':
780
		case L'l':
620
			packages->SetLanguage(Utils::WString(argv[*arg]).toInt());
781
			packages->SetLanguage(Utils::WString(argv[*arg]).toInt());
621
			++(*arg);
782
			++(*arg);
622
			++start;
783
			++start;
623
			break;
784
			break;
624
		case L'c':
785
		case L'c':
625
			packages->SetAutoEnable(true);
786
			packages->SetAutoEnable(true);
626
			break;
787
			break;
627
		case L'm':
788
		case L'm':
628
			packages->SetForceModInstall(true);
789
			packages->SetForceModInstall(true);
629
			break;
790
			break;
630
	}
791
	}
631
 
792
 
632
	return start;
793
	return start;
633
}
-
 
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
}
794
}
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
 
795
 
695
	wprintf(L"\nDone!\n");
-
 
696
 
796
 
697
	return true;
-
 
698
}
-
 
699
 
797
 
700
/*
798
/*
701
TODO:
799
TODO:
702
Additional Features
800
Additional Features
703
	Patch Mods
801
	Patch Mods
704
	Update Packages
802
	Update Packages
705
*/
803
*/
706
 
804
 
707
/*
805
/*
708
	Main entry point to program
806
	Main entry point to program
709
*/
807
*/
710
int main ( int argc, char **argv )
808
int main ( int argc, char **argv )
711
{
809
{
Line 740... Line 838...
740
		packages.SetLanguage(cmd.switchData(L"lang").toInt());
838
		packages.SetLanguage(cmd.switchData(L"lang").toInt());
741
	else if (cmd.hasSwitch(L"language"))
839
	else if (cmd.hasSwitch(L"language"))
742
		packages.SetLanguage(cmd.switchData(L"language").toInt());
840
		packages.SetLanguage(cmd.switchData(L"language").toInt());
743
 
841
 
744
	// check for verbose mode
842
	// check for verbose mode
-
 
843
	g_debug = cmd.hasSwitch(L"verbose") || cmd.hasFlag('v');
-
 
844
	g_force = cmd.hasSwitch(L"override") || cmd.hasFlag('o');
-
 
845
 
745
	if (cmd.hasSwitch(L"verbose"))
846
	if (cmd.hasSwitch(L"textrename";) || cmd.hasFlag('t&apos;))
746
		g_debug = true;
847
		packages.SetRenameText(true);
-
 
848
 
747
	else if (cmd.hasFlag('v'))
849
	if (cmd.hasSwitch(L"enablechild") || cmd.hasFlag('c'))
748
		g_debug = true;
850
		packages.SetAutoEnable(true);
-
 
851
	if (cmd.hasSwitch(L"forcemod") || cmd.hasFlag('m'))
-
 
852
		packages.SetForceModInstall(true);
749
 
853
 
750
	int start = 2;
854
	int start = 2;
751
	/*
855
	/*
752
	// check for switchs
856
	// check for switchs
753
	while ( command[0] == '-' )
857
	while ( command[0] == '-' )
Line 789... Line 893...
789
		else
893
		else
790
		{
894
		{
791
			// now parse arguments
895
			// now parse arguments
792
			for ( int i = 1; i < (int)command.length(); i++ )
896
			for ( int i = 1; i < (int)command.length(); i++ )
793
				start = ParseCommandSwitchs(command[i], destination, &packages, start, &arg, argv);
897
				start = ParseCommandSwitchs(command[i], destination, &packages, start, &arg, argv);
794
		}
898
		}
795
 
899
 
796
		if ( argc < start )
900
		if ( argc < start )
797
		{
901
		{
798
			PrintSyntax(cmd);
902
			PrintSyntax(cmd);
799
			exit( 1 );
903
			exit( 1 );
Line 808... Line 912...
808
	{
912
	{
809
		if (OpenDestination(cmd, destination))
913
		if (OpenDestination(cmd, destination))
810
		{
914
		{
811
			ListPackages(&packages);
915
			ListPackages(&packages);
812
			CloseDestination(cmd, false);
916
			CloseDestination(cmd, false);
-
 
917
		}
-
 
918
	}
-
 
919
	else if (command.Compare(L"info"))
-
 
920
	{
-
 
921
		if (cmd.argCount() < 2)
-
 
922
		{
-
 
923
			wprintf(L"Syntax: %s [flags] info <package#>\n\tDisplays info about an installed package\n", cmd.cmdName().c_str());
-
 
924
			wprintf(L"\tUse the <list> command to get the package number to use");
-
 
925
		}
-
 
926
		else
-
 
927
		{
-
 
928
			if (OpenDestination(cmd, destination))
-
 
929
			{
-
 
930
				ShowInfo(cmd);
-
 
931
				CloseDestination(cmd, false);
-
 
932
			}
-
 
933
		}
-
 
934
	}
-
 
935
	else if (command.Compare(L"install"))
-
 
936
	{
-
 
937
		Utils::WString aftertext = InstallPackage(cmd, destination, &lErrors, &packages, false);
-
 
938
		PrintDebug(&lErrors);
-
 
939
		if (!aftertext.empty())
-
 
940
			wprintf(L"\n%s\n", aftertext.c_str());
-
 
941
	}
-
 
942
	else if (command.Compare(L"uninstall"))
-
 
943
	{
-
 
944
		if (cmd.argCount() < 2)
-
 
945
		{
-
 
946
			wprintf(L"Syntax: %s [flags] uninstall <package#>\n\tUninstalls a package, package# is from the /l list command\n", cmd.cmdName().c_str());
-
 
947
			Pause();
-
 
948
			exit(1);
-
 
949
		}
-
 
950
		else
-
 
951
		{
-
 
952
			if (OpenDestination(cmd, destination))
-
 
953
			{
-
 
954
				bool prepare = UninstallPackage(Utils::WString(cmd.arg(1)).toInt(), &lErrors, &packages, command);
-
 
955
				PrintDebug(&lErrors);
-
 
956
				if (prepare)
-
 
957
					CloseDestination(cmd, true);
-
 
958
				else
-
 
959
					packages.RestoreFakePatch();
-
 
960
			}
-
 
961
		}
-
 
962
	}
-
 
963
	else if (command.Compare(L"enable"))
-
 
964
	{
-
 
965
		if (cmd.argCount() < 2)
-
 
966
		{
-
 
967
			wprintf(L"Syntax: %s [flags] enable <package#>\n\tEnables an installed package thats been disabled\n", cmd.cmdName().c_str());
-
 
968
			Pause();
-
 
969
			exit(1);
-
 
970
		}
-
 
971
		else
-
 
972
		{
-
 
973
			if (OpenDestination(cmd, destination))
-
 
974
			{
-
 
975
				bool prepare = EnablePackage(Utils::WString(cmd.arg(1)).toInt(), &lErrors, &packages, command);
-
 
976
				PrintDebug(&lErrors);
-
 
977
				if (prepare)
-
 
978
					CloseDestination(cmd, true);
-
 
979
				else
-
 
980
					packages.RestoreFakePatch();
-
 
981
			}
813
		}
982
		}
814
	}
983
	}
815
 
984
 
816
	if ( command[0] == '/' )
985
	if ( command[0] == '/' )
817
	{
986
	{
Line 837... Line 1006...
837
			c = L'l';
1006
			c = L'l';
838
		else if ( checkCmd == L"/removeshared" )
1007
		else if ( checkCmd == L"/removeshared" )
839
			c = L's';
1008
			c = L's';
840
		else if ( checkCmd == L"/removeunisntall" )
1009
		else if ( checkCmd == L"/removeunisntall" )
841
			c = L'r';
1010
			c = L'r';
842
 
1011
 
843
		if ( c == L'i' || c == L'l' || c == L'u' || c == L'e' || c == L'd' || c == L'r' || c == L's' )
1012
		if ( c == L'i' || c == L'l' || c == L'u' || c == L'e' || c == L'd' || c == L'r' || c == L's' )
844
		{
1013
		{
845
			Utils::WString endMessage;
1014
			Utils::WString endMessage;
846
 
1015
 
847
			wprintf(L"                                   |0              100|\n\n");
1016
			wprintf(L"                                   |0              100|\n\n");
Line 873... Line 1042...
873
			}
1042
			}
874
 
1043
 
875
			bool prepare = false;
1044
			bool prepare = false;
876
 
1045
 
877
			packages.AssignPackageNumbers();
1046
			packages.AssignPackageNumbers();
878
 
1047
 
879
			Utils::WStringList lArguments;
1048
			Utils::WStringList lArguments;
880
			SplitArguments(argv, argc, start, &lArguments);
1049
			SplitArguments(argv, argc, start, &lArguments);
881
 
1050
 
882
			switch ( c )
1051
			switch ( c )
883
			{
1052
			{
884
				case 'i':
-
 
885
					if ( argc <= start )
-
 
886
						wprintf(L"Syntax: %s [flags] /i <file>\n\tInstalls a package to the destination\n", cmd.cmdName().c_str() );
-
 
887
					else
-
 
888
					{
-
 
889
						Utils::WString aftertext = InstallPackage(lArguments, &lErrors, &packages, disabled);
-
 
890
						if(!aftertext.empty())
-
 
891
						{
-
 
892
							prepare = true;
-
 
893
							endMessage = aftertext;
-
 
894
						}
-
 
895
						PrintDebug(&lErrors);
-
 
896
					}
-
 
897
					break;
-
 
898
 
1053
 
899
				case 'u':
1054
				case 'u':
900
					if ( argc <= start )
1055
					if ( argc <= start )
901
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tUninstalls a package, package# is from the /l list command\n", cmd.cmdName().c_str() );
1056
						wprintf(L"Syntax: %s [flags] /u <package#>\n\tUninstalls a package, package# is from the /l list command\n", cmd.cmdName().c_str() );
902
					else
1057
					else