void device_image_interface::setup_working_directory() { bool success = false; // get user-specified directory and make sure it exists m_working_directory = device().mconfig().options().sw_path(); // if multipath, get first size_t i = m_working_directory.find_first_of(";"); if (i != std::string::npos) m_working_directory.resize(i); // validate directory if (!m_working_directory.empty()) if (osd::directory::open(m_working_directory)) success = true; // if not exist, use previous method if (!success) { // first set up the working directory to be the starting directory osd_get_full_path(m_working_directory, "."); // now try browsing down to "software" if (try_change_working_directory("software")) success = true; } if (success) { // now down to a directory for this computer int gamedrv = driver_list::find(device().machine().system()); while(gamedrv != -1 && !try_change_working_directory(driver_list::driver(gamedrv).name)) { gamedrv = driver_list::compatible_with(gamedrv); } } }
ui_menu_add_change_folder::ui_menu_add_change_folder(running_machine &machine, render_container *container, int ref, bool _change) : ui_menu(machine, container) { m_ref = ref - 1; m_change = _change; m_search[0] = '\0'; // configure the starting's path char *dst = nullptr; osd_get_full_path(&dst, "."); m_current_path = dst; osd_free(dst); }
void device_image_interface::setup_working_directory() { // first set up the working directory to be the starting directory osd_get_full_path(m_working_directory, "."); // now try browsing down to "software" if (try_change_working_directory("software")) { // now down to a directory for this computer int gamedrv = driver_list::find(device().machine().system()); while(gamedrv != -1 && !try_change_working_directory(driver_list::driver(gamedrv).name)) { gamedrv = driver_list::compatible_with(gamedrv); } } }
void device_image_interface::setup_working_directory() { char *dst = NULL; osd_get_full_path(&dst,"."); /* first set up the working directory to be the starting directory */ m_working_directory = dst; /* now try browsing down to "software" */ if (try_change_working_directory("software")) { /* now down to a directory for this computer */ int gamedrv = driver_list::find(device().machine().system()); while(gamedrv != -1 && !try_change_working_directory(driver_list::driver(gamedrv).name)) { gamedrv = driver_list::compatible_with(gamedrv); } } osd_free(dst); }
menu_add_change_folder::menu_add_change_folder(mame_ui_manager &mui, render_container &container, int ref) : menu(mui, container) { m_ref = ref; m_change = (s_folders[ref].action == CHANGE); m_search[0] = '\0'; // configure the starting path osd_get_full_path(m_current_path, "."); std::string searchpath; if (mui.options().exists(s_folders[m_ref].option)) searchpath = mui.options().value(s_folders[m_ref].option); else searchpath = mui.machine().options().value(s_folders[m_ref].option); path_iterator path(searchpath.c_str()); std::string curpath; while (path.next(curpath, nullptr)) m_folders.push_back(curpath); }
menu_control_device_image::menu_control_device_image(mame_ui_manager &mui, render_container &container, device_image_interface &image) : menu(mui, container) , m_image(image) , m_create_ok(false) , m_create_confirmed(false) { m_submenu_result.i = -1; if (m_image.software_list_name()) m_sld = software_list_device::find_by_name(mui.machine().config(), m_image.software_list_name()); else m_sld = nullptr; m_swi = m_image.software_entry(); m_swp = m_image.part_entry(); if (m_swi != nullptr) { m_state = START_OTHER_PART; m_current_directory = m_image.working_directory(); } else { m_state = START_FILE; // if the image exists, set the working directory to the parent directory if (m_image.exists()) { m_current_file.assign(m_image.filename()); util::zippath_parent(m_current_directory, m_current_file); } else { m_current_directory = m_image.working_directory(); } // check to see if the path exists; if not then set to current directory util::zippath_directory::ptr dir; if (util::zippath_directory::open(m_current_directory, dir) != osd_file::error::NONE) osd_get_full_path(m_current_directory, "."); } }
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; }
static BOOL DevView_GetOpenFileName(HWND hwndDevView, const machine_config *config, const device_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength) { BOOL bResult = 0; TCHAR *t_s; int i = 0; mess_image_type imagetypes[256]; HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); int drvindex = Picker_GetSelectedItem(hwndList); std::string as, dst; const char *s, *opt_name = dev->instance_name(); windows_options o; load_options(o, OPTIONS_GAME, drvindex); s = o.value(opt_name); /* Get the path to the currently mounted image */ util::zippath_parent(as, s); dst = as; /* See if an image was loaded, and that the path still exists */ if ((!osd::directory::open(as.c_str())) || (as.find(':') == std::string::npos)) { /* Get the path from the software tab */ int driver_index = drvindex; windows_options o; load_options(o, OPTIONS_GAME, driver_index); const char* paths = o.value(OPTION_SWPATH); if (paths && (paths[0] > 64)) {} else // search deeper when looking for software { // not specified in driver, try parent if it has one int nParentIndex = -1; if (DriverIsClone(driver_index) == TRUE) { nParentIndex = GetParentIndex(&driver_list::driver(driver_index)); if (nParentIndex >= 0) { load_options(o, OPTIONS_PARENT, nParentIndex); paths = o.value(OPTION_SWPATH); } } if (paths && (paths[0] > 64)) {} else { // still nothing, try for a system in the 'compat' field if (nParentIndex >= 0) driver_index = nParentIndex; // now recycle variable as a compat system number nParentIndex = GetCompatIndex(&driver_list::driver(driver_index)); if (nParentIndex >= 0) { load_options(o, OPTIONS_PARENT, nParentIndex); paths = o.value(OPTION_SWPATH); } } } as = paths; /* We only want the first path; throw out the rest */ i = as.find(';'); if (i > 0) as.substr(0, i); dst = as; /* Make sure a folder was specified in the tab, and that it exists */ if ((!osd::directory::open(as.c_str())) || (as.find(':') == std::string::npos)) { // Get the global loose software path as = GetSWDir(); /* We only want the first path; throw out the rest */ i = as.find(';'); if (i > 0) as.substr(0, i); dst = as; /* Make sure a folder was specified in the tab, and that it exists */ if ((!osd::directory::open(as.c_str())) || (as.find(':') == std::string::npos)) { /* Default to emu directory */ osd_get_full_path(dst,"."); } } } SetupImageTypes(config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); t_s = ui_wstring_from_utf8(dst.c_str()); bResult = CommonFileImageDialog(t_s, GetOpenFileName, pszFilename, config, imagetypes); CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); free(t_s); return bResult; }
static BOOL DevView_GetOpenItemName(HWND hwndDevView, const machine_config *config, const device_image_interface *dev, LPTSTR pszFilename, UINT nFilenameLength) { BOOL bResult = 0; TCHAR *t_s; int i = 0; mess_image_type imagetypes[256]; HWND hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); int drvindex = Picker_GetSelectedItem(hwndList); std::string as, dst; const char *s, *opt_name = dev->instance_name(); windows_options o; load_options(o, OPTIONS_GAME, drvindex); s = o.value(opt_name); /* Get the path to the currently mounted image, chop off any trailing backslash */ util::zippath_parent(as, s); size_t t1 = as.length()-1; if (as[t1] == '\\') as[t1]='\0'; dst = as; /* See if an image was loaded, and that the path still exists */ if ((!osd::directory::open(as.c_str())) || (as.find(':') == std::string::npos)) { /* Get the path from the SL base */ as = GetSLDir(); /* We only want the first path; throw out the rest */ i = as.find(';'); if (i > 0) as.substr(0, i); // Get the path to suitable software i = 0; for (software_list_device &swlist : software_list_device_iterator(config->root_device())) { for (const software_info &swinfo : swlist.get_info()) { const software_part &part = swinfo.parts().front(); if (swlist.is_compatible(part) == SOFTWARE_IS_COMPATIBLE) { for (device_image_interface &image : image_interface_iterator(config->root_device())) { if ((i == 0) && (std::string(opt_name) == std::string(image.instance_name()))) { const char *interface = image.image_interface(); if (interface != nullptr && part.matches_interface(interface)) { as.append("\\").append(swlist.list_name()); i++; } } } } } } dst = as; /* Make sure a folder was specified in the tab, and that it exists */ if ((!osd::directory::open(as.c_str())) || (as.find(':') == std::string::npos)) { /* Default to emu directory */ osd_get_full_path(dst,"."); } } SetupImageTypes(config, imagetypes, ARRAY_LENGTH(imagetypes), TRUE, dev); t_s = ui_wstring_from_utf8(dst.c_str()); bResult = CommonFileImageDialog(t_s, GetOpenFileName, pszFilename, config, imagetypes); CleanupImageTypes(imagetypes, ARRAY_LENGTH(imagetypes)); // This crappy code is typical of what you get with strings in c++ // All we want to do is get the Item name out of the full path char t2[nFilenameLength]; wcstombs(t2, pszFilename, nFilenameLength-1); // convert wide string to a normal one std::string t3 = t2; // then convert to a c++ string so we can manipulate it t1 = t3.find(".zip"); // get rid of zip name and anything after if (t1) t3[t1] = '\0'; t1 = t3.find(".7z"); // get rid of 7zip name and anything after if (t1) t3[t1] = '\0'; // t1 = t3.find_last_of("\\"); // we can force the swlist name in, if needed // t3[t1] = ':'; t1 = t3.find_last_of("\\"); // get rid of path; we only want the item name t3.erase(0, t1+1); // set up editbox display text mbstowcs(pszFilename, t3.c_str(), nFilenameLength-1); // convert it back to a wide string // set up inifile text to signify to MAME that a SW ITEM is to be used strcpy(g_szSelectedSoftware, t3.c_str()); // store to global item name strcpy(g_szSelectedDevice, opt_name); // get media-device name (brief_instance_name is ok too) free(t_s); return bResult; }