yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
file_dialog_nfd.cc
Go to the documentation of this file.
1// Windows and Linux implementation of FileDialogWrapper using
2// nativefiledialog-extended
3#include <nfd.h>
4
5#include <filesystem>
6#include <string>
7#include <vector>
8
9#include "util/file_util.h"
10
11namespace yaze {
12namespace util {
13
15 nfdchar_t* outPath = nullptr;
16 nfdfilteritem_t filterItem[2] = {{"ROM Files", "sfc,smc"},
17 {"All Files", "*"}};
18 nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, nullptr);
19
20 if (result == NFD_OKAY) {
21 std::string path(outPath);
22 NFD_FreePath(outPath);
23 return path;
24 }
25
26 return "";
27}
28
30 nfdchar_t* outPath = nullptr;
31 nfdresult_t result = NFD_PickFolder(&outPath, nullptr);
32
33 if (result == NFD_OKAY) {
34 std::string path(outPath);
35 NFD_FreePath(outPath);
36 return path;
37 }
38
39 return "";
40}
41
43 const std::string& default_name, const std::string& default_extension) {
44 nfdchar_t* outPath = nullptr;
45 nfdfilteritem_t filterItem[1] = {
46 {default_extension.empty() ? "All Files" : default_extension.c_str(),
47 default_extension.empty() ? "*" : default_extension.c_str()}};
48
49 nfdresult_t result = NFD_SaveDialog(
50 &outPath, default_extension.empty() ? nullptr : filterItem,
51 default_extension.empty() ? 0 : 1, nullptr, default_name.c_str());
52
53 if (result == NFD_OKAY) {
54 std::string path(outPath);
55 NFD_FreePath(outPath);
56 return path;
57 }
58
59 return "";
60}
61
63 const std::string& folder_path) {
64 std::vector<std::string> subdirs;
65
66 try {
67 for (const auto& entry : std::filesystem::directory_iterator(folder_path)) {
68 if (entry.is_directory()) {
69 subdirs.push_back(entry.path().string());
70 }
71 }
72 } catch (...) {
73 // Return empty vector on error
74 }
75
76 return subdirs;
77}
78
79std::vector<std::string> FileDialogWrapper::GetFilesInFolder(
80 const std::string& folder_path) {
81 std::vector<std::string> files;
82
83 try {
84 for (const auto& entry : std::filesystem::directory_iterator(folder_path)) {
85 if (entry.is_regular_file()) {
86 files.push_back(entry.path().string());
87 }
88 }
89 } catch (...) {
90 // Return empty vector on error
91 }
92
93 return files;
94}
95
96// Delegate to main implementations
100
104
106 const std::string& default_name, const std::string& default_extension) {
107 return ShowSaveFileDialog(default_name, default_extension);
108}
109
111 const std::string& default_name, const std::string& default_extension) {
112 return ShowSaveFileDialog(default_name, default_extension);
113}
114
118
122
123} // namespace util
124} // namespace yaze
static std::string ShowSaveFileDialogBespoke(const std::string &default_name="", const std::string &default_extension="")
static std::string ShowOpenFileDialogBespoke()
static std::string ShowSaveFileDialogNFD(const std::string &default_name="", const std::string &default_extension="")
static std::string ShowOpenFolderDialogNFD()
static std::string ShowSaveFileDialog(const std::string &default_name="", const std::string &default_extension="")
ShowSaveFileDialog opens a save file dialog and returns the selected filepath. Uses global feature fl...
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path. Uses global feature fl...
static std::vector< std::string > GetFilesInFolder(const std::string &folder_path)
static std::vector< std::string > GetSubdirectoriesInFolder(const std::string &folder_path)
static std::string ShowOpenFolderDialogBespoke()
static std::string ShowOpenFileDialogNFD()