Ejemplo n.º 1
0
int __cdecl main( int argc, char *argv[] )
{
	char *path, *suffix, *source, target[255];
	unsigned resolution;

	if( argc <= 2 )
		goto error;

	path = argv[2];
	suffix = get_suffix( path );
	resolution = atoi( suffix );

	source = get_name( path );
	sprintf( target, "%s%s", source, ".dds" );

	if( strcmp( argv[1], "-c" ) == 0 )
	{
		if( strcmp( suffix, "dds" ) != 0 )
			goto error;

		cut_header( path );
	}
	else if( strcmp( argv[1], "-r" ) != 0 )
	{
		
	}

	free( suffix );
	free( source );

	switch( resolution )
	{
	case 512:
		recover_texture( path, target, 512 );
		break;
	case 1024:
		recover_texture( path, target, 1024 );
		break;
	case 2048:
		recover_texture( path, target, 2048 );
		break;
	}

	goto exit;

error:
	printf( "syntax: magicdds.exe option filename\n"
				"options:\n-c - convert .dds image into 4A-Engine format\n"
				"-r - recover 4A-Engine image into original .dds format\n" );

exit:
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
	// I'm using linux file descriptors instead of streams because it's easier to handle ints
	// than some polymorphic stream types (ostream, ofstream etc)
	int buf = 0, fileout = 1, sock;
	unsigned short number = 1;
	char base = 10; 
	bool fileio = false;
	const char* outfile;
	long long top = 100, bottom = 0;

	while ( -1 != (buf = getopt(argc,argv,"b:ho:n:vT:B:")) )
	{
		try {
			switch ( buf )
			{
				case 'n' :
					number = static_cast<short>(strtoul(optarg,0,10));
					break;
				case 'b' :
					base = strtoul(optarg,0,10);
					if ( base != 2 && base != 8 && base != 10 && base != 16 )
						throw err("The specified base is not valid for random.org!");

					break;
				case 'v' :
					verbose = true;
					break;
				case 'o' :
					fileio = true;
					outfile = optarg;
					break;
				case 'T' :
					top = strtoull(optarg,0,10);
					break;
				case 'B' :
					bottom = strtoull(optarg,0,10);
					break;
				case 'h' :
					std::cout << help_string;
					exit(0);
			}

			if ( top <= bottom )
				throw err("Invalid range!");

			if ( top < -1E9 || top > 1E9 )
				throw err("top is too big or too small");

			if ( bottom < -1E9 || bottom > 1E9 )
				throw err("bottom is too big or too small"); 
			if ( number > 1000 )
				throw err("Number too high");

		} catch (err error)
		{
			std::cout << "Exception raised: " << error.errmsg << std::endl;
			exit(1);
		}
	}

	if ( verbose == true )
		std::cout << "DBG: Done with processing arguments\n";
	
	if ( fileio == true )
	{
		fileout = open_outfile(outfile);
	}

	if ( verbose == true )
		std::cout << "DBG: Sending Request\n";

	// Build network connection and send the HTTP request
	sock = request(number,bottom,top,base);
	
	if ( verbose == true )
		std::cout << "DBG: Got answer, processing response\n";

	// Remove the HTTP header (algorithm is explained above)
	cut_header(sock);

	if ( verbose == true )
		std::cout << "DBG: Processed raw answer, continuing with getting numbers\n";

	// Simply read the numbers from the socket and write it to stdout
	get_data(sock,fileout);

	return 0;
}