14static void DisplayROMImgDetails(
const ROMIMG *ROMImg)
16 unsigned int i, TotalSize;
19 if (ROMImg->date != 0)
20 printf(
"ROM datestamp:\t%04x/%02x/%02x\n", ((
unsigned short int *)&ROMImg->date)[1], ((
unsigned char *)&ROMImg->date)[1], ((
unsigned char *)&ROMImg->date)[0]);
21 if (ROMImg->comment != NULL)
22 printf(
"ROM comment:\t%s\n", ROMImg->comment);
25 GREEN
"Name"DEFCOL
" \tSize\n"
26 "-----------------------------\n");
27 for (i = 0, file = ROMImg->files, TotalSize = 0; i < ROMImg->NumFiles; TotalSize += file->RomDir.size, i++, file++) {
28 strncpy(filename, file->RomDir.name,
sizeof(filename) - 1);
29 filename[
sizeof(filename) - 1] =
'\0';
30 printf(GREEN
"%-10s"DEFCOL
"\t%u\n", filename, file->RomDir.size);
33 printf(
"\nTotal size: %u bytes.\n", TotalSize);
36static void DisplaySyntaxHelp(
void)
39 "ROMIMG -c <ROM image> <files>\n\tCreate ROM image *\n"
40 "ROMIMG -l <ROM image>\n\tList files in ROM image\n"
41 "ROMIMG -a <ROM image> <file(s)>\n\tAdd file(s) to ROM image *\n"
42 "ROMIMG -d <ROM image> <file(s)>\n\tDelete file(s) from ROM image\n"
43 "ROMIMG -x <ROM image>\n\tExtract all files from ROM image\n"
44 "ROMIMG -x <ROM image> <file>\n\tExtract file from ROM image\n"
45 "\n note*: write the switch in uppercase to perform filename transformation (eg: 'ioman.irx' > 'IOMAN')\n"
49static void DisplayAddDeleteOperationResult(
int result,
const char *InvolvedFile)
53 printf(GRNBOLD
"done!"DEFCOL
"\n");
56 printf(YELBOLD
"file not found."DEFCOL
"\n");
59 printf(REDBOLD
"Error writing to file: %s"DEFCOL
"\n", InvolvedFile);
62 printf(YELBOLD
"File already exists."DEFCOL
"\n");
65 printf(REDBOLD
"failed! code: %d"DEFCOL
"\n", result);
69int main(
int argc,
char **argv)
74 unsigned int i, FilesAffected;
78 printf(
"PlayStation 2 ROM image generator v1.12\n"
79 "Compiled on " __DATE__
" - " __TIME__
"\n"
80 "---------------------------------------\n\n");
81 for (result = 0; result < argc; result++)
82 DPRINTF(
"\t -- argv[%d] = %s\n", result, argv[result]);
89 if (argc >= 4 && strcasecmp(argv[1],
"-c") == 0) {
90 if ((result = CreateBlankROMImg(argv[2], &ROMImg)) == 0) {
91 for (FilesAffected = 0, i = 0; i < argc - 3; i++) {
92 printf(
"Adding file '%s'", argv[3 + i]);
93 if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0)
95 printf(result == 0 ? GRNBOLD
" done!"DEFCOL
"\n" : REDBOLD
" failed!"DEFCOL
"\n");
98 if (FilesAffected > 0) {
99 printf(
"Writing image... ");
100 printf(
"%s", (result = WriteROMImg(argv[2], &ROMImg)) == 0 ? GRNBOLD
"done!"DEFCOL
"\n" : REDBOLD
"failed!"DEFCOL
"\n");
102 UnloadROMImg(&ROMImg);
104 ERROR(
"(Internal fault) Can't create blank image file: %d (%s). Please report.\n", result, strerror(result));
105 }
else if (argc >= 4 && strcasecmp(argv[1],
"-a") == 0) {
106 if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) {
107 for (i = 0, FilesAffected = 0; i < argc - 3; i++) {
108 printf(
"Adding file '%s'", argv[3 + i]);
109 if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0)
111 DisplayAddDeleteOperationResult(result, argv[3 + i]);
114 if (FilesAffected > 0) {
115 printf(
"Writing image... ");
116 printf(
"%s", (result = WriteROMImg(argv[2], &ROMImg)) == 0 ? GRNBOLD
"done!"DEFCOL
"\n" : REDBOLD
"failed!"DEFCOL
"\n");
118 UnloadROMImg(&ROMImg);
120 ERROR(
"Can't load image file: %s\n", argv[2]);
121 }
else if (argc >= 4 && strcmp(argv[1],
"-d") == 0) {
122 if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) {
123 for (i = 0, FilesAffected = 0; i < argc - 3; i++) {
124 printf(
"Removing file %s...", argv[3 + i]);
125 if ((result = DeleteFile(&ROMImg, argv[3 + i])) == 0)
127 DisplayAddDeleteOperationResult(result, argv[3 + i]);
130 if (FilesAffected > 0) {
131 printf(
"Writing image...");
132 printf(
"%s", (result = WriteROMImg(argv[2], &ROMImg)) == 0 ? GRNBOLD
"done!"DEFCOL
"\n" : REDBOLD
"failed!"DEFCOL
"\n");
134 UnloadROMImg(&ROMImg);
136 ERROR(
"Can't load image file: %s\n", argv[2]);
137 }
else if (argc == 3 && strcmp(argv[1],
"-l") == 0) {
138 if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) {
139 DisplayROMImgDetails(&ROMImg);
140 UnloadROMImg(&ROMImg);
142 ERROR(
"Can't load image file: %s\n", argv[2]);
143 }
else if ((argc == 3 || argc == 4) && strcmp(argv[1],
"-x") == 0) {
144 if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) {
146 char FOLDER[256] =
"ext_";
147 strcat(FOLDER, argv[2]);
148#if defined(_WIN32) || defined(WIN32)
154 ERROR(
"Can't change directory to %s\n", FOLDER);
155 UnloadROMImg(&ROMImg);
159 printf(
"File list:\n"
160 GREEN
"Name"DEFCOL
" \tSize\n"
161 "-----------------------------\n");
162 for (i = 0, file = ROMImg.files; i < ROMImg.NumFiles; i++, file++) {
163 strncpy(filename, file->RomDir.name,
sizeof(filename) - 1);
164 filename[
sizeof(filename) - 1] =
'\0';
165 printf(GREEN
"%-10s"DEFCOL
"\t%u\n", filename, file->RomDir.size);
167 if (file->RomDir.size > 0) {
168 if ((OutputFile = fopen(filename,
"wb")) != NULL) {
169 if (fwrite(file->FileData, 1, file->RomDir.size, OutputFile) != file->RomDir.size) {
170 ERROR(
"Error writing to file %s\n", filename);
174 ERROR(
"Can't create file: %s\n", filename);
179 printf(
"Extracting file %s...", argv[3]);
180 DisplayAddDeleteOperationResult(result = ExtractFile(&ROMImg, argv[3], argv[3]), argv[3]);
183 UnloadROMImg(&ROMImg);
185 ERROR(
"Can't load image file: %s\n", argv[2]);
187 WARNING(
"Unrecognized command or incorrect syntax: %s\n", argv[1]);