Subversion Repositories spk

Rev

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

Rev 315 Rev 321
Line 13... Line 13...
13
#include "../spk/spkcmdprogress.h"
13
#include "../spk/spkcmdprogress.h"
14
#endif
14
#endif
15
// Multi Spk File format, required if using Multi Spk files
15
// Multi Spk File format, required if using Multi Spk files
16
// Displays 7Zip compression progress to the command line
16
// Displays 7Zip compression progress to the command line
17
#include <time.h>
17
#include <time.h>
18
#ifdef _WIN32
-
 
19
#include <windows.h>
-
 
20
#include <direct.h>
-
 
21
#include <shlobj.h>
-
 
22
#endif
-
 
23
 
18
 
24
#include "Utils/CommandLine.h"
19
#include "Utils/CommandLine.h"
25
 
20
 
26
Utils::WString g_dir;
21
Utils::WString g_dir;
27
bool g_read;
22
bool g_read;
Line 29... Line 24...
29
class CFileProgress : public CProgressInfo
24
class CFileProgress : public CProgressInfo
30
{
25
{
31
private:
26
private:
32
	Utils::WString _display;
27
	Utils::WString _display;
33
	CBaseFile *_package;
28
	CBaseFile *_package;
34
	CPackages *_packages;
29
	const CPackages *_packages;
35
 
30
 
36
public:
31
public:
37
	CFileProgress(CPackages *packages, CBaseFile *package, const Utils::WString &display) : 
32
	CFileProgress(const CPackages *packages, CBaseFile *package, const Utils::WString &display) : 
38
		_display(display),
33
		_display(display),
39
		_packages(packages),
34
		_packages(packages),
40
		_package(package)
35
		_package(package)
41
	{
36
	{
42
 
37
 
Line 61... Line 56...
61
		{
56
		{
62
			for (unsigned int i = 0; i < 31; ++i)
57
			for (unsigned int i = 0; i < 31; ++i)
63
			{
58
			{
64
				if (file->game() & (1 << i))
59
				if (file->game() & (1 << i))
65
				{
60
				{
66
					Utils::WString g = _packages->GetGameExe()->gameNameFromType(i - 1);
61
					Utils::WString g = _packages->gameExe()->gameNameFromType(i - 1);
67
					if (!g.empty())
62
					if (!g.empty())
68
					{
63
					{
69
						if (game.empty())
64
						if (game.empty())
70
							game = g;
65
							game = g;
71
						else
66
						else
Line 415... Line 410...
415
		case GAME_X3FL:
410
		case GAME_X3FL:
416
			return L"X3: Farnham's Legacy";
411
			return L"X3: Farnham's Legacy";
417
	}
412
	}
418
	return L"Unknown";
413
	return L"Unknown";
419
}
414
}
420
void DisplayVersion(const Utils::WString &filename)
415
void DisplayVersion(const Utils::CommandLine &cmd)
421
{
416
{
-
 
417
	const Utils::WString& filename = cmd.arg(1);
-
 
418
 
422
	// first chekc if file even exists
419
	// first chekc if file even exists
423
	FILE *id = _wfopen(filename.c_str(), L"rb+");
420
	FILE *id = _wfopen(filename.c_str(), L"rb+");
424
	if ( !id )
421
	if ( !id )
425
	{
422
	{
426
		wprintf(L"Error: File, %s, doesn't exist\n", filename.c_str());
423
		wprintf(L"Error: File, %s, doesn't exist\n", filename.c_str());
Line 481... Line 478...
481
		read = true;
478
		read = true;
482
	}
479
	}
483
 
480
 
484
	if ( pBaseFile && read)
481
	if ( pBaseFile && read)
485
	{
482
	{
486
		CPackages p;
-
 
487
		p.startup(L".", L".", L".");
-
 
488
 
-
 
489
		CSpkFile *pSpkFile = NULL;
483
		CSpkFile *pSpkFile = NULL;
490
		CXspFile *pXspFile = NULL;
484
		CXspFile *pXspFile = NULL;
491
		if ( check == SPKFILE_SINGLE )
485
		if ( check == SPKFILE_SINGLE )
492
			pSpkFile = (CSpkFile *)pBaseFile;
486
			pSpkFile = (CSpkFile *)pBaseFile;
493
		else
487
		else
Line 511... Line 505...
511
		//for game
505
		//for game
512
		printf("For Games: ");
506
		printf("For Games: ");
513
		if ( !pBaseFile->AnyGameCompatability() )
507
		if ( !pBaseFile->AnyGameCompatability() )
514
			printf("All");
508
			printf("All");
515
		else
509
		else
516
			wprintf(L"%s", p.getGameTypesString(pBaseFile, true).c_str());
510
			wprintf(L"%s", cmd.packages().getGameTypesString(pBaseFile, true).c_str());
517
		printf("\n");
511
		printf("\n");
518
 
512
 
519
		if ( pXspFile )
513
		if ( pXspFile )
520
		{
514
		{
521
			wprintf(L"Ship Display Name: %s\n", pXspFile->shipName(44).c_str());
515
			wprintf(L"Ship Display Name: %s\n", pXspFile->shipName(44).c_str());
Line 653... Line 647...
653
 
647
 
654
					if (display)
648
					if (display)
655
					{
649
					{
656
						if (heading)
650
						if (heading)
657
						{
651
						{
658
							Utils::WString sGame = p.GetGameExe()->gameNameFromType(game - 1);
652
							Utils::WString sGame = cmd.packages().gameExe()->gameNameFromType(game - 1);
659
							wprintf(L"\tGame: %s\n", sGame.c_str());
653
							wprintf(L"\tGame: %s\n", sGame.c_str());
660
							heading = false;
654
							heading = false;
661
						}
655
						}
662
						wprintf(L"\t\t%s (%s) Size: %s\n", file->getNameDirectory(pBaseFile).c_str(), file->fileTypeString().c_str(), file->dataSizeString().c_str());
656
						wprintf(L"\t\t%s (%s) Size: %s\n", file->getNameDirectory(pBaseFile).c_str(), file->fileTypeString().c_str(), file->dataSizeString().c_str());
663
 
657
 
Line 975... Line 969...
975
	{
969
	{
976
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
970
		wprintf(L"Error: File, %s, doesn't exist\n", sfile.c_str() );
977
		return;
971
		return;
978
	}
972
	}
979
 
973
 
980
	CPackages packages;
-
 
981
	packages.startup(L".", L".", L".");
-
 
982
 
-
 
983
	int check = CSpkFile::CheckFile(File.fullFilename());
974
	int check = CSpkFile::CheckFile(File.fullFilename());
984
 
975
 
985
	// extracts a file from single packages file
976
	// extracts a file from single packages file
986
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
977
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
987
	{
978
	{
Line 1005... Line 996...
1005
		wprintf(L"(Done)\n");
996
		wprintf(L"(Done)\n");
1006
 
997
 
1007
		if(game == 0)
998
		if(game == 0)
1008
			wprintf(L"Extracting all files from archive...\n\n");
999
			wprintf(L"Extracting all files from archive...\n\n");
1009
		else
1000
		else
1010
			wprintf(L"Extracting %s files from archive...\n\n", packages.GetGameExe()->gameNameFromType(game - 1).c_str());
1001
			wprintf(L"Extracting %s files from archive...\n\n", cmd.packages().gameExe()->gameNameFromType(game - 1).c_str());
1011
 
1002
 
1012
		CFileProgress info(&packages, pBaseFile, "Extracting");
1003
		CFileProgress info(&cmd.packages(), pBaseFile, "Extracting");
1013
		if (packages.extractAll(pBaseFile, File.dirIO().dir(dir), game, true, &info) )
1004
		if (cmd.packages().extractAll(pBaseFile, File.dirIO().dir(dir), game, true, &info))
1014
			wprintf(L"\n(Done)\nFiles have been extracted successfully\n");
1005
			wprintf(L"\n(Done)\nFiles have been extracted successfully\n");
1015
		else
1006
		else
1016
			wprintf(L"\n(Error)\nThere was a problem extracting the files\n");
1007
			wprintf(L"\n(Error)\nThere was a problem extracting the files\n");
1017
	}
1008
	}
1018
	else
1009
	else
Line 1241... Line 1232...
1241
{
1232
{
1242
	wprintf(L"(ASK) Enter the value for, %s: ", command.c_str());
1233
	wprintf(L"(ASK) Enter the value for, %s: ", command.c_str());
1243
	return GetInput();
1234
	return GetInput();
1244
}
1235
}
1245
 
1236
 
1246
void GenerateUpdateList(int argc, char **argv)
1237
void GenerateUpdateList(const Utils::CommandLine &cmd)
1247
{
1238
{
1248
	Utils::WString currentDir = CFileIO(Utils::WString::FromString(argv[0])).dir();
-
 
1249
	CDirIO Dir(currentDir);
-
 
1250
 
-
 
1251
	Utils::WStringList list;
1239
	Utils::WStringList list;
1252
	for (int i = 2; i < argc; ++i)
1240
	for (int i = 1; i < cmd.argCount(); ++i)
1253
	{
1241
	{
1254
		Utils::WString file(argv[i]);
1242
		Utils::WString file(cmd.arg(i));
1255
		if (CFileIO::Exists(file))
1243
		if (CFileIO::Exists(file))
1256
			list.pushBack(file, L"file");
1244
			list.pushBack(file, L"file");
1257
		else if (CFileIO::Exists(Dir.file(file)))
1245
		else if (CFileIO::Exists(cmd.dirIO().file(file)))
1258
			list.pushBack(Dir.file(file), L"file");
1246
			list.pushBack(cmd.dirIO().file(file), L"file");
1259
		else if (CDirIO::Exists(file))
1247
		else if (CDirIO::Exists(file))
1260
			list.pushBack(file, L"dir");
1248
			list.pushBack(file, L"dir");
1261
		else if (CDirIO::Exists(Dir.dir(file)))
1249
		else if (CDirIO::Exists(cmd.dirIO().dir(file)))
1262
			list.pushBack(Dir.dir(file), L"dir");
1250
			list.pushBack(cmd.dirIO().dir(file), L"dir");
1263
		else
1251
		else
1264
			list.pushBack(file, L"pattern");
1252
			list.pushBack(file, L"pattern");
1265
	}
1253
	}
1266
 
1254
 
1267
	if (list.empty())
1255
	if (list.empty())
Line 1293... Line 1281...
1293
			{				
1281
			{				
1294
				CFileIO f(file);
1282
				CFileIO f(file);
1295
				CDirIO dir(f.dir());
1283
				CDirIO dir(f.dir());
1296
 
1284
 
1297
				if (!dir.exists())
1285
				if (!dir.exists())
1298
					dir = CDirIO(Dir.dir(dir.dir()));
1286
					dir = CDirIO(cmd.dirIO().dir(dir.dir()));
1299
 
1287
 
1300
				Utils::WStringList d;
1288
				Utils::WStringList d;
1301
				if (dir.dirList(d, Utils::WString::Null(), f.filename()))
1289
				if (dir.dirList(d, Utils::WString::Null(), f.filename()))
1302
				{
1290
				{
1303
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
1291
					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
Line 1312... Line 1300...
1312
 
1300
 
1313
		if (fileList.empty())
1301
		if (fileList.empty())
1314
			wprintf(L"unable to find any packages");
1302
			wprintf(L"unable to find any packages");
1315
		else
1303
		else
1316
		{
1304
		{
1317
			CPackages packages;
-
 
1318
 
-
 
1319
			Utils::WStringList filedata;
1305
			Utils::WStringList filedata;
1320
			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
1306
			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
1321
			{
1307
			{
1322
				wprintf(L"Reading file: %s\n", (*itr)->str.c_str());
1308
				wprintf(L"Reading file: %s\n", (*itr)->str.c_str());
1323
 
1309
 
1324
				int error = 0;
1310
				int error = 0;
1325
				CBaseFile *p = packages.openPackage((*itr)->str.toString(), &error, 0, SPKREAD_NODATA);
1311
				CBaseFile *p = cmd.packages().openPackage((*itr)->str.toString(), &error, 0, SPKREAD_NODATA);
1326
				if (!p)
1312
				if (!p)
1327
				{
1313
				{
1328
					printf("\tERROR!\n");
1314
					printf("\tERROR!\n");
1329
					continue;
1315
					continue;
1330
				}
1316
				}
Line 1340... Line 1326...
1340
 
1326
 
1341
			if (filedata.empty())
1327
			if (filedata.empty())
1342
				wprintf(L"unable to find any packages");
1328
				wprintf(L"unable to find any packages");
1343
			else				
1329
			else				
1344
			{
1330
			{
1345
				Utils::WString dest = Dir.file(L"xpackagedata.dat");
1331
				Utils::WString dest = cmd.dirIO().file(L"xpackagedata.dat");
1346
				if (CFileIO(dest).writeFile(&filedata))
1332
				if (CFileIO(dest).writeFile(&filedata))
1347
					wprintf(L"web update file, xpackagedata.dat, generated");
1333
					wprintf(L"web update file, xpackagedata.dat, generated");
1348
				else
1334
				else
1349
					wprintf(L"unable to write update file");
1335
					wprintf(L"unable to write update file");
1350
			}
1336
			}
Line 1479... Line 1465...
1479
 
1465
 
1480
	if ( verify )
1466
	if ( verify )
1481
		wprintf(L"Verifying Packager Script: %s\n", filename.c_str());
1467
		wprintf(L"Verifying Packager Script: %s\n", filename.c_str());
1482
 
1468
 
1483
	CPackages p;
1469
	CPackages p;
1484
	p.startup(L".", L".", myDoc);
1470
	p.startup(L".", cmd.tempDir(), cmd.myDoc());
1485
	Utils::WStringList malformed, unknown;
1471
	Utils::WStringList malformed, unknown;
1486
 
1472
 
1487
	Utils::WString curDir = CFileIO(filename).dir();
1473
	Utils::WString curDir = CFileIO(filename).dir();
1488
	if ( curDir.empty() ) curDir = L"./";
1474
	if ( curDir.empty() ) curDir = L"./";
1489
 
1475
 
Line 1621... Line 1607...
1621
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1607
	if ( command == L"-v" || command == L"-view" || command == L"-version")
1622
	{
1608
	{
1623
		if ( argc < 3 )
1609
		if ( argc < 3 )
1624
			wprintf(L"Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.cmdName().c_str());
1610
			wprintf(L"Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.cmdName().c_str());
1625
		else
1611
		else
1626
			DisplayVersion(argv[2]);
1612
			DisplayVersion(cmd);
1627
	}
1613
	}
1628
 
1614
 
1629
	// creates a new spk file
1615
	// creates a new spk file
1630
	else if ( command == L"-c" || command == L"-create" )
1616
	else if ( command == L"-c" || command == L"-create" )
1631
	{
1617
	{
Line 1812... Line 1798...
1812
	else if (command == L"-packagelist")
1798
	else if (command == L"-packagelist")
1813
	{
1799
	{
1814
		if (argc < 3)
1800
		if (argc < 3)
1815
			wprintf(L"Syntax:\n\t%s -packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.cmdName().c_str());
1801
			wprintf(L"Syntax:\n\t%s -packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.cmdName().c_str());
1816
		else
1802
		else
1817
			GenerateUpdateList(argc, argv);
1803
			GenerateUpdateList(cmd);
1818
	}
1804
	}
1819
 
1805
 
1820
	// not a valid switch, display syntax
1806
	// not a valid switch, display syntax
1821
	else
1807
	else
1822
		PrintSyntax(cmd.cmdName());
1808
		PrintSyntax(cmd.cmdName());