mirror of
https://github.com/DarkStore-3DS/bannertool.git
synced 2026-07-03 00:39:33 +00:00
Improve file related error reporting, allow for creating CWAV and LZ11 compressed files.
This commit is contained in:
+79
-1
@@ -63,17 +63,77 @@ int make_banner(const char* image, const char* audio, const char* output) {
|
||||
|
||||
FILE* fd = fopen(output, "wb");
|
||||
if(!fd) {
|
||||
printf("ERROR: Could not open output file.\n");
|
||||
printf("ERROR: Could not open output file: %s\n", strerror(errno));
|
||||
return 3;
|
||||
}
|
||||
|
||||
fwrite(bnr, 1, bnrSize, fd);
|
||||
fclose(fd);
|
||||
|
||||
free(bnr);
|
||||
|
||||
printf("Created banner \"%s\".\n", output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int make_cwav(char* input, char* output) {
|
||||
u32 cwavSize = 0;
|
||||
u8* cwav = convert_to_cwav(input, &cwavSize);
|
||||
if(!cwav) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
FILE* fd = fopen(output, "wb");
|
||||
if(!fd) {
|
||||
printf("ERROR: Could not open output file: %s\n", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
|
||||
fwrite(cwav, 1, cwavSize, fd);
|
||||
fclose(fd);
|
||||
|
||||
free(cwav);
|
||||
|
||||
printf("Created CWAV \"%s\".\n", output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lz11(char* input, char* output) {
|
||||
FILE* in = fopen(input, "r");
|
||||
if(!in) {
|
||||
printf("ERROR: Could not open input file: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
u32 size = (u32) ftell(in);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
u8 data[size];
|
||||
fread(data, 1, size, in);
|
||||
fclose(in);
|
||||
|
||||
u32 compressedSize;
|
||||
u8* compressed = lz11_compress(data, size, &compressedSize);
|
||||
if(!compressed) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
FILE* fd = fopen(output, "wb");
|
||||
if(!fd) {
|
||||
printf("ERROR: Could not open output file: %s\n", strerror(errno));
|
||||
return 3;
|
||||
}
|
||||
|
||||
fwrite(compressed, 1, compressedSize, fd);
|
||||
fclose(fd);
|
||||
|
||||
free(compressed);
|
||||
|
||||
printf("Compressed to file \"%s\".\n", output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if(argc < 2) {
|
||||
cmd_print_usage(argv[0]);
|
||||
@@ -92,6 +152,24 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
return make_banner(banner, audio, output);
|
||||
} else if(strcmp(command, "makecwav") == 0) {
|
||||
char* input = cmd_find_arg(args, "i", "input");
|
||||
char* output = cmd_find_arg(args, "o", "output");
|
||||
if(!input || !output) {
|
||||
cmd_missing_args(command);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return make_cwav(input, output);
|
||||
} else if(strcmp(command, "lz11") == 0) {
|
||||
char* input = cmd_find_arg(args, "i", "input");
|
||||
char* output = cmd_find_arg(args, "o", "output");
|
||||
if(!input || !output) {
|
||||
cmd_missing_args(command);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return lz11(input, output);
|
||||
} else {
|
||||
cmd_invalid_command(command);
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user