Subversion Repositories spk

Rev

Rev 126 | Rev 129 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
/*
2
 SPKTool V1.00 Created by Cycrow (Matthew Gravestock)
3
*/
4
 
5
// Main Spk File Library Include
6
#ifdef _WIN32
7
#include <spk.h>
8
#include <MultiSpkFile.h>
9
#include <spkcmdprogress.h>
10
#else
11
#include "../spk/spk.h"
12
#include "../spk/MultiSpkFile.h"
13
#include "../spk/spkcmdprogress.h"
14
#endif
15
// Multi Spk File format, required if using Multi Spk files
16
// Displays 7Zip compression progress to the command line
17
#include <time.h>
18
#ifdef _WIN32
19
#include <windows.h>
20
#include <direct.h>
21
#include <shlobj.h>
22
#endif
23
 
24
CyString g_dir;
25
bool g_read;
26
 
27
/*
28
	Func:	GetInput
29
	Desc:	Gets an input from the user, ie, any settings required to be typed in
30
*/
127 cycrow 31
Utils::String GetInput ()
1 cycrow 32
{
33
	g_read = true;
34
 
127 cycrow 35
	Utils::String line;
1 cycrow 36
	char c = getchar();
37
 
38
	while ( (c != '\n') && (c != '\0') )
39
	{
40
		line += c;
41
		c = getchar();
42
	}
43
 
44
	return line;
45
}
46
 
47
 
