/* this code tries opening the image as a raw ZIP file, and if relevant, returns the * zip file and the entry */ char *mess_try_image_file_as_zip(int pathindex, const char *path, const struct IODevice *dev) { zip_file *zip = NULL; zip_entry *zipentry = NULL; char *name; const char *ext; int is_zip; char *new_path = NULL; char path_sep[2] = { PATH_SEPARATOR, '\0' }; name = osd_basename((char *) path); if (!name) goto done; ext = strrchr(name, '.'); is_zip = (ext && !mame_stricmp(ext, ".zip")); if (is_zip) { zip = openzip(FILETYPE_IMAGE, pathindex, path); if (!zip) goto done; while((zipentry = readzip(zip)) != NULL) { ext = strrchr(zipentry->name, '.'); if (!dev || (ext && findextension(dev->file_extensions, ext))) { new_path = malloc(strlen(path) + 1 + strlen(zipentry->name) + 1); if (!new_path) goto done; strcpy(new_path, path); strcat(new_path, path_sep); strcat(new_path, zipentry->name); break; } } } done: if (zip) closezip(zip); return new_path; }
const char *image_basename(mess_image *img) { return osd_basename((char *) image_filename(img)); }
static char *battery_nvramfilename(mess_image *img) { const char *filename; filename = image_filename(img); return strip_extension(osd_basename((char *) filename)); }
static mame_file *image_fopen_custom(mess_image *img, int filetype, int read_or_write) { const char *sysname; char *lpExt; const game_driver *gamedrv = Machine->gamedrv; assert(img); if (!img->name) return NULL; if (img->fp) { /* If already open, we won't open the file again until it is closed. */ return NULL; } do { sysname = gamedrv->name; logerror("image_fopen: trying %s for system %s\n", img->name, sysname); img->fp = mame_fopen(sysname, img->name, filetype, read_or_write); if (img->fp && (read_or_write == OSD_FOPEN_READ)) { lpExt = strrchr( img->name, '.' ); if (lpExt && (mame_stricmp( lpExt, ".ZIP" ) == 0)) { int pathindex; int pathcount = osd_get_path_count(filetype); zip_file *zipfile; zip_entry *zipentry; char *newname; char *name; char *zipname; const char *ext; const struct IODevice *dev; mame_fclose( img->fp ); img->fp = NULL; dev = image_device(img); assert(dev); newname = NULL; zipname = image_malloc( img, strlen( sysname ) + 1 + strlen( img->name ) + 1 ); if( osd_is_absolute_path( img->name ) ) { strcpy( zipname, img->name ); } else { strcpy( zipname, sysname ); strcat( zipname, osd_path_separator() ); strcat( zipname, img->name ); } for (pathindex = 0; pathindex < pathcount; pathindex++) { zipfile = openzip(filetype, pathindex, zipname); if (zipfile) { zipentry = readzip(zipfile); while( zipentry ) { /* mess doesn't support paths in zip files */ name = osd_basename( zipentry->name ); lpExt = strrchr(name, '.'); if (lpExt) { lpExt++; ext = dev->file_extensions; while(*ext) { if( mame_stricmp( lpExt, ext ) == 0 ) { if( newname ) { image_freeptr( img, newname ); } newname = image_malloc(img, strlen(img->name) + 1 + strlen(name) + 1); if (!newname) return NULL; strcpy(newname, img->name); strcat(newname, osd_path_separator()); strcat(newname, name); } ext += strlen(ext) + 1; } } zipentry = readzip(zipfile); } closezip(zipfile); } if( !newname ) { return NULL; } img->fp = mame_fopen(sysname, newname, filetype, read_or_write); if (img->fp) { image_freeptr(img, img->name); img->name = newname; break; } } image_freeptr( img, zipname ); } } gamedrv = mess_next_compatible_driver(gamedrv); } while(!img->fp && gamedrv); if (img->fp) { logerror("image_fopen: found image %s for system %s\n", img->name, sysname); img->length = mame_fsize(img->fp); img->hash = NULL; } return img->fp; }