diff --git a/sphaira/include/ui/menus/filebrowser.hpp b/sphaira/include/ui/menus/filebrowser.hpp index 03503fc..e9ee244 100644 --- a/sphaira/include/ui/menus/filebrowser.hpp +++ b/sphaira/include/ui/menus/filebrowser.hpp @@ -89,6 +89,18 @@ struct FileAssocEntry { std::string name{}; // ini name std::vector ext{}; // list of ext std::vector database{}; // list of systems + + auto IsExtension(std::string_view extension, std::string_view internal_extension) const -> bool { + for (const auto& assoc_ext : ext) { + if (extension.length() == assoc_ext.length() && !strncasecmp(assoc_ext.data(), extension.data(), assoc_ext.length())) { + return true; + } + if (internal_extension.length() == assoc_ext.length() && !strncasecmp(assoc_ext.data(), internal_extension.data(), assoc_ext.length())) { + return true; + } + } + return false; + } }; struct LastFile { diff --git a/sphaira/source/ui/menus/filebrowser.cpp b/sphaira/source/ui/menus/filebrowser.cpp index 1a67769..a972fe6 100644 --- a/sphaira/source/ui/menus/filebrowser.cpp +++ b/sphaira/source/ui/menus/filebrowser.cpp @@ -942,15 +942,13 @@ auto Menu::FindFileAssocFor() -> std::vector { // only support roms in correctly named folders, sorry! const auto db_indexs = GetRomDatabaseFromPath(m_path); const auto& entry = GetEntry(); - const auto extension = entry.internal_extension.empty() ? entry.extension : entry.internal_extension; - if (extension.empty()) { + const auto extension = entry.extension; + const auto internal_extension = entry.internal_extension.empty() ? entry.extension : entry.internal_extension; + if (extension.empty() && internal_extension.empty()) { // log_write("failed to get extension for db: %s path: %s\n", database_entry.c_str(), m_path); return {}; } - // log_write("got extension for db: %s path: %s\n", database_entry.c_str(), m_path); - - std::vector out_entries; if (!db_indexs.empty()) { // if database isn't empty, then we are in a valid folder @@ -960,15 +958,14 @@ auto Menu::FindFileAssocFor() -> std::vector { // if (assoc_db == PATHS[db_idx].folder || assoc_db == PATHS[db_idx].database) { for (auto db_idx : db_indexs) { if (PATHS[db_idx].IsDatabase(assoc_db)) { - for (const auto& assoc_ext : assoc.ext) { - if (assoc_ext == extension) { - log_write("found ext: %s assoc_ext: %s assoc.ext: %s\n", assoc.path.s, assoc_ext.c_str(), extension.c_str()); - out_entries.emplace_back(assoc); - } + if (assoc.IsExtension(extension, internal_extension)) { + out_entries.emplace_back(assoc); + goto jump; } } } } + jump: } } else { // otherwise, if not in a valid folder, find an entry that doesn't @@ -979,11 +976,9 @@ auto Menu::FindFileAssocFor() -> std::vector { // to be in the correct folder, ie psx, to know what system that .iso is for. for (const auto& assoc : m_assoc_entries) { if (assoc.database.empty()) { - for (const auto& assoc_ext : assoc.ext) { - if (assoc_ext == extension) { - log_write("found ext: %s\n", assoc.path.s); - out_entries.emplace_back(assoc); - } + if (assoc.IsExtension(extension, internal_extension)) { + log_write("found ext: %s\n", assoc.path.s); + out_entries.emplace_back(assoc); } } } diff --git a/sphaira/source/ui/menus/menu_base.cpp b/sphaira/source/ui/menus/menu_base.cpp index 97fbaf6..4d9d8fd 100644 --- a/sphaira/source/ui/menus/menu_base.cpp +++ b/sphaira/source/ui/menus/menu_base.cpp @@ -18,17 +18,18 @@ MenuBase::~MenuBase() { void MenuBase::Update(Controller* controller, TouchInfo* touch) { Widget::Update(controller, touch); - - // update every second. - if (m_poll_timestamp.GetSeconds() >= 1) { - UpdateVars(); - } } void MenuBase::Draw(NVGcontext* vg, Theme* theme) { DrawElement(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ThemeEntryID_BACKGROUND); Widget::Draw(vg, theme); + // update every second, do this in Draw because Update() isn't called if it + // doesn't have focus. + if (m_poll_timestamp.GetSeconds() >= 1) { + UpdateVars(); + } + const float start_y = 70; const float font_size = 22; const float spacing = 30;