int device_image_interface::reopen_for_write(const char *path) { if(m_file) core_fclose(m_file); file_error filerr = FILERR_NOT_FOUND; image_error_t err = IMAGE_ERROR_FILENOTFOUND; astring revised_path; /* attempt to open the file for writing*/ filerr = zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path); /* did the open succeed? */ switch(filerr) { case FILERR_NONE: /* success! */ m_readonly = 0; m_created = 1; err = IMAGE_ERROR_SUCCESS; break; case FILERR_NOT_FOUND: case FILERR_ACCESS_DENIED: /* file not found (or otherwise cannot open); continue */ err = IMAGE_ERROR_FILENOTFOUND; break; case FILERR_OUT_OF_MEMORY: /* out of memory */ err = IMAGE_ERROR_OUTOFMEMORY; break; case FILERR_ALREADY_OPEN: /* this shouldn't happen */ err = IMAGE_ERROR_ALREADYOPEN; break; case FILERR_FAILURE: case FILERR_TOO_MANY_FILES: case FILERR_INVALID_DATA: default: /* other errors */ err = IMAGE_ERROR_INTERNAL; break; } /* if successful, set the file name */ if (filerr == FILERR_NONE) set_image_filename(revised_path); return err; }
int device_image_interface::reopen_for_write(const char *path) { m_file.reset(); image_error_t err; std::string revised_path; // attempt to open the file for writing auto const filerr = util::zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path); // did the open succeed? switch(filerr) { case osd_file::error::NONE: // success! m_readonly = 0; m_created = 1; err = IMAGE_ERROR_SUCCESS; break; case osd_file::error::NOT_FOUND: case osd_file::error::ACCESS_DENIED: // file not found (or otherwise cannot open); continue err = IMAGE_ERROR_FILENOTFOUND; break; case osd_file::error::OUT_OF_MEMORY: // out of memory err = IMAGE_ERROR_OUTOFMEMORY; break; case osd_file::error::ALREADY_OPEN: // this shouldn't happen err = IMAGE_ERROR_ALREADYOPEN; break; case osd_file::error::FAILURE: case osd_file::error::TOO_MANY_FILES: case osd_file::error::INVALID_DATA: default: // other errors err = IMAGE_ERROR_INTERNAL; break; } // if successful, set the file name if (filerr == osd_file::error::NONE) set_image_filename(revised_path.c_str()); return err; }
image_error_t legacy_image_device_base::load_image_by_path(UINT32 open_flags, const char *path) { file_error filerr = FILERR_NOT_FOUND; image_error_t err = IMAGE_ERROR_FILENOTFOUND; astring revised_path; /* attempt to read the file */ filerr = zippath_fopen(path, open_flags, &m_file, &revised_path); /* did the open succeed? */ switch(filerr) { case FILERR_NONE: /* success! */ m_writeable = (open_flags & OPEN_FLAG_WRITE) ? 1 : 0; m_created = (open_flags & OPEN_FLAG_CREATE) ? 1 : 0; err = IMAGE_ERROR_SUCCESS; break; case FILERR_NOT_FOUND: case FILERR_ACCESS_DENIED: /* file not found (or otherwise cannot open); continue */ err = IMAGE_ERROR_FILENOTFOUND; break; case FILERR_OUT_OF_MEMORY: /* out of memory */ err = IMAGE_ERROR_OUTOFMEMORY; break; case FILERR_ALREADY_OPEN: /* this shouldn't happen */ err = IMAGE_ERROR_ALREADYOPEN; break; case FILERR_FAILURE: case FILERR_TOO_MANY_FILES: case FILERR_INVALID_DATA: default: /* other errors */ err = IMAGE_ERROR_INTERNAL; break; } /* if successful, set the file name */ if (filerr == FILERR_NONE) set_image_filename(revised_path); return err; }
image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, const std::string &path) { std::string revised_path; // attempt to read the file auto const filerr = util::zippath_fopen(path, open_flags, m_file, revised_path); if (filerr != osd_file::error::NONE) return image_error_from_file_error(filerr); m_readonly = (open_flags & OPEN_FLAG_WRITE) ? 0 : 1; m_created = (open_flags & OPEN_FLAG_CREATE) ? 1 : 0; set_image_filename(revised_path); return IMAGE_ERROR_SUCCESS; }
image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, const char *path) { image_error_t err; std::string revised_path; /* attempt to read the file */ auto const filerr = util::zippath_fopen(path, open_flags, m_file, revised_path); /* did the open succeed? */ switch(filerr) { case osd_file::error::NONE: /* success! */ m_readonly = (open_flags & OPEN_FLAG_WRITE) ? 0 : 1; m_created = (open_flags & OPEN_FLAG_CREATE) ? 1 : 0; err = IMAGE_ERROR_SUCCESS; break; case osd_file::error::NOT_FOUND: case osd_file::error::ACCESS_DENIED: /* file not found (or otherwise cannot open); continue */ err = IMAGE_ERROR_FILENOTFOUND; break; case osd_file::error::OUT_OF_MEMORY: /* out of memory */ err = IMAGE_ERROR_OUTOFMEMORY; break; case osd_file::error::ALREADY_OPEN: /* this shouldn't happen */ err = IMAGE_ERROR_ALREADYOPEN; break; case osd_file::error::FAILURE: case osd_file::error::TOO_MANY_FILES: case osd_file::error::INVALID_DATA: default: /* other errors */ err = IMAGE_ERROR_INTERNAL; break; } /* if successful, set the file name */ if (filerr == osd_file::error::NONE) set_image_filename(revised_path.c_str()); return err; }
int device_image_interface::reopen_for_write(const std::string &path) { m_file.reset(); std::string revised_path; // attempt to open the file for writing auto const filerr = util::zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path); if (filerr != osd_file::error::NONE) return image_error_from_file_error(filerr); // success! m_readonly = 0; m_created = 1; set_image_filename(revised_path); return IMAGE_ERROR_SUCCESS; }
bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args, bool just_load) { UINT32 open_plan[4]; int i; bool softload = FALSE; m_from_swlist = FALSE; // if the path contains no period, we are using softlists, so we won't create an image astring pathstr(path); bool filename_has_period = (pathstr.rchr(0, '.') != -1) ? TRUE : FALSE; /* first unload the image */ unload(); /* clear any possible error messages */ clear_error(); /* we are now loading */ m_is_loading = TRUE; /* record the filename */ m_err = set_image_filename(path); if (m_err) goto done; /* Check if there's a software list defined for this device and use that if we're not creating an image */ if (!filename_has_period && !just_load) { softload = load_software_part( device().machine().options(), this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name, &m_software_list_name ); // if we had launched from softlist with a specified part, e.g. "shortname:part" // we would have recorded the wrong name, so record it again based on software_info if (m_software_info_ptr && m_full_software_name) m_err = set_image_filename(m_full_software_name); m_from_swlist = TRUE; } if (is_create || filename_has_period) { /* determine open plan */ determine_open_plan(is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !m_file && open_plan[i]; i++) { /* open the file */ m_err = load_image_by_path(open_plan[i], path); if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } /* Copy some image information when we have been loaded through a software list */ if ( m_software_info_ptr ) { m_longname = m_software_info_ptr->longname; m_manufacturer = m_software_info_ptr->publisher; m_year = m_software_info_ptr->year; //m_playable = m_software_info_ptr->supported; } /* did we fail to find the file? */ if (!is_loaded() && !softload) { m_err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* call device load or create */ m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { m_err = (image_error_t)finish_load(); if (m_err) goto done; } /* success! */ done: if (just_load) { if(m_err) clear(); return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; } if (m_err!=0) { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) popmessage("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); else mame_printf_error("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if (device().machine().time() > attotime::zero && is_reset_on_load()) device().machine().schedule_hard_reset(); else { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else mame_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
bool legacy_image_device_base::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args) { image_error_t err; UINT32 open_plan[4]; int i; bool softload = FALSE; /* first unload the image */ unload(); /* clear any possible error messages */ clear_error(); /* we are now loading */ m_is_loading = TRUE; /* record the filename */ err = set_image_filename(path); if (err) goto done; /* Check if there's a software list defined for this device and use that if we're not creating an image */ softload = load_software_part( this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name ); if (is_create || (!softload && m_software_info_ptr==NULL)) { /* determine open plan */ determine_open_plan(is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !m_file && open_plan[i]; i++) { /* open the file */ err = load_image_by_path(open_plan[i], path); if (err && (err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } /* Copy some image information when we have been loaded through a software list */ if ( m_software_info_ptr ) { m_longname = m_software_info_ptr->longname; m_manufacturer = m_software_info_ptr->publisher; m_year = m_software_info_ptr->year; //m_playable = m_software_info_ptr->supported; } /* did we fail to find the file? */ if (!is_loaded() && !softload) { err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* call device load or create */ m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { err = (image_error_t)finish_load(); if (err) goto done; } /* success! */ done: if (m_err) { if (!m_init_phase) { if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); else mame_printf_error("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if ((attotime_compare(timer_get_time(device().machine), attotime_zero) > 0) && m_image_config.is_reset_on_load()) device().machine->schedule_hard_reset(); else { if (!m_init_phase) { if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else mame_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
image_init_result device_image_interface::load_internal(const std::string &path, bool is_create, int create_format, util::option_resolution *create_args, bool just_load) { // first unload the image unload(); // clear any possible error messages clear_error(); // we are now loading m_is_loading = true; // record the filename set_image_filename(path); if (core_opens_image_file()) { // determine open plan std::vector<UINT32> open_plan = determine_open_plan(is_create); // attempt to open the file in various ways for (auto iter = open_plan.cbegin(); !m_file && iter != open_plan.cend(); iter++) { // open the file m_err = load_image_by_path(*iter, path); if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) goto done; } // did we fail to find the file? if (!is_loaded()) { m_err = IMAGE_ERROR_FILENOTFOUND; goto done; } } // call device load or create m_create_format = create_format; m_create_args = create_args; if (m_init_phase==false) { m_err = (finish_load() == image_init_result::PASS) ? IMAGE_ERROR_SUCCESS : IMAGE_ERROR_INTERNAL; if (m_err) goto done; } // success! done: if (just_load) { if (m_err) clear(); return m_err ? image_init_result::FAIL : image_init_result::PASS; } if (m_err!=0) { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) device().popmessage("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); else osd_printf_error("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path.c_str(), error()); } clear(); } else { // do we need to reset the CPU? only schedule it if load/create is successful if (!schedule_postload_hard_reset_if_needed()) { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) device().popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else osd_printf_info("Image '%s' was successfully %s.\n", path.c_str(), is_create ? "created" : "loaded"); } } } return m_err ? image_init_result::FAIL : image_init_result::PASS; }
bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, util::option_resolution *create_args, bool just_load) { UINT32 open_plan[4]; int i; bool softload = FALSE; m_from_swlist = FALSE; // if the path contains no period, we are using softlists, so we won't create an image std::string pathstr(path); bool filename_has_period = (pathstr.find_last_of('.') != -1) ? TRUE : FALSE; // first unload the image unload(); // clear any possible error messages clear_error(); // we are now loading m_is_loading = TRUE; // record the filename m_err = set_image_filename(path); if (m_err) goto done; if (core_opens_image_file()) { // Check if there's a software list defined for this device and use that if we're not creating an image if (!filename_has_period && !just_load) { softload = load_software_part(path, m_software_part_ptr); if (softload) { m_software_info_ptr = &m_software_part_ptr->info(); m_software_list_name.assign(m_software_info_ptr->list().list_name()); m_full_software_name.assign(m_software_part_ptr->info().shortname()); // if we had launched from softlist with a specified part, e.g. "shortname:part" // we would have recorded the wrong name, so record it again based on software_info if (m_software_info_ptr && !m_full_software_name.empty()) m_err = set_image_filename(m_full_software_name.c_str()); // check if image should be read-only const char *read_only = get_feature("read_only"); if (read_only && !strcmp(read_only, "true")) { make_readonly(); } m_from_swlist = TRUE; } } if (is_create || filename_has_period) { // determine open plan determine_open_plan(is_create, open_plan); // attempt to open the file in various ways for (i = 0; !m_file && open_plan[i]; i++) { // open the file m_err = load_image_by_path(open_plan[i], path); if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } // Copy some image information when we have been loaded through a software list if ( m_software_info_ptr ) { // sanitize if (m_software_info_ptr->longname().empty() || m_software_info_ptr->publisher().empty() || m_software_info_ptr->year().empty()) fatalerror("Each entry in an XML list must have all of the following fields: description, publisher, year!\n"); // store m_longname = m_software_info_ptr->longname(); m_manufacturer = m_software_info_ptr->publisher(); m_year = m_software_info_ptr->year(); //m_playable = m_software_info_ptr->supported(); } // did we fail to find the file? if (!is_loaded() && !softload) { m_err = IMAGE_ERROR_FILENOTFOUND; goto done; } } // call device load or create m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { m_err = (image_error_t)finish_load(); if (m_err) goto done; } // success! done: if (just_load) { if(m_err) clear(); return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; } if (m_err!=0) { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) device().popmessage("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); else osd_printf_error("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if (device().machine().time() > attotime::zero && is_reset_on_load()) device().machine().schedule_hard_reset(); else { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) device().popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else osd_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
static int image_load_internal(mess_image *image, const char *path, int is_create, int create_format, option_resolution *create_args) { image_error_t err; const char *software_path; char *software_path_list = NULL; const void *buffer; const game_driver *gamedrv; UINT32 open_plan[4]; int i; /* sanity checks */ assert_always(image, "image_load(): image is NULL"); assert_always(path, "image_load(): path is NULL"); /* we are now loading */ image->is_loading = 1; /* first unload the image */ image_unload(image); /* record the filename */ image->err = set_image_filename(image, path, NULL); if (image->err) goto done; /* tell the OSD layer that this is changing */ osd_image_load_status_changed(image, 0); /* do we need to reset the CPU? */ if ((timer_get_time() > 0) && image->dev->reset_on_load) mame_schedule_soft_reset(Machine); /* determine open plan */ determine_open_plan(image, is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !image->file && open_plan[i]; i++) { software_path = software_path_list; do { gamedrv = Machine->gamedrv; while(!is_loaded(image) && gamedrv) { /* open the file */ image->err = load_image_by_path(image, software_path, gamedrv, open_plan[i], path); if (image->err && (image->err != IMAGE_ERROR_FILENOTFOUND)) goto done; /* move on to the next driver */ gamedrv = mess_next_compatible_driver(gamedrv); } /* move on to the next entry in the software path; if we can */ if (software_path) software_path += strlen(software_path) + 1; } while(!is_loaded(image) && software_path && *software_path); } /* did we fail to find the file? */ if (!is_loaded(image)) { image->err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* if applicable, call device verify */ if (image->dev->imgverify && !image_has_been_created(image)) { /* access the memory */ buffer = image_ptr(image); if (!buffer) { image->err = IMAGE_ERROR_OUTOFMEMORY; goto done; } /* verify the file */ err = image->dev->imgverify(buffer, (size_t) image->length); if (err) { image->err = IMAGE_ERROR_INVALIDIMAGE; goto done; } } /* call device load or create */ if (image_has_been_created(image) && image->dev->create) { err = image->dev->create(image, create_format, create_args); if (err) { if (!image->err) image->err = IMAGE_ERROR_UNSPECIFIED; goto done; } } else if (image->dev->load) { /* using device load */ err = image->dev->load(image); if (err) { if (!image->err) image->err = IMAGE_ERROR_UNSPECIFIED; goto done; } } /* success! */ done: if (software_path_list) free(software_path_list); if (image->err) image_clear(image); image->is_loading = 1; return image->err ? INIT_FAIL : INIT_PASS; }
static image_error_t load_zip_path(mess_image *image, const char *path) { image_error_t err = IMAGE_ERROR_FILENOTFOUND; zip_file *zip = NULL; zip_error ziperr; const zip_file_header *header; const char *zip_extension = ".zip"; char *path_copy; const char *zip_entry; void *ptr; int pos; /* create our own copy of the path */ path_copy = mame_strdup(path); if (!path_copy) { err = IMAGE_ERROR_OUTOFMEMORY; goto done; } /* loop through the path and try opening zip files */ ziperr = ZIPERR_FILE_ERROR; zip_entry = NULL; pos = strlen(path_copy); while(pos > strlen(zip_extension)) { /* is this a potential zip path? */ if ((path_copy[pos] == '\0') || !strncmp(&path_copy[pos], PATH_SEPARATOR, strlen(PATH_SEPARATOR))) { /* parse out the zip path */ if (path_copy[pos] == '\0') { /* no zip path */ zip_entry = NULL; } else { /* we are at a zip path */ path_copy[pos] = '\0'; zip_entry = &path_copy[pos + strlen(PATH_SEPARATOR)]; } /* try to open the zip file */ ziperr = zip_file_open(path_copy, &zip); if (ziperr != ZIPERR_FILE_ERROR) break; /* restore the path if we changed */ if (zip_entry) path_copy[pos] = PATH_SEPARATOR[0]; } pos--; } /* did we succeed in opening up a zip file? */ if (ziperr == ZIPERR_NONE) { /* iterate through the zip file */ header = zip_file_first_file(zip); /* if we specified a zip partial path, find it */ if (zip_entry) { while(header) { if (!mame_stricmp(header->filename, zip_entry)) break; header = zip_file_next_file(zip); } } /* were we successful? */ if (header) { /* if no zip path was specified, we have to change the name */ if (!zip_entry) { /* use the first entry; tough part is we have to change the name */ err = set_image_filename(image, image->name, header->filename); if (err) goto done; } /* allocate space for this zip file */ ptr = image_malloc(image, header->uncompressed_length); if (!ptr) { err = IMAGE_ERROR_OUTOFMEMORY; goto done; } ziperr = zip_file_decompress(zip, ptr, header->uncompressed_length); if (ziperr == ZIPERR_NONE) { /* success! */ err = IMAGE_ERROR_SUCCESS; image->ptr = ptr; image->length = header->uncompressed_length; } } } done: if (path_copy) free(path_copy); if (zip) zip_file_close(zip); return err; }