Refactor where ROM is loaded.

This commit is contained in:
Themaister 2013-01-21 21:01:12 +01:00
parent ef9825c6bd
commit e04217e373
3 changed files with 16 additions and 19 deletions

26
file.c
View File

@ -533,34 +533,38 @@ static bool load_roms(unsigned rom_type, const char **rom_paths, size_t roms)
void *rom_buf[MAX_ROMS] = {NULL};
ssize_t rom_len[MAX_ROMS] = {0};
struct retro_game_info info[MAX_ROMS] = {{NULL}};
char *xml_buf = load_xml_map(g_extern.xml_name);
FILE *rom_file = NULL;
if (rom_paths[0])
{
RARCH_LOG("Loading ROM file: %s.\n", rom_paths[0]);
rom_file = fopen(rom_paths[0], "rb");
}
if (!g_extern.system.info.need_fullpath)
{
if ((rom_len[0] = read_rom_file(g_extern.rom_file, &rom_buf[0])) == -1)
if ((rom_len[0] = read_rom_file(rom_file, &rom_buf[0])) == -1)
{
RARCH_ERR("Could not read ROM file.\n");
return false;
ret = false;
goto end;
}
if (g_extern.rom_file)
fclose(g_extern.rom_file);
RARCH_LOG("ROM size: %u bytes.\n", (unsigned)rom_len[0]);
}
else
{
if (!g_extern.rom_file)
if (!rom_file)
{
RARCH_ERR("Implementation requires a full path to be set, cannot load ROM from stdin. Aborting ...\n");
return false;
ret = false;
goto end;
}
fclose(g_extern.rom_file);
RARCH_LOG("ROM loading skipped. Implementation will load it on its own.\n");
}
char *xml_buf = load_xml_map(g_extern.xml_name);
info[0].path = rom_paths[0];
info[0].data = rom_buf[0];
info[0].size = rom_len[0];
@ -594,6 +598,8 @@ end:
for (unsigned i = 0; i < MAX_ROMS; i++)
free(rom_buf[i]);
free(xml_buf);
if (rom_file)
fclose(rom_file);
return ret;
}

View File

@ -309,7 +309,6 @@ struct global
bool has_justifiers;
bool has_multitap;
FILE *rom_file;
enum rarch_game_type game_type;
uint32_t cart_crc;

View File

@ -718,14 +718,6 @@ static void set_paths(const char *path)
{
set_basename(path);
RARCH_LOG("Opening file: \"%s\"\n", path);
g_extern.rom_file = fopen(path, "rb");
if (g_extern.rom_file == NULL)
{
RARCH_ERR("Could not open file: \"%s\"\n", path);
rarch_fail(1, "set_paths()");
}
if (!g_extern.has_set_save_path)
fill_pathname_noext(g_extern.savefile_name_srm, g_extern.basename, ".srm", sizeof(g_extern.savefile_name_srm));
if (!g_extern.has_set_state_path)