Subversion Repositories spk

Rev

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

Rev 220 Rev 226
Line 126... Line 126...
126
	printf ( "\t--generateupdatefile <package>\n\t\tCreates an update file for the spk/xsp file\n\n");
126
	printf ( "\t--generateupdatefile <package>\n\t\tCreates an update file for the spk/xsp file\n\n");
127
	printf ( "\t--packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n\n");
127
	printf ( "\t--packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n\n");
128
	//	printf ( "\t--convertxspwizard <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
128
	//	printf ( "\t--convertxspwizard <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
129
}
129
}
130
 
130
 
131
void Settings(CyString filename, CyString settings, int argc, char **argv, CyString cmd)
131
void Settings(const Utils::WString &filename, const Utils::WString &settings, int argc, char **argv, const Utils::WString &cmd)
132
{
132
{
133
	if ( settings.Compare("author") )
133
	if ( settings.Compare(L"author") )
134
	{
134
	{
135
		if ( argc < 5 )
135
		if ( argc < 5 )
136
		{
136
		{
137
			printf ( "Syntax: %s -set <spkfile> Author <authorname>\n\tSets the authors name of the package\n", cmd.c_str() );
137
			wprintf(L"Syntax: %s -set <spkfile> Author <authorname>\n\tSets the authors name of the package\n", cmd.c_str() );
138
			return;
138
			return;
139
		}
139
		}
140
	}
140
	}
141
	else
141
	else
142
	{
142
	{
143
		printf("Error! Unknown settings: %s\n", settings.c_str());
143
		wprintf(L"Error! Unknown settings: %s\n", settings.c_str());
144
		return;
144
		return;
145
	}
145
	}
146
 
146
 
147
	// first chekc if file even exists
147
	// first chekc if file even exists
148
	FILE *id = fopen ( filename.c_str(), ";rb+" );
148
	FILE *id = _wfopen(filename.c_str(), L";rb+");
149
	if ( !id )
149
	if ( !id )
150
	{
150
	{
151
		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
151
		wprintf(L"Error: File, %s, doesn't exist\n", filename.c_str() );
152
		return;
152
		return;
153
	}
153
	}
154
	fclose ( id );
154
	fclose ( id );
155
 
155
 
156
	int check = CSpkFile::CheckFile(filename.ToString());
156
	int check = CSpkFile::CheckFile(filename);
157
	if ( check == SPKFILE_SINGLE )
157
	if ( check == SPKFILE_SINGLE )
158
	{
158
	{
159
		CSpkFile spkfile;
159
		CSpkFile spkfile;
160
		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
160
		wprintf(L"* Opening SPK File, %s...\n", filename.c_str());
161
		if ( !spkfile.readFile(filename.ToString(), SPKREAD_ALL))
161
		if ( !spkfile.readFile(filename, SPKREAD_ALL))
162
		{
162
		{
163
			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
163
			wprintf(L"Failed to open the spk files, %s\n", filename.c_str() );
164
			return;
164
			return;
165
		}
165
		}
166
 
166
 
167
		// now do the settings
167
		// now do the settings
168
		if ( settings.Compare("author") )
168
		if ( settings.Compare(L"author") )
169
		{
169
		{
170
			spkfile.setAuthor(argv[4]);
170
			spkfile.setAuthor(Utils::WString::FromString(argv[4]));
171
			wprintf(L"Settings Author to: %s\n", spkfile.author().c_str());
171
			wprintf(L"Settings Author to: %s\n", spkfile.author().c_str());
172
		}
172
		}
173
 
173
 
174
		spkfile.writeFile(filename.ToString());
174
		spkfile.writeFile(filename);
175
		printf ( "\nSPK file has been written sucessfully\n" );
175
		printf ( "\nSPK file has been written sucessfully\n" );
176
	}
176
	}
177
	else
177
	else
178
		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
178
		wprintf(L"File, %s, is not a valid SPK file\n", filename.c_str() );
179
}
179
}
180
 
180
 
181
void SetRating ( CyString filename, int ease, int changing, int rec )
181
void SetRating ( CyString filename, int ease, int changing, int rec )
182
{
182
{
183
	if ( ease > 5 )
183
	if ( ease > 5 )
Line 376... Line 376...
376
		struct tm   *currDate;
376
		struct tm   *currDate;
377
		char    dateString[100];
377
		char    dateString[100];
378
		time_t now = time(NULL);
378
		time_t now = time(NULL);
379
		currDate = localtime( &now );
379
		currDate = localtime( &now );
380
		strftime(dateString, sizeof dateString, "%d/%m/%Y", currDate);
380
		strftime(dateString, sizeof dateString, "%d/%m/%Y", currDate);
381
		ship.setCreationDate(dateString);
381
		ship.setCreationDate(Utils::WString::FromString(dateString));
382
 
382
 
383
		printf("\nWriting file: %s...\n", to.c_str());
383
		printf("\nWriting file: %s...\n", to.c_str());
384
		if ( ship.writeFile(to) )
384
		if ( ship.writeFile(to) )
385
			printf("Ship file has been created: %s\n", to.c_str());
385
			printf("Ship file has been created: %s\n", to.c_str());
386
		else
386
		else
Line 474... Line 474...
474
	}
474
	}
