Subversion Repositories spk

Rev

Rev 129 | Rev 134 | 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
 
129 cycrow 885
void ExtractFiles (const Utils::String &sfile, const Utils::String &dir, int game )
1 cycrow 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
 
129 cycrow 896
	CPackages packages;
897
	packages.startup(".", ".", ".");
898
 
1 cycrow 899
	int check = CSpkFile::CheckFile ( sfile );
900
 
901
	// extracts a file from single packages file
902
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
903
	{
904
		// creates the spkfile object
905
		CBaseFile *pBaseFile = 0;
906
		if ( check == SPKFILE_SINGLE )
907
			pBaseFile = (CBaseFile *)new CSpkFile();
908
		else if ( check == SPKFILE_SINGLESHIP )
909
			pBaseFile = (CBaseFile *)new CXspFile();
910
		else
911
			pBaseFile = new CBaseFile();
912
 
913
		printf ( "Opening File, %s... ", sfile.c_str() );
914
		// reads the file into memory
915
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
916
		if ( !pBaseFile->ReadFile ( sfile, SPKREAD_NODATA ) )
917
		{
918
			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
919
			return;
920
		}
921
		printf ( "(Done)\n" );
922
 
923
		printf ( "Extracting all files from archive..." );
129 cycrow 924
		if (packages.extractAll(pBaseFile, dir, game) )
1 cycrow 925
			printf ( "(Done)\nFiles have been extracted successfully\n" );
926
		else
927
			printf ( "(Error)\nThere was a problem extracting the files\n" );
928
	}
929
	else
930
		printf("Invalid package file, %s\n", sfile.c_str());
931
}
932
 
933
 
934
/*
935
	Func:	AppendMultiFile
936
	Args:	String toFile	- The spk file to append onto
937
			String addfile	- The spk file to append
938
	Desc:	Appends a spk file into a Multi-Spk Archive
939
			If toFile is a single spk file, it will be converted to a Multi-Spk File
940
			if addfile is a Multi-Spk file, all files from it will be appended
941
*/
942
void AppendMultiFile ( CyString toFile, CyString addfile )
943
{
944
	// create destination object
945
	CMultiSpkFile spkfile;
946
 
947
	// checks the destination
948
	int checkto = CSpkFile::CheckFile ( toFile );
949
 
950
	// if the destination is a single file, then convert it to a Multi-Spk package
951
	if ( checkto == SPKFILE_SINGLE )
952
	{
953
		// adds the single file to the Multi-Spk object
954
		// Add file also reads it into memory
955
		if ( !spkfile.AddFile ( toFile ) )
956
		{
957
			printf ( "Error: Unable to create Multi-Spk file\n" );
958
			return;
959
		}
960
	}
961
	else
962
	{
963
		// if its already a multispk file, then simply open it and read it to memory
964
		if ( !spkfile.ReadFile ( toFile ) )
965
		{
966
			printf ( "Error: Unable to open Multi-Spk file, %s\n", toFile.c_str() );
967
			return;
968
		}
969
	}
970
 
971
	// now add the file into the Multi-Spk Object
972
	// the AddFile function will handle both single and Multi-Spk files
973
	// So you dont need to test what the appending file is
974
	if ( spkfile.AddFile ( addfile ) )
975
	{
976
 
977
		// if it added correctly, then simply write the new Multi-Spk Object to disk
978
		printf ( "File, %s, has been added to Multi-Spk Package\n", addfile.c_str() );
979
		printf ( "Saving Multi-Spk File: %s... ", toFile.c_str() );
980
		if ( spkfile.WriteFile ( toFile ) )
981
			printf ( "(Done)\n" );
982
		else
983
			printf ( "(Error)\n" );
984
	}
985
	else
986
		printf ( "Error: Unable to add files, %s, to Multi-Spk Package\n", addfile.c_str() );
987
}
988
 
