void Roms::add_data_roms() { std::string system = get_raw_path("/data/multiboot"); DIR *dp = opendir(system.c_str()); if (!dp ) { return; } auto close_dp = util::finally([&]{ closedir(dp); }); struct stat sb; struct dirent *ent; while ((ent = readdir(dp))) { if (strcmp(ent->d_name, "data-slot-") == 0 || !util::starts_with(ent->d_name, "data-slot-")) { continue; } std::string fullpath(system); fullpath += "/"; fullpath += ent->d_name; if (stat(fullpath.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) { roms.push_back(create_rom_data_slot(ent->d_name + 10)); } } }
std::shared_ptr<Rom> Roms::create_rom(const std::string &id) { if (id == "primary") { return create_rom_primary(); } else if (id == "dual") { return create_rom_dual(); } else if (util::starts_with(id, "multi-slot-")) { unsigned int num; if (sscanf(id.c_str(), "multi-slot-%u", &num) == 1) { return create_rom_multi_slot(num); } } else if (util::starts_with(id, "data-slot-") && id != "data-slot-") { return create_rom_data_slot(id.substr(10)); } else if (util::starts_with(id, "extsd-slot-") && id != "extsd-slot-") { return create_rom_extsd_slot(id.substr(11)); } return std::shared_ptr<Rom>(); }
void Roms::add_data_roms() { std::string system = get_raw_path("/data/multiboot"); DIR *dp = opendir(system.c_str()); if (!dp ) { return; } auto close_dp = util::finally([&]{ closedir(dp); }); struct stat sb; std::vector<std::shared_ptr<Rom>> temp_roms; struct dirent *ent; while ((ent = readdir(dp))) { if (strcmp(ent->d_name, "data-slot-") == 0 || !util::starts_with(ent->d_name, "data-slot-")) { continue; } std::string fullpath(system); fullpath += "/"; fullpath += ent->d_name; if (stat(fullpath.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) { temp_roms.push_back(create_rom_data_slot(ent->d_name + 10)); } } // Sort by ID std::sort(temp_roms.begin(), temp_roms.end(), &cmp_rom_id); std::move(temp_roms.begin(), temp_roms.end(), std::back_inserter(roms)); }