From 4787600ca8849ec93b00814d72ddeb169bc124c4 Mon Sep 17 00:00:00 2001 From: Tom Chapple Date: Mon, 1 Apr 2024 19:54:54 +1100 Subject: [PATCH] Make use of containing ROM folder optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is mostly useful for distributions where it is not expected for permission to be granted to the directory a ROM is contained in (e.g. Flatpak or other Portal API use). To this end, the `ImGui::Combo` API now uses a list rather that a double null-terminated string as—combined with trailing commas in C++11—this allows for entries in this list to be easily added and removed. Currently, no platform uses this, but this will likely be useful for a contained release. --- platforms/desktop-shared/gui.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/platforms/desktop-shared/gui.cpp b/platforms/desktop-shared/gui.cpp index 052962b9..2db27000 100644 --- a/platforms/desktop-shared/gui.cpp +++ b/platforms/desktop-shared/gui.cpp @@ -556,10 +556,17 @@ static void main_menu(void) ImGui::Separator(); + static const char* const SAVE_FILES_LOCATION_OPTS[] = { + "Save Files In Custom Folder", +#ifndef PREVENT_ROM_FOLDER_USAGE + "Save Files In ROM Folder", +#endif + }; + static constexpr int SAVE_FILES_LOCATION_OPTS_COUNT = sizeof(SAVE_FILES_LOCATION_OPTS) / sizeof(const char*); if (ImGui::BeginMenu("Save File Location")) { ImGui::PushItemWidth(220.0f); - if (ImGui::Combo("##savefile_option", &config_emulator.savefiles_dir_option, "Save Files In Custom Folder\0Save Files In ROM Folder\0\0")) + if (ImGui::Combo("##savefile_option", &config_emulator.savefiles_dir_option, SAVE_FILES_LOCATION_OPTS, SAVE_FILES_LOCATION_OPTS_COUNT)) { emu_savefiles_dir_option = config_emulator.savefiles_dir_option; } @@ -583,10 +590,17 @@ static void main_menu(void) ImGui::EndMenu(); } + static const char* const SAVE_STATES_LOCATION_OPTS[] = { + "Savestates In Custom Folder", +#ifndef PREVENT_ROM_FOLDER_USAGE + "Savestates In ROM Folder", +#endif + }; + static constexpr int SAVE_STATES_LOCATION_OPTS_COUNT = sizeof(SAVE_STATES_LOCATION_OPTS) / sizeof(const char*); if (ImGui::BeginMenu("Save State Location")) { ImGui::PushItemWidth(220.0f); - if (ImGui::Combo("##savestate_option", &config_emulator.savestates_dir_option, "Savestates In Custom Folder\0Savestates In ROM Folder\0\0")) + if (ImGui::Combo("##savestate_option", &config_emulator.savestates_dir_option, SAVE_STATES_LOCATION_OPTS, SAVE_STATES_LOCATION_OPTS_COUNT)) { emu_savestates_dir_option = config_emulator.savestates_dir_option; }