Subversion Repositories spk

Rev

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

Rev 182 Rev 185
Line 218... Line 218...
218
	}
218
	}
219
	else
219
	else
220
		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
220
		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
221
}
221
}
222
 
222
 
223
CyString GetTerranConflictDir()
223
Utils::String GetTerranConflictDir()
224
{
224
{
225
	while ( true )
225
	while ( true )
226
	{
226
	{
227
		printf ( "\nPlease enter the directory for terran conflict: ");
227
		printf ( "\nPlease enter the directory for terran conflict: ");
228
		CyString dir = GetInput();
228
		Utils::String dir = GetInput();
229
		if ( dir.Empty() )
229
		if ( dir.empty() )
230
			return NullString;
230
			return Utils::String::Null();
231
 
231
 
232
		// check if the directory exists
232
		// check if the directory exists
233
		if ( CFileIO(dir + "/x3tc.exe").ExistsOld() )
233
		if ( CFileIO::Exists(dir + "/x3tc.exe") )
234
			return dir;
234
			return dir;
235
		printf("\nTerran Conflict installation doesn't exist: %s\n\n", dir.c_str());
235
		printf("\nTerran Conflict installation doesn't exist: %s\n\n", dir.c_str());
236
	}
236
	}
237
 
237
 
238
	return NullString;
238
	return Utils::String::Null();
239
}
239
}
240
 
240
 
241
void ConvertXsp(CyString filename, CyString tofile, bool wizard)
241
void ConvertXsp(const Utils::String &filename, const Utils::String &tofile, bool wizard)
242
{
242
{
243
	// first chekc if file even exists
243
	// first chekc if file even exists
244
	FILE *id = fopen ( filename.c_str(), "rb+" );
244
	FILE *id = fopen ( filename.c_str(), "rb+" );
245
	if ( !id )
245
	if ( !id )
246
	{
246
	{
Line 248... Line 248...
248
		return;
248
		return;
249
	}
249
	}
250
	fclose ( id );
250
	fclose ( id );
251
 
251
 
252
	// check its not a new format already
252
	// check its not a new format already
253
	int check = CSpkFile::CheckFile(filename.ToString());
253
	int check = CSpkFile::CheckFile(filename);
254
	if ( check == SPKFILE_INVALID && CFileIO(filename).isFileExtension("xsp") )
254
	if ( check == SPKFILE_INVALID && CFileIO(filename).isFileExtension("xsp") )
255
	{
255
	{
256
		printf ( "* Converting XSP File, %s... ", filename.c_str() );
256
		printf ( "* Converting XSP File, %s... ", filename.c_str() );
257
		CXspFile xspFile;
257
		CXspFile xspFile;
258
		if ( !xspFile.ConvertOld(filename.ToString()) )
258
		if ( !xspFile.ConvertOld(filename) )
259
		{
259
		{
260
			printf ( "[ERROR]\n\nFailed to convert old xsp file, %s\n", filename.c_str() );
260
			printf ( "[ERROR]\n\nFailed to convert old xsp file, %s\n", filename.c_str() );
261
			return;
261
			return;
262
		}
262
		}
263
 
263
 
Line 274... Line 274...
274
			}
274
			}
275
		}
275
		}
276
 
276
 
277
		printf ( "* Writing XSP File, %s... ", tofile.c_str() );
277
		printf ( "* Writing XSP File, %s... ", tofile.c_str() );
278
		// now we need to save it
278
		// now we need to save it
279
		if ( !xspFile.writeFile(tofile.ToString()) )
279
		if ( !xspFile.writeFile(tofile) )
280
			printf ( "[ERROR]\n\nFailed to write file to, %s\n", tofile.c_str() );
280
			printf ( "[ERROR]\n\nFailed to write file to, %s\n", tofile.c_str() );
281
		else
281
		else
282
			printf ( "[DONE]\n\nFile: %s, has been converted to, %s\n", filename.c_str(), tofile.c_str() );
282
			printf ( "[DONE]\n\nFile: %s, has been converted to, %s\n", filename.c_str(), tofile.c_str() );
283
	}
283
	}
284
	else
284
	else
285
		printf ( "Error: File, %s, is not an old style XSP file\n", filename.c_str() );
285
		printf ( "Error: File, %s, is not an old style XSP file\n", filename.c_str() );
286
}
286
}
287
 
287
 