989
/*
990
	Func:	ExtractFile
991
	Args:	String sfile	- the spk file to read from
992
			String type		- the type of the file to find
993
			String addfile	- The filename to extract
994
			String dir		- The directory to extract to
995
	Desc:	Finds and extracts a file from a Spk Package
996
*/
997
void ExtractFile ( CyString sfile, CyString type, CyString addfile, CyString dir )
998
{
999
	// First checks if the file exists by opening it
1000
	FILE *id = fopen ( sfile.c_str(), "rb+" );
1001
	if ( !id )
1002
	{
1003
		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
1004
		return;
1005
	}
1006
	fclose ( id );
1007
 
1008
	// now check the type of file it is, using the static function CheckFile(filename).
1009
	// This will return the type of file
1010
	//		SPK_INVALID		- Invalid file format, wont be able to open
1011
	//		SPK_SINGLE		- A Single spk package file
1012
	//		SPK_MULTI		- A Multi-Spk Archive
1013
	//		SPK_BASE		- A Base File
1014
	//		SPK_SINGLESHIP	- A Ship file
1015
	int check = CSpkFile::CheckFile ( sfile );
1016
 
1017
	// extracts a file from single packages file
1018
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
1019
	{
1020
		// first get the file type is valid
1021
		// converts the string type into its filetype flag
1022
		int t = GetFileTypeFromString(type);
1023
		// incorrect text type, display the error
1024
		if ( t == -1 )
1025
		{
1026
			printf ( "The file type \"%s\" is invalid\n", type.c_str() );
1027
			return;
1028
		}
1029
 
1030
		// creates the spkfile object
1031
		CBaseFile *pBaseFile = 0;
1032
		if ( check == SPKFILE_SINGLE )
1033
			pBaseFile = (CBaseFile *)new CSpkFile();
1034
		else if ( check == SPKFILE_SINGLESHIP )
1035
			pBaseFile = (CBaseFile *)new CXspFile();
1036
		else
1037
			pBaseFile = new CBaseFile();
1038
 
1039
		printf ( "Opening File, %s... ", sfile.c_str() );
1040
		// reads the file into memory
1041
		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
1042
		if ( !pBaseFile->ReadFile ( sfile, SPKREAD_NODATA ) )
1043
		{
1044
			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
1045
			return;
1046
		}
1047
 
1048
		// No read all the file data into memory
1049
		// This can be done all together in the ReadFile function
1050
		// 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
1051
		pBaseFile->ReadAllFilesToMemory ();
1052
 
1053
		printf ( "(Done)\n" );
1054
 
1055
		// uses the FindFile function to find the selected file in the archive
1056
		// requires the filename, type and custom directory (only for Extra File Type)
1057
		C_File *f = pBaseFile->FindFile ( addfile, t );
1058
		if ( !f )
1059
		{
1060
			printf ( "Unable to find the file \"%s\" in the package\n", addfile.c_str() );
1061
			return;
1062
		}
1063
 
1064
		// creates the directory so it can be extracted
1065
		CDirIO Dir(dir);
1066
		if ( !Dir.Create(f->GetDirectory(pBaseFile)) )
1067
		{
1068
			printf ( "Unable to create the directory \"%s\" to extract into\n", dir.c_str() );
1069
			return;
1070
		}
1071
 
1072
		// sets up the progress pointer
1073
		// if it uses 7zip, the progress will be displayed in the command prompt
1074
		MyProgress progress(0);
1075
		printf ( "Extracting the file from package\n\t>" );
1076
 
1077
		// Extracts the file to the specified directory
1078
		if ( !pBaseFile->ExtractFile ( f, dir, true, &progress ) )
1079
			printf ( "< (Error)\nUnable to extract the file\n" );
1080
		else
1081
		{
1082
			progress.PrintDone ();
1083
			printf ( "< (Done)\nFile has been extracted successfully\n" );
1084
		}
1085
	}
1086
 
1087
	// the file is a Multi-Spk File, extracts a single spk file from the archive
1088
	else if ( check == SPKFILE_MULTI )
1089
	{
1090
		// creates MultiSpkFile object
1091
		CMultiSpkFile spkfile;
1092
		printf ( "Opening Multi-SPK file, %s...", sfile.c_str() );
1093
 
1094
		// reads the MultiSpkFile into memory
1095
		if ( !spkfile.ReadFile ( sfile ) )
1096
		{
1097
			printf ( "(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str() );
1098
			return;
1099
		}
1100
		printf ( "(Done)\n" );
1101
 
1102
		// searchs the archive for a matching file
1103
		SMultiSpkFile *ms = spkfile.FindFile ( type );
1104
		if ( !ms )
1105
		{
1106
			printf ( "Unable to find the file \"%s\" in the package\n", type.c_str() );
1107
			return;
1108
		}
1109
 
1110
		// extracts the file from the archive, to the given directory
1111
		printf ( "Extracting SPK file, %s, from package... ", ms->sName.c_str() );
1112
		if ( spkfile.ExtractFile ( ms, addfile ) )
1113
			printf ( "(Done)\n" );
1114
		else
1115
			printf ( "(Error)\n" );
1116
	}
1117
	else
1118
		printf ( "Error: Invalid file format, unable to open\n" );
1119
}
1120
 
1121
/*
1122
	Func:	SplitMulti
1123
	Args:	String filename - the filename of the multispk file to open
1124
			String dest		- The destination directory to extract the files to
1125
	Desc:	Splits a multi-spk file into its seperate spk files
1126
*/
1127
void SplitMulti ( CyString filename, CyString dest )
1128
{
1129
	// Check the file type, Must return SPKFILE_MULTI, otherwise its not a Multi-Spk Packages
1130
	if ( CSpkFile::CheckFile ( filename ) != SPKFILE_MULTI )
1131
	{
1132
		printf ( "Error: The file is not a Multi-Spk packages\n" );
1133
		return;
1134
	}
1135
 
1136
	printf ( "Spliting Multi-SPK File to, %s... ", dest.c_str() );
1137
 
1138
	// create the MultiSpkFile object
1139
	CMultiSpkFile spkfile;
1140
 
1141
	// Splits the files to the destination
1142
	if ( !spkfile.SplitMulti  ( filename, dest ) )
1143
	{
1144
		printf ( "(Error)\nUnable to split Multi-SPK package, %s\n", filename.c_str() );
1145
		return;
1146
	}
1147
 
1148
	printf ( "(Done)\n" );
1149
}
1150
 
127 cycrow 1151
Utils::String GetAsk(const Utils::String &command)
1 cycrow 1152
{
1153
	printf("(ASK) Enter the value for, %s: ", command.c_str());
1154
	return GetInput();
1155
}
1156
 
126 cycrow 1157
void GenerateUpdateList(int argc, char **argv)
1158
{
1159
	Utils::String currentDir = CFileIO(argv[0]).dir();
1160
	CDirIO Dir(currentDir);
1161
 
1162
	Utils::CStringList list;
1163
	for (int i = 2; i < argc; ++i)
1164
	{
1165
		Utils::String file(argv[i]);
1166
		if (CFileIO::Exists(file))
1167
			list.pushBack(file, "file");
1168
		else if (CFileIO::Exists(Dir.file(file)))
1169
			list.pushBack(Dir.file(file), "file");
1170
		else if (CDirIO::Exists(file))
1171
			list.pushBack(file, "dir");
1172
		else if (CDirIO::Exists(Dir.dir(file)))
1173
			list.pushBack(Dir.dir(file), "dir");
1174
		else
1175
			list.pushBack(file, "pattern");
1176
	}
1177
 
1178
	if (list.empty())
1179
		printf("unable to find any packages");
1180
	else
1181
	{
1182
		Utils::CStringList fileList;
1183
		for (auto itr = list.begin(); itr != list.end(); itr++)
1184
		{
1185
			Utils::String file = (*itr)->str;
1186
			Utils::String data = (*itr)->data;
1187
			if (data == "file")
1188
				fileList.pushBack(file);
1189
			else if (data == "dir")
1190
			{
1191
				CDirIO dir(file);
1192
				Utils::CStringList d;
1193
				if (dir.dirList(d))
1194
				{
1195
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1196
					{
1197
						Utils::String ext = CFileIO((*itr2)->str).extension().lower();
1198
						if(ext == "xsp" || ext == "spk")
1199
							fileList.pushBack(dir.file((*itr2)->str));
1200
					}
1201
				}
1202
			}
1203
			else if (data == "pattern")
1204
			{				
1205
				CFileIO f(file);
1206
				CDirIO dir(f.dir());
1207
 
1208
				if (!dir.exists())
1209
					dir = CDirIO(Dir.dir(dir.dir()));
1210
 
1211
				Utils::CStringList d;
1212
				if (dir.dirList(d, Utils::String::Null(), f.filename()))
1213
				{
1214
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1215
					{
1216
						Utils::String ext = CFileIO((*itr2)->str).extension().lower();
1217
						if (ext == "xsp" || ext == "spk")
1218
							fileList.pushBack(dir.file((*itr2)->str));
1219
					}
1220
				}
1221
			}
1222
		}
1223
 
1224
		if (fileList.empty())
1225
			printf("unable to find any packages");
1226
		else
1227
		{
1228
			CPackages packages;
1229
 
1230
			Utils::CStringList filedata;
1231
			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
1232
			{
1233
				printf("Reading file: %s\n", (*itr)->str.c_str());
1234
 
1235
				int error = 0;
1236
				CBaseFile *p = packages.OpenPackage((*itr)->str, &error, 0, SPKREAD_NODATA);
1237
				if (!p)
1238
				{
1239
					printf("\tERROR!\n");
1240
					continue;
1241
				}
1242
				printf("\tData extracted: %s %s by %s\n", p->name().c_str(), p->version().c_str(), p->author().c_str());
1243
				if (!p->creationDate().empty())
1244
					printf("\t\tCreated: %s\n", p->creationDate().c_str());
1245
				if(!p->description().empty())
1246
					printf("\t\t%s\n", p->description().c_str());
1247
 
1248
				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
1249
				delete p;
1250
			}
1251
 
1252
			if (filedata.empty())
1253
				printf("unable to find any packages");
1254
			else				
1255
			{
1256
				Utils::String dest = Dir.file("xpackagedata.dat");
1257
				if (CFileIO(dest).writeFile(&filedata))
1258
					printf("web update file, xpackagedata.dat, generated");
1259
				else
1260
					printf("unable to write update file");
1261
			}
1262
		}
1263
	}
1264
}
1265
 
1 cycrow 1266
void GenerateUpdateFile(CyString spkfile)
1267
{
52 cycrow 1268
	if ( !CFileIO(spkfile).ExistsOld() )
1 cycrow 1269
	{
1270
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1271
		return;
1272
	}
1273
 
1274
	int check = CSpkFile::CheckFile(spkfile);
1275
	if ( check == SPKFILE_MULTI )
1276
	{
1277
		printf("Error: Multi-Package files currently not supported\n");
1278
		return;
1279
	}
1280
	else if ( check == SPKFILE_OLD )
1281
	{
1282
		printf("Error: unable to read old format spk file, try spkconvert first\n");
1283
		return;
1284
	}
1285
	else if ( check == SPKFILE_INVALID )
1286
	{
1287
		printf("Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
1288
		return;
1289
	}
1290
 
1291
	CPackages p;
1292
	int error;
1293
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1294
	if ( !package )
1295
	{
1296
		printf("Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
1297
		return;
1298
	}
1299
 
102 cycrow 1300
	Utils::String file = package->CreateUpdateFile(CFileIO(spkfile).dir()).ToString();
1301
	if ( file.empty() )
1302
		printf("Error: unable to create update file for: %s, Directory=%s\n", spkfile.c_str(), CFileIO(spkfile).dir().c_str());
1 cycrow 1303
	else
1304
		printf("Update file: %s has been created for package, %s\n", file.c_str(), spkfile.c_str());
1305
 
1306
	delete package;
1307
 
1308
}
1309
 
126 cycrow 1310
void GeneratePackagerScript(const Utils::String &spkfile, CyString toFile, int game)
1 cycrow 1311
{
126 cycrow 1312
	if (!CFileIO::Exists(spkfile))
1 cycrow 1313
	{
1314
		printf("Error: The package file, %s, does not exist", spkfile.c_str());
1315
		return;
1316
	}
1317
 
1318
	int check = CSpkFile::CheckFile(spkfile);
1319
	if ( check == SPKFILE_MULTI )
1320
	{
1321
		printf("Error: Cant generate a script from a multi-spk file\n");
1322
		return;
1323
	}
1324
	else if ( check == SPKFILE_OLD )
1325
	{
1326
		printf("Error: unable to read old format spk file, try spkconvert first\n");
1327
		return;
1328
	}
1329
	else if ( check == SPKFILE_INVALID )
1330
	{
1331
		printf("Error: %s doesn't appear to be a spk file\n", spkfile.c_str());
1332
		return;
1333
	}
1334
 
1335
	CPackages p;
127 cycrow 1336
	p.startup(".", ".", ".");
1 cycrow 1337
	int error;
1338
	CBaseFile *package = p.OpenPackage(spkfile, &error, 0, SPKREAD_NODATA);
1339
	if ( !package )
1340
	{
1341
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1342
		return;
1343
	}
1344
 
126 cycrow 1345
	Utils::CStringList list;
127 cycrow 1346
	if ( !p.generatePackagerScript(package, true, &list, game) )
1 cycrow 1347
	{
1348
		printf("Error: Unable to generate packager script\n");
1349
		return;
1350
	}
1351
 
1352
	if ( toFile.Empty() )
50 cycrow 1353
		toFile = CFileIO(spkfile).GetDirIO().File(package->name() + "_" + package->author() + ".sps");
1 cycrow 1354
 
1355
	// save package file
126 cycrow 1356
	if ( CFileIO(toFile).writeFile(&list) )
1 cycrow 1357
		printf("Packager script, %s, has been geenrated\n", toFile.c_str());
1358
	else
1359
		printf("Error: unable to write packager script, %s\n", toFile.c_str());
1360
 
1361
	delete package;
1362
}
1363
 
1364
/*
1365
	Func:	LoadPackagerScript
1366
	Args:	String filename	-	The filename of the packager script to load
1367
	Desc:	Loads the packager scripts and creates a spk/xsp file from it
1368
*/
131 cycrow 1369
void LoadPackagerScript(const Utils::String &filename, bool verify)
1 cycrow 1370
{
131 cycrow 1371
	if ( !CFileIO::Exists(filename) )
1 cycrow 1372
	{
1373
		printf("Error: The packager script, %s, does not exist", filename.c_str());
1374
		return;
1375
	}
1376
 
131 cycrow 1377
	Utils::String myDoc;
1 cycrow 1378
#ifdef _WIN32
1379
	TCHAR pszPath[MAX_PATH];
1380
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
1381
	{
1382
		myDoc = (char *)pszPath;
1383
	}
1384
#endif
1385
 
1386
	if ( verify )
1387
		printf("Verifying Packager Script: %s\n", filename.c_str());
1388
 
1389
	CPackages p;
131 cycrow 1390
	p.startup(".", ".", myDoc);
1391
	Utils::CStringList malformed, unknown;
1 cycrow 1392
 
131 cycrow 1393
	Utils::String curDir = CFileIO(filename).dir();
1394
	if ( curDir.empty() ) curDir = "./";
1 cycrow 1395
 
131 cycrow 1396
	Utils::CStringList variables;
1397
	variables.pushBack("$PATH", curDir);
1 cycrow 1398
 
1399
	CBaseFile *package = p.LoadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables);
1400
 
1401
	if ( verify )
1402
	{
131 cycrow 1403
		if ( !malformed.empty() )
1 cycrow 1404
		{
131 cycrow 1405
			printf("Malformed Lines (%d):\n", malformed.size());
1406
			for(auto itr = malformed.begin(); itr != malformed.end(); itr++)				
1407
				printf("\t(Line %3d) %s\n", (*itr)->data.toInt(), (*itr)->str.c_str());
1 cycrow 1408
		}
131 cycrow 1409
		if ( !unknown.empty() )
1 cycrow 1410
		{
131 cycrow 1411
			printf("Unknown Commands (%d):\n", unknown.size());
1412
			for (auto itr = unknown.begin(); itr != unknown.end(); itr++)
1413
				printf("\t* Command: %s = %s\n", (*itr)->str.c_str(), (*itr)->data.c_str());
1 cycrow 1414
		}
1415
	}
1416
 
1417
	if ( !package )
1418
	{
1419
		if ( verify )
1420
			printf("Error: There are errors in the packager script which prevents it from being created\n");
1421
		else
1422
			printf("Error: Unable to create package, from script: %s\n", filename.c_str());
1423
	}
1424
	else
1425
	{
131 cycrow 1426
		Utils::String saveto = package->filename();
1427
		saveto = saveto.findReplace("$DEFAULTDIR", curDir + "/");
1428
		saveto = saveto.findReplace("$PATH", curDir);
1429
		saveto = saveto.findReplace("\\", "/");
1430
		saveto = saveto.findReplace("//", "/");
1431
		if ( !saveto.right(4).Compare(".spk") && package->GetType() != TYPE_XSP )
1 cycrow 1432
			saveto += ".spk";
131 cycrow 1433
		else if ( !saveto.right(4).Compare(".xsp") && package->GetType() == TYPE_XSP )
1 cycrow 1434
			saveto += ".xsp";
102 cycrow 1435
		printf("Saving file to: %s\n", CFileIO(saveto).fullFilename().c_str());
1 cycrow 1436
		if ( verify )
1437
			printf("Package can be created from this script\n");
1438
		else
1439
		{
1440
			// write script
1441
			if ( package->WriteFile(saveto) )
1442
			{
1443
				if ( package->AutoGenerateUpdateFile() )
102 cycrow 1444
					package->CreateUpdateFile(CFileIO(saveto).dir());
1 cycrow 1445
				printf("Package: %s was created\n", saveto.c_str());
1446
			}
1447
			else
1448
				printf("Error! There was a problem writing the package\n");
1449
		}
1450
 
50 cycrow 1451
		saveto = package->exportFilename();
131 cycrow 1452
		if ( !saveto.empty() ) {
1453
			saveto = saveto.findReplace("$DEFAULTDIR", curDir + "/");
1454
			saveto = saveto.findReplace("$PATH", curDir);
1455
			saveto = saveto.findReplace("\\", "/");
1456
			saveto = saveto.findReplace("//", "/");
102 cycrow 1457
			printf("Exporting file to: %s\n", CFileIO(saveto).fullFilename().c_str());
1 cycrow 1458
			if ( verify )
1459
				printf("Package can be exported from this script\n");
1460
			else
1461
			{
1462
				// export
126 cycrow 1463
				if ( package->SaveToArchive(saveto, 0, p.GetGameExe()) ) {
1 cycrow 1464
					if ( package->IsAnyGameInPackage() ) {
1465
						for ( int i = 0; i < p.GetGameExe()->GetNumGames(); i++ ) {
1466
							if ( package->IsGameInPackage(i + 1) ) {								
102 cycrow 1467
								Utils::String exportFile = CFileIO(saveto).dir() + "/" + CFileIO(saveto).baseName() + "_" + CBaseFile::ConvertGameToString(i + 1) + "." + CFileIO(saveto).extension();
126 cycrow 1468
								package->SaveToArchive(exportFile, i + 1, p.GetGameExe());
1 cycrow 1469
							}
1470
						}
1471
					}
1472
					printf("Package: %s was exported\n", saveto.c_str());
1473
				}
1474
				else
1475
					printf("Error! There was a problem exporting the package\n");
1476
			}
1477
		}
1478
	}
1479
}
1480
 
1481
/*
1482
	Main entry point to program
1483
*/
1484
int main ( int argc, char **argv )
1485
{
1486
	// display program header to command prompt
126 cycrow 1487
	printf ( "\nSPKTool V1.50 (SPK File Version %.2f) 14/02/2021 Created by Cycrow\n\n", (float)FILEVERSION );
1 cycrow 1488
 
1489
	// parse the cmd name
1490
	CyString cmd (argv[0]);
1491
	cmd = cmd.FindReplace ( "\\", "/" );
1492
	g_dir = cmd.GetToken ( 0, cmd.NumToken('/') - 1, '/' );
1493
	cmd = cmd.GetToken ( cmd.NumToken('/'), '/' );
1494
 
1495
	g_read = false;
1496
 
1497
	// not enough arguments, display the syntax and exit
1498
	if ( argc < 2 )
1499
	{
1500
		PrintSyntax ( cmd );
1501
		exit ( 1 );
1502
	}
1503
 
1504
	CyString fileTypes;
1505
	for ( int i = 0; i < FILETYPE_MAX; i++ )
1506
	{
1507
		CyString sT = GetFileTypeString(i);
1508
		if ( !sT.Empty() )
1509
		{
1510
			if ( fileTypes.Empty() )
1511
				fileTypes = sT;
1512
			else
1513
			{
1514
				fileTypes += ", ";
1515
				fileTypes += sT;
1516
			}
1517
		}
1518
	}
1519
 
1520
	// get the command flag
1521
	CyString command(argv[1]);
1522
 
1523
	// display the contents of the spk file
1524
	if ( command == "-v" || command == "--version" )
1525
	{
1526
		if ( argc < 3 )
1527
			printf ( "Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.c_str() );
1528
		else
1529
			DisplayVersion ( argv[2] );
1530
	}
1531
 
1532
	// creates a new spk file
1533
	else if ( command == "-c" || command == "--create" )
1534
	{
1535
		if ( argc < 3 )
1536
			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() );
1537
		else
1538
			CreateFile ( argv[2] );
1539
	}
1540
 
1541
	// appends a file onto the spk archive
1542
	else if ( command == "-a" || command == "--append" )
1543
	{
1544
		if ( argc < 4 )
1545
			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() );
1546
		else
1547
		{
1548
			CyString arg4;
1549
			if ( argc > 4 )
1550
				arg4 = argv[4];
1551
			AppendFile ( argv[2], argv[3], arg4 );
1552
		}
1553
	}
1554
 
1555
	// removes a file from the spk archive
1556
	else if ( command == "-r" || command == "--remove" || command == "--removespk" )
1557
	{
1558
		if ( argc < 4 )
1559
		{
1560
			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() );
1561
			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() );
1562
		}
1563
		else
1564
		{
1565
			CyString arg4;
1566
			if ( argc > 4 )
1567
				arg4 = argv[4];
1568
			RemoveFile ( argv[2], argv[3], arg4 );
1569
		}
1570
	}
