This commit is contained in:
Steveice10 2015-09-20 15:23:05 -07:00
parent 1c2101a5c4
commit 15a3c8ab1e
2 changed files with 133 additions and 137 deletions

View File

@ -2,6 +2,8 @@
#include "../pc/lodepng.h" #include "../pc/lodepng.h"
#include <stdlib.h>
u8 TILE_ORDER[64] = { 0, 1, 8, 9, 2, 3, 10, 11, 16, 17, 24, 25, 18, 19, 26, 27, u8 TILE_ORDER[64] = { 0, 1, 8, 9, 2, 3, 10, 11, 16, 17, 24, 25, 18, 19, 26, 27,
4, 5, 12, 13, 6, 7, 14, 15, 20, 21, 28, 29, 22, 23, 30, 31, 4, 5, 12, 13, 6, 7, 14, 15, 20, 21, 28, 29, 22, 23, 30, 31,
32, 33, 40, 41, 34, 35, 42, 43, 48, 49, 56, 57, 50, 51, 58, 59, 32, 33, 40, 41, 34, 35, 42, 43, 48, 49, 56, 57, 50, 51, 58, 59,
@ -81,5 +83,9 @@ u16* image_data_to_tiles(u8* img, u32 width, u32 height, PixelFormat format, u32
u16* image_to_tiles(const char* image, u32 width, u32 height, PixelFormat format, u32* size) { u16* image_to_tiles(const char* image, u32 width, u32 height, PixelFormat format, u32* size) {
u8* img = load_image(image, width, height); u8* img = load_image(image, width, height);
if(img == NULL) {
return NULL;
}
return image_data_to_tiles(img, width, height, format, size); return image_data_to_tiles(img, width, height, format, size);
} }

View File

@ -4,14 +4,16 @@
#include "pc/wav.h" #include "pc/wav.h"
#include "types.h" #include "types.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <map> #include <map>
#include <vector> #include <vector>
u8* convert_to_cgfx(const char* image, u32 width, u32 height, u32* size) { u8* convert_to_cgfx(const std::string image, u32 width, u32 height, u32* size) {
u32 convertedSize = 0; u32 convertedSize = 0;
u16* converted = image_to_tiles(image, width, height, RGBA4444, &convertedSize); u16* converted = image_to_tiles(image.c_str(), width, height, RGBA4444, &convertedSize);
if(converted == NULL) { if(converted == NULL) {
return NULL; return NULL;
} }
@ -24,9 +26,9 @@ u8* convert_to_cgfx(const char* image, u32 width, u32 height, u32* size) {
return ret; return ret;
} }
u8* convert_to_cwav(const char* file, u32* size) { u8* convert_to_cwav(const std::string file, u32* size) {
WAV* wav = wav_read(file); WAV* wav = wav_read(file.c_str());
if(!wav) { if(wav == NULL) {
return NULL; return NULL;
} }
@ -44,13 +46,14 @@ u8* convert_to_cwav(const char* file, u32* size) {
return ret; return ret;
} }
int cmd_make_banner(const char* image, const char* audio, const char* cgfxFile, const char* cwavFile, const char* output) { int cmd_make_banner(const std::string image, const std::string audio, const std::string cgfxFile, const std::string cwavFile, const std::string output) {
u32 cgfxSize = 0; u32 cgfxSize = 0;
u8* cgfx = NULL; u8* cgfx = NULL;
if(cgfxFile != NULL) { if(!cgfxFile.empty()) {
FILE* fd = fopen(cgfxFile, "r"); FILE* fd = fopen(cgfxFile.c_str(), "r");
if(!fd) { if(!fd) {
printf("ERROR: Could not open CGFX file: %s\n", strerror(errno)); printf("ERROR: Could not open CGFX file: %s\n", strerror(errno));
return 1;
} }
fseek(fd, 0, SEEK_END); fseek(fd, 0, SEEK_END);
@ -62,17 +65,18 @@ int cmd_make_banner(const char* image, const char* audio, const char* cgfxFile,
fclose(fd); fclose(fd);
} else { } else {
cgfx = convert_to_cgfx(image, 256, 128, &cgfxSize); cgfx = convert_to_cgfx(image, 256, 128, &cgfxSize);
if(!cgfx) { if(cgfx == NULL) {
return 1; return 2;
} }
} }
u32 cwavSize = 0; u32 cwavSize = 0;
u8* cwav = NULL; u8* cwav = NULL;
if(cwavFile != NULL) { if(!cwavFile.empty()) {
FILE* fd = fopen(cwavFile, "r"); FILE* fd = fopen(cwavFile.c_str(), "r");
if(!fd) { if(!fd) {
printf("ERROR: Could not open CWAV file: %s\n", strerror(errno)); printf("ERROR: Could not open CWAV file: %s\n", strerror(errno));
return 3;
} }
fseek(fd, 0, SEEK_END); fseek(fd, 0, SEEK_END);
@ -84,8 +88,8 @@ int cmd_make_banner(const char* image, const char* audio, const char* cgfxFile,
fclose(fd); fclose(fd);
} else { } else {
cwav = convert_to_cwav(audio, &cwavSize); cwav = convert_to_cwav(audio, &cwavSize);
if(!cwav) { if(cwav == NULL) {
return 2; return 4;
} }
} }
@ -100,10 +104,10 @@ int cmd_make_banner(const char* image, const char* audio, const char* cgfxFile,
free(cgfx); free(cgfx);
free(cwav); free(cwav);
FILE* fd = fopen(output, "wb"); FILE* fd = fopen(output.c_str(), "wb");
if(!fd) { if(fd == NULL) {
printf("ERROR: Could not open output file: %s\n", strerror(errno)); printf("ERROR: Could not open output file: %s\n", strerror(errno));
return 3; return 5;
} }
fwrite(bnr, 1, bnrSize, fd); fwrite(bnr, 1, bnrSize, fd);
@ -111,12 +115,12 @@ int cmd_make_banner(const char* image, const char* audio, const char* cgfxFile,
free(bnr); free(bnr);
printf("Created banner \"%s\".\n", output); printf("Created banner \"%s\".\n", output.c_str());
return 0; return 0;
} }
int cmd_make_smdh(const char* shortTitle, const char* longTitle, const char* publisher, const char* icon, SMDHRegionFlag regionFlags, u64 matchMakerId, u32 smdhFlags, u16 eulaVersion, u32 optimalBannerFrame, u32 streetpassId, const char* output) { int cmd_make_smdh(const std::string shortTitle, const std::string longTitle, const std::string publisher, const std::string icon, SMDHRegionFlag regionFlags, u64 matchMakerId, u32 smdhFlags, u16 eulaVersion, u32 optimalBannerFrame, u32 streetpassId, const std::string output) {
u8* icon48Data = load_image(icon, 48, 48); u8* icon48Data = load_image(icon.c_str(), 48, 48);
if(icon48Data == NULL) { if(icon48Data == NULL) {
return 1; return 1;
} }
@ -168,9 +172,9 @@ int cmd_make_smdh(const char* shortTitle, const char* longTitle, const char* pub
SMDH smdh; SMDH smdh;
for(int i = 0; i < 0x10; i++) { for(int i = 0; i < 0x10; i++) {
utf8_to_utf16(smdh.titles[i].shortTitle, shortTitle, 0x40); utf8_to_utf16(smdh.titles[i].shortTitle, shortTitle.c_str(), 0x40);
utf8_to_utf16(smdh.titles[i].longTitle, longTitle, 0x80); utf8_to_utf16(smdh.titles[i].longTitle, longTitle.c_str(), 0x80);
utf8_to_utf16(smdh.titles[i].publisher, publisher, 0x40); utf8_to_utf16(smdh.titles[i].publisher, publisher.c_str(), 0x40);
} }
smdh.settings.regionLock = regionFlags; smdh.settings.regionLock = regionFlags;
@ -184,8 +188,8 @@ int cmd_make_smdh(const char* shortTitle, const char* longTitle, const char* pub
memcpy(smdh.smallIcon, icon24, 0x480); memcpy(smdh.smallIcon, icon24, 0x480);
free(icon48); free(icon48);
FILE* fd = fopen(output, "wb"); FILE* fd = fopen(output.c_str(), "wb");
if(!fd) { if(fd == NULL) {
printf("ERROR: Could not open output file: %s\n", strerror(errno)); printf("ERROR: Could not open output file: %s\n", strerror(errno));
return 2; return 2;
} }
@ -193,19 +197,19 @@ int cmd_make_smdh(const char* shortTitle, const char* longTitle, const char* pub
fwrite(&smdh, 1, sizeof(SMDH), fd); fwrite(&smdh, 1, sizeof(SMDH), fd);
fclose(fd); fclose(fd);
printf("Created SMDH \"%s\".\n", output); printf("Created SMDH \"%s\".\n", output.c_str());
return 0; return 0;
} }
int cmd_make_cwav(const char* input, const char* output) { int cmd_make_cwav(const std::string input, const std::string output) {
u32 cwavSize = 0; u32 cwavSize = 0;
u8* cwav = convert_to_cwav(input, &cwavSize); u8* cwav = convert_to_cwav(input, &cwavSize);
if(!cwav) { if(cwav == NULL) {
return 1; return 1;
} }
FILE* fd = fopen(output, "wb"); FILE* fd = fopen(output.c_str(), "wb");
if(!fd) { if(fd == NULL) {
printf("ERROR: Could not open output file: %s\n", strerror(errno)); printf("ERROR: Could not open output file: %s\n", strerror(errno));
return 2; return 2;
} }
@ -215,13 +219,13 @@ int cmd_make_cwav(const char* input, const char* output) {
free(cwav); free(cwav);
printf("Created CWAV \"%s\".\n", output); printf("Created CWAV \"%s\".\n", output.c_str());
return 0; return 0;
} }
int cmd_lz11(const char* input, const char* output) { int cmd_lz11(const std::string input, const std::string output) {
FILE* in = fopen(input, "r"); FILE* in = fopen(input.c_str(), "r");
if(!in) { if(in == NULL) {
printf("ERROR: Could not open input file: %s\n", strerror(errno)); printf("ERROR: Could not open input file: %s\n", strerror(errno));
return 1; return 1;
} }
@ -230,20 +234,26 @@ int cmd_lz11(const char* input, const char* output) {
u32 size = (u32) ftell(in); u32 size = (u32) ftell(in);
fseek(in, 0, SEEK_SET); fseek(in, 0, SEEK_SET);
u8 data[size]; u8* data = (u8*) malloc(size);
if(data == NULL) {
printf("ERROR: Could not allocate data buffer.\n");
return 2;
}
fread(data, 1, size, in); fread(data, 1, size, in);
fclose(in); fclose(in);
u32 compressedSize; u32 compressedSize;
u8* compressed = lz11_compress(data, size, &compressedSize); u8* compressed = lz11_compress(data, size, &compressedSize);
if(!compressed) { free(data);
return 2; if(compressed == NULL) {
return 3;
} }
FILE* fd = fopen(output, "wb"); FILE* fd = fopen(output.c_str(), "wb");
if(!fd) { if(fd == NULL) {
printf("ERROR: Could not open output file: %s\n", strerror(errno)); printf("ERROR: Could not open output file: %s\n", strerror(errno));
return 3; return 4;
} }
fwrite(compressed, 1, compressedSize, fd); fwrite(compressed, 1, compressedSize, fd);
@ -251,21 +261,15 @@ int cmd_lz11(const char* input, const char* output) {
free(compressed); free(compressed);
printf("Compressed to file \"%s\".\n", output); printf("Compressed to file \"%s\".\n", output.c_str());
return 0; return 0;
} }
struct compare_strings { std::map<std::string, std::string> cmd_get_args(int argc, char* argv[]) {
bool operator()(char const *a, char const *b) { std::map<std::string, std::string> args;
return strcmp(a, b) < 0;
}
};
std::map<char*, char*, compare_strings> cmd_get_args(int argc, char* argv[]) {
std::map<char*, char*, compare_strings> args;
for(int i = 0; i < argc; i++) { for(int i = 0; i < argc; i++) {
if((strncmp(argv[i], "-", 1) == 0 || strncmp(argv[i], "--", 2) == 0) && argc != i + 1) { if((strncmp(argv[i], "-", 1) == 0 || strncmp(argv[i], "--", 2) == 0) && argc != i + 1) {
args.insert(std::pair<char*, char*>(argv[i], argv[i + 1])); args.insert(std::pair<std::string, std::string>(argv[i], argv[i + 1]));
i++; i++;
} }
} }
@ -273,13 +277,11 @@ std::map<char*, char*, compare_strings> cmd_get_args(int argc, char* argv[]) {
return args; return args;
} }
const char* cmd_find_arg(std::map<char*, char*, compare_strings> args, const char* shortOpt, const char* longOpt, const char* def) { std::string cmd_find_arg(std::map<std::string, std::string> args, const std::string shortOpt, const std::string longOpt, const std::string def) {
char sopt[strlen(shortOpt) + 2]; std::string sopt = "-" + shortOpt;
sprintf(sopt, "-%s", shortOpt); std::string lopt = "--" + longOpt;
char lopt[strlen(longOpt) + 3];
sprintf(lopt, "--%s", longOpt);
std::map<char*, char*, compare_strings>::iterator match = args.find(sopt); std::map<std::string, std::string>::iterator match = args.find(sopt);
if(match != args.end()) { if(match != args.end()) {
return (*match).second; return (*match).second;
} }
@ -292,40 +294,31 @@ const char* cmd_find_arg(std::map<char*, char*, compare_strings> args, const cha
return def; return def;
} }
std::vector<const char*> cmd_parse_list(const char* list) { std::vector<std::string> cmd_parse_list(const std::string list) {
std::vector<const char*> ret; std::vector<std::string> ret;
const char* curr = list; std::string::size_type lastPos = 0;
const char* found = NULL; std::string::size_type pos = 0;
while((found = strchr(curr, ',')) != NULL) { while((pos = list.find(',')) != std::string::npos) {
char* substr = (char*) malloc(found - curr + 1); ret.push_back(list.substr(lastPos, pos - lastPos));
memcpy(substr, curr, found - curr); lastPos = pos + 1;
ret.push_back(substr);
curr = found + 1;
} }
if(strlen(curr) > 0) { if(lastPos < list.size()) {
ret.push_back(strdup(curr)); ret.push_back(list.substr(lastPos));
} }
return ret; return ret;
} }
void cmd_free_list(std::vector<const char*> list) { void cmd_print_info(const std::string command) {
for(std::vector<const char*>::iterator it = list.begin(); it != list.end(); it++) { if(command.compare("makebanner") == 0) {
free((void*) *it);
}
}
void cmd_print_info(const char* command) {
if(strcmp(command, "makebanner") == 0) {
printf("makebanner - Creates a .bnr file.\n"); printf("makebanner - Creates a .bnr file.\n");
printf(" -i/--image: PNG file to use as the banner's image. Interchangeable with -ci.\n"); printf(" -i/--image: PNG file to use as the banner's image. Interchangeable with -ci.\n");
printf(" -a/--audio: WAV file to use as the banner's tune. Interchangeable with -ca.\n"); printf(" -a/--audio: WAV file to use as the banner's tune. Interchangeable with -ca.\n");
printf(" -ci/--cgfximage: CGFX file to use as the banner's image. Interchangeable with -i.\n"); printf(" -ci/--cgfximage: CGFX file to use as the banner's image. Interchangeable with -i.\n");
printf(" -ca/--cwavaudio: CWAV file to use as the banner's tune. Interchangeable with -a.\n"); printf(" -ca/--cwavaudio: CWAV file to use as the banner's tune. Interchangeable with -a.\n");
printf(" -o/--output: File to output the created banner to.\n"); printf(" -o/--output: File to output the created banner to.\n");
} else if(strcmp(command, "makesmdh") == 0) { } else if(command.compare("makesmdh") == 0) {
printf("makesmdh - Creates a .smdh/.icn file.\n"); printf("makesmdh - Creates a .smdh/.icn file.\n");
printf(" -s/--shorttitle: Short title of the application.\n"); printf(" -s/--shorttitle: Short title of the application.\n");
printf(" -l/--longtitle: Long title of the application.\n"); printf(" -l/--longtitle: Long title of the application.\n");
@ -340,11 +333,11 @@ void cmd_print_info(const char* command) {
printf(" -ev/--eulaversion: Optional. Version of the EULA required to be accepted before launching.\n"); printf(" -ev/--eulaversion: Optional. Version of the EULA required to be accepted before launching.\n");
printf(" -obf/--optimalbannerframe: Optional. Optimal frame of the accompanying banner.\n"); printf(" -obf/--optimalbannerframe: Optional. Optimal frame of the accompanying banner.\n");
printf(" -spid/--streetpassid: Optional. Streetpass ID of the SMDH.\n"); printf(" -spid/--streetpassid: Optional. Streetpass ID of the SMDH.\n");
} else if(strcmp(command, "makecwav") == 0) { } else if(command.compare("makecwav") == 0) {
printf("makecwav - Creates a CWAV file from a WAV.\n"); printf("makecwav - Creates a CWAV file from a WAV.\n");
printf(" -i/--input: WAV file to convert.\n"); printf(" -i/--input: WAV file to convert.\n");
printf(" -o/--output: File to output the created CWAV to.\n"); printf(" -o/--output: File to output the created CWAV to.\n");
} else if(strcmp(command, "lz11") == 0) { } else if(command.compare("lz11") == 0) {
printf("lz11 - Compresses a file with LZ11.\n"); printf("lz11 - Compresses a file with LZ11.\n");
printf(" -i/--input: File to compress.\n"); printf(" -i/--input: File to compress.\n");
printf(" -o/--output: File to output the compressed data to.\n"); printf(" -o/--output: File to output the compressed data to.\n");
@ -359,23 +352,23 @@ void cmd_print_commands() {
cmd_print_info("lz11"); cmd_print_info("lz11");
} }
void cmd_print_usage(const char* executedFrom) { void cmd_print_usage(const std::string executedFrom) {
printf("Usage: %s <command> <args>\n", executedFrom); printf("Usage: %s <command> <args>\n", executedFrom.c_str());
cmd_print_commands(); cmd_print_commands();
} }
void cmd_missing_args(const char* command) { void cmd_missing_args(const std::string command) {
printf("Missing arguments for command \"%s\".\n", command); printf("Missing arguments for command \"%s\".\n", command.c_str());
cmd_print_info(command); cmd_print_info(command);
} }
void cmd_invalid_arg(const char* argument, const char* command) { void cmd_invalid_arg(const std::string argument, const std::string command) {
printf("Invalid value for argument \"%s\" in command \"%s\".\n", argument, command); printf("Invalid value for argument \"%s\" in command \"%s\".\n", argument.c_str(), command.c_str());
cmd_print_info(command); cmd_print_info(command);
} }
void cmd_invalid_command(const char* command) { void cmd_invalid_command(const std::string command) {
printf("Invalid command \"%s\".\n", command); printf("Invalid command \"%s\".\n", command.c_str());
cmd_print_commands(); cmd_print_commands();
} }
@ -386,56 +379,56 @@ int cmd_process_command(int argc, char* argv[]) {
} }
char* command = argv[1]; char* command = argv[1];
std::map<char*, char*, compare_strings> args = cmd_get_args(argc, argv); std::map<std::string, std::string> args = cmd_get_args(argc, argv);
if(strcmp(command, "makebanner") == 0) { if(strcmp(command, "makebanner") == 0) {
const char *banner = cmd_find_arg(args, "i", "image", NULL); const std::string banner = cmd_find_arg(args, "i", "image", "");
const char *audio = cmd_find_arg(args, "a", "audio", NULL); const std::string audio = cmd_find_arg(args, "a", "audio", "");
const char *cgfxFile = cmd_find_arg(args, "ci", "cgfximage", NULL); const std::string cgfxFile = cmd_find_arg(args, "ci", "cgfximage", "");
const char *cwavFile = cmd_find_arg(args, "ca", "cwavaudio", NULL); const std::string cwavFile = cmd_find_arg(args, "ca", "cwavaudio", "");
const char *output = cmd_find_arg(args, "o", "output", NULL); const std::string output = cmd_find_arg(args, "o", "output", "");
if(!(banner || cgfxFile) || !(audio || cwavFile) || !output) { if((banner.empty() && cgfxFile.empty()) || (audio.empty() && cwavFile.empty()) || output.empty()) {
cmd_missing_args(command); cmd_missing_args(command);
return -1; return -1;
} }
return cmd_make_banner(banner, audio, cgfxFile, cwavFile, output); return cmd_make_banner(banner, audio, cgfxFile, cwavFile, output);
} else if(strcmp(command, "makesmdh") == 0) { } else if(strcmp(command, "makesmdh") == 0) {
const char* shortTitle = cmd_find_arg(args, "s", "shorttitle", NULL); const std::string shortTitle = cmd_find_arg(args, "s", "shorttitle", "");
const char* longTitle = cmd_find_arg(args, "l", "longtitle", NULL); const std::string longTitle = cmd_find_arg(args, "l", "longtitle", "");
const char* publisher = cmd_find_arg(args, "p", "publisher", NULL); const std::string publisher = cmd_find_arg(args, "p", "publisher", "");
const char* icon = cmd_find_arg(args, "i", "icon", NULL); const std::string icon = cmd_find_arg(args, "i", "icon", "");
const char* output = cmd_find_arg(args, "o", "output", NULL); const std::string output = cmd_find_arg(args, "o", "output", "");
if(!shortTitle || !longTitle || !publisher || !icon || !output) { if(shortTitle.empty() || longTitle.empty() || publisher.empty() || icon.empty() || output.empty()) {
cmd_missing_args(command); cmd_missing_args(command);
return -1; return -1;
} }
std::vector<const char*> regions = cmd_parse_list(cmd_find_arg(args, "r", "regions", "regionfree")); std::vector<std::string> regions = cmd_parse_list(cmd_find_arg(args, "r", "regions", "regionfree"));
std::vector<const char*> flags = cmd_parse_list(cmd_find_arg(args, "f", "flags", "visible,allow3d,recordusage")); std::vector<std::string> flags = cmd_parse_list(cmd_find_arg(args, "f", "flags", "visible,allow3d,recordusage"));
u64 matchMakerId = (u64) atoll(cmd_find_arg(args, "mmid", "matchmakerid", "0")); u64 matchMakerId = (u64) atoll(cmd_find_arg(args, "mmid", "matchmakerid", "0").c_str());
u16 eulaVersion = (u16) atoi(cmd_find_arg(args, "ev", "eulaversion", "0")); u16 eulaVersion = (u16) atoi(cmd_find_arg(args, "ev", "eulaversion", "0").c_str());
u32 optimalBannerFrame = (u32) atoll(cmd_find_arg(args, "obf", "optimalbannerframe", "0")); u32 optimalBannerFrame = (u32) atoll(cmd_find_arg(args, "obf", "optimalbannerframe", "0").c_str());
u32 streetpassId = (u32) atoll(cmd_find_arg(args, "spid", "streetpassid", "0")); u32 streetpassId = (u32) atoll(cmd_find_arg(args, "spid", "streetpassid", "0").c_str());
u32 regionFlags = 0; u32 regionFlags = 0;
for(std::vector<const char*>::iterator it = regions.begin(); it != regions.end(); it++) { for(std::vector<std::string>::iterator it = regions.begin(); it != regions.end(); it++) {
const char* region = *it; const std::string region = *it;
if(strcmp(region, "regionfree") == 0) { if(region.compare("regionfree") == 0) {
regionFlags = REGION_FREE; regionFlags = REGION_FREE;
break; break;
} else if(strcmp(region, "japan") == 0) { } else if(region.compare("japan") == 0) {
regionFlags |= JAPAN; regionFlags |= JAPAN;
} else if(strcmp(region, "northamerica") == 0) { } else if(region.compare("northamerica") == 0) {
regionFlags |= NORTH_AMERICA; regionFlags |= NORTH_AMERICA;
} else if(strcmp(region, "europe") == 0) { } else if(region.compare("europe") == 0) {
regionFlags |= EUROPE; regionFlags |= EUROPE;
} else if(strcmp(region, "australia") == 0) { } else if(region.compare("australia") == 0) {
regionFlags |= AUSTRALIA; regionFlags |= AUSTRALIA;
} else if(strcmp(region, "china") == 0) { } else if(region.compare("china") == 0) {
regionFlags |= CHINA; regionFlags |= CHINA;
} else if(strcmp(region, "korea") == 0) { } else if(region.compare("korea") == 0) {
regionFlags |= KOREA; regionFlags |= KOREA;
} else if(strcmp(region, "taiwan") == 0) { } else if(region.compare("taiwan") == 0) {
regionFlags |= TAIWAN; regionFlags |= TAIWAN;
} else { } else {
cmd_invalid_arg("regions", command); cmd_invalid_arg("regions", command);
@ -443,50 +436,47 @@ int cmd_process_command(int argc, char* argv[]) {
} }
u32 smdhFlags = 0; u32 smdhFlags = 0;
for(std::vector<const char*>::iterator it = flags.begin(); it != flags.end(); it++) { for(std::vector<std::string>::iterator it = flags.begin(); it != flags.end(); it++) {
const char* flag = *it; const std::string flag = *it;
if(strcmp(flag, "visible") == 0) { if(flag.compare("visible") == 0) {
smdhFlags |= VISIBLE; smdhFlags |= VISIBLE;
} else if(strcmp(flag, "autoboot") == 0) { } else if(flag.compare("autoboot") == 0) {
smdhFlags |= AUTO_BOOT; smdhFlags |= AUTO_BOOT;
} else if(strcmp(flag, "allow3d") == 0) { } else if(flag.compare("allow3d") == 0) {
smdhFlags |= ALLOW_3D; smdhFlags |= ALLOW_3D;
} else if(strcmp(flag, "requireeula") == 0) { } else if(flag.compare("requireeula") == 0) {
smdhFlags |= REQUIRE_EULA; smdhFlags |= REQUIRE_EULA;
} else if(strcmp(flag, "autosave") == 0) { } else if(flag.compare("autosave") == 0) {
smdhFlags |= AUTO_SAVE_ON_EXIT; smdhFlags |= AUTO_SAVE_ON_EXIT;
} else if(strcmp(flag, "extendedbanner") == 0) { } else if(flag.compare("extendedbanner") == 0) {
smdhFlags |= USE_EXTENDED_BANNER; smdhFlags |= USE_EXTENDED_BANNER;
} else if(strcmp(flag, "ratingrequired") == 0) { } else if(flag.compare("ratingrequired") == 0) {
smdhFlags |= RATING_REQUIED; smdhFlags |= RATING_REQUIED;
} else if(strcmp(flag, "savedata") == 0) { } else if(flag.compare("savedata") == 0) {
smdhFlags |= USE_SAVE_DATA; smdhFlags |= USE_SAVE_DATA;
} else if(strcmp(flag, "recordusage") == 0) { } else if(flag.compare("recordusage") == 0) {
smdhFlags |= RECORD_USAGE; smdhFlags |= RECORD_USAGE;
} else if(strcmp(flag, "nosavebackups") == 0) { } else if(flag.compare("nosavebackups") == 0) {
smdhFlags |= DISABLE_SAVE_BACKUPS; smdhFlags |= DISABLE_SAVE_BACKUPS;
} else { } else {
cmd_invalid_arg("flags", command); cmd_invalid_arg("flags", command);
} }
} }
cmd_free_list(regions);
cmd_free_list(flags);
return cmd_make_smdh(shortTitle, longTitle, publisher, icon, (SMDHRegionFlag) regionFlags, matchMakerId, smdhFlags, eulaVersion, optimalBannerFrame, streetpassId, output); return cmd_make_smdh(shortTitle, longTitle, publisher, icon, (SMDHRegionFlag) regionFlags, matchMakerId, smdhFlags, eulaVersion, optimalBannerFrame, streetpassId, output);
} else if(strcmp(command, "makecwav") == 0) { } else if(strcmp(command, "makecwav") == 0) {
const char* input = cmd_find_arg(args, "i", "input", NULL); const std::string input = cmd_find_arg(args, "i", "input", "");
const char* output = cmd_find_arg(args, "o", "output", NULL); const std::string output = cmd_find_arg(args, "o", "output", "");
if(!input || !output) { if(input.empty() || output.empty()) {
cmd_missing_args(command); cmd_missing_args(command);
return -1; return -1;
} }
return cmd_make_cwav(input, output); return cmd_make_cwav(input, output);
} else if(strcmp(command, "lz11") == 0) { } else if(strcmp(command, "lz11") == 0) {
const char* input = cmd_find_arg(args, "i", "input", NULL); const std::string input = cmd_find_arg(args, "i", "input", "");
const char* output = cmd_find_arg(args, "o", "output", NULL); const std::string output = cmd_find_arg(args, "o", "output", "");
if(!input || !output) { if(input.empty() || output.empty()) {
cmd_missing_args(command); cmd_missing_args(command);
return -1; return -1;
} }