From aa0ffe6ba6361180b379a7cd65420359d5a81bd1 Mon Sep 17 00:00:00 2001 From: doom <61824552+JustDoom@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:41:36 +1000 Subject: [PATCH] Switch to nativefiledialog-extended --- .gitmodules | 5 ++++- dependencies/nativefiledialog | 1 + src/CMakeLists.txt | 2 +- src/sfml/MainMenu.cpp | 16 ++++++++++------ 4 files changed, 16 insertions(+), 8 deletions(-) create mode 160000 dependencies/nativefiledialog diff --git a/.gitmodules b/.gitmodules index 7eeea09..0dbc2bf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,7 @@ url = https://github.com/SFML/SFML.git [submodule "dependencies/libconfig"] path = dependencies/libconfig - url = https://github.com/hyperrealm/libconfig.git \ No newline at end of file + url = https://github.com/hyperrealm/libconfig.git +[submodule "dependencies/nativefiledialog"] + path = dependencies/nativefiledialog + url = git@github.com:btzy/nativefiledialog-extended.git diff --git a/dependencies/nativefiledialog b/dependencies/nativefiledialog new file mode 160000 index 0000000..388549a --- /dev/null +++ b/dependencies/nativefiledialog @@ -0,0 +1 @@ +Subproject commit 388549a5badaa7cbd138f5f189f50c67d5bf060c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a7add0..f378291 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ else() set(libname "config") endif() -target_link_libraries(8ChocChip PRIVATE sfml-graphics sfml-audio sfml-window sfml-system nativefiledialog ${libname}++) +target_link_libraries(8ChocChip PRIVATE sfml-graphics sfml-audio sfml-window sfml-system nfd ${libname}++) # Set the RPATH of the executable to include the directory where SFML libraries are located set_target_properties(8ChocChip PROPERTIES diff --git a/src/sfml/MainMenu.cpp b/src/sfml/MainMenu.cpp index f5f5fc9..0808ac8 100644 --- a/src/sfml/MainMenu.cpp +++ b/src/sfml/MainMenu.cpp @@ -5,7 +5,7 @@ #include "libconfig.h" #include "libconfig.hh" -#include "nfd.h" +#include "nfd.hpp" #include "Emulator.h" #include "ui/TextButton.h" @@ -18,6 +18,11 @@ MainMenu::MainMenu(std::unordered_map>& window(sf::VideoMode(640, 480), "8ChocChip - Chip8 Emulator"), inputHandler() { + NFD::Guard nfdGuard; + + // auto-freeing memory + NFD::UniquePath outPath; + sf::Vector2u originalWindowSize = this->window.getSize(); sf::Image icon; icon.loadFromFile("../../assets/icon.png"); @@ -105,8 +110,7 @@ MainMenu::MainMenu(std::unordered_map>& button.update(&this->inputHandler, pos); if (button.isJustClicked()) { - nfdchar_t* outPath = nullptr; - nfdresult_t result = NFD_PickFolder(nullptr, &outPath); + nfdresult_t result = NFD::PickFolder(outPath); if (result == NFD_OKAY) { libconfig::Config config; @@ -119,11 +123,11 @@ MainMenu::MainMenu(std::unordered_map>& } libconfig::Setting& directories = settings["directories"]; - directories.add(libconfig::Setting::TypeString) = outPath; + directories.add(libconfig::Setting::TypeString) = outPath.get(); - romDirectories.emplace_back(outPath); + romDirectories.emplace_back(outPath.get()); - for (const auto& file : std::filesystem::directory_iterator(outPath)) { + for (const auto& file : std::filesystem::directory_iterator(outPath.get())) { if (file.is_directory()) continue; // TODO: Make sure its a file that can be emulated, at least basic checks so it isn't like a word doc printf("Processing file - : %s\n", file.path().c_str());