288
void ExtractShip(CyString catfile, CyString to, CyString shipid)
288
void ExtractShip(const Utils::String &catfile, const Utils::String &to, Utils::String shipid)
289
{
289
{
290
	if ( !CFileIO(catfile).ExistsOld() )
290
	if ( !CFileIO::Exists(catfile) )
291
	{
291
	{
292
		printf ( "Error: Mod File, %s, does not exist\n", catfile.c_str() );
292
		printf ( "Error: Mod File, %s, does not exist\n", catfile.c_str() );
293
		return;
293
		return;
294
	}
294
	}
295
 
295
 
296
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
296
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
297
	if ( !pVfs->loadMod(catfile.ToString()) ) {
297
	if ( !pVfs->loadMod(catfile) ) {
298
		printf("Error: Unable to read mod file, %s\n", catfile.c_str());
298
		printf("Error: Unable to read mod file, %s\n", catfile.c_str());
299
		delete pVfs;
299
		delete pVfs;
300
		return;
300
		return;
301
	}
301
	}
302
 
302
 
Line 308... Line 308...
308
		return;
308
		return;
309
	}
309
	}
310
 
310
 
311
	// now get the ship line to extract
311
	// now get the ship line to extract
312
	Utils::String tShipsLine;
312
	Utils::String tShipsLine;
313
	if ( shipid.Empty() )
313
	if (shipid.empty())
314
	{
314
	{
315
		// no ship id, lets get one
315
		// no ship id, lets get one
316
		Utils::String ids[2];
316
		Utils::String ids[2];
317
		int i = 0;
317
		int i = 0;
318
		int id = 0;
318
		int id = 0;
Line 331... Line 331...
331
		if ( i == 1 )
331
		if ( i == 1 )
332
			printf("[%3d][%30s]\n", id, ids[0].c_str());
332
			printf("[%3d][%30s]\n", id, ids[0].c_str());
333
		printf("Enter ID to use > ");
333
		printf("Enter ID to use > ");
334
		shipid = GetInput();
334
		shipid = GetInput();
335
 
335
 
336
		if ( shipid.IsNumber() )
336
		if ( shipid.isNumber() )
337
			tShipsLine = ships->get(shipid.ToInt())->str;
337
			tShipsLine = ships->get(shipid.toInt())->str;
338
		else
338
		else
339
			tShipsLine = ships->findData(shipid.ToString(), true);
339
			tShipsLine = ships->findData(shipid, true);
340
	}
340
	}
341
	else
341
	else
342
		ships->findData(shipid.ToString(), true);
342
		ships->findData(shipid, true);
343
 
343
 
344
	if ( tShipsLine.empty() )
344
	if ( tShipsLine.empty() )
345
	{
345
	{
346
		printf("Error, %s is not a valid ship id to use\n", shipid.c_str());
346
		printf("Error, %s is not a valid ship id to use\n", shipid.c_str());
347
		delete pVfs;
347
		delete pVfs;
Line 379... Line 379...
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(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.ToString()) )
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
387
			printf("Error: Unable to write ship file, %s\n", to.c_str());
387
			printf("Error: Unable to write ship file, %s\n", to.c_str());
388
	}
388
	}
389
	else
389
	else
Line 1427... Line 1427...
1427
 
1427
 
1428
	if ( toFile.Empty() )
1428
	if ( toFile.Empty() )
1429
		toFile = CFileIO(spkfile).GetDirIO().file(package->name() + "_" + package->author() + ".sps");
1429
		toFile = CFileIO(spkfile).GetDirIO().file(package->name() + "_" + package->author() + ".sps");
1430
 
1430
 
1431
	// save package file
1431
	// save package file
1432
	if ( CFileIO(toFile).writeFile(&list) )
1432
	if ( CFileIO(toFile.ToString()).writeFile(&list) )
1433
		printf("Packager script, %s, has been geenrated\n", toFile.c_str());
1433
		printf("Packager script, %s, has been geenrated\n", toFile.c_str());
1434
	else
1434
	else
1435
		printf("Error: unable to write packager script, %s\n", toFile.c_str());
1435
		printf("Error: unable to write packager script, %s\n", toFile.c_str());
1436
 
1436
 
1437
	delete package;
1437
	delete package;
Line 1743... Line 1743...
1743
	{
1743
	{
1744
		if ( argc < 3 )
1744
		if ( argc < 3 )
1745
			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() );
1745
			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() );
1746
		else
1746
		else
1747
		{
1747
		{
1748
			CyString 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 == "--convertxspwizard") ? true : false);
1751
			ConvertXsp(argv[2], arg3, (command == "--convertxspwizard") ? true : false);
1752
		}
1752
		}
1753
	}
1753
	}