Subversion Repositories spk

Rev

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

Rev 322 Rev 323
Line 363... Line 363...
363
 
363
 
364
			if ( !f.writeFilePointer() )
364
			if ( !f.writeFilePointer() )
365
				wprintf(L"Error: unable to write file: %s\n", tofile.c_str() );
365
				wprintf(L"Error: unable to write file: %s\n", tofile.c_str() );
366
			else
366
			else
367
				wprintf(L"%s has been packed to %s\n", CFileIO(filename).filename().c_str(), f.filename().c_str());
367
				wprintf(L"%s has been packed to %s\n", CFileIO(filename).filename().c_str(), f.filename().c_str());
-
 
368
		}
-
 
369
	}
-
 
370
}
-
 
371
 
-
 
372
void BobFile(const Utils::CommandLine& cmd)
-
 
373
{
-
 
374
	Utils::WString filename = cmd.arg(1);
-
 
375
	Utils::WString tofile = cmd.arg(2);
-
 
376
 
-
 
377
	CFileIO File((filename.contains(L":")) ? filename : cmd.cmdDir() + L"/" + filename);
-
 
378
 
-
 
379
	C_File f(File.fullFilename());
-
 
380
	if (!f.CheckValidFilePointer())
-
 
381
		wprintf(L"Error: %s doesn't exists\n", filename.c_str());
-
 
382
	else if (!f.ReadFromFile())
-
 
383
		wprintf(L"Error: unable to open file: %s\n", filename.c_str());
-
 
384
	else
-
 
385
	{
-
 
386
		size_t size = 0;
-
 
387
		unsigned char* data = nullptr;
-
 
388
 
-
 
389
		if (f.checkFileExt(L"bob"))
-
 
390
			data = f.BobDecompile(&size);
-
 
391
		else if (f.checkFileExt(L"bod"))
-
 
392
			data = f.BobCompile(&size);
-
 
393
		else
-
 
394
		{
-
 
395
			wprintf(L"Error: %s is not a valid BOB/BOD file\n", filename.c_str());
-
 
396
			return;
-
 
397
		}
-
 
398
 
-
 
399
		if (data && size)
-
 
400
		{
-
 
401
			if (!tofile.empty())
-
 
402
				File.open((tofile.contains(L":")) ? tofile : cmd.cmdDir() + L"/" + tofile);
-
 
403
			CFileIO ToFile(File.changeFileExtension(f.checkFileExt(L"bob") ? L"bod" : L"bob"));
-
 
404
 
-
 
405
			if(!ToFile.WriteData((const char*)data, size))
-
 
406
				wprintf(L"Error: unable to write file: %s\n", ToFile.filename().c_str());
-
 
407
			else
-
 
408
				wprintf(L"%s has been converted to %s\n", File.filename().c_str(), ToFile.filename().c_str());
-
 
409
 
-
 
410
			delete[] data;
-
 
411
		}
-
 
412
		else
-
 
413
		{
-
 
414
			if (f.checkFileExt(L"bob"))
-
 
415
				wprintf(L"Error: unable to decompile file: %s\n", filename.c_str());
-
 
416
			else
-
 
417
				wprintf(L"Error: unable to compile file: %s\n", filename.c_str());
368
		}
418
		}
369
	}
419
	}
370
}
420
}
371
 
421
 
372
void PrintSyntax(const Utils::WString &cmd)
422
void PrintSyntax(const Utils::WString &cmd)
Line 385... Line 435...
385
	wprintf(L"\t\tRemoves a file from an archive\n");
435
	wprintf(L"\t\tRemoves a file from an archive\n");
386
	wprintf(L"\t[--ext:EXTENSION] -u <filename> [tofile]\n");
436
	wprintf(L"\t[--ext:EXTENSION] -u <filename> [tofile]\n");
387
	wprintf(L"\t\tUnpacks a file, ie from pck to xml/txt\n");
437
	wprintf(L"\t\tUnpacks a file, ie from pck to xml/txt\n");
388
	wprintf(L"\t-p <filename> <tofile>\n");
438
	wprintf(L"\t-p <filename> <tofile>\n");
389
	wprintf(L"\t\tPacks a file, ie from xml/txt to pck\n");
439
	wprintf(L"\t\tPacks a file, ie from xml/txt to pck\n");
-
 
440
	wprintf(L"\t-b <filename> <tofile>\n");
-
 
441
	wprintf(L"\t\tConverts between BOB and BOD files\n");
390
}
442
}
391
 
443
 
