void image_seterror(mess_image *image, image_error_t err, const char *message) { image_clear_error(image); image->err = err; if (message) { image->err_message = malloc(strlen(message) + 1); if (image->err_message) strcpy(image->err_message, message); } }
static void image_unload_internal(mess_image *image, int is_final_unload) { /* is there an actual image loaded? */ if (!is_loaded(image)) return; /* call the unload function */ if (image->dev->unload) image->dev->unload(image); image_clear(image); image_clear_error(image); osd_image_load_status_changed(image, is_final_unload); }
static void image_unload_internal(mess_image *img, int is_final_unload) { const struct IODevice *dev; int type = image_devtype(img); if ((img->status & IMAGE_STATUS_ISLOADED) == 0) return; dev = device_find(Machine->devices, type); assert(dev); if (dev->unload) dev->unload(img); if (img->fp) { mame_fclose(img->fp); img->fp = NULL; } pool_exit(&img->mempool); image_clear_error(img); img->status = 0; img->name = NULL; img->dir = NULL; img->hash = NULL; img->length = 0; img->longname = NULL; img->manufacturer = NULL; img->year = NULL; img->playable = NULL; img->extrainfo = NULL; img->basename_noext = NULL; osd_image_load_status_changed(img, is_final_unload); }
static int image_load_internal(mess_image *img, const char *name, int is_create, int create_format, option_resolution *create_args) { const struct IODevice *dev; const char *s; char *newname; int err = INIT_PASS; mame_file *file = NULL; UINT8 *buffer = NULL; UINT64 size; unsigned int readable, writeable, creatable; /* unload if we are loaded */ if (img->status & IMAGE_STATUS_ISLOADED) image_unload(img); /* clear out the error */ image_clear_error(img); /* if we are attempting to "load" NULL, then exit at this point */ if (!name) return INIT_PASS; dev = image_device(img); assert(dev); img->status |= IMAGE_STATUS_ISLOADING; if (name && *name) { newname = image_strdup(img, name); if (!newname) { err = IMAGE_ERROR_OUTOFMEMORY; goto error; } } else newname = NULL; img->name = newname; img->dir = NULL; osd_image_load_status_changed(img, 0); /* do we need to reset the CPU? */ if ((timer_get_time() > 0) && dev->reset_on_load) machine_reset(); /* prepare to open the file */ img->created = 0; img->writeable = 0; file = NULL; if (dev->getdispositions) { dev->getdispositions(dev, image_index_in_device(img), &readable, &writeable, &creatable); } else { readable = dev->readable; writeable = dev->writeable; creatable = dev->creatable; } /* is this a ZIP file? */ s = strrchr(img->name, '.'); if (s && !mame_stricmp(s, ".ZIP")) { /* ZIP files are writeable */ writeable = 0; creatable = 0; } if (readable && !writeable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ); } else if (!readable && writeable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_WRITE); img->writeable = file ? 1 : 0; } else if (readable && writeable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW); img->writeable = file ? 1 : 0; if (!file) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ); if (!file && creatable) { file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW_CREATE); img->writeable = file ? 1 : 0; img->created = file ? 1 : 0; } } } /* did this attempt succeed? */ if (!file) { img->err = IMAGE_ERROR_FILENOTFOUND; goto error; } /* if applicable, call device verify */ if (dev->imgverify && !image_has_been_created(img)) { size = mame_fsize(file); buffer = malloc(size); if (!buffer) { img->err = IMAGE_ERROR_OUTOFMEMORY; goto error; } if (mame_fread(file, buffer, (UINT32) size) != size) { img->err = IMAGE_ERROR_INVALIDIMAGE; goto error; } err = dev->imgverify(buffer, size); if (err) { img->err = IMAGE_ERROR_INVALIDIMAGE; goto error; } mame_fseek(file, 0, SEEK_SET); free(buffer); buffer = NULL; } /* call device load or create */ if (image_has_been_created(img) && dev->create) { err = dev->create(img, file, create_format, create_args); if (err) { if (!img->err) img->err = IMAGE_ERROR_UNSPECIFIED; goto error; } } else if (dev->load) { /* using device load */ err = dev->load(img, file); if (err) { if (!img->err) img->err = IMAGE_ERROR_UNSPECIFIED; goto error; } } img->status &= ~IMAGE_STATUS_ISLOADING; img->status |= IMAGE_STATUS_ISLOADED; return INIT_PASS; error: if (file) mame_fclose(file); if (buffer) free(buffer); if (img) { img->fp = NULL; img->name = NULL; img->status &= ~IMAGE_STATUS_ISLOADING|IMAGE_STATUS_ISLOADED; } osd_image_load_status_changed(img, 0); return INIT_FAIL; }