Skip to content

Commit

Permalink
Switch to nativefiledialog-extended
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDoom committed Dec 7, 2024
1 parent 22384fb commit aa0ffe6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
url = https://github.com/SFML/SFML.git
[submodule "dependencies/libconfig"]
path = dependencies/libconfig
url = https://github.com/hyperrealm/libconfig.git
url = https://github.com/hyperrealm/libconfig.git
[submodule "dependencies/nativefiledialog"]
path = dependencies/nativefiledialog
url = git@github.com:btzy/nativefiledialog-extended.git
1 change: 1 addition & 0 deletions dependencies/nativefiledialog
Submodule nativefiledialog added at 388549
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/sfml/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "libconfig.h"
#include "libconfig.hh"
#include "nfd.h"
#include "nfd.hpp"

#include "Emulator.h"
#include "ui/TextButton.h"
Expand All @@ -18,6 +18,11 @@ MainMenu::MainMenu(std::unordered_map<std::string *, std::vector<std::string>>&
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");
Expand Down Expand Up @@ -105,8 +110,7 @@ MainMenu::MainMenu(std::unordered_map<std::string *, std::vector<std::string>>&
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;
Expand All @@ -119,11 +123,11 @@ MainMenu::MainMenu(std::unordered_map<std::string *, std::vector<std::string>>&
}

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());
Expand Down

0 comments on commit aa0ffe6

Please sign in to comment.