From 4bd50b9182a4cbd7258dc8d1e8bf21dff644b304 Mon Sep 17 00:00:00 2001 From: Edward Li Date: Wed, 4 Nov 2020 05:40:20 +0800 Subject: [PATCH 1/4] Display warning when it takes too long to find a game --- core/rend/game_scanner.h | 17 +++++++++++++ core/rend/gui.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/core/rend/game_scanner.h b/core/rend/game_scanner.h index c27f9c0ee..0c8312fd5 100644 --- a/core/rend/game_scanner.h +++ b/core/rend/game_scanner.h @@ -57,6 +57,19 @@ class GameScanner void add_game_directory(const std::string& path) { //printf("Exploring %s\n", path.c_str()); + if (game_list.size() == 0) + { + ++still_no_rom_counter; + if (still_no_rom_counter > 1000) + { + path_is_too_dirty = true; + } + } + else + { + path_is_too_dirty = false; + } + DIR *dir = opendir(path.c_str()); if (dir == NULL) return; @@ -130,6 +143,8 @@ public: void stop() { running = false; + still_no_rom_counter = 0; + path_is_too_dirty = false; if (scan_thread && scan_thread->joinable()) scan_thread->join(); } @@ -168,4 +183,6 @@ public: std::mutex& get_mutex() { return mutex; } const std::vector& get_game_list() { return game_list; } + uint still_no_rom_counter = 0; + bool path_is_too_dirty = false; }; diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 7f4b8e5a6..9088e4c9a 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -668,6 +668,57 @@ static void error_popup() } } +static void contentpath_warning_popup() +{ + static bool show_contentpath_warning_popup = true; + static bool show_contentpath_selection = false; + if (show_contentpath_warning_popup && scanner.path_is_too_dirty) + { + ImGui::OpenPopup("Incorrect Content Location?"); + if (ImGui::BeginPopupModal("Incorrect Content Location?", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) + { + ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + 400.f * scaling); + ImGui::TextWrapped(" Still searching in %d folders, no game can be found! ", scanner.still_no_rom_counter); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(16 * scaling, 3 * scaling)); + float currentwidth = ImGui::GetContentRegionAvailWidth(); + ImGui::SetCursorPosX((currentwidth - 100.f * scaling) / 2.f + ImGui::GetStyle().WindowPadding.x - 55.f * scaling); + if (ImGui::Button("Reselect", ImVec2(100.f * scaling, 0.f))) + { + settings.dreamcast.ContentPath.clear(); + scanner.stop(); + show_contentpath_warning_popup = false; + ImGui::CloseCurrentPopup(); + show_contentpath_selection = true; + } + + ImGui::SameLine(); + ImGui::SetCursorPosX((currentwidth - 100.f * scaling) / 2.f + ImGui::GetStyle().WindowPadding.x + 55.f * scaling); + if (ImGui::Button("Cancel", ImVec2(100.f * scaling, 0.f))) + { + show_contentpath_warning_popup = false; + ImGui::CloseCurrentPopup(); + } + ImGui::SetItemDefaultFocus(); + ImGui::PopStyleVar(); + ImGui::EndPopup(); + } + } + if (show_contentpath_selection) + { + ImGui::OpenPopup("Select Directory"); + select_directory_popup("Select Directory", scaling, [](bool cancelled, std::string selection) + { + show_contentpath_selection = false; + show_contentpath_warning_popup = true; + if (!cancelled) + { + settings.dreamcast.ContentPath.push_back(selection); + scanner.refresh(); + } + }); + } +} + void directory_selected_callback(bool cancelled, std::string selection) { if (!cancelled) @@ -1572,6 +1623,7 @@ static void gui_display_content() ImGui::PopStyleVar(); error_popup(); + contentpath_warning_popup(); ImGui::Render(); ImGui_impl_RenderDrawData(ImGui::GetDrawData(), false); From fe1c77b9ae1fc60bed4eba50a39da8faabb11ebf Mon Sep 17 00:00:00 2001 From: Edward Li Date: Wed, 4 Nov 2020 05:41:05 +0800 Subject: [PATCH 2/4] Display relevant game files in the select_directory_popup --- core/rend/gui_util.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/rend/gui_util.cpp b/core/rend/gui_util.cpp index de7680969..e0351cd4d 100644 --- a/core/rend/gui_util.cpp +++ b/core/rend/gui_util.cpp @@ -39,6 +39,7 @@ extern int screen_width, screen_height; static std::string select_current_directory; static std::vector select_subfolders; +static std::vector display_files; bool subfolders_read; #ifdef _WIN32 static const std::string separators = "/\\"; @@ -103,6 +104,7 @@ void select_directory_popup(const char *prompt, float scaling, StringCallback ca if (!subfolders_read) { select_subfolders.clear(); + display_files.clear(); error_message.clear(); #ifdef _WIN32 if (select_current_directory == PSEUDO_ROOT) @@ -175,6 +177,14 @@ void select_directory_popup(const char *prompt, float scaling, StringCallback ca dotdot_seen = true; select_subfolders.push_back(name); } + else + { + std::string extension = get_file_extension(name); + if ( extension == "zip" || extension == "7z" || extension == "chd" || extension == "gdi" || ((settings.dreamcast.HideLegacyNaomiRoms + || (extension != "bin" && extension != "lst" && extension != "dat")) + && extension != "cdi" && extension != "cue") == false ) + display_files.push_back(name); + } } closedir(dir); #if defined(_WIN32) || defined(__ANDROID__) @@ -249,6 +259,13 @@ void select_directory_popup(const char *prompt, float scaling, StringCallback ca select_current_directory = child_path; } } + ImGui::PushStyleColor(ImGuiCol_Text, { 1, 1, 1, 0.3}); + for (auto& name : display_files) + { + ImGui::Text(name.c_str()); + } + ImGui::PopStyleColor(); + ImGui::PopStyleVar(); ImGui::EndChild(); if (ImGui::Button("Select Current Directory", ImVec2(0, 30 * scaling))) From 4516f9790ad5fa138e3caf0a90c13164ec2b7e90 Mon Sep 17 00:00:00 2001 From: Edward Li Date: Wed, 4 Nov 2020 05:59:25 +0800 Subject: [PATCH 3/4] Restore the problematic Content Path if user clicks cancel --- core/rend/gui.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 9088e4c9a..d341daf07 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -684,8 +684,6 @@ static void contentpath_warning_popup() ImGui::SetCursorPosX((currentwidth - 100.f * scaling) / 2.f + ImGui::GetStyle().WindowPadding.x - 55.f * scaling); if (ImGui::Button("Reselect", ImVec2(100.f * scaling, 0.f))) { - settings.dreamcast.ContentPath.clear(); - scanner.stop(); show_contentpath_warning_popup = false; ImGui::CloseCurrentPopup(); show_contentpath_selection = true; @@ -705,6 +703,9 @@ static void contentpath_warning_popup() } if (show_contentpath_selection) { + static auto original = settings.dreamcast.ContentPath; + settings.dreamcast.ContentPath.clear(); + scanner.stop(); ImGui::OpenPopup("Select Directory"); select_directory_popup("Select Directory", scaling, [](bool cancelled, std::string selection) { @@ -715,6 +716,11 @@ static void contentpath_warning_popup() settings.dreamcast.ContentPath.push_back(selection); scanner.refresh(); } + else + { + settings.dreamcast.ContentPath = original; + scanner.refresh(); + } }); } } From 11336a3e1f43a520f6c94633eb7579cd24d6b92d Mon Sep 17 00:00:00 2001 From: Edward Li Date: Wed, 4 Nov 2020 06:34:25 +0800 Subject: [PATCH 4/4] use `unsigned int` instead of `uint` --- core/rend/game_scanner.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rend/game_scanner.h b/core/rend/game_scanner.h index 0c8312fd5..0dc2efd0f 100644 --- a/core/rend/game_scanner.h +++ b/core/rend/game_scanner.h @@ -183,6 +183,6 @@ public: std::mutex& get_mutex() { return mutex; } const std::vector& get_game_list() { return game_list; } - uint still_no_rom_counter = 0; + unsigned int still_no_rom_counter = 0; bool path_is_too_dirty = false; };