Attempt to change logic of NFD and show error.

This commit is contained in:
Dario 2024-12-18 11:39:41 -03:00
parent 0085b7844d
commit d4735d8791

View file

@ -135,6 +135,7 @@ static std::string g_currentMessagePrompt = "";
static bool g_currentMessagePromptConfirmation = false; static bool g_currentMessagePromptConfirmation = false;
static std::list<std::filesystem::path> g_currentPickerResults; static std::list<std::filesystem::path> g_currentPickerResults;
static std::atomic<bool> g_currentPickerResultsReady = false; static std::atomic<bool> g_currentPickerResultsReady = false;
static std::string g_currentPickerErrorMessage;
static std::unique_ptr<std::thread> g_currentPickerThread; static std::unique_ptr<std::thread> g_currentPickerThread;
static bool g_currentPickerVisible = false; static bool g_currentPickerVisible = false;
static bool g_currentPickerFolderMode = false; static bool g_currentPickerFolderMode = false;
@ -872,15 +873,15 @@ static bool ConvertPathSet(const nfdpathset_t *pathSet, std::list<std::filesyste
for (nfdpathsetsize_t i = 0; i < pathSetCount; i++) for (nfdpathsetsize_t i = 0; i < pathSetCount; i++)
{ {
char *pathSetPath = nullptr; nfdnchar_t *pathSetPath = nullptr;
if (NFD_PathSet_GetPathU8(pathSet, i, &pathSetPath) != NFD_OKAY) if (NFD_PathSet_GetPathN(pathSet, i, &pathSetPath) != NFD_OKAY)
{ {
filePaths.clear(); filePaths.clear();
return false; return false;
} }
filePaths.emplace_back(std::filesystem::path(std::u8string_view((const char8_t *)(pathSetPath)))); filePaths.emplace_back(std::filesystem::path(pathSetPath));
NFD_PathSet_FreePathU8(pathSetPath); NFD_PathSet_FreePathN(pathSetPath);
} }
return true; return true;
@ -892,21 +893,11 @@ static void PickerThreadProcess()
nfdresult_t result = NFD_ERROR; nfdresult_t result = NFD_ERROR;
if (g_currentPickerFolderMode) if (g_currentPickerFolderMode)
{ {
nfdpickfolderu8args_t openArgs = {}; result = NFD_PickFolderMultipleN(&pathSet, nullptr);
#if defined(__linux__)
openArgs.parentWindow.type = NFD_WINDOW_HANDLE_TYPE_X11;
openArgs.parentWindow.handle = (void*)(GameWindow::s_renderWindow.window);
#endif
result = NFD_PickFolderMultipleU8_With(&pathSet, &openArgs);
} }
else else
{ {
nfdopendialogu8args_t openArgs = {}; result = NFD_OpenDialogMultipleN(&pathSet, nullptr, 0, nullptr);
#if defined(__linux__)
openArgs.parentWindow.type = NFD_WINDOW_HANDLE_TYPE_X11;
openArgs.parentWindow.handle = (void*)(GameWindow::s_renderWindow.window);
#endif
result = NFD_OpenDialogMultipleU8_With(&pathSet, &openArgs);
} }
if (result == NFD_OKAY) if (result == NFD_OKAY)
@ -914,6 +905,10 @@ static void PickerThreadProcess()
bool pathsConverted = ConvertPathSet(pathSet, g_currentPickerResults); bool pathsConverted = ConvertPathSet(pathSet, g_currentPickerResults);
NFD_PathSet_Free(pathSet); NFD_PathSet_Free(pathSet);
} }
else if (result == NFD_ERROR)
{
g_currentPickerErrorMessage = NFD_GetError();
}
g_currentPickerResultsReady = true; g_currentPickerResultsReady = true;
g_currentPickerVisible = false; g_currentPickerVisible = false;
@ -1351,6 +1346,13 @@ static void CheckPickerResults()
return; return;
} }
if (!g_currentPickerErrorMessage.empty())
{
g_currentMessagePrompt = g_currentPickerErrorMessage;
g_currentMessagePromptConfirmation = false;
g_currentPickerErrorMessage.clear();
}
ParseSourcePaths(g_currentPickerResults); ParseSourcePaths(g_currentPickerResults);
g_currentPickerResultsReady = false; g_currentPickerResultsReady = false;
g_currentPickerVisible = false; g_currentPickerVisible = false;