Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
    // ensure proper usage
    if (argc < 2)
    {
		printf("ICN Icon Extractor v0.4 by 3DSGuy\n");
        printf("Usage: %s -i <ICN File> -l <Large Icon> -s <Small Icon>\n",argv[0]);
        return 1;
    }
	
	char *InputICN = NULL;
	char *SmallIcon = NULL;
	char *LargeIcon = NULL;
	
	if(argc == 2){ // Drag&Drop
		InputICN = argv[1]; 
		
		char outfile_large[1024];
		append_filextention(outfile_large,1024,argv[1],".png");
		LargeIcon = (char*)&outfile_large;
	}
	
	else{ // user has entered command line arguments
		for(int i = 1; i < argc-1; i++){
			if(strcmp(argv[i],"-i")==0 && argv[i+1][0] != '-') InputICN = argv[i+1];
			else if(strcmp(argv[i],"-l")==0 && argv[i+1][0] != '-') LargeIcon = argv[i+1];
			else if(strcmp(argv[i],"-s")==0 && argv[i+1][0] != '-') SmallIcon = argv[i+1];
		}
	}
	
	if(InputICN == NULL){
		fprintf(stderr, "No input ICN data specified.");
		return 1;
	}
	
	if(LargeIcon == NULL && SmallIcon == NULL){
		fprintf(stderr, "Nothing to do.");
		return 1;
	}

    FILE* icn = fopen(InputICN, "rb");
    if (icn == NULL)
    {
        printf("Could not open %s.\n", InputICN);
        return 2;
    }

	// Checking if ICN file is actually an ICN file
	char magic[4];
	fseek(icn,0,SEEK_SET);
	fread(&magic,4,1,icn);
	if(strncmp("SMDH",magic,4)!=0){
		fclose(icn);
		fprintf(stderr, "%s is not an ICN file", InputICN);
		return 1;
	}
	
	if(SmallIcon != NULL) ConvertIcon(icn,SmallIcon,0x2040,24);
    if(LargeIcon != NULL) ConvertIcon(icn,LargeIcon,0x24C0,48);
	
    // close infile
    fclose(icn);
	
    return 0;
}
Ejemplo n.º 2
0
int ParseArgs(int argc, char *argv[], user_settings *set)
{
	if(argv == NULL || set == NULL)
		return USR_PTR_PASS_FAIL;
		
	if(argc < 2){
		DisplayHelp(argv[0]);
		return USR_HELP;
	}
		
	// Detecting Help Requried
	for(int i = 1; i < argc; i++){
		if(strcmp(argv[i],"-help") == 0){
			DisplayHelp(argv[0]);
			return USR_HELP;
		}
	}
	
	// Allocating Memory for Content Path Ptrs
	set->common.contentPath = calloc(CIA_MAX_CONTENT,sizeof(char*));
	if(set->common.contentPath == NULL){
		fprintf(stderr,"[SETTING ERROR] Not Enough Memory\n");
		return USR_MEM_ERROR;
	}
	
	// Initialise Keys
	InitKeys(&set->common.keys);

	// Setting Defaults
	SetDefaults(set);
	
	// Parsing Arguments
	int set_result;
	int i = 1;
	while(i < argc){
		set_result = SetArgument(argc,i,argv,set);
		if(set_result < 1){
			fprintf(stderr,"[RESULT] Invalid arguments, see '%s -help'\n",argv[0]);
			return set_result;
		}
		i += set_result;
	}
	
	// Checking arguments
	if((set_result = CheckArgumentCombination(set)) != 0) 
		return set_result;
	
	// Setting Keys
	if((set_result = SetKeys(&set->common.keys)) != 0) 
		return set_result;

	// Generating outpath if required
	if(!set->common.outFileName){
		char *source_path = NULL;
		if(set->ncch.buildNcch0) 
			source_path = set->common.rsfPath;
		else if(set->common.workingFileType == infile_ncsd || set->common.workingFileType == infile_cia || set->common.workingFileType == infile_srl) 
			source_path = set->common.workingFilePath;
		else 
			source_path = set->common.contentPath[0];
		u16 outfile_len = strlen(source_path) + 0x10;
		set->common.outFileName = calloc(outfile_len,sizeof(char));
		if(!set->common.outFileName){
			fprintf(stderr,"[SETTING ERROR] Not Enough Memory\n");
			return USR_MEM_ERROR;
		}
		set->common.outFileName_mallocd = true;
		append_filextention(set->common.outFileName,outfile_len,source_path,(char*)&output_extention[set->common.outFormat-1]);
	}
	return 0;
}