48
/*
49
	Func:	PrintSyntax
50
	Args:	String cmd - The command name to be displayed
51
	Desc:	Displays the syntax for the program
52
*/
53
void PrintSyntax ( CyString cmd )
54
{
55
	printf ( "Syntax: %s <command>\n", cmd.c_str() );
56
	printf ( "Commands:\n" );
57
	printf ( "\t-v <spkfile>\n\t--version <spkfile>\n\t\tViews the contents of a spk file\n\n" );
58
	printf ( "\t-e <spkfile> [destination]\n\t--extractall <spkfile> [destination]\n\t\tExtracts all the files to the destination directory [or current if no destiantion is set]\n\n" );
59
	printf ( "\t-x <spkfile> <type> <file> [destination]\n\t--extract <spkfile> <type> <file> [destination]\n\t\tExtracts a single file of <type> to destination directory\n\n" );
60
	printf ( "\t-x <multispkfile> <file> [destination]\n\t--extractspk <multispkfile> <spkfile> [destination]\n\t\tExtracts a single spk file from a Multi-Spk Package\n\n" );
61
	printf ( "\t-c <spkfile>\n\t--create\n\t\tCreates a new spk file\n\n" );
62
	printf ( "\t-a <spkfile> <type> <filename>\n\t--append <spkfile> <type> <filename>\n\t\tAppends a file to the package of set <type>\n\n" );
63
	printf ( "\t-r <spkfile> <type> <filename>\n\t--remove <spkfile> <type> <filename>\n\t\tRemoves a file from the package of set <type>\n\n" );
64
	printf ( "\t-r <multispkfile> <filename>\n\t--removespk <multispkfile> <filename>\n\t\tRemoves a spk file from the Multi-SPK package\n\n" );
65
	printf ( "\t-m <spkfile> <spkfile>\n\t--mergemulti <spkfile> <spkfile>\n\t\tMerges spk files together, the second file will be merged into the first\n\n" );
66
	printf ( "\t-n <multispkfile>\n\t--createmulti\n\t\tCreates a multi spk file, and adds the spkfiles in\n\n" );
67
	printf ( "\t-s <multispkfile> [destination]\n\t--splitmulti <multispkfile> [destination]\n\t\tSplits a Multi-SPK file up, saves all the spk files to Destination\n\n" );
68
	printf ( "\t--set <setting> [value]\n\t\tChanges the settings of the script\n\n" );
69
	printf ( "\t--convertxsp <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
70
	printf ( "\t--createscript <packagescript>\n\t\tCreates a spk file from a packager script\n\n");
71
	printf ( "\t--verifyscript <packagescript>\n\t\tChecks a packager script is valid without creating the resulting file\n\n");
72
	printf ( "\t--generatescript <package> [packagescript]\n\t\tCreates a packager script (.sps) from a spk file\n\n");
73
	printf ( "\t--extractship <modfile> <xspfile> [shipid]\n\t\tCreates an XSP ship file from a mod package\n\n");
74
	printf ( "\t--generateupdatefile <package>\n\t\tCreates an update file for the spk/xsp file\n\n");
126 cycrow 75
	printf ( "\t--packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n\n");
76
	//	printf ( "\t--convertxspwizard <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
1 cycrow 77
}
78
 
79
void Settings(CyString filename, CyString settings, int argc, char **argv, CyString cmd)
80
{
81
	if ( settings.Compare("author") )
82
	{
83
		if ( argc < 5 )
84
		{
85
			printf ( "Syntax: %s -set <spkfile> Author <authorname>\n\tSets the authors name of the package\n", cmd.c_str() );
86
			return;
87
		}
88
	}
89
	else
90
	{
91
		printf("Error! Unknown settings: %s\n", settings.c_str());
92
		return;
93
	}
94
 
95
	// first chekc if file even exists
96
	FILE *id = fopen ( filename.c_str(), "rb+" );
97
	if ( !id )
98
	{
99
		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
100
		return;
101
	}
102
	fclose ( id );
103
 
104
	int check = CSpkFile::CheckFile ( filename );
105
	if ( check == SPKFILE_SINGLE )
106
	{
107
		CSpkFile spkfile;
108
		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
109
		if ( !spkfile.ReadFile ( filename, SPKREAD_ALL ) )
110
		{
111
			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
112
			return;
113
		}
114
 
115
		// now do the settings
116
		if ( settings.Compare("author") )
117
		{
50 cycrow 118
			spkfile.setAuthor(argv[4]);
119
			printf( "Settings Author to: %s\n", spkfile.author().c_str());
1 cycrow 120
		}
121
 
122
		spkfile.WriteFile ( filename );
123
		printf ( "\nSPK file has been written sucessfully\n" );
124
	}
125
	else
126
		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
127
}
128
 
129
void SetRating ( CyString filename, int ease, int changing, int rec )
130
{
131
	if ( ease > 5 )
132
		ease = 5;
133
	if ( changing > 5 )
134
		changing = 5;
135
	if ( changing > 5 )
136
		changing = 5;
137
 
138
	FILE *id = fopen ( filename.c_str(), "rb+" );
139
	if ( !id )
140
	{
141
		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
142
		return;
143
	}
144
	fclose ( id );
145
 
146
	int check = CSpkFile::CheckFile ( filename );
147
	if ( check == SPKFILE_SINGLE )
148
	{
149
		CSpkFile spkfile;
150
		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
151
		if ( !spkfile.ReadFile ( filename, SPKREAD_ALL ) )
152
		{
153
			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
154
			return;
155
		}
156
 
157
		printf ( "File Format Version: %.2f\n", spkfile.GetFileVersion() );
158
 
159
		printf ( "Assigning Ease Of Use:\t\t%d\nAssigning Game Changing:\t%d\nAssigning Recommended:\t\t%d\n", ease, changing, rec);
46 cycrow 160
		spkfile.setEaseOfUse(ease);
161
		spkfile.setGameChanging(changing);
162
		spkfile.setRecommended(rec);
1 cycrow 163
		spkfile.WriteFile ( filename );
164
		printf ( "\nSPK file has been written sucessfully\n" );
165
 
166
	}
167
	else
168
		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
169
}
170
 
171
CyString GetTerranConflictDir()
172
{
173
	while ( true )
174
	{
175
		printf ( "\nPlease enter the directory for terran conflict: ");
176
		CyString dir = GetInput();
177
		if ( dir.Empty() )
178
			return NullString;
179
 
180
		// check if the directory exists
52 cycrow 181
		if ( CFileIO(dir + "/x3tc.exe").ExistsOld() )
1 cycrow 182
			return dir;
183
		printf("\nTerran Conflict installation doesn't exist: %s\n\n", dir.c_str());
184
	}
185
 
186
	return NullString;
187
}
188
 
189
void ConvertXsp(CyString filename, CyString tofile, bool wizard)
190
{
191
	// first chekc if file even exists
192
	FILE *id = fopen ( filename.c_str(), "rb+" );
193
	if ( !id )
194
	{
195
		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
196
		return;
197
	}
198
	fclose ( id );
199
 
200
	// check its not a new format already
201
	int check = CSpkFile::CheckFile ( filename );
202
	if ( check == SPKFILE_INVALID && CFileIO(filename).CheckFileExtension("xsp") )
203
	{
204
		printf ( "* Converting XSP File, %s... ", filename.c_str() );
205
		CXspFile xspFile;
39 cycrow 206
		if ( !xspFile.ConvertOld(filename.ToString()) )
1 cycrow 207
		{
208
			printf ( "[ERROR]\n\nFailed to convert old xsp file, %s\n", filename.c_str() );
209
			return;
210
		}
211
 
212
		printf ( "[DONE]\n");
213
 
214
		CyString dir;
215
		printf ("Do you want to create weapon masks for Terran conflict? ");
216
		CyString input = GetInput();
217
		if ( input.Compare("y") || input.Compare("yes") )
218
		{
219
			dir = GetTerranConflictDir();
220
			if ( !dir.Empty() )
221
			{
222
			}
223
		}
224
 
225
		printf ( "* Writing XSP File, %s... ", tofile.c_str() );
226
		// now we need to save it
227
		if ( !xspFile.WriteFile(tofile) )
228
			printf ( "[ERROR]\n\nFailed to write file to, %s\n", tofile.c_str() );
229
		else
230
			printf ( "[DONE]\n\nFile: %s, has been converted to, %s\n", filename.c_str(), tofile.c_str() );
231
	}
232
	else
233
		printf ( "Error: File, %s, is not an old style XSP file\n", filename.c_str() );
234
}
235
 
236
void ExtractShip(CyString catfile, CyString to, CyString shipid)
237
{
52 cycrow 238
	if ( !CFileIO(catfile).ExistsOld() )
1 cycrow 239
	{
240
		printf ( "Error: Mod File, %s, does not exist\n", catfile.c_str() );
241
		return;
242
	}
243
 
36 cycrow 244
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
37 cycrow 245
	if ( !pVfs->loadMod(catfile.ToString()) ) {
1 cycrow 246
		printf("Error: Unable to read mod file, %s\n", catfile.c_str());
36 cycrow 247
		delete pVfs;
1 cycrow 248
		return;
249
	}
250
 
101 cycrow 251
	Utils::CStringList *ships = pVfs->getTShipsEntries();
1 cycrow 252
	if ( !ships )
253
	{
254
		printf("Error: Failed to read %s::types\\TShips.pck\n", catfile.c_str());
36 cycrow 255
		delete pVfs;
1 cycrow 256
		return;
257
	}
258
 
259
	// now get the ship line to extract
101 cycrow 260
	Utils::String tShipsLine;
1 cycrow 261
	if ( shipid.Empty() )
262
	{
263
		// no ship id, lets get one
101 cycrow 264
		Utils::String ids[2];
1 cycrow 265
		int i = 0;
266
		int id = 0;
116 cycrow 267
		for ( Utils::SStringList *str = ships->first(); str; str = ships->next() )
1 cycrow 268
		{
116 cycrow 269
			ids[i++] = str->data;
1 cycrow 270
			if ( i >= 2 )
271
			{
272
				printf("[%3d][%30s]\t[%3d][%30s]\n", id - 1, ids[0].c_str(), id, ids[1].c_str());
273
				for ( i = 0; i < 2; i++ )
274
					ids[i] = "";
275
				i = 0;
276
			}
277
			++id;
278
		}
279
		if ( i == 1 )
280
			printf("[%3d][%30s]\n", id, ids[0].c_str());
281
		printf("Enter ID to use > ");
282
		shipid = GetInput();
283
 
284
		if ( shipid.IsNumber() )
116 cycrow 285
			tShipsLine = ships->get(shipid.ToInt())->str;
1 cycrow 286
		else
101 cycrow 287
			tShipsLine = ships->findData(shipid.ToString(), true);
1 cycrow 288
	}
289
	else
101 cycrow 290
		ships->findData(shipid.ToString(), true);
1 cycrow 291
 
101 cycrow 292
	if ( tShipsLine.empty() )
1 cycrow 293
	{
294
		printf("Error, %s is not a valid ship id to use\n", shipid.c_str());
36 cycrow 295
		delete pVfs;
1 cycrow 296
		return;
297
	}
298
 
299
	// now we have the tships to use, lets start to extract the ship
101 cycrow 300
	printf("Extracting ship from %s, Ship=%s\n", catfile.c_str(), tShipsLine.token(";", -2).c_str());
1 cycrow 301
 
302
	CXspFile ship;
101 cycrow 303
	if ( ship.extractShip(pVfs, tShipsLine.token(";", -2), 0) )
1 cycrow 304
	{
305
		printf ( "Ship has been successfully extracted\n" );
306
 
307
		printf("\t- Models:\t %d\n", ship.CountFiles(FILETYPE_SHIPMODEL));
308
		printf("\t- Textures:\t %d\n", ship.CountFiles(FILETYPE_SHIPOTHER));
309
		printf("\t- Dummies:\t %d\n", ship.GetDummies()->size());
310
		printf("\t- Components:\t %d\n", ship.GetComponents()->size());
311
		printf("\t- Bodies:\t %d\n", ship.GetBodies()->Count());
312
		printf("\t- Cockpits:\t %d\n", ship.GetCockpits()->size());
313
		printf("\t- Text Entries:\t %d\n", ship.GetTexts()->size());
314
 
315
		printf("\nEnter the name for the ship: ");
127 cycrow 316
		ship.setName(GetInput());
1 cycrow 317
		printf("Enter the author for the ship: ");
127 cycrow 318
		ship.setAuthor(GetInput());
1 cycrow 319
		printf("Enter the version for the ship: V");
127 cycrow 320
		ship.setVersion(GetInput());
1 cycrow 321
		printf("Enter the description for the ship: ");
127 cycrow 322
		ship.setDescription(GetInput());
1 cycrow 323
 
324
		struct tm   *currDate;
325
		char    dateString[100];
326
		time_t now = time(NULL);
327
		currDate = localtime( &now );
328
		strftime(dateString, sizeof dateString, "%d/%m/%Y", currDate);
50 cycrow 329
		ship.setCreationDate(dateString);
1 cycrow 330
 
331
		printf("\nWriting file: %s...\n", to.c_str());
332
		if ( ship.WriteFile(to) )
333
			printf("Ship file has been created: %s\n", to.c_str());
334
		else
335
			printf("Error: Unable to write ship file, %s\n", to.c_str());
336
	}
337
	else
338
		printf("Error: Unable to extract the ship\n");
36 cycrow 339
 
340
	delete pVfs;
1 cycrow 341
}
342
 
343
CyString GetGameName(int game)
344
{
345
	switch(game)
346
	{
347
		case GAME_X2:
348
			return "X2: The Threat";
349
		case GAME_X3:
350
			return "X3: Reunion";
351
		case GAME_X3TC:
352
			return "X3: Terran Conflict";
353
		case GAME_X3AP:
354
			return "X3: Albion Prelude";
126 cycrow 355
		case GAME_X3FL:
356
			return "X3: Farnham's Legacy";
1 cycrow 357
	}
358
	return "Unknown";
359
}
360
void DisplayVersion ( CyString filename )
361
{
362
	// first chekc if file even exists
363
	FILE *id = fopen ( filename.c_str(), "rb+" );
364
	if ( !id )
365
	{
366
		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
367
		return;
368
	}
369
	fclose ( id );
370
 
371
	bool read = false;
372
	CBaseFile *pBaseFile = NULL;
373
 
374
	int check = CSpkFile::CheckFile ( filename );
375
	if ( check == SPKFILE_BASE )
376
	{
377
		pBaseFile = new CBaseFile();
378
		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
379
		if ( !pBaseFile->ReadFile ( filename, SPKREAD_NODATA ) )
380
		{
381
			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
382
			return;
383
		}
384
		read = true;
385
	}
386
	else if ( check == SPKFILE_SINGLE )
387
	{
388
		pBaseFile = (CBaseFile *)new CSpkFile();
389
		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
390
		if ( !pBaseFile->ReadFile ( filename, SPKREAD_NODATA ) )
391
		{
392
			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
393
			return;
394
		}
395
		read = true;
396
	}
397
	else if ( check == SPKFILE_SINGLESHIP )
398
	{
399
		pBaseFile = (CBaseFile *)new CXspFile();
400
		printf ( "* Opening XSP File, %s...\n", filename.c_str() );
401
		if ( !pBaseFile->ReadFile ( filename, SPKREAD_NODATA ) )
402
		{
403
			printf ( "Failed to open the xsp files, %s\n", filename.c_str() );
404
			return;
405
		}
406
		read = true;
407
	}
408
	// otherwise its an old ship file
409
	else if ( CFileIO(filename).CheckFileExtension("xsp") )
410
	{
411
		printf ( "* Converting XSP File, %s...\n", filename.c_str() );
412
		pBaseFile = new CXspFile;
39 cycrow 413
		if ( !((CXspFile *)pBaseFile)->ConvertOld(filename.ToString()) )
1 cycrow 414
		{
415
			delete pBaseFile;
416
			pBaseFile = NULL;
417
			printf ( "Failed to convert old xsp file, %s\n", filename.c_str() );
418
			return;
419
		}
420
		check = SPKFILE_SINGLESHIP;
421
		read = true;
422
	}
423
 
424
	if ( pBaseFile && read)
425
	{
426
		CPackages p;
427
		p.Startup(".", ".", ".");
428
 
429
		CSpkFile *pSpkFile = NULL;
430
		CXspFile *pXspFile = NULL;
431
		if ( check == SPKFILE_SINGLE )
432
			pSpkFile = (CSpkFile *)pBaseFile;
433
		else
434
			pXspFile = (CXspFile *)pBaseFile;
435
 
436
		printf ( "File Format Version: %.2f\n", pBaseFile->GetFileVersion() );
437
 
438
		CyString sType;
439
		if ( check == SPKFILE_SINGLESHIP )
440
			sType = "Ship";
441
		else
442
			sType = "Package";
443
 
50 cycrow 444
		printf ( "%s Name: %s\n", sType.c_str(), pBaseFile->name().c_str() );
49 cycrow 445
		if ( !pBaseFile->email().empty() )
50 cycrow 446
			printf ( "%s Author: %s (%s)\n", sType.c_str(), pBaseFile->author().c_str(), pBaseFile->email().c_str() );
1 cycrow 447
		else
50 cycrow 448
			printf ( "%s Author: %s\n", sType.c_str(), pBaseFile->author().c_str() );
449
		if ( !pBaseFile->version().empty() ) printf ( "%s Version: %s\n", sType.c_str(), pBaseFile->version().c_str() );
1 cycrow 450
 
451
		//for game
452
		printf("For Games: ");
453
		if ( !pBaseFile->AnyGameCompatability() )
454
			printf("All");
455
		else
456
			printf("%s", p.GetGameTypesString(pBaseFile, true).c_str());
457
		printf("\n");
458
 
459
		if ( pXspFile )
460
		{
461
			printf ("Ship Display Name: %s\n", pXspFile->GetShipName(44).c_str());
462
			if ( pXspFile->IsExistingShip() )
463
				printf ( "Ship ID: %s (Replace Existing Ship)\n", pXspFile->GetShipID().c_str() );
464
			else
465
				printf ( "Ship ID: %s\n", pXspFile->GetShipID().c_str() );
466
 
467
			if ( pXspFile->AnyShipyards() )
468
			{
469
				printf ( "Add To Shipyards:\n" );
470
				for ( int i = 1; i <= GetMaxShipyards(); i *= 2 )
471
				{
472
					if ( pXspFile->IsShipyard(i) )
473
						printf("\t%s\n", GetShipyardName(i).c_str());
474
				}
475
			}
476
 
477
			for ( SWeaponMask *text = pXspFile->GetLaserMasks()->First(); text; text = pXspFile->GetLaserMasks()->Next() )
478
				printf ( "Laser Mask, Game: %s, Mask: %d\n", GetGameName(text->iGame).c_str(), text->iMask);
479
			for ( SWeaponMask *text = pXspFile->GetMissileMasks()->First(); text; text = pXspFile->GetMissileMasks()->Next() )
480
				printf ( "Missile Mask, Game: %s, Mask: %d\n", GetGameName(text->iGame).c_str(), text->iMask);
481
 
482
			if ( pXspFile->GetOriginalDescription() )
483
				printf("Use Existing Text, ID: %d\n", pXspFile->GetOriginalDescription());
484
 
485
			if ( pXspFile->AnyTexts() )
486
			{
487
				for ( SText *text = pXspFile->GetTexts()->First(); text; text = pXspFile->GetTexts()->Next() )
488
				{
489
					printf("Ship Text, Language: %d\n", text->iId);
39 cycrow 490
					if ( !text->sName.empty() )
1 cycrow 491
						printf("\tName: %s\n", text->sName.c_str());
39 cycrow 492
					if ( !text->sDesc.empty() )
1 cycrow 493
						printf("\tDescription: %s\n", text->sDesc.c_str());
494
				}
495
			}
496
 
497
			if ( pXspFile->AnyComponents() )
498
			{
499
				printf ( "Component Entries:\n" );
500
				for ( SComponent *c = pXspFile->GetComponents()->First(); c; c = pXspFile->GetComponents()->Next() )
501
					printf ( "\t%s\n\t\t%s\n\t\t\t%s\n", c->sSection.c_str(), c->sSection2.c_str(), c->sData.c_str());
502
			}
503
			if ( pXspFile->AnyDummies() )
504
			{
505
				printf ( "Dummy Entries:\n" );
506
				for ( SDummy *d = pXspFile->GetDummies()->First(); d; d = pXspFile->GetDummies()->Next() )
507
					printf ( "\t%s\n\t\t%s\n", d->sSection.c_str(), d->sData.c_str());
508
			}
509
			if ( pXspFile->AnyCockpits() )
510
			{
511
				printf ( "Cockpit Entries:\n" );
512
				for ( SCockpit *c = pXspFile->GetCockpits()->First(); c; c = pXspFile->GetCockpits()->Next() )
513
					printf("\t%s\n", c->sCockpit.c_str());
514
			}
515
			if ( pXspFile->AnyCutData() )
516
			{
517
				printf ( "CutData Entries [%d]:\n", pXspFile->GetCutData()->Count() );
518
				for ( SStringList *c = pXspFile->GetCutData()->Head(); c; c = c->next )
519
					printf("\t%s\n", c->str.c_str());
520
			}
521
		}
522
 
50 cycrow 523
		if ( !pBaseFile->creationDate().empty() ) printf ( "Creation Date: %s\n", pBaseFile->creationDate().c_str() );
48 cycrow 524
		if ( !pBaseFile->description().empty() ) printf ( "Description: %s\n", pBaseFile->description().c_str() );
1 cycrow 525
		if ( pSpkFile )
526
		{
527
			if ( pSpkFile->IsLibrary() )
528
				printf ( "Script Type: Library\n" );
529
			else if ( pSpkFile->IsPatch() )
530
				printf ( "Script Type: Patch Mod\n" );
531
			else if ( pSpkFile->IsCustomStart() )
532
				printf ( "Script Type: Custom Start\n" );
533
			else if ( pSpkFile->IsPackageUpdate() )
534
				printf ( "Script Type: Package Update\n" );
10 cycrow 535
			else if ( !pSpkFile->GetScriptTypeString(44).empty() )
1 cycrow 536
				printf ( "Script Type: %s\n", pSpkFile->GetScriptTypeString(44).c_str() );
537
 
538
			if ( !pSpkFile->GetWaresList()->empty() )
539
			{
540
				for ( CListNode<SWares> * wNode = pSpkFile->GetWaresList()->Front(); wNode; wNode = wNode->next() )
541
				{
542
					SWares *w = wNode->Data();
543
					printf ( "Ware: (%c) %s\n", w->cType, CSpkFile::GetWareText(w, 44).c_str() );
544
					CyString desc = CSpkFile::GetWareDesc(w, 44);
545
					if ( !desc.Empty() )
546
						printf ( "\tDescription: %s\n", desc.c_str() );
547
				}
548
			}
549
		}
49 cycrow 550
		if ( !pBaseFile->forumLink().empty() ) printf ( "Forum Link: %s\n", pBaseFile->forumLink().c_str() );
551
		if ( !pBaseFile->webSite().empty() ) printf ( "Web Site Address: %s\n", pBaseFile->webSite().c_str() );
552
		if ( !pBaseFile->webAddress().empty() ) printf ( "Update Address: %s\n", pBaseFile->webAddress().c_str() );
1 cycrow 553
 
554
		if ( pBaseFile->AnyWebMirrors() )
555
		{
556
			printf("Update Mirror Addresses:\n");
557
			for ( int i = 0; i < pBaseFile->GetMaxWebMirrors(); i++ )
558
				printf ("\t%s\n", pBaseFile->GetWebMirror(i).c_str());
559
		}
560
		if ( pSpkFile )
561
		{
10 cycrow 562
			if ( (!pSpkFile->GetOtherName().empty()) && (!pSpkFile->GetOtherAuthor().empty()) )
1 cycrow 563
				printf ( "Script is a child to the mod: %s by %s\n", pSpkFile->GetOtherName().c_str(), pSpkFile->GetOtherAuthor().c_str() );
564
		}
565
 
566
		if ( pBaseFile->AnyDependacies() )
567
		{
568
			printf ( "Required Dependacies:\n" );
569
			for ( SNeededLibrary *needed = pBaseFile->GetNeededLibraries()->First(); needed; needed = pBaseFile->GetNeededLibraries()->Next() )
570
				printf ( "\t%s by %s (Minimum Version=%s)\n", needed->sName.c_str(), needed->sAuthor.c_str(), needed->sMinVersion.c_str() );
571
		}
46 cycrow 572
		if ( pBaseFile->easeOfUse() != -1 ) printf ( "Ease Of Use Rating: %d\n", pBaseFile->easeOfUse() );
573
		if ( pBaseFile->gameChanging() != -1 ) printf ( "Game Changing Rating: %d\n", pBaseFile->gameChanging() );
574
		if ( pBaseFile->recommended() != -1 ) printf ( "Recommendation Rating: %d\n", pBaseFile->recommended() );
1 cycrow 575
		if ( pBaseFile->GetIcon() )
576
		{
577
			C_File *icon = pBaseFile->GetIcon();
578
			printf ( "Icon File Found, Type: %s, Size: %s\n", pBaseFile->GetIconExt().c_str(), icon->GetDataSizeString().c_str() );
579
		}
580
 
581
		if ( pBaseFile->GetFileList()->size() )
582
		{
583
			printf ( "\nListing files in package:\n" );
584
			if ( pBaseFile->GetIcon() )
585
				printf("\tIcon: %s (Size: %s)\n", pBaseFile->GetIconExt().c_str(), pBaseFile->GetIcon()->GetDataSizeString().c_str());
586
			CLinkList<C_File> *list = pBaseFile->GetFileList();
587
			for ( C_File *file = list->First(); file; file = list->Next() )
588
				printf ( "\t%s (%s) Size: %s\n", file->GetNameDirectory(pBaseFile).c_str(), file->GetFileTypeString().c_str(), file->GetDataSizeString().c_str() );
589
		}
590
		else
591
			printf ( "\nThere are currently no files in the package\n" );
592
	}
593
	else if ( check == SPKFILE_MULTI )
594
	{
595
		CMultiSpkFile spkfile;
596
		printf ( "* Opening Multi-SPK file, %s...\n", filename.c_str() );
597
		if ( !pBaseFile->ReadFile ( filename, false ) )
598
		{
599
			printf ( "Error: Failed to open the Multi-SPK file, %s\n", filename.c_str() );
600
			return;
601
		}
602
 
603
		printf ( "Multi Package Name: %s\n", spkfile.GetName().c_str() );
604
		printf ( "Selection Mode: " );
605
		if ( spkfile.IsSelection () )
606
			printf ( "On\n" );
607
		else
608
			printf ( "Off\n" );
609
 
610
		CLinkList<SMultiSpkFile> *list = spkfile.GetFileList();
611
		for ( SMultiSpkFile *ms = list->First(); ms; ms = list->Next() )
612
		{
613
			printf ( "File, %s:\n", ms->sName.c_str() );
614
			printf ( "\tSize: %s\n", SPK::GetSizeString (ms->lSize).c_str() );
615
			if ( (!ms->sScriptName.Empty()) && (!ms->sScriptAuthor.Empty()) )
616
				printf ( "\tScript: %s %s by %s\n", ms->sScriptName.c_str(), ms->sScriptVersion.c_str(), ms->sScriptAuthor.c_str() );
617
			printf ( "\tDefault Install: " );
618
			if ( ms->bOn )
619
				printf ( "Yes\n" );
620
			else
621
				printf ( "No\n" );
622
		}
623
	}
624
	else
625
		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
626
 
627
	if ( pBaseFile )
628
		delete pBaseFile;
629
}
630
 
631
void AppendFile ( CyString sfile, CyString type, CyString addfile )
632
{
633
	int t = GetFileTypeFromString(type);
634
	if ( t == -1 )
635
	{
636
		printf ( "The file type \"%s\" is invalid\n", type.c_str() );
637
		return;
638
	}
639
 
640
	int check = CSpkFile::CheckFile ( sfile );
641
	CBaseFile *pBaseFile = 0;
642
	if ( check == SPKFILE_SINGLE )
643
		pBaseFile = new CSpkFile();
644
	else if ( check == SPKFILE_SINGLESHIP )
645
		pBaseFile = new CXspFile();
646
	else if ( check == SPKFILE_BASE )
647
		pBaseFile = new CBaseFile();
648
 
649
	if ( !pBaseFile )
650
	{
651
		printf ( "Error: Invalid file format, unable to open\n" );
652
		return;
653
	}
654
 
655
	printf ( "Opening File, %s... ", sfile.c_str() );
656
	if ( !pBaseFile->ReadFile ( sfile ) )
657
	{
658
		printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
659
		return;
660
	}
661
	printf ( "(Done)\n" );
662
 
663
	MyProgress progress(0);
664
 
665
	printf ( "Adding file %s to package\n\t>", addfile.c_str() );
666
 
667
	if ( pBaseFile->AppendFile ( addfile, t, 0, NullString, &progress ) )
668
	{
669
		progress.PrintDone();
670
		printf ( "< (Done)\n" );
671
 
672
		pBaseFile->WriteFile ( sfile );
673
		printf ( "\nFile has been written sucessfully\n" );
674
	}
675
	else
676
		printf ( "< (Error)\n" );
677
}
678
 
679
void RemoveFile ( CyString sfile, CyString type, CyString addfile )
680
{
681
	FILE *id = fopen ( sfile.c_str(), "rb+" );
682
	if ( !id )
683
	{
684
		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
685
		return;
686
	}
687
 
688
	if ( addfile.Empty() )
689
	{
690
		printf ( "Error: Remove filename is invalid\n" );
691
		return;
692
	}
693
	int t = GetFileTypeFromString(type);
694
	if ( t == -1 )
695
	{
696
		printf ( "The file type \"%s\" is invalid\n", type.c_str() );
697
		return;
698
	}
699
 
700
	int check = CSpkFile::CheckFile ( sfile );
701
	CBaseFile *pBaseFile = 0;
702
	if ( check == SPKFILE_SINGLE )
703
		pBaseFile = new CSpkFile();
704
	else if ( check == SPKFILE_SINGLESHIP )
705
		pBaseFile = new CXspFile();
706
	else if ( check == SPKFILE_BASE )
707
		pBaseFile = new CBaseFile();
708
 
709
	if ( pBaseFile )
710
	{
711
		printf ( "Opening File, %s... ", sfile.c_str() );
712
		if ( !pBaseFile->ReadFile ( sfile ) )
713
		{
714
			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
715
			return;
716
		}
717
		printf ( "(Done)\n" );
718
 
719
		printf ( "Removing file, %s, from Package\n", addfile.c_str() );
720
 
721
		if ( pBaseFile->RemoveFile ( addfile, t ) )
722
		{
723
			printf ( "File, %s, has been remove from package\n", addfile.c_str() );
724
			pBaseFile->WriteFile ( sfile );
725
			printf ( "File has been written to disk successfully\n" );
726
		}
727
		else
728
			printf ( "Unable to remove the file, %s, from the package\n", addfile.c_str() );
729
	}
730
	else if ( check == SPKFILE_MULTI )
731
	{
732
		CMultiSpkFile spkfile;
733
		printf ( "Opening Multi-SPK file, %s...", sfile.c_str() );
734
		if ( !spkfile.ReadFile ( sfile ) )
735
		{
736
			printf ( "(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str() );
737
			return;
738
		}
739
		printf ( "(Done)\n" );
740
 
741
		SMultiSpkFile *ms = spkfile.FindFile ( type );
742
		if ( !ms )
743
		{
744
			printf ( "Unable to find the file \"%s\" in the package\n", type.c_str() );
745
			return;
746
		}
747
 
748
		printf ( "Removing file, %s, from Package\n", addfile.c_str() );
749
		if ( !spkfile.RemoveFile ( ms ) )
750
		{
751
			printf ( "Error: Unable to remove file, %s, from package\n", type.c_str() );
752
			return;
753
		}
754
 
755
		printf ( "Writing SPK File, %s... ", sfile.c_str() );
756
		if ( spkfile.WriteFile ( sfile ) )
757
			printf ( "(Done)\n" );
758
		else
759
			printf ( "(Error)\n" );
760
	}
761
	else
762
		printf ( "Error: Invalid file format, unable to open\n" );
763
}
764
 
765
 
766
void CreateMultiFile ( CyString filename )
767
{
768
	printf ( "* Creating new Multi-SPK File, %s\n\n", filename.c_str() );
769
 
770
	FILE *id = fopen ( filename.c_str(), "rb+" );
771
	if ( id )
772
	{
773
		fclose ( id );
774
		printf ( "* File already exists, unable to create\n" );
775
		return;
776
	}
777
 
778
	id = fopen ( filename.c_str(), "wb" );
779
	if ( !id )
780
	{
781
		printf ( "* Unable to open file for writing\n" );
782
		return;
783
	}
784
	fclose ( id );
785
	remove ( filename.c_str() );
786
 
787
	CMultiSpkFile spkfile;
788
 
789
	CyString sInput;
790
	printf ( "Enter Multi-Spk Package Name: " );
791
	spkfile.SetName ( GetInput() );
792
 
793
	while ( true )
794
	{
795
		printf ( "\nDo you want users to select scripts to install? (Y/N): " );
796
		CyString i = GetInput();
797
		i = i.ToUpper();
798
		if ( i == "Y" )
799
			spkfile.SetSelection ( true );
800
		if ( (i == "Y") || (i == "N") )
801
			break;
802
	}
803
 
804
	while ( true )
805
	{
806
		printf ( "\nEnter Spk File to add (Enter \"0\" to finish): " );
807
		sInput = GetInput();
808
		if ( sInput == "0" )
809
			break;
810
 
811
		// check if file can be opened
812
		FILE *id2 = fopen ( sInput.c_str(), "rb+" );
813
		if ( !id2 )
814
			printf ( "Error: Unable to open SPK file %s\n", sInput.c_str() );
815
		else
816
		{
817
			fclose ( id2 );
818
			if ( !spkfile.AddFile ( sInput ) )
819
				printf ( "Error: Unable to add SPK file to package\n" );
820
			else
821
				printf ( "File Added to package (%s)\n", sInput.c_str() );
822
		}
823
	}
824
 
825
	if ( spkfile.GetNumFiles() < 1 )
826
		printf ( "\nError: You have added no files, you must add at least one file to create a package\n" );
827
	else
828
	{
829
		printf ( "Writing MultiSpk file... " );
830
		if ( spkfile.WriteFile ( filename ) )
831
			printf ( "(Done)\n" );
832
		else
833
			printf ( "(Error)\n" );
834
	}
835
 
836
}
837
 
838
void CreateFile ( CyString filename )
839
{
840
	printf ( "* Creating new SPK File, %s\n\n", filename.c_str() );
841
 
842
	FILE *id = fopen ( filename.c_str(), "rb+" );
843
	if ( id )
844
	{
845
		fclose ( id );
846
		printf ( "* File already exists, unable to create\n" );
847
		return;
848
	}
849
 
850
	id = fopen ( filename.c_str(), "wb" );
851
	if ( !id )
852
	{
853
		printf ( "* Unable to open file for writing\n" );
854
		return;
855
	}
856
	fclose ( id );
857
	remove ( filename.c_str() );
858
 
859
	CSpkFile spkfile;
860
 
861
	printf ( "Enter Script Name: " );
127 cycrow 862
	spkfile.setName(GetInput());
1 cycrow 863
 
864
	printf ( "Enter Script Author: " );
127 cycrow 865
	spkfile.setAuthor(GetInput());
1 cycrow 866
 
867
	printf ( "Enter Script Version: " );
127 cycrow 868
	spkfile.setVersion(GetInput());
1 cycrow 869
 
870
	printf ( "Enter Script Description: " );
127 cycrow 871
	spkfile.setDescription(GetInput());
1 cycrow 872
 
873
	struct tm   *currDate;
874
	char    dateString[100];
875
	time_t now = time(NULL);
876
 
877
	currDate = localtime( &now );
878
	strftime(dateString, sizeof dateString, "%d %m %Y", currDate);
50 cycrow 879
	spkfile.setCreationDate(dateString);
1 cycrow 880
 
881
	spkfile.WriteFile ( filename, NULL );
882
	printf ( "SPK file has been written to disk: %s\n", filename.c_str() );
883
}
884
 
885
void ExtractFiles ( CyString sfile, CyString dir, int game )
886
{
887
	// First checks if the file exists by opening it
888
	FILE *id = fopen ( sfile.c_str(), "rb+" );
889
	if ( !id )
890
	{
891
		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
892
		return;
893
	}
894
	fclose ( id );
895
 
896
	int check = CSpkFile::CheckFile ( sfile );
897
 
898
	// extracts a file from single packages file
899
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
900
	{
901
		// creates the spkfile object
902
		CBaseFile *pBaseFile = 0;
903
		if ( check == SPKFILE_SINGLE )
904
			pBaseFile = (CBaseFile *)new CSpkFile();
905
		else if ( check == SPKFILE_SINGLESHIP )
906
			pBaseFile = (CBaseFile *)new CXspFile();
907
		else
908
			pBaseFile = new CBaseFile();
909
 
910
		printf ( "Opening File, %s... ", sfile.c_str() );
911
		// reads the file into memory
912
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
913
		if ( !pBaseFile->ReadFile ( sfile, SPKREAD_NODATA ) )
914
		{
915
			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
916
			return;
917
		}
918
		printf ( "(Done)\n" );
919
 
920
		printf ( "Extracting all files from archive..." );
921
		if ( pBaseFile->ExtractAll ( dir, game ) )
922
			printf ( "(Done)\nFiles have been extracted successfully\n" );
923
		else
924
			printf ( "(Error)\nThere was a problem extracting the files\n" );
925
	}
926
	else
927
		printf("Invalid package file, %s\n", sfile.c_str());
928
}
929
 
930
 
931
/*
932
	Func:	AppendMultiFile
933
	Args:	String toFile	- The spk file to append onto
934
			String addfile	- The spk file to append
935
	Desc:	Appends a spk file into a Multi-Spk Archive
936
			If toFile is a single spk file, it will be converted to a Multi-Spk File
937
			if addfile is a Multi-Spk file, all files from it will be appended
938
*/
939
void AppendMultiFile ( CyString toFile, CyString addfile )
940
{
941
	// create destination object
942
	CMultiSpkFile spkfile;
943
 
944
	// checks the destination
945
	int checkto = CSpkFile::CheckFile ( toFile );
946
 
947
	// if the destination is a single file, then convert it to a Multi-Spk package
948
	if ( checkto == SPKFILE_SINGLE )
949
	{
950
		// adds the single file to the Multi-Spk object
951
		// Add file also reads it into memory
952
		if ( !spkfile.AddFile ( toFile ) )
953
		{
954
			printf ( "Error: Unable to create Multi-Spk file\n" );
955
			return;
956
		}
957
	}
958
	else
959
	{
960
		// if its already a multispk file, then simply open it and read it to memory
961
		if ( !spkfile.ReadFile ( toFile ) )
962
		{
963
			printf ( "Error: Unable to open Multi-Spk file, %s\n", toFile.c_str() );
964
			return;
965
		}
966
	}
967
 
968
	// now add the file into the Multi-Spk Object
969
	// the AddFile function will handle both single and Multi-Spk files
970
	// So you dont need to test what the appending file is
971
	if ( spkfile.AddFile ( addfile ) )
972
	{
973
 
974
		// if it added correctly, then simply write the new Multi-Spk Object to disk
975
		printf ( "File, %s, has been added to Multi-Spk Package\n", addfile.c_str() );
976
		printf ( "Saving Multi-Spk File: %s... ", toFile.c_str() );
977
		if ( spkfile.WriteFile ( toFile ) )
978
			printf ( "(Done)\n" );
979
		else
980
			printf ( "(Error)\n" );
981
	}
982
	else
983
		printf ( "Error: Unable to add files, %s, to Multi-Spk Package\n", addfile.c_str() );
984
}
985
 
986
/*
987
	Func:	ExtractFile
988
	Args:	String sfile	- the spk file to read from
989
			String type		- the type of the file to find
990
			String addfile	- The filename to extract
991
			String dir		- The directory to extract to
992
	Desc:	Finds and extracts a file from a Spk Package
993
*/
994
void ExtractFile ( CyString sfile, CyString type, CyString addfile, CyString dir )
995
{
996
	// First checks if the file exists by opening it
997
	FILE *id = fopen ( sfile.c_str(), "rb+" );
998
	if ( !id )
999
	{
1000
		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
1001
		return;
1002
	}
1003
	fclose ( id );
1004
 
1005
	// now check the type of file it is, using the static function CheckFile(filename).
1006
	// This will return the type of file
1007
	//		SPK_INVALID		- Invalid file format, wont be able to open
1008
	//		SPK_SINGLE		- A Single spk package file
1009
	//		SPK_MULTI		- A Multi-Spk Archive
1010
	//		SPK_BASE		- A Base File
1011
	//		SPK_SINGLESHIP	- A Ship file
1012
	int check = CSpkFile::CheckFile ( sfile );
1013
 
1014
	// extracts a file from single packages file
1015
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
1016
	{
1017
		// first get the file type is valid
1018
		// converts the string type into its filetype flag
1019
		int t = GetFileTypeFromString(type);
1020
		// incorrect text type, display the error
1021
		if ( t == -1 )
1022
		{
1023
			printf ( "The file type \"%s\" is invalid\n", type.c_str() );
1024
			return;
1025
		}
1026
 
1027
		// creates the spkfile object
1028
		CBaseFile *pBaseFile = 0;
1029
		if ( check == SPKFILE_SINGLE )
1030
			pBaseFile = (CBaseFile *)new CSpkFile();
1031
		else if ( check == SPKFILE_SINGLESHIP )
1032
			pBaseFile = (CBaseFile *)new CXspFile();
1033
		else
1034
			pBaseFile = new CBaseFile();
1035
 
1036
		printf ( "Opening File, %s... ", sfile.c_str() );
1037
		// reads the file into memory
1038
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
1039
		if ( !pBaseFile->ReadFile ( sfile, SPKREAD_NODATA ) )
1040
		{
1041
			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
1042
			return;
1043
		}
1044
 
1045
		// No read all the file data into memory
1046
		// This can be done all together in the ReadFile function
1047
		// Doing it seperatly allows you to save time if an error occurs, so you dont have to wait for it to read the whole thing
1048
		pBaseFile->ReadAllFilesToMemory ();
1049
 
1050
		printf ( "(Done)\n" );
1051
 
1052
		// uses the FindFile function to find the selected file in the archive
1053
		// requires the filename, type and custom directory (only for Extra File Type)
1054
		C_File *f = pBaseFile->FindFile ( addfile, t );
1055
		if ( !f )
1056
		{
1057
			printf ( "Unable to find the file \"%s\" in the package\n", addfile.c_str() );
1058
			return;
1059
		}
1060
 
1061
		// creates the directory so it can be extracted
1062
		CDirIO Dir(dir);
1063
		if ( !Dir.Create(f->GetDirectory(pBaseFile)) )
1064
		{
1065
			printf ( "Unable to create the directory \"%s\" to extract into\n", dir.c_str() );
1066
			return;
1067
		}
1068
 
1069
		// sets up the progress pointer
1070
		// if it uses 7zip, the progress will be displayed in the command prompt
1071
		MyProgress progress(0);
1072
		printf ( "Extracting the file from package\n\t>" );
1073
 
1074
		// Extracts the file to the specified directory
1075
		if ( !pBaseFile->ExtractFile ( f, dir, true, &progress ) )
1076
			printf ( "< (Error)\nUnable to extract the file\n" );
1077
		else
1078
		{
1079
			progress.PrintDone ();
1080
			printf ( "< (Done)\nFile has been extracted successfully\n" );
1081
		}
1082
	}
1083
 
1084
	// the file is a Multi-Spk File, extracts a single spk file from the archive
1085
	else if ( check == SPKFILE_MULTI )
1086
	{
1087
		// creates MultiSpkFile object
1088
		CMultiSpkFile spkfile;
1089
		printf ( "Opening Multi-SPK file, %s...", sfile.c_str() );
1090
 
1091
		// reads the MultiSpkFile into memory
1092
		if ( !spkfile.ReadFile ( sfile ) )
1093
		{
1094
			printf ( "(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str() );
1095
			return;
1096
		}
1097
		printf ( "(Done)\n" );
1098
 
1099
		// searchs the archive for a matching file
1100
		SMultiSpkFile *ms = spkfile.FindFile ( type );
1101
		if ( !ms )
1102
		{
1103
			printf ( "Unable to find the file \"%s\" in the package\n", type.c_str() );
1104
			return;
1105
		}
1106
 
1107
		// extracts the file from the archive, to the given directory
1108
		printf ( "Extracting SPK file, %s, from package... ", ms->sName.c_str() );
1109
		if ( spkfile.ExtractFile ( ms, addfile ) )
1110
			printf ( "(Done)\n" );
1111
		else
1112
			printf ( "(Error)\n" );
1113
	}
1114
	else
1115
		printf ( "Error: Invalid file format, unable to open\n" );
1116
}
1117
 
1118
/*
1119
	Func:	SplitMulti
1120
	Args:	String filename - the filename of the multispk file to open
1121
			String dest		- The destination directory to extract the files to
1122
	Desc:	Splits a multi-spk file into its seperate spk files
1123
*/
1124
void SplitMulti ( CyString filename, CyString dest )
1125
{
1126
	// Check the file type, Must return SPKFILE_MULTI, otherwise its not a Multi-Spk Packages
1127
	if ( CSpkFile::CheckFile ( filename ) != SPKFILE_MULTI )
1128
	{
1129
		printf ( "Error: The file is not a Multi-Spk packages\n" );
1130
		return;
1131
	}
1132
 
1133
	printf ( "Spliting Multi-SPK File to, %s... ", dest.c_str() );
1134
 
1135
	// create the MultiSpkFile object
1136
	CMultiSpkFile spkfile;
1137
 
1138
	// Splits the files to the destination
1139
	if ( !spkfile.SplitMulti  ( filename, dest ) )
1140
	{
1141
		printf ( "(Error)\nUnable to split Multi-SPK package, %s\n", filename.c_str() );
1142
		return;
1143
	}
1144
 
1145
	printf ( "(Done)\n" );
1146
}
1147
 
127 cycrow 1148
Utils::String GetAsk(const Utils::String &command)
1 cycrow 1149
{
1150
	printf("(ASK) Enter the value for, %s: ", command.c_str());
1151
	return GetInput();
1152
}
1153
 
126 cycrow 1154
void GenerateUpdateList(int argc, char **argv)
1155
{
1156
	Utils::String currentDir = CFileIO(argv[0]).dir();
1157
	CDirIO Dir(currentDir);
1158
 
1159
	Utils::CStringList list;
1160
	for (int i = 2; i < argc; ++i)
1161
	{
1162
		Utils::String file(argv[i]);
1163
		if (CFileIO::Exists(file))
1164
			list.pushBack(file, "file");
1165
		else if (CFileIO::Exists(Dir.file(file)))
1166
			list.pushBack(Dir.file(file), "file");
1167
		else if (CDirIO::Exists(file))
1168
			list.pushBack(file, "dir");
1169
		else if (CDirIO::Exists(Dir.dir(file)))
1170
			list.pushBack(Dir.dir(file), "dir");
1171
		else
1172
			list.pushBack(file, "pattern");
1173
	}
1174
 
1175
	if (list.empty())
1176
		printf("unable to find any packages");
1177
	else
1178
	{
1179
		Utils::CStringList fileList;
1180
		for (auto itr = list.begin(); itr != list.end(); itr++)
1181
		{
1182
			Utils::String file = (*itr)->str;
1183
			Utils::String data = (*itr)->data;
1184
			if (data == "file")
1185
				fileList.pushBack(file);
1186
			else if (data == "dir")
1187
			{
1188
				CDirIO dir(file);
1189
				Utils::CStringList d;
1190
				if (dir.dirList(d))
1191
				{
1192
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1193
					{
1194
						Utils::String ext = CFileIO((*itr2)->str).extension().lower();
1195
						if(ext == "xsp" || ext == "spk")
1196
							fileList.pushBack(dir.file((*itr2)->str));
1197
					}
1198
				}
1199
			}
1200
			else if (data == "pattern")
1201
			{				
1202
				CFileIO f(file);
1203
				CDirIO dir(f.dir());
1204
 
1205
				if (!dir.exists())
1206
					dir = CDirIO(Dir.dir(dir.dir()));
1207
 
1208
				Utils::CStringList d;
1209
				if (dir.dirList(d, Utils::String::Null(), f.filename()))
1210
				{
1211
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1212
					{
1213
						Utils::String ext = CFileIO((*itr2)->str).extension().lower();
1214
						if (ext == "xsp" || ext == "spk")
1215
							fileList.pushBack(dir.file((*itr2)->str));
1216
					}
1217
				}
1218
			}
1219
		}
1220
 
1221
		if (fileList.empty())
1222
			printf("unable to find any packages");
1223
		else
1224
		{
1225
			CPackages packages;
1226
 
1227
			Utils::CStringList filedata;
1228
			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
1229
			{
1230
				printf("Reading file: %s\n", (*itr)->str.c_str());
1231
 
1232
				int error = 0;
1233
				CBaseFile *p = packages.OpenPackage((*itr)->str, &error, 0, SPKREAD_NODATA);
1234
				if (!p)
1235
				{
1236
					printf("\tERROR!\n");
1237
					continue;
1238
				}
1239
				printf("\tData extracted: %s %s by %s\n", p->name().c_str(), p->version().c_str(), p->author().c_str());
1240
				if (!p->creationDate().empty())
1241
					printf("\t\tCreated: %s\n", p->creationDate().c_str());
1242
				if(!p->description().empty())
1243
					printf("\t\t%s\n", p->description().c_str());
1244
 
1245
				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
1246
				delete p;
1247
			}
1248
 
1249
			if (filedata.empty())
1250
				printf("unable to find any packages");
1251
			else				
1252
			{
1253
				Utils::String dest = Dir.file("xpackagedata.dat");
1254
				if (CFileIO(dest).writeFile(&filedata))
1255
					printf("web update file, xpackagedata.dat, generated");
1256
				else
1257
					printf("unable to write update file");
1258
			}
1259
		}
1260
	}
1261
}
1262
 
1 cycrow 1263
void GenerateUpdateFile(CyString spkfile)
1264
{
52 cycrow 1265
	if ( !CFileIO(spkfile).ExistsOld() )
1 cycrow 1266
	{
1267
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1268
		return;
1269
	}
1270
 
1271
	int check = CSpkFile::CheckFile(spkfile);
1272
	if ( check == SPKFILE_MULTI )
1273
	{
1274
		printf("Error: Multi-Package files currently not supported\n");
1275
		return;
1276
	}
1277
	else if ( check == SPKFILE_OLD )
1278
	{
1279
		printf("Error: unable to read old format spk file, try spkconvert first\n");
1280
		return;
1281
	}
1282
	else if ( check == SPKFILE_INVALID )
1283
	{
1284
		printf("Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
1285
		return;
1286
	}
1287
 
1288
	CPackages p;
1289
	int error;
1290
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1291
	if ( !package )
1292
	{
1293
		printf("Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
1294
		return;
1295
	}
1296
 
102 cycrow 1297
	Utils::String file = package->CreateUpdateFile(CFileIO(spkfile).dir()).ToString();
1298
	if ( file.empty() )
1299
		printf("Error: unable to create update file for: %s, Directory=%s\n", spkfile.c_str(), CFileIO(spkfile).dir().c_str());
1 cycrow 1300
	else
1301
		printf("Update file: %s has been created for package, %s\n", file.c_str(), spkfile.c_str());
1302
 
1303
	delete package;
1304
 
1305
}
1306
 
126 cycrow 1307
void GeneratePackagerScript(const Utils::String &spkfile, CyString toFile, int game)
1 cycrow 1308
{
126 cycrow 1309
	if (!CFileIO::Exists(spkfile))
1 cycrow 1310
	{
1311
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1312
		return;
1313
	}
1314
 
1315
	int check = CSpkFile::CheckFile(spkfile);
1316
	if ( check == SPKFILE_MULTI )
1317
	{
1318
		printf("Error: Cant generate a script from a multi-spk file\n");
1319
		return;
1320
	}
1321
	else if ( check == SPKFILE_OLD )
1322
	{
1323
		printf("Error: unable to read old format spk file, try spkconvert first\n");
1324
		return;
1325
	}
1326
	else if ( check == SPKFILE_INVALID )
1327
	{
1328
		printf("Error: %s doesn't appear to be a spk file\n", spkfile.c_str());
1329
		return;
1330
	}
1331
 
1332
	CPackages p;
127 cycrow 1333
	p.startup(".", ".", ".");
1 cycrow 1334
	int error;
1335
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1336
	if ( !package )
1337
	{
1338
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1339
		return;
1340
	}
1341
 
126 cycrow 1342
	Utils::CStringList list;
127 cycrow 1343
	if ( !p.generatePackagerScript(package, true, &list, game) )
1 cycrow 1344
	{
1345
		printf("Error: Unable to generate packager script\n");
1346
		return;
1347
	}
1348
 
1349
	if ( toFile.Empty() )
50 cycrow 1350
		toFile = CFileIO(spkfile).GetDirIO().File(package->name() + "_" + package->author() + ".sps");
1 cycrow 1351
 
1352
	// save package file
126 cycrow 1353
	if ( CFileIO(toFile).writeFile(&list) )
1 cycrow 1354
		printf("Packager script, %s, has been geenrated\n", toFile.c_str());
1355
	else
1356
		printf("Error: unable to write packager script, %s\n", toFile.c_str());
1357
 
1358
	delete package;
1359
}
1360
 
1361
/*
1362
	Func:	LoadPackagerScript
1363
	Args:	String filename	-	The filename of the packager script to load
1364
	Desc:	Loads the packager scripts and creates a spk/xsp file from it
1365
*/
1366
void LoadPackagerScript(CyString filename, bool verify)
1367
{
52 cycrow 1368
	if ( !CFileIO(filename).ExistsOld() )
1 cycrow 1369
	{
1370
		printf("Error: The packager script, %s, does not exist", filename.c_str());
1371
		return;
1372
	}
1373
 
1374
	CyString myDoc;
1375
#ifdef _WIN32
1376
	TCHAR pszPath[MAX_PATH];
1377
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
1378
	{
1379
		myDoc = (char *)pszPath;
1380
	}
1381
#endif
1382
 
1383
	if ( verify )
1384
		printf("Verifying Packager Script: %s\n", filename.c_str());
1385
 
1386
	CPackages p;
1387
	p.Startup(".", ".", myDoc);
1388
	CyStringList malformed, unknown;
1389
 
102 cycrow 1390
	CyString curDir = CFileIO(filename).dir();
1 cycrow 1391
	if ( curDir.Empty() ) curDir = "./";
1392
 
1393
	CyStringList variables;
1394
	variables.PushBack("$PATH", curDir);
1395
 
1396
	CBaseFile *package = p.LoadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables);
1397
 
1398
	if ( verify )
1399
	{
1400
		if ( !malformed.Empty() )
1401
		{
1402
			printf("Malformed Lines (%d):\n", malformed.Count());
1403
			for ( SStringList *strNode = malformed.Head(); strNode; strNode = strNode->next )
1404
				printf("\t(Line %3d) %s\n", strNode->data.ToInt(), strNode->str.c_str());
1405
		}
1406
		if ( !unknown.Empty() )
1407
		{
1408
			printf("Unknown Commands (%d):\n", unknown.Count());
1409
			for ( SStringList *strNode = unknown.Head(); strNode; strNode = strNode->next )
1410
				printf("\t* Command: %s = %s\n", strNode->str.c_str(), strNode->data.c_str());
1411
		}
1412
	}
1413
 
1414
	if ( !package )
1415
	{
1416
		if ( verify )
1417
			printf("Error: There are errors in the packager script which prevents it from being created\n");
1418
		else
1419
			printf("Error: Unable to create package, from script: %s\n", filename.c_str());
1420
	}
1421
	else
1422
	{
50 cycrow 1423
		CyString saveto = package->filename();
1 cycrow 1424
		saveto = saveto.FindReplace("$DEFAULTDIR", curDir + "/");
1425
		saveto = saveto.FindReplace("$PATH", curDir);
1426
		saveto = saveto.FindReplace("\\", "/");
1427
		saveto = saveto.FindReplace("//", "/");
1428
		if ( !saveto.Right(4).Compare(".spk") && package->GetType() != TYPE_XSP )
1429
			saveto += ".spk";
1430
		else if ( !saveto.Right(4).Compare(".xsp") && package->GetType() == TYPE_XSP )
1431
			saveto += ".xsp";
102 cycrow 1432
		printf("Saving file to: %s\n", CFileIO(saveto).fullFilename().c_str());
1 cycrow 1433
		if ( verify )
1434
			printf("Package can be created from this script\n");
1435
		else
1436
		{
1437
			// write script
1438
			if ( package->WriteFile(saveto) )
1439
			{
1440
				if ( package->AutoGenerateUpdateFile() )
102 cycrow 1441
					package->CreateUpdateFile(CFileIO(saveto).dir());
1 cycrow 1442
				printf("Package: %s was created\n", saveto.c_str());
1443
			}
1444
			else
1445
				printf("Error! There was a problem writing the package\n");
1446
		}
1447
 
50 cycrow 1448
		saveto = package->exportFilename();
1 cycrow 1449
		if ( !saveto.Empty() ) {
1450
			saveto = saveto.FindReplace("$DEFAULTDIR", curDir + "/");
1451
			saveto = saveto.FindReplace("$PATH", curDir);
1452
			saveto = saveto.FindReplace("\\", "/");
1453
			saveto = saveto.FindReplace("//", "/");
102 cycrow 1454
			printf("Exporting file to: %s\n", CFileIO(saveto).fullFilename().c_str());
1 cycrow 1455
			if ( verify )
1456
				printf("Package can be exported from this script\n");
1457
			else
1458
			{
1459
				// export
126 cycrow 1460
				if ( package->SaveToArchive(saveto, 0, p.GetGameExe()) ) {
1 cycrow 1461
					if ( package->IsAnyGameInPackage() ) {
1462
						for ( int i = 0; i < p.GetGameExe()->GetNumGames(); i++ ) {
1463
							if ( package->IsGameInPackage(i + 1) ) {								
102 cycrow 1464
								Utils::String exportFile = CFileIO(saveto).dir() + "/" + CFileIO(saveto).baseName() + "_" + CBaseFile::ConvertGameToString(i + 1) + "." + CFileIO(saveto).extension();
126 cycrow 1465
								package->SaveToArchive(exportFile, i + 1, p.GetGameExe());
1 cycrow 1466
							}
1467
						}
1468
					}
1469
					printf("Package: %s was exported\n", saveto.c_str());
1470
				}
1471
				else
1472
					printf("Error! There was a problem exporting the package\n");
1473
			}
1474
		}
1475
	}
1476
}
1477
 
1478
/*
1479
	Main entry point to program
1480
*/
1481
int main ( int argc, char **argv )
1482
{
1483
	// display program header to command prompt
126 cycrow 1484
	printf ( "\nSPKTool V1.50 (SPK File Version %.2f) 14/02/2021 Created by Cycrow\n\n", (float)FILEVERSION );
1 cycrow 1485
 
1486
	// parse the cmd name
1487
	CyString cmd (argv[0]);
1488
	cmd = cmd.FindReplace ( "\\", "/" );
1489
	g_dir = cmd.GetToken ( 0, cmd.NumToken('/') - 1, '/' );
1490
	cmd = cmd.GetToken ( cmd.NumToken('/'), '/' );
1491
 
1492
	g_read = false;
1493
 
1494
	// not enough arguments, display the syntax and exit
1495
	if ( argc < 2 )
1496
	{
1497
		PrintSyntax ( cmd );
1498
		exit ( 1 );
1499
	}
1500
 
1501
	CyString fileTypes;
1502
	for ( int i = 0; i < FILETYPE_MAX; i++ )
1503
	{
1504
		CyString sT = GetFileTypeString(i);
1505
		if ( !sT.Empty() )
1506
		{
1507
			if ( fileTypes.Empty() )
1508
				fileTypes = sT;
1509
			else
1510
			{
1511
				fileTypes += ", ";
1512
				fileTypes += sT;
1513
			}
1514
		}
1515
	}
1516
 
1517
	// get the command flag
1518
	CyString command(argv[1]);
1519
 
1520
	// display the contents of the spk file
1521
	if ( command == "-v" || command == "--version" )
1522
	{
1523
		if ( argc < 3 )
1524
			printf ( "Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.c_str() );
1525
		else
1526
			DisplayVersion ( argv[2] );
1527
	}
1528
 
1529
	// creates a new spk file
1530
	else if ( command == "-c" || command == "--create" )
1531
	{
1532
		if ( argc < 3 )
1533
			printf ( "Syntax:\n\t%s -c <spkfile>\n\t%s --create <spkfile>\n\t\tThis will create a new SPK file and allow you to set some basic settings for the file\n", cmd.c_str(), cmd.c_str() );
1534
		else
1535
			CreateFile ( argv[2] );
1536
	}
1537
 
1538
	// appends a file onto the spk archive
1539
	else if ( command == "-a" || command == "--append" )
1540
	{
1541
		if ( argc < 4 )
1542
			printf ( "Syntax:\n\t%s -a <spkfile> <type> <filename>\n\t%s --append <spkfile> <type> <filename>\n\t\tThis will append the file into the archive and compress it according to the files default compression\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
1543
		else
1544
		{
1545
			CyString arg4;
1546
			if ( argc > 4 )
1547
				arg4 = argv[4];
1548
			AppendFile ( argv[2], argv[3], arg4 );
1549
		}
1550
	}
1551
 
1552
	// removes a file from the spk archive
1553
	else if ( command == "-r" || command == "--remove" || command == "--removespk" )
1554
	{
1555
		if ( argc < 4 )
1556
		{
1557
			printf ( "Syntax:\n\t%s -r <spkfile> <type> <filename>\n\t%s --remove <spkfile> <type> <filename\n\t\tThis will remove a file from the archive\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
1558
			printf ( "\t%s -r <multispkfile> <filename>\n\t%s --removespk <multispkfile> <filename>\n\t\tThis will remove a spk file from the Multi-SPK package\n", cmd.c_str(), cmd.c_str() );
1559
		}
1560
		else
1561
		{
1562
			CyString arg4;
1563
			if ( argc > 4 )
1564
				arg4 = argv[4];
1565
			RemoveFile ( argv[2], argv[3], arg4 );
1566
		}
1567
	}
1568
 
1569
	// extracts a file from a spk file
1570
	else if ( command == "--extractspk" )
1571
	{
1572
		if ( argc < 4 )
1573
			printf ( "Syntax:\n\t%s --extractspk <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
1574
		else
1575
		{
1576
			CyString arg4;
1577
			if ( argc > 4 )
1578
				arg4 = argv[3];
1579
			ExtractFile ( argv[2], argv[3], arg4, NullString );
1580
		}
1581
	}
1582
	else if ( command == "-x" || command == "--extract")
1583
	{
1584
		if ( argc < 4 )
1585
		{
1586
			printf ( "Syntax:\n\t%s -x <spkfile> <type> <filename> [destination]\n\tThis will extract a file from the package and save it to the corect path in <directory>\n\t<type> = %s\n", cmd.c_str(), fileTypes.c_str() );
1587
			printf ( "\t%s -x <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
1588
		}
1589
		else
1590
		{
1591
			CyString arg5, arg4;
1592
			if ( argc > 5 )
1593
				arg5 = argv[5];
1594
			if ( argc > 4 )
1595
				arg4 = argv[4];
1596
			ExtractFile ( argv[2], argv[3], arg4, arg5 );
1597
		}
1598
	}
1599
 
1600
	// extracts all the files from an archive
1601
	else if ( command == "-e" || command == "--extractall" )
1602
	{
1603
		if ( argc < 3 )
1604
			printf ( "Syntax:\n\t%s -e <spkfile> [destination]\n\t--extractall <spkfile> <game> [destination]\n\t\tThis will extract all files of a set game into the destination directory\n\n\t\tGame = 0 will extract all files", cmd.c_str() );
1605
		else
1606
		{
1607
			CyString arg4;
1608
			if ( argc > 4 )
1609
				arg4 = argv[4];
1610
			ExtractFiles ( argv[2], arg4, atoi(argv[3]) );
1611
		}
1612
	}
1613
 
1614
	// creates a multispk archive
1615
	else if ( command == "-n" || command == "--createmulti" )
1616
	{
1617
		if ( argc < 3 )
1618
			printf ( "Syntax:\n\t%s -n <multispkfile>\n\t%s --createmulti <multispkfile>\n\t\tThis will create a multispk file and allow you to add spk files to it\n", cmd.c_str(), cmd.c_str() );
1619
		else
1620
			CreateMultiFile ( argv[2] );
1621
	}
1622
 
1623
	// merges 2 multi-spk archives together, or appends a single spk file into a multi-spk file
1624
	else if ( command == "-m" || command == "--mergemulti" )
1625
	{
1626
		if ( argc < 4 )
1627
			printf ( "Syntax:\n\t%s -m <spkfile1> <spkfile2>\n\t%s --mergemulti <spkfile1> <spkfile2>\n\t\tThis will add spkfile2 into spkfile1, if spkfile1 is a normal SPK file, it will be saved into a Multi-Spk file\nspkfile2 can also be a Multi-Spk file, all files within it will be added\n", cmd.c_str(), cmd.c_str() );
1628
		else
1629
			AppendMultiFile ( argv[2], argv[3] );
1630
	}
1631
 
1632
	// splits the multi-spk file, exracts all spk files
1633
	else if ( command == "-s" || command == "--splitmulti" )
1634
	{
1635
		if ( argc < 3 )
1636
			printf ( "Syntax: %s -s <multispkfile> [destination]\n\tSplits the Multi-SPK file and saves each spk file to the destiantion directory\n", cmd.c_str() );
1637
		else
1638
		{
1639
			CyString arg3;
1640
			if ( argc > 3 )
1641
				arg3 = argv[3];
1642
			SplitMulti ( argv[2], arg3 );
1643
		}
1644
	}
1645
 
1646
	else if ( command == "--set" )
1647
	{
1648
		if ( argc < 4 )
1649
			printf ( "Syntax: %s --set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.c_str() );
1650
		else
1651
			Settings(argv[2], argv[3], argc, argv, cmd);
1652
	}
1653
	else if ( command == "--setrating" )
1654
	{
1655
		if ( argc < 6 )
1656
			printf ( "Syntax: %s --setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.c_str() );
1657
		else
1658
			SetRating(argv[2], CyString(argv[3]).ToInt(), CyString(argv[4]).ToInt(), CyString(argv[5]).ToInt());
1659
	}
1660
	else if ( command == "--convertxsp" || command == "--convertxspwizard" )
1661
	{
1662
		if ( argc < 3 )
1663
			printf ( "Syntax: %s %s <xspfile> [newxspfile]\n\tConverts an old format xsp file to work with the new format\n", cmd.c_str(), command.c_str() );
1664
		else
1665
		{
1666
			CyString arg3;
1667
			if ( argc > 3 )
1668
				arg3 = argv[3];
1669
			ConvertXsp(argv[2], arg3, (command == "--convertxspwizard") ? true : false);
1670
		}
1671
	}
1672
	else if ( command == "--createscript" )
1673
	{
1674
		if ( argc < 3 )
1675
			printf ( "Syntax:\n\t%s --createscript <packagerscript>\n\t\tThis will create a spk/xsp file from a packager script\n", cmd.c_str() );
1676
		else
1677
			LoadPackagerScript ( argv[2], false );
1678
	}
1679
	else if ( command == "--generatescript" )
1680
	{
1681
		if ( argc < 3 )
126 cycrow 1682
			printf ( "Syntax:\n\t%s --generatescript <package> [packagerscript]\n\t\tThis will generate a packager script file from a spk/xsp file.\n", cmd.c_str() );
1 cycrow 1683
		else
1684
		{
1685
			if ( argc < 4 )
126 cycrow 1686
				GeneratePackagerScript ( argv[2], "", 0);
1 cycrow 1687
			else
126 cycrow 1688
				GeneratePackagerScript ( argv[2], argv[3], 0);
1 cycrow 1689
		}
1690
	}
1691
	else if ( command == "--verifyscript" )
1692
	{
1693
		if ( argc < 3 )
1694
			printf ( "Syntax:\n\t%s --verifyscript <packagerscript>\n\t\tThis will read a packager script and check its correct without creating the resulting spk/xsp file\n", cmd.c_str() );
1695
		else
1696
			LoadPackagerScript ( argv[2], true );
1697
	}
1698
	else if ( command == "--extractship" )
1699
	{
1700
		if ( argc < 4 )
1701
			printf ( "Syntax:\n\t%s --extractship <modfile> <xspfile> [shipid]\n\t\tThis will create an xsp ship file by extracting from a mod file\n", cmd.c_str() );
1702
		else
1703
		{
1704
			if ( argc < 5 )
1705
				ExtractShip ( argv[2], argv[3], "" );
1706
			else
1707
				ExtractShip ( argv[2], argv[3], argv[4] );
1708
		}
1709
	}
126 cycrow 1710
	else if (command == "--generateupdatefile")
1 cycrow 1711
	{
126 cycrow 1712
	if (argc < 3)
1713
		printf("Syntax:\n\t%s --generateupdatefile <package>\n\t\tThis will generate the update file to allow auto updates for a package\n", cmd.c_str());
1714
	else
1715
		GenerateUpdateFile(argv[2]);
1716
	}
1717
	else if (command == "--packagelist")
1718
	{
1719
		if (argc < 3)
1720
			printf("Syntax:\n\t%s --packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.c_str());
1 cycrow 1721
		else
126 cycrow 1722
			GenerateUpdateList(argc, argv);
1 cycrow 1723
	}
1724
 
1725
	// not a valid switch, display syntax
1726
	else
1727
		PrintSyntax ( cmd );
1728
 
1729
#ifdef _DEBUG
1730
	char pause;
1731
	scanf ( "%s", &pause );
1732
#endif
1733
 
1734
	return 0;
1735
}