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(); } }
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(); } }
void ui_menu_control_device_image::handle() { switch(state) { case START_FILE: { bool can_create = false; if(image->is_creatable()) { zippath_directory *directory = NULL; file_error err = zippath_opendir(current_directory, &directory); can_create = err == FILERR_NONE && !zippath_is_zip(directory); if(directory) zippath_closedir(directory); } submenu_result = -1; ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_selector(machine(), container, image, current_directory, current_file, true, image->image_interface()!=NULL, can_create, &submenu_result))); state = SELECT_FILE; break; } case START_SOFTLIST: sld = 0; ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software(machine(), container, image->image_interface(), &sld))); state = SELECT_SOFTLIST; break; case START_OTHER_PART: { submenu_result = -1; ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, swp->interface_, &swp, true, &submenu_result))); state = SELECT_OTHER_PART; break; } case SELECT_SOFTLIST: if(!sld) { ui_menu::stack_pop(machine()); break; } software_info_name = ""; ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, sld, image->image_interface(), software_info_name))); state = SELECT_PARTLIST; break; case SELECT_PARTLIST: swl = software_list_open(machine().options(), sld->list_name(), false, NULL); swi = software_list_find(swl, software_info_name, NULL); if(swinfo_has_multiple_parts(swi, image->image_interface())) { submenu_result = -1; swp = 0; ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, image->image_interface(), &swp, false, &submenu_result))); state = SELECT_ONE_PART; } else { swp = software_find_part(swi, NULL, NULL); load_software_part(); software_list_close(swl); ui_menu::stack_pop(machine()); } break; case SELECT_ONE_PART: switch(submenu_result) { case ui_menu_software_parts::T_ENTRY: { load_software_part(); software_list_close(swl); ui_menu::stack_pop(machine()); break; } case -1: // return to list software_list_close(swl); state = SELECT_SOFTLIST; break; } break; case SELECT_OTHER_PART: switch(submenu_result) { case ui_menu_software_parts::T_ENTRY: { load_software_part(); break; } case ui_menu_software_parts::T_FMGR: state = START_FILE; handle(); break; case -1: // return to system ui_menu::stack_pop(machine()); break; } break; case SELECT_FILE: switch(submenu_result) { case ui_menu_file_selector::R_EMPTY: image->unload(); ui_menu::stack_pop(machine()); break; case ui_menu_file_selector::R_FILE: hook_load(current_file, false); break; case ui_menu_file_selector::R_CREATE: ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, image, current_directory, current_file))); state = CREATE_FILE; break; case ui_menu_file_selector::R_SOFTLIST: state = START_SOFTLIST; handle(); break; case -1: // return to system ui_menu::stack_pop(machine()); break; } break; case CREATE_FILE: { bool can_create, need_confirm; test_create(can_create, need_confirm); if(can_create) { if(need_confirm) { ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, &create_confirmed))); state = CREATE_CONFIRM; } else { state = DO_CREATE; handle(); } } else { state = START_FILE; handle(); } break; } case CREATE_CONFIRM: { state = create_confirmed ? DO_CREATE : START_FILE; handle(); break; } case DO_CREATE: { astring path; zippath_combine(path, current_directory, current_file); int err = image->create(path, 0, NULL); if (err != 0) popmessage("Error: %s", image->error()); ui_menu::stack_pop(machine()); break; } } }
void ui_menu_file_selector::handle() { file_error err; const file_selector_entry *entry; const file_selector_entry *selected_entry = NULL; int bestmatch = 0; // process the menu const ui_menu_event *event = process(0); if (event != NULL && event->itemref != NULL) { // handle selections if (event->iptkey == IPT_UI_SELECT) { entry = (const file_selector_entry *) event->itemref; switch(entry->type) { case SELECTOR_ENTRY_TYPE_EMPTY: // empty slot - unload *m_result = R_EMPTY; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_CREATE: // create *m_result = R_CREATE; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST: *m_result = R_SOFTLIST; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_DRIVE: case SELECTOR_ENTRY_TYPE_DIRECTORY: // drive/directory - first check the path err = zippath_opendir(entry->fullpath, NULL); if (err != FILERR_NONE) { // this path is problematic; present the user with an error and bail machine().ui().popup_time(1, "Error accessing %s", entry->fullpath); break; } m_current_directory.assign(entry->fullpath); reset((ui_menu_reset_options)0); break; case SELECTOR_ENTRY_TYPE_FILE: // file m_current_file.assign(entry->fullpath); *m_result = R_FILE; ui_menu::stack_pop(machine()); break; } // reset the char buffer when pressing IPT_UI_SELECT if (m_filename_buffer[0] != '\0') memset(m_filename_buffer, '\0', ARRAY_LENGTH(m_filename_buffer)); } else if (event->iptkey == IPT_SPECIAL) { int buflen = strlen(m_filename_buffer); bool update_selected = FALSE; // if it's a backspace and we can handle it, do so if ((event->unichar == 8 || event->unichar == 0x7f) && buflen > 0) { *(char *)utf8_previous_char(&m_filename_buffer[buflen]) = 0; update_selected = TRUE; if (ARRAY_LENGTH(m_filename_buffer) > 0) machine().ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename_buffer); } // if it's any other key and we're not maxed out, update else if (event->unichar >= ' ' && event->unichar < 0x7f) { buflen += utf8_from_uchar(&m_filename_buffer[buflen], ARRAY_LENGTH(m_filename_buffer) - buflen, event->unichar); m_filename_buffer[buflen] = 0; update_selected = TRUE; if (ARRAY_LENGTH(m_filename_buffer) > 0) machine().ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename_buffer); } if (update_selected) { const file_selector_entry *cur_selected = (const file_selector_entry *)get_selection(); // check for entries which matches our m_filename_buffer: // from current entry to the end for (entry = cur_selected; entry != NULL; entry = entry->next) { if (entry->basename != NULL && m_filename_buffer != NULL) { int match = 0; for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++) { if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = entry; } } } // and from the first entry to current one for (entry = m_entrylist; entry != cur_selected; entry = entry->next) { if (entry->basename != NULL && m_filename_buffer != NULL) { int match = 0; for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++) { if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = entry; } } } if (selected_entry != NULL && selected_entry != cur_selected) set_selection((void *) selected_entry); } } else if (event->iptkey == IPT_UI_CANCEL) { // reset the char buffer also in this case if (m_filename_buffer[0] != '\0') memset(m_filename_buffer, '\0', ARRAY_LENGTH(m_filename_buffer)); } } }
void ui_menu_file_selector::populate() { zippath_directory *directory = NULL; file_error err; const osd_directory_entry *dirent; const file_selector_entry *entry; const file_selector_entry *selected_entry = NULL; int i; const char *volume_name; const char *path = m_current_directory.c_str(); // open the directory err = zippath_opendir(path, &directory); // clear out the menu entries m_entrylist = NULL; if (m_has_empty) { // add the "[empty slot]" entry append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL); } if (m_has_create) { // add the "[create]" entry append_entry(SELECTOR_ENTRY_TYPE_CREATE, NULL, NULL); } if (m_has_softlist) { // add the "[software list]" entry entry = append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL); selected_entry = entry; } // add the drives i = 0; while((volume_name = osd_get_volume_name(i))!=NULL) { append_entry(SELECTOR_ENTRY_TYPE_DRIVE, volume_name, volume_name); i++; } // build the menu for each item if (err == FILERR_NONE) { while((dirent = zippath_readdir(directory)) != NULL) { // append a dirent entry entry = append_dirent_entry(dirent); if (entry != NULL) { // set the selected item to be the first non-parent directory or file if ((selected_entry == NULL) && strcmp(dirent->name, "..")) selected_entry = entry; // do we have to select this file? if (!core_stricmp(m_current_file.c_str(), dirent->name)) selected_entry = entry; } } } // append all of the menu entries for (entry = m_entrylist; entry != NULL; entry = entry->next) append_entry_menu_item(entry); // set the selection (if we have one) if (selected_entry != NULL) set_selection((void *) selected_entry); // set up custom render proc customtop = machine().ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER; if (directory != NULL) zippath_closedir(directory); }
void ui_menu_file_selector::populate() { zippath_directory *directory = NULL; file_error err = FILERR_NONE; const osd_directory_entry *dirent; const file_selector_entry *entry; const file_selector_entry *selected_entry = NULL; int i; const char *volume_name; const char *path = current_directory; /* open the directory */ err = zippath_opendir(path, &directory); if (err != FILERR_NONE) goto done; /* clear out the menu entries */ entrylist = NULL; if (has_empty) { /* add the "[empty slot]" entry */ append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL); } if (has_create) { /* add the "[create]" entry */ append_entry(SELECTOR_ENTRY_TYPE_CREATE, NULL, NULL); } if (has_softlist) /* add the "[software list]" entry */ append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL); /* add the drives */ i = 0; while((volume_name = osd_get_volume_name(i))!=NULL) { append_entry(SELECTOR_ENTRY_TYPE_DRIVE, volume_name, volume_name); i++; } /* build the menu for each item */ while((dirent = zippath_readdir(directory)) != NULL) { /* append a dirent entry */ entry = append_dirent_entry(dirent); if (entry != NULL) { /* set the selected item to be the first non-parent directory or file */ if ((selected_entry == NULL) && strcmp(dirent->name, "..")) selected_entry = entry; /* do we have to select this file? */ if (!mame_stricmp(current_file, dirent->name)) selected_entry = entry; } } /* append all of the menu entries */ for (entry = entrylist; entry != NULL; entry = entry->next) append_entry_menu_item(entry); /* set the selection (if we have one) */ if (selected_entry != NULL) set_selection((void *) selected_entry); /* set up custom render proc */ customtop = ui_get_line_height(machine()) + 3.0f * UI_BOX_TB_BORDER; done: if (directory != NULL) zippath_closedir(directory); }
void ui_menu_control_device_image::handle() { switch(state) { case START_FILE: { bool can_create = false; if(image->is_creatable()) { zippath_directory *directory = nullptr; osd_file::error err = zippath_opendir(current_directory.c_str(), &directory); can_create = err == osd_file::error::NONE && !zippath_is_zip(directory); if(directory) zippath_closedir(directory); } submenu_result = -1; ui_menu::stack_push(global_alloc_clear<ui_menu_file_selector>(machine(), container, image, current_directory, current_file, true, image->image_interface()!=nullptr, can_create, &submenu_result)); state = SELECT_FILE; break; } case START_SOFTLIST: sld = nullptr; ui_menu::stack_push(global_alloc_clear<ui_menu_software>(machine(), container, image->image_interface(), &sld)); state = SELECT_SOFTLIST; break; case START_OTHER_PART: { submenu_result = -1; ui_menu::stack_push(global_alloc_clear<ui_menu_software_parts>(machine(), container, swi, swp->interface(), &swp, true, &submenu_result)); state = SELECT_OTHER_PART; break; } case SELECT_SOFTLIST: if(!sld) { ui_menu::stack_pop(machine()); break; } software_info_name = ""; ui_menu::stack_push(global_alloc_clear<ui_menu_software_list>(machine(), container, sld, image->image_interface(), software_info_name)); state = SELECT_PARTLIST; break; case SELECT_PARTLIST: swi = sld->find(software_info_name.c_str()); if (!swi) state = START_SOFTLIST; else if(swi->has_multiple_parts(image->image_interface())) { submenu_result = -1; swp = nullptr; ui_menu::stack_push(global_alloc_clear<ui_menu_software_parts>(machine(), container, swi, image->image_interface(), &swp, false, &submenu_result)); state = SELECT_ONE_PART; } else { swp = swi->first_part(); load_software_part(); } break; case SELECT_ONE_PART: switch(submenu_result) { case ui_menu_software_parts::T_ENTRY: { load_software_part(); break; } case -1: // return to list state = SELECT_SOFTLIST; break; } break; case SELECT_OTHER_PART: switch(submenu_result) { case ui_menu_software_parts::T_ENTRY: load_software_part(); break; case ui_menu_software_parts::T_FMGR: state = START_FILE; handle(); break; case ui_menu_software_parts::T_EMPTY: image->unload(); ui_menu::stack_pop(machine()); break; case ui_menu_software_parts::T_SWLIST: state = START_SOFTLIST; handle(); break; case -1: // return to system ui_menu::stack_pop(machine()); break; } break; case SELECT_FILE: switch(submenu_result) { case ui_menu_file_selector::R_EMPTY: image->unload(); ui_menu::stack_pop(machine()); break; case ui_menu_file_selector::R_FILE: hook_load(current_file, false); break; case ui_menu_file_selector::R_CREATE: ui_menu::stack_push(global_alloc_clear<ui_menu_file_create>(machine(), container, image, current_directory, current_file, &create_ok)); state = CHECK_CREATE; break; case ui_menu_file_selector::R_SOFTLIST: state = START_SOFTLIST; handle(); break; case -1: // return to system ui_menu::stack_pop(machine()); break; } break; case CREATE_FILE: { bool can_create, need_confirm; test_create(can_create, need_confirm); if(can_create) { if(need_confirm) { ui_menu::stack_push(global_alloc_clear<ui_menu_confirm_save_as>(machine(), container, &create_confirmed)); state = CREATE_CONFIRM; } else { state = DO_CREATE; handle(); } } else { state = START_FILE; handle(); } break; } case CREATE_CONFIRM: state = create_confirmed ? DO_CREATE : START_FILE; handle(); break; case CHECK_CREATE: state = create_ok ? CREATE_FILE : START_FILE; handle(); break; case DO_CREATE: { std::string path; zippath_combine(path, current_directory.c_str(), current_file.c_str()); int err = image->create(path.c_str(), nullptr, nullptr); if (err != 0) machine().popmessage("Error: %s", image->error()); ui_menu::stack_pop(machine()); break; } } }
void node_testzippath(xml_data_node *node) { xml_attribute_node *attr_node; xml_data_node *first_child_node; xml_data_node *child_node; const char *path; const char *plus; astring *apath = NULL; zippath_directory *directory = NULL; const osd_directory_entry *dirent; const char *type_string; file_error err; UINT64 size; mess_pile pile; core_file *file = NULL; pile_init(&pile); /* name the test case */ report_testcase_begin("zippath"); /* retrieve path */ attr_node = xml_get_attribute(node, "path"); path = (attr_node != NULL) ? attr_node->value : ""; /* retrieve 'plus' - for testing zippath_combine */ attr_node = xml_get_attribute(node, "plus"); if (attr_node != NULL) { plus = attr_node->value; apath = zippath_combine(astring_alloc(), path, plus); report_message(MSG_INFO, "Testing ZIP Path '%s' + '%s' ==> '%s'", path, plus, astring_c(apath)); } else { apath = astring_cpyc(astring_alloc(), path); report_message(MSG_INFO, "Testing ZIP Path '%s'", astring_c(apath)); } /* try doing a file compare */ messtest_get_data(node, &pile); if (pile_size(&pile) > 0) { err = zippath_fopen(astring_c(apath), OPEN_FLAG_READ, &file, NULL); if (err != FILERR_NONE) { report_message(MSG_FAILURE, "Error %d opening file", (int) err); goto done; } if (pile_size(&pile) != core_fsize(file)) { report_message(MSG_FAILURE, "Expected file to be of length %d, instead got %d", (int) pile_size(&pile), (int) core_fsize(file)); goto done; } if (memcmp(pile_getptr(&pile), core_fbuffer(file), pile_size(&pile))) { report_message(MSG_FAILURE, "File sizes match, but contents do not"); goto done; } } /* try doing a directory listing */ first_child_node = xml_get_sibling(node->child, "entry"); if (first_child_node != NULL) { err = zippath_opendir(astring_c(apath), &directory); if (err != FILERR_NONE) { report_message(MSG_FAILURE, "Error %d opening directory", (int) err); goto done; } /* read each directory entry */ while((dirent = zippath_readdir(directory)) != NULL) { /* find it in the list */ for (child_node = first_child_node; child_node != NULL; child_node = xml_get_sibling(child_node->next, "entry")) { attr_node = xml_get_attribute(child_node, "name"); if ((attr_node != NULL) && !strcmp(attr_node->value, dirent->name)) break; } /* did we find the node? */ if (child_node != NULL) { /* check dirent type */ attr_node = xml_get_attribute(child_node, "type"); if (attr_node != NULL) { type_string = dir_entry_type_string(dirent->type); if (mame_stricmp(attr_node->value, type_string)) report_message(MSG_FAILURE, "Expected '%s' to be '%s', but instead got '%s'", dirent->name, attr_node->value, type_string); } /* check size */ attr_node = xml_get_attribute(child_node, "size"); if (attr_node != NULL) { size = atoi(attr_node->value); if (size != dirent->size) report_message(MSG_FAILURE, "Expected '%s' to be of size '%ld', but instead got '%ld'", dirent->name, (long) size, (long) dirent->size); } } else { report_message(MSG_FAILURE, "Unexpected directory entry '%s'", dirent->name); } } } done: pile_delete(&pile); if (apath != NULL) astring_free(apath); if (file != NULL) core_fclose(file); if (directory != NULL) zippath_closedir(directory); }