software_list_device *software_list_device::find_by_name(const machine_config &config, const std::string &name) { // iterate over each device in the system and find a match for (software_list_device &swlistdev : software_list_device_iterator(config.root_device())) if (swlistdev.list_name() == name) return &swlistdev; return nullptr; }
const software_part *device_image_interface::find_software_item(const std::string &identifier, bool restrict_to_interface, software_list_device **dev) const { // split full software name into software list name and short software name std::string list_name, software_name, part_name; if (!software_name_parse(identifier, &list_name, &software_name, &part_name)) return nullptr; // determine interface const char *interface = restrict_to_interface ? image_interface() : nullptr; // find the software list if explicitly specified for (software_list_device &swlistdev : software_list_device_iterator(device().mconfig().root_device())) { if (list_name.empty() || (list_name == swlistdev.list_name())) { const software_info *info = swlistdev.find(software_name); if (info != nullptr) { const software_part *part = info->find_part(part_name, interface); if (part != nullptr) { if (dev != nullptr) *dev = &swlistdev; return part; } } } if (software_name == swlistdev.list_name()) { // ad hoc handling for the case path = swlist_name:swinfo_name (e.g. // gameboy:sml) which is not handled properly by software_name_split // since the function cannot distinguish between this and the case // path = swinfo_name:swpart_name const software_info *info = swlistdev.find(part_name); if (info != nullptr) { const software_part *part = info->find_part("", interface); if (part != nullptr) { if (dev != nullptr) *dev = &swlistdev; return part; } } } } // if explicitly specified and not found, just error here if (dev != nullptr) *dev = nullptr; return nullptr; }
const software_part *device_image_interface::find_software_item(const char *path, bool restrict_to_interface) const { // split full software name into software list name and short software name std::string swlist_name, swinfo_name, swpart_name; software_name_split(path, swlist_name, swinfo_name, swpart_name); // determine interface const char *interface = nullptr; if (restrict_to_interface) interface = image_interface(); // find the software list if explicitly specified for (software_list_device &swlistdev : software_list_device_iterator(device().mconfig().root_device())) { if (swlist_name.compare(swlistdev.list_name())==0 || !(swlist_name.length() > 0)) { const software_info *info = swlistdev.find(swinfo_name.c_str()); if (info != nullptr) { const software_part *part = info->find_part(swpart_name.c_str(), interface); if (part != nullptr) return part; } } if (swinfo_name == swlistdev.list_name()) { // ad hoc handling for the case path = swlist_name:swinfo_name (e.g. // gameboy:sml) which is not handled properly by software_name_split // since the function cannot distinguish between this and the case // path = swinfo_name:swpart_name const software_info *info = swlistdev.find(swpart_name.c_str()); if (info != nullptr) { const software_part *part = info->find_part(nullptr, interface); if (part != nullptr) return part; } } } // if explicitly specified and not found, just error here return nullptr; }
void media_identifier::match_hashes(std::vector<file_info> &info) { std::unordered_set<std::string> listnames; // iterate over drivers m_drivlist.reset(); while (m_drivlist.next()) { // iterate over regions and files within the region device_t &device = m_drivlist.config()->root_device(); for (romload::region const ®ion : romload::entries(device.rom_region()).get_regions()) { for (romload::file const &rom : region.get_files()) { util::hash_collection const romhashes(rom.get_hashdata()); if (!romhashes.flag(util::hash_collection::FLAG_NO_DUMP)) { for (file_info &file : info) file.match(device, rom, romhashes); } } } // next iterate over softlists for (software_list_device &swlistdev : software_list_device_iterator(device)) { if (listnames.insert(swlistdev.list_name()).second) { for (software_info const &swinfo : swlistdev.get_info()) { for (software_part const &part : swinfo.parts()) { for (rom_entry const *region = part.romdata().data(); region; region = rom_next_region(region)) { for (rom_entry const *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { util::hash_collection romhashes(ROM_GETHASHDATA(rom)); if (!romhashes.flag(util::hash_collection::FLAG_NO_DUMP)) { for (file_info &file : info) file.match(swlistdev.list_name(), swinfo, *rom, romhashes); } } } } } } } } // iterator over devices machine_config config(GAME_NAME(___empty), m_drivlist.options()); for (device_type type : registered_device_types) { // iterate over regions and files within the region device_t *const device = config.device_add(&config.root_device(), "_tmp", type, 0); for (romload::region const ®ion : romload::entries(device->rom_region()).get_regions()) { for (romload::file const &rom : region.get_files()) { util::hash_collection const romhashes(rom.get_hashdata()); if (!romhashes.flag(util::hash_collection::FLAG_NO_DUMP)) { for (file_info &file : info) file.match(*device, rom, romhashes); } } } config.device_remove(&config.root_device(), "_tmp"); } }
void MyFillSoftwareList(int drvindex, BOOL bForce) { BOOL is_same = 0; HWND hwndSoftwarePicker; HWND hwndSoftwareList; HWND hwndSoftwareDevView; // do we have to do anything? if (!bForce) { if (s_config != NULL) is_same = (drvindex == s_config->driver_index); else is_same = (drvindex < 0); if (is_same) return; } // free the machine config, if necessary MySoftwareListClose(); // allocate the machine config, if necessary if (drvindex >= 0) s_config = software_config_alloc(drvindex); // locate key widgets hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); // set up the device view DevView_SetDriver(hwndSoftwareDevView, s_config); // set up the software picker SoftwarePicker_Clear(hwndSoftwarePicker); SoftwarePicker_SetDriver(hwndSoftwarePicker, s_config); // Get the game's software path 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); } } } // These are the only paths that matter AddSoftwarePickerDirs(hwndSoftwarePicker, paths, NULL); paths = 0; // set up the software picker SoftwareList_Clear(hwndSoftwareList); SoftwareList_SetDriver(hwndSoftwareList, s_config); /* allocate the machine config */ machine_config config(driver_list::driver(drvindex),MameUIGlobal()); for (software_list_device &swlistdev : software_list_device_iterator(config.root_device())) { for (const software_info &swinfo : swlistdev.get_info()) { const software_part &swpart = swinfo.parts().front(); // search for a device with the right interface for (device_image_interface &image : image_interface_iterator(config.root_device())) { const char *interface = image.image_interface(); if (interface) { if (swpart.matches_interface(interface)) { // Extract the Usage data from the "info" fields. const char* usage = NULL; for (const feature_list_item &flist : swinfo.other_info()) if (flist.name() == "usage") usage = flist.value().c_str(); // Now actually add the item SoftwareList_AddFile(hwndSoftwareList, swinfo.shortname().c_str(), swlistdev.list_name().c_str(), swinfo.longname().c_str(), swinfo.publisher().c_str(), swinfo.year().c_str(), usage, image.brief_instance_name()); break; } } } } } }
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; }