475
 
475
 
476
	if ( pBaseFile && read)
476
	if ( pBaseFile && read)
477
	{
477
	{
478
		CPackages p;
478
		CPackages p;
479
		p.startup(".", ".", ".");
479
		p.startup(L".", L".", L".");
480
 
480
 
481
		CSpkFile *pSpkFile = NULL;
481
		CSpkFile *pSpkFile = NULL;
482
		CXspFile *pXspFile = NULL;
482
		CXspFile *pXspFile = NULL;
483
		if ( check == SPKFILE_SINGLE )
483
		if ( check == SPKFILE_SINGLE )
484
			pSpkFile = (CSpkFile *)pBaseFile;
484
			pSpkFile = (CSpkFile *)pBaseFile;
485
		else
485
		else
486
			pXspFile = (CXspFile *)pBaseFile;
486
			pXspFile = (CXspFile *)pBaseFile;
487
 
487
 
488
		printf("File Format Version: %.2f\n", pBaseFile->fileVersion());
488
		printf("File Format Version: %.2f\n", pBaseFile->fileVersion());
489
 
489
 
490
		CyString sType;
490
		Utils::WString sType;
491
		if ( check == SPKFILE_SINGLESHIP )
491
		if ( check == SPKFILE_SINGLESHIP )
492
			sType = "Ship";
492
			sType = L"Ship";
493
		else
493
		else
494
			sType = "Package";
494
			sType = L"Package";
495
 
495
 
496
		wprintf(L"%hs Name: %s\n", sType.c_str(), pBaseFile->name().c_str() );
496
		wprintf(L"%s Name: %s\n", sType.c_str(), pBaseFile->name().c_str() );
497
		if ( !pBaseFile->email().empty() )
497
		if ( !pBaseFile->email().empty() )
498
			wprintf(L"%hs Author: %s (%s)\n", sType.c_str(), pBaseFile->author().c_str(), pBaseFile->email().c_str() );
498
			wprintf(L"%s Author: %s (%s)\n", sType.c_str(), pBaseFile->author().c_str(), pBaseFile->email().c_str() );
499
		else
499
		else
500
			wprintf(L"%hs Author: %s\n", sType.c_str(), pBaseFile->author().c_str() );
500
			wprintf(L"%s Author: %s\n", sType.c_str(), pBaseFile->author().c_str() );
501
		if ( !pBaseFile->version().empty() ) wprintf(L"%hs Version: %s\n", sType.c_str(), pBaseFile->version().c_str() );
501
		if ( !pBaseFile->version().empty() ) wprintf(L"%s Version: %s\n", sType.c_str(), pBaseFile->version().c_str() );
502
 
502
 
503
		//for game
503
		//for game
504
		printf("For Games: ");
504
		printf("For Games: ");
505
		if ( !pBaseFile->AnyGameCompatability() )
505
		if ( !pBaseFile->AnyGameCompatability() )
506
			printf("All");
506
			printf("All");
Line 874... Line 874...
874
 
874
 
875
	while ( true )
875
	while ( true )
876
	{
876
	{
877
		printf ( "\nEnter Spk File to add (Enter \"0\" to finish): " );
877
		printf ( "\nEnter Spk File to add (Enter \"0\" to finish): " );
878
		sInput = GetInput();
878
		sInput = GetInput();
879
		if ( sInput == "0" )
879
		if ( sInput == L"0" )
880
			break;
880
			break;
881
 
881
 
882
		// check if file can be opened
882
		// check if file can be opened
883
		FILE *id2 = fopen ( sInput.toString().c_str(), "rb+");
883
		FILE *id2 = fopen ( sInput.toString().c_str(), "rb+");
884
		if ( !id2 )
884
		if ( !id2 )
Line 945... Line 945...
945
	char    dateString[100];
945
	char    dateString[100];
946
	time_t now = time(NULL);
946
	time_t now = time(NULL);
947
 
947
 
948
	currDate = localtime( &now );
948
	currDate = localtime( &now );
949
	strftime(dateString, sizeof dateString, "%d %m %Y", currDate);
949
	strftime(dateString, sizeof dateString, "%d %m %Y", currDate);
950
	spkfile.setCreationDate(dateString);
950
	spkfile.setCreationDate(Utils::WString::FromString(dateString));
951
 
951
 
952
	spkfile.writeFile(filename.ToString(), NULL);
952
	spkfile.writeFile(filename.ToString(), NULL);
953
	printf ( "SPK file has been written to disk: %s\n", filename.c_str() );
953
	printf ( "SPK file has been written to disk: %s\n", filename.c_str() );
954
}
954
}
955
 
955
 
Line 963... Line 963...
963
		return;
963
		return;
964
	}
964
	}
965
	fclose ( id );
965
	fclose ( id );
966
 
966
 
967
	CPackages packages;
967
	CPackages packages;
968
	packages.startup(".", ".", ".");
