Enhance NFD support in file dialog implementation for Linux and macOS

- Updated preprocessor directives to ensure NFD functionality is only included when YAZE_ENABLE_NFD is defined and enabled.
- Corrected the usage of NFD functions to improve resource management by replacing deprecated calls with the appropriate alternatives.
- Ensured consistent handling of file and folder dialog operations across platforms, enhancing overall user experience.
This commit is contained in:
scawful
2025-09-26 11:12:41 -04:00
parent 7e08601970
commit 132823701b
2 changed files with 10 additions and 10 deletions

View File

@@ -219,7 +219,7 @@ std::vector<std::string> FileDialogWrapper::GetFilesInFolder(
#elif defined(__linux__)
#ifdef YAZE_ENABLE_NFD
#if defined(YAZE_ENABLE_NFD) && YAZE_ENABLE_NFD
#include <nfd.h>
#endif
@@ -233,17 +233,17 @@ std::string FileDialogWrapper::ShowOpenFileDialog() {
}
std::string FileDialogWrapper::ShowOpenFileDialogNFD() {
#ifdef YAZE_ENABLE_NFD
#if defined(YAZE_ENABLE_NFD) && YAZE_ENABLE_NFD
NFD_Init();
nfdu8char_t *out_path = NULL;
nfdu8filter_item_t filters[1] = {{"Rom File", "sfc,smc"}};
nfdu8filteritem_t filters[1] = {{"Rom File", "sfc,smc"}};
nfdopendialogu8args_t args = {0};
args.filterList = filters;
args.filterCount = 1;
nfdresult_t result = NFD_OpenDialogU8_With(&out_path, &args);
if (result == NFD_OKAY) {
std::string file_path_linux(out_path);
NFD_Free(out_path);
NFD_FreePath(out_path);
NFD_Quit();
return file_path_linux;
} else if (result == NFD_CANCEL) {
@@ -274,13 +274,13 @@ std::string FileDialogWrapper::ShowOpenFolderDialog() {
}
std::string FileDialogWrapper::ShowOpenFolderDialogNFD() {
#ifdef YAZE_ENABLE_NFD
#if defined(YAZE_ENABLE_NFD) && YAZE_ENABLE_NFD
NFD_Init();
nfdu8char_t *out_path = NULL;
nfdresult_t result = NFD_PickFolderU8(&out_path);
nfdresult_t result = NFD_PickFolderU8(&out_path, NULL);
if (result == NFD_OKAY) {
std::string folder_path_linux(out_path);
NFD_Free(out_path);
NFD_FreePath(out_path);
NFD_Quit();
return folder_path_linux;
} else if (result == NFD_CANCEL) {

View File

@@ -6,7 +6,7 @@
#include "app/core/features.h"
#ifdef YAZE_ENABLE_NFD
#if defined(YAZE_ENABLE_NFD) && YAZE_ENABLE_NFD
#include <nfd.h>
#endif
@@ -107,7 +107,7 @@ std::string yaze::core::FileDialogWrapper::ShowOpenFolderDialog() {
// NFD implementation for macOS (fallback to bespoke if NFD not available)
std::string yaze::core::FileDialogWrapper::ShowOpenFileDialogNFD() {
#ifdef YAZE_ENABLE_NFD
#if defined(YAZE_ENABLE_NFD) && YAZE_ENABLE_NFD
NFD_Init();
nfdu8char_t *out_path = NULL;
nfdu8filteritem_t filters[1] = {{"Rom File", "sfc,smc"}};
@@ -134,7 +134,7 @@ std::string yaze::core::FileDialogWrapper::ShowOpenFileDialogNFD() {
}
std::string yaze::core::FileDialogWrapper::ShowOpenFolderDialogNFD() {
#ifdef YAZE_ENABLE_NFD
#if defined(YAZE_ENABLE_NFD) && YAZE_ENABLE_NFD
NFD_Init();
nfdu8char_t *out_path = NULL;
nfdresult_t result = NFD_PickFolderU8(&out_path, NULL);