Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/asar/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ static asar_error_mapping asar_errors[] =

{ error_id_failed_to_open_file_access_denied, "Failed to open file '%s'. Access denied." },
{ error_id_failed_to_open_not_regular_file, "Failed to open file '%s'. Not a regular file (did you try to use a directory?)" },

{ error_id_outputfile_cannot_open, "Failed to open output destination for writing." },
};

// RPG Hacker: Sanity check. This makes sure that the element count of asar_warnings
Expand Down
2 changes: 2 additions & 0 deletions src/asar/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ enum asar_error_id : int
error_id_failed_to_open_file_access_denied,
error_id_failed_to_open_not_regular_file,

error_id_outputfile_cannot_open,

error_id_end,
error_id_count = error_id_end - error_id_start - 1,
};
Expand Down
34 changes: 31 additions & 3 deletions src/asar/interface-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int main(int argc, char * argv[])
}
//if (dot) *dot='.';
libcon_init(argc, argv,
"[options] asm_file [rom_file]\n\n"
"[options] asm_file [input_rom_file] [optional_output_rom_file]\n\n"
"Supported options:\n\n"
" --version \n"
" Display version information.\n\n"
Expand Down Expand Up @@ -332,10 +332,37 @@ int main(int argc, char * argv[])
printed_version = true;
}
string asmname=libcon_require_filename("Enter patch name:");
string romname=libcon_optional_filename("Enter ROM name:", nullptr);
//char * outname=libcon_optional_filename("Enter output ROM name:", nullptr);
string romname=libcon_optional_filename("Enter input ROM name:", nullptr);
string outname=libcon_optional_filename("Enter optional output ROM name:", nullptr);
libcon_end();
if (!strchr(asmname, '.') && !file_exists(asmname)) asmname+=".asm";

// Optional copy and work on outname instead of romname. This can be useful for auto build processes of final ROMs based on others
if(outname) { // Outname was set, so we create a copy of the file
if (!file_exists(romname))
{
asar_throw_error(pass, error_type_fatal, error_id_create_rom_failed);
}

char buf[BUFSIZ];
size_t size;
FILE* source = fopen(romname, "rb");
FILE* dest = fopen(outname, "wb");

if(!dest)
{
asar_throw_error(pass, error_type_fatal, error_id_outputfile_cannot_open);
}

while ((size = fread(buf, 1, BUFSIZ, source))) {
fwrite(buf, 1, size, dest);
}
fclose(source);
fclose(dest);

romname = outname;
}

if (!romname)
{
string romnametmp = get_base_name(asmname);
Expand Down Expand Up @@ -364,6 +391,7 @@ int main(int argc, char * argv[])
pause(err);
return 1;
}

//check if the ROM title and checksum looks sane
if (romlen>=32768 && !ignoretitleerrors)
{
Expand Down