1571
 
1572
	// extracts a file from a spk file
1573
	else if ( command == "--extractspk" )
1574
	{
1575
		if ( argc < 4 )
1576
			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() );
1577
		else
1578
		{
1579
			CyString arg4;
1580
			if ( argc > 4 )
1581
				arg4 = argv[3];
1582
			ExtractFile ( argv[2], argv[3], arg4, NullString );
1583
		}
1584
	}
1585
	else if ( command == "-x" || command == "--extract")
1586
	{
1587
		if ( argc < 4 )
1588
		{
1589
			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() );
1590
			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() );
1591
		}
1592
		else
1593
		{
1594
			CyString arg5, arg4;
1595
			if ( argc > 5 )
1596
				arg5 = argv[5];
1597
			if ( argc > 4 )
1598
				arg4 = argv[4];
1599
			ExtractFile ( argv[2], argv[3], arg4, arg5 );
1600
		}
1601
	}
1602
 
1603
	// extracts all the files from an archive
1604
	else if ( command == "-e" || command == "--extractall" )
1605
	{
1606
		if ( argc < 3 )
1607
			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() );
1608
		else
1609
		{
129 cycrow 1610
			Utils::String arg4;
1 cycrow 1611
			if ( argc > 4 )
1612
				arg4 = argv[4];
129 cycrow 1613
			ExtractFiles(argv[2], arg4, atoi(argv[3]) );
1 cycrow 1614
		}
