ui_menu_control_device_image::ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu(machine, container) { image = _image; sld = 0; swi = image->software_entry(); swp = image->part_entry(); if(swi) { state = START_OTHER_PART; current_directory.cpy(image->working_directory()); } else { state = START_FILE; /* if the image exists, set the working directory to the parent directory */ if (image->exists()) { current_file.cpy(image->filename()); zippath_parent(current_directory, current_file); } else current_directory.cpy(image->working_directory()); /* check to see if the path exists; if not clear it */ if (zippath_opendir(current_directory, NULL) != FILERR_NONE) current_directory.reset(); } }
image_error_t device_image_interface::set_image_filename(const char *filename) { m_image_name = filename; zippath_parent(m_working_directory, filename); m_basename.cpy(m_image_name); int loc1 = m_image_name.rchr(0,'\\'); int loc2 = m_image_name.rchr(0,'/'); int loc3 = m_image_name.rchr(0,':'); int loc = MAX(loc1,MAX(loc2,loc3)); if (loc!=-1) { if (loc == loc3) { // temp workaround for softlists now that m_image_name contains the part name too (e.g. list:gamename:cart) astring tmpstr = astring(m_basename.substr(0,loc)); int tmploc = tmpstr.rchr(0,':'); m_basename = m_basename.substr(tmploc + 1,loc-tmploc); } else m_basename = m_basename.substr(loc + 1,m_basename.len()-loc); } m_basename_noext = m_basename.cpy(m_basename); m_filetype = ""; loc = m_basename_noext.rchr(0,'.'); if (loc!=-1) { m_basename_noext = m_basename_noext.substr(0,loc); m_filetype = m_basename.cpy(m_basename); m_filetype = m_filetype.substr(loc + 1,m_filetype.len()-loc); } return IMAGE_ERROR_SUCCESS; }
image_error_t device_image_interface::set_image_filename(const char *filename) { m_image_name = filename; zippath_parent(m_working_directory, filename); m_basename.assign(m_image_name); size_t loc1 = m_image_name.find_last_of('\\'); size_t loc2 = m_image_name.find_last_of('/'); size_t loc3 = m_image_name.find_last_of(':'); size_t loc = MAX(loc1,MAX(loc2, loc3)); if (loc != -1) { if (loc == loc3) { // temp workaround for softlists now that m_image_name contains the part name too (e.g. list:gamename:cart) m_basename = m_basename.substr(0, loc); size_t tmploc = m_basename.find_last_of(':'); m_basename = m_basename.substr(tmploc + 1, loc - tmploc); } else m_basename = m_basename.substr(loc + 1); } m_basename_noext = m_basename; m_filetype = ""; loc = m_basename_noext.find_last_of('.'); if (loc != -1) { m_basename_noext = m_basename_noext.substr(0, loc); m_filetype = m_basename.substr(loc + 1); } return IMAGE_ERROR_SUCCESS; }
ui_menu_control_device_image::ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu(machine, container), submenu_result(0), create_ok(false), create_confirmed(false) { image = _image; sld = nullptr; if (image->software_list_name()) { software_list_device_iterator iter(machine.config().root_device()); for (software_list_device *swlist = iter.first(); swlist != nullptr; swlist = iter.next()) { if (strcmp(swlist->list_name(),image->software_list_name())==0) sld = swlist; } } swi = image->software_entry(); swp = image->part_entry(); if(swi) { state = START_OTHER_PART; current_directory.assign(image->working_directory()); } else { state = START_FILE; /* if the image exists, set the working directory to the parent directory */ if (image->exists()) { current_file.assign(image->filename()); zippath_parent(current_directory, current_file.c_str()); } else current_directory.assign(image->working_directory()); /* check to see if the path exists; if not clear it */ if (zippath_opendir(current_directory.c_str(), nullptr) != osd_file::error::NONE) current_directory.clear(); } }
ui_menu_control_device_image::ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu(machine, container) { image = _image; sld = 0; if (image->software_list_name()) { software_list_device_iterator iter(machine.config().root_device()); for (software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) { if (strcmp(swlist->list_name(),image->software_list_name())==0) sld = swlist; } } swi = image->software_entry(); swp = image->part_entry(); if(swi) { state = START_OTHER_PART; current_directory.cpy(image->working_directory()); } else { state = START_FILE; /* if the image exists, set the working directory to the parent directory */ if (image->exists()) { current_file.cpy(image->filename()); zippath_parent(current_directory, current_file); } else current_directory.cpy(image->working_directory()); /* check to see if the path exists; if not clear it */ if (zippath_opendir(current_directory, NULL) != FILERR_NONE) current_directory.reset(); } }
std::string &zippath_combine(std::string &dst, const char *path1, const char *path2) { if (!strcmp(path2, ".")) { dst.assign(path1); } else if (!strcmp(path2, "..")) { zippath_parent(dst, path1); } else if (osd_is_absolute_path(path2)) { dst.assign(path2); } else if ((path1[0] != '\0') && !is_path_separator(path1[strlen(path1) - 1])) { dst.assign(path1).append(PATH_SEPARATOR).append(path2); } else { dst.assign(path1).append(path2); } return dst; }
image_error_t device_image_interface::set_image_filename(const char *filename) { m_image_name = filename; zippath_parent(m_working_directory, filename); m_basename.cpy(m_image_name); int loc1 = m_image_name.rchr(0,'\\'); int loc2 = m_image_name.rchr(0,'/'); int loc3 = m_image_name.rchr(0,':'); int loc = MAX(loc1,MAX(loc2,loc3)); if (loc!=-1) { m_basename = m_basename.substr(loc + 1,m_basename.len()-loc); } m_basename_noext = m_basename.cpy(m_basename); m_filetype = ""; loc = m_basename_noext.rchr(0,'.'); if (loc!=-1) { m_basename_noext = m_basename_noext.substr(0,loc); m_filetype = m_basename.cpy(m_basename); m_filetype = m_filetype.substr(loc + 1,m_filetype.len()-loc); } return IMAGE_ERROR_SUCCESS; }
static file_error zippath_resolve(const char *path, osd_dir_entry_type &entry_type, zip_file *&zipfile, std::string &newpath) { file_error err; osd_directory_entry *current_entry = NULL; osd_dir_entry_type current_entry_type; int went_up = FALSE; int i; newpath.clear(); /* be conservative */ entry_type = ENTTYPE_NONE; zipfile = NULL; std::string apath(path); std::string apath_trimmed; do { /* trim the path of trailing path separators */ i = apath.length(); while (i > 1 && is_path_separator(apath[i - 1])) i--; apath = apath.substr(0, i); apath_trimmed.assign(apath); /* stat the path */ current_entry = osd_stat(apath_trimmed.c_str()); /* did we find anything? */ if (current_entry != NULL) { /* get the entry type and free the stat entry */ current_entry_type = current_entry->type; osd_free(current_entry); current_entry = NULL; } else { /* if we have not found the file or directory, go up */ current_entry_type = ENTTYPE_NONE; went_up = TRUE; std::string parent; apath.assign(zippath_parent(parent, apath.c_str())); } } while (current_entry_type == ENTTYPE_NONE && !is_root(apath.c_str())); /* if we did not find anything, then error out */ if (current_entry_type == ENTTYPE_NONE) { err = FILERR_NOT_FOUND; goto done; } /* is this file a ZIP file? */ if ((current_entry_type == ENTTYPE_FILE) && is_zip_file(apath_trimmed.c_str()) && (zip_file_open(apath_trimmed.c_str(), &zipfile) == ZIPERR_NONE)) { i = strlen(path + apath.length()); while (i > 0 && is_zip_path_separator(path[apath.length() + i - 1])) i--; newpath.assign(path + apath.length(), i); /* this was a true ZIP path - attempt to identify the type of path */ zippath_find_sub_path(zipfile, newpath.c_str(), ¤t_entry_type); if (current_entry_type == ENTTYPE_NONE) { err = FILERR_NOT_FOUND; goto done; } } else { /* this was a normal path */ if (went_up) { err = FILERR_NOT_FOUND; goto done; } newpath.assign(path); } /* success! */ entry_type = current_entry_type; err = FILERR_NONE; done: return err; }
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&file, std::string &revised_path) { file_error filerr = FILERR_NOT_FOUND; zip_error ziperr; zip_file *zip = NULL; const zip_file_header *header; osd_dir_entry_type entry_type; char *alloc_fullpath = NULL; int len; /* first, set up the two types of paths */ std::string mainpath(filename); std::string subpath; file = NULL; /* loop through */ while((file == NULL) && (mainpath.length() > 0) && ((openflags == OPEN_FLAG_READ) || (subpath.length() == 0))) { /* is the mainpath a ZIP path? */ if (is_zip_file(mainpath.c_str())) { /* this file might be a zip file - lets take a look */ ziperr = zip_file_open(mainpath.c_str(), &zip); if (ziperr == ZIPERR_NONE) { /* it is a zip file - error if we're not opening for reading */ if (openflags != OPEN_FLAG_READ) { filerr = FILERR_ACCESS_DENIED; goto done; } if (subpath.length() > 0) header = zippath_find_sub_path(zip, subpath.c_str(), &entry_type); else header = zip_file_first_file(zip); if (header == NULL) { filerr = FILERR_NOT_FOUND; goto done; } /* attempt to read the file */ filerr = create_core_file_from_zip(zip, header, file); if (filerr != FILERR_NONE) goto done; /* update subpath, if appropriate */ if (subpath.length() == 0) subpath.assign(header->filename); /* we're done */ goto done; } } else if (is_7z_file(mainpath.c_str())) { filerr = FILERR_INVALID_DATA; goto done; } if (subpath.length() == 0) filerr = core_fopen(filename, openflags, &file); else filerr = FILERR_NOT_FOUND; /* if we errored, then go up a directory */ if (filerr != FILERR_NONE) { /* go up a directory */ std::string temp; zippath_parent(temp, mainpath.c_str()); /* append to the sub path */ if (subpath.length() > 0) { std::string temp2; mainpath = mainpath.substr(temp.length()); temp2.assign(mainpath).append(PATH_SEPARATOR).append(subpath); subpath.assign(temp2); } else { mainpath = mainpath.substr(temp.length()); subpath.assign(mainpath); } /* get the new main path, truncating path separators */ len = temp.length(); while (len > 0 && is_zip_file_separator(temp[len - 1])) len--; temp = temp.substr(0, len); mainpath.assign(temp); } } done: /* store the revised path */ revised_path.clear(); if (filerr == FILERR_NONE) { /* cannonicalize mainpath */ filerr = osd_get_full_path(&alloc_fullpath, mainpath.c_str()); if (filerr == FILERR_NONE) { if (subpath.length() > 0) revised_path.assign(alloc_fullpath).append(PATH_SEPARATOR).append(subpath); else revised_path.assign(alloc_fullpath); } } if (zip != NULL) zip_file_close(zip); if (alloc_fullpath != NULL) osd_free(alloc_fullpath); return filerr; }