392
int main ( int argc, char **argv )
444
int main ( int argc, char **argv )
393
{
445
{
394
	printf ( "\nCATPCK Tool V1.22 17/05/2025 (SPK: %.2f) Created by Cycrow\n\n", GetLibraryVersion() );
446
	printf ( "\nCATPCK Tool V1.22 17/05/2025 (SPK: %.2f) Created by Cycrow\n\n", GetLibraryVersion() );
Line 408... Line 460...
408
		{
460
		{
409
			if (cmd.argCount() < 2)
461
			if (cmd.argCount() < 2)
410
				wprintf(L"Syntax: %s -l <filename> [filemask]\n\tLists the contents of the cat file\n", cmd.cmdName().c_str());
462
				wprintf(L"Syntax: %s -l <filename> [filemask]\n\tLists the contents of the cat file\n", cmd.cmdName().c_str());
411
			else
463
			else
412
				ListFiles(cmd);
464
				ListFiles(cmd);
413
		}
465
		}
414
		else if ((command == L"-x") || (command == L"-extract"))
466
		else if ((command == L"-x") || (command == L"-extract"))
415
		{
467
		{
416
			if (cmd.argCount() < 2 )
468
			if (cmd.argCount() < 2 )
417
				wprintf(L"Syntax: %s %s [--preserve] <catfile::filemask> [dir]\n\tExtracts a file from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
469
				wprintf(L"Syntax: %s %s [--preserve] <catfile::filemask> [dir]\n\tExtracts a file from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
418
			else
470
			else
419
				ExtractFile (cmd, L"", false);
471
				ExtractFile (cmd, L"", false);
420
		}
472
		}
421
		else if ( (command == L"-xa") || (command == L"-extractall") )
473
		else if ( (command == L"-xa") || (command == L"-extractall") )
422
		{
474
		{
423
			if (cmd.argCount() < 2)
475
			if (cmd.argCount() < 2)
424
				wprintf(L"Syntax: %s %s <catfile> [dir]\n\tExtracts all files from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
476
				wprintf(L"Syntax: %s %s <catfile> [dir]\n\tExtracts all files from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
425
			else
477
			else
426
				ExtractFile(cmd, L"::*", true);
478
				ExtractFile(cmd, L"::*", true);
427
		}
479
		}
428
		else if ( (command == L"-a") || (command == L"-append") )
480
		else if ( (command == L"-a") || (command == L"-append") )
429
		{
481
		{
430
			if (cmd.argCount() < 3 )
482
			if (cmd.argCount() < 3 )
431
				wprintf(L"Syntax: %s -a <filename> <catfile::tofile>\n\tAppends a file into the archive\n", cmd.cmdName().c_str() );
483
				wprintf(L"Syntax: %s -a <filename> <catfile::tofile>\n\tAppends a file into the archive\n", cmd.cmdName().c_str() );
432
			else
484
			else
433
				AppendFile(cmd);
485
				AppendFile(cmd);
434
		}
486
		}
435
		else if ( (command == L"-r") || (command == L"-remove") )
487
		else if ( (command == L"-r") || (command == L"-remove") )
436
		{
488
		{
437
			if (cmd.argCount() < 3 )
489
			if (cmd.argCount() < 3 )
438
				wprintf(L"Syntax: %s -r <catfile> <filename>\n\tRemoves a file from the archive\n", cmd.cmdName().c_str() );
490
				wprintf(L"Syntax: %s -r <catfile> <filename>\n\tRemoves a file from the archive\n", cmd.cmdName().c_str() );
439
			else
491
			else
440
				RemoveFile(cmd);
492
				RemoveFile(cmd);
441
		}
493
		}
442
		else if ( (command == L"-u") || (command == L"-unpack") )
494
		else if ( (command == L"-u") || (command == L"-unpack") )
443
		{
495
		{
444
			if (cmd.argCount() < 2 )
496
			if (cmd.argCount() < 2 )
445
				wprintf(L"Syntax: %s [--ext:EXTENSION] -u <filename> [to]\n\tUnpacks a file", cmd.cmdName().c_str() );
497
				wprintf(L"Syntax: %s [--ext:EXTENSION] -u <filename> [to]\n\tUnpacks a file", cmd.cmdName().c_str() );
446
			else
498
			else
447
				UnpackFile(cmd);
499
				UnpackFile(cmd);
448
		}
500
		}
449
		else if ( (command == L"-p") || (command == L"-pack") )
501
		else if ( (command == L"-p") || (command == L"-pack") )
450
		{
502
		{
451
			if (cmd.argCount() < 2 )
503
			if (cmd.argCount() < 2 )
452
				wprintf(L"Syntax: %s -p <filename> [to]\n\tPacks a file to .pck", cmd.cmdName().c_str() );
504
				wprintf(L"Syntax: %s -p <filename> [to]\n\tPacks a file to .pck", cmd.cmdName().c_str() );
453
			else
505
			else
454
				PackFile(cmd);
506
				PackFile(cmd);
-
 
507
		}
-
 
508
		else if (command == L"-b")
-
 
509
		{
-
 
510
			if (cmd.argCount() < 2)
-
 
511
				wprintf(L"Syntax: %s -b <filename> [to]\n\tConverts a file between BOB and BOD", cmd.cmdName().c_str());
-
 
512
			else
-
 
513
				BobFile(cmd);
455
		}
514
		}
456
		else
515
		else
457
		{
516
		{
458
			wprintf(L"Invalid flag: %s\n\n", command.c_str());
517
			wprintf(L"Invalid flag: %s\n\n", command.c_str());
459
			PrintSyntax(cmd.cmdName());
518
			PrintSyntax(cmd.cmdName());