1615
	}
1616
 
1617
	// creates a multispk archive
1618
	else if ( command == "-n" || command == "--createmulti" )
1619
	{
1620
		if ( argc < 3 )
1621
			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() );
1622
		else
1623
			CreateMultiFile ( argv[2] );
1624
	}
1625
 
1626
	// merges 2 multi-spk archives together, or appends a single spk file into a multi-spk file
1627
	else if ( command == "-m" || command == "--mergemulti" )
1628
	{
1629
		if ( argc < 4 )
1630
			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() );
1631
		else
1632
			AppendMultiFile ( argv[2], argv[3] );
1633
	}
1634
 
1635
	// splits the multi-spk file, exracts all spk files
1636
	else if ( command == "-s" || command == "--splitmulti" )
1637
	{
1638
		if ( argc < 3 )
1639
			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() );
1640
		else
1641
		{
1642
			CyString arg3;
1643
			if ( argc > 3 )
1644
				arg3 = argv[3];
1645
			SplitMulti ( argv[2], arg3 );
1646
		}
1647
	}
1648
 
1649
	else if ( command == "--set" )
1650
	{
1651
		if ( argc < 4 )
1652
			printf ( "Syntax: %s --set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.c_str() );
1653
		else
1654
			Settings(argv[2], argv[3], argc, argv, cmd);
1655
	}
1656
	else if ( command == "--setrating" )
1657
	{
1658
		if ( argc < 6 )
1659
			printf ( "Syntax: %s --setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.c_str() );
1660
		else
1661
			SetRating(argv[2], CyString(argv[3]).ToInt(), CyString(argv[4]).ToInt(), CyString(argv[5]).ToInt());
1662
	}
1663
	else if ( command == "--convertxsp" || command == "--convertxspwizard" )
1664
	{
1665
		if ( argc < 3 )
1666
			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() );
1667
		else
1668
		{
1669
			CyString arg3;
1670
			if ( argc > 3 )
1671
				arg3 = argv[3];
1672
			ConvertXsp(argv[2], arg3, (command == "--convertxspwizard") ? true : false);
1673
		}
1674
	}
1675
	else if ( command == "--createscript" )
1676
	{
1677
		if ( argc < 3 )
1678
			printf ( "Syntax:\n\t%s --createscript <packagerscript>\n\t\tThis will create a spk/xsp file from a packager script\n", cmd.c_str() );
1679
		else
1680
			LoadPackagerScript ( argv[2], false );
1681
	}
1682
	else if ( command == "--generatescript" )
1683
	{
1684
		if ( argc < 3 )
126 cycrow 1685
			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 1686
		else
1687
		{
1688
			if ( argc < 4 )
126 cycrow 1689
				GeneratePackagerScript ( argv[2], "", 0);
1 cycrow 1690
			else
126 cycrow 1691
				GeneratePackagerScript ( argv[2], argv[3], 0);
1 cycrow 1692
		}
1693
	}
1694
	else if ( command == "--verifyscript" )
1695
	{
1696
		if ( argc < 3 )
1697
			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() );
1698
		else
1699
			LoadPackagerScript ( argv[2], true );
1700
	}
1701
	else if ( command == "--extractship" )
1702
	{
1703
		if ( argc < 4 )
1704
			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() );
1705
		else
1706
		{
1707
			if ( argc < 5 )
1708
				ExtractShip ( argv[2], argv[3], "" );
1709
			else
1710
				ExtractShip ( argv[2], argv[3], argv[4] );
1711
		}
1712
	}
126 cycrow 1713
	else if (command == "--generateupdatefile")
1 cycrow 1714
	{
126 cycrow 1715
	if (argc < 3)
1716
		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());
1717
	else
1718
		GenerateUpdateFile(argv[2]);
1719
	}
1720
	else if (command == "--packagelist")
1721
	{
1722
		if (argc < 3)
1723
			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 1724
		else
126 cycrow 1725
			GenerateUpdateList(argc, argv);
1 cycrow 1726
	}
1727
 
1728
	// not a valid switch, display syntax
1729
	else
1730
		PrintSyntax ( cmd );
1731
 
1732
#ifdef _DEBUG
1733
	char pause;
1734
	scanf ( "%s", &pause );
1735
#endif
1736
 
1737
	return 0;
1738
}