968
	packages.startup(L".", L".", L".");
969
 
969
 
970
	int check = CSpkFile::CheckFile ( sfile );
970
	int check = CSpkFile::CheckFile ( sfile );
971
 
971
 
972
	// extracts a file from single packages file
972
	// extracts a file from single packages file
973
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
973
	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
Line 1230... Line 1230...
1230
	return GetInput();
1230
	return GetInput();
1231
}
1231
}
1232
 
1232
 
1233
void GenerateUpdateList(int argc, char **argv)
1233
void GenerateUpdateList(int argc, char **argv)
1234
{
1234
{
1235
	Utils::WString currentDir = CFileIO(argv[0]).dir();
1235
	Utils::WString currentDir = CFileIO(Utils::WString::FromString(argv[0])).dir();
1236
	CDirIO Dir(currentDir);
1236
	CDirIO Dir(currentDir);
1237
 
1237
 
1238
	Utils::WStringList list;
1238
	Utils::WStringList list;
1239
	for (int i = 2; i < argc; ++i)
1239
	for (int i = 2; i < argc; ++i)
1240
	{
1240
	{
Line 1274... Line 1274...
1274
						if(ext == L"xsp" || ext == L"spk")
1274
						if(ext == L"xsp" || ext == L"spk")
1275
							fileList.pushBack(dir.file((*itr2)->str));
1275
							fileList.pushBack(dir.file((*itr2)->str));
1276
					}
1276
					}
1277
				}
1277
				}
1278
			}
1278
			}
1279
			else if (data == "pattern")
1279
			else if (data == L"pattern")
1280
			{				
1280
			{				
1281
				CFileIO f(file);
1281
				CFileIO f(file);
1282
				CDirIO dir(f.dir());
1282
				CDirIO dir(f.dir());
1283
 
1283
 
1284
				if (!dir.exists())
1284
				if (!dir.exists())
Line 1327... Line 1327...
1327
 
1327
 
1328
			if (filedata.empty())
1328
			if (filedata.empty())
1329
				printf("unable to find any packages");
1329
				printf("unable to find any packages");
1330
			else				
1330
			else				
1331
			{
1331
			{
1332
				Utils::WString dest = Dir.file("xpackagedata.dat");
1332
				Utils::WString dest = Dir.file(L"xpackagedata.dat");
1333
				if (CFileIO(dest).writeFile(&filedata))
1333
				if (CFileIO(dest).writeFile(&filedata))
1334
					printf("web update file, xpackagedata.dat, generated");
1334
					printf("web update file, xpackagedata.dat, generated");
1335
				else
1335
				else
1336
					printf("unable to write update file");
1336
					printf("unable to write update file");
1337
			}
1337
			}
Line 1407... Line 1407...
1407
		printf("Error: %s doesn't appear to be a spk file\n", spkfile.c_str());
1407
		printf("Error: %s doesn't appear to be a spk file\n", spkfile.c_str());
1408
		return;
1408
		return;
1409
	}
1409
	}
1410
 
1410
 
1411
	CPackages p;
1411
	CPackages p;
1412
	p.startup(".", ".", ".");
1412
	p.startup(L".", L".", L".");
1413
	int error;
1413
	int error;
1414
	CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
1414
	CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
1415
	if ( !package )
1415
	if ( !package )
1416
	{
1416
	{
1417
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
1417
		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
Line 1728... Line 1728...
1728
	else if ( command == L"--set" )
1728
	else if ( command == L"--set" )
1729
	{
1729
	{
1730
		if ( argc < 4 )
1730
		if ( argc < 4 )
1731
			wprintf(L"Syntax: %s --set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.c_str() );
1731
			wprintf(L"Syntax: %s --set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.c_str() );
1732
		else
1732
		else
1733
			Settings(argv[2], argv[3], argc, argv, CyString(cmd.toString()));
1733
			Settings(argv[2], argv[3], argc, argv, cmd);
1734
	}
1734
	}
1735
	else if ( command == L"--setrating" )
1735
	else if ( command == L"--setrating" )
1736
	{
1736
	{
1737
		if ( argc < 6 )
1737
		if ( argc < 6 )
1738
			wprintf(L"Syntax: %s --setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.c_str() );
1738
			wprintf(L"Syntax: %s --setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.c_str() );
Line 1746... Line 1746...
1746
		else
1746
		else
1747
		{
1747
		{
1748
			Utils::String arg3;
1748
			Utils::String arg3;
1749
			if ( argc > 3 )
1749
			if ( argc > 3 )
1750
				arg3 = argv[3];
1750
				arg3 = argv[3];
1751
			ConvertXsp(argv[2], arg3, (command == L"--convertxspwizard") ? true : false);
1751
			ConvertXsp(Utils::WString::FromString(argv[2]), arg3, (command == L"--convertxspwizard") ? true : false);
1752
		}
1752
		}
1753
	}
1753
	}
1754
	else if ( command == L"--createscript" )
1754
	else if ( command == L"--createscript" )
1755
	{
1755
	{
1756
		if ( argc < 3 )
1756
		if ( argc < 3 )