From c97eb5321ddc297cf79cd2cc0b2304affddc14f0 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 11 Aug 2024 14:24:42 -0400 Subject: [PATCH] file dialog windows updates --- src/app/core/platform/file_dialog.h | 77 ++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/app/core/platform/file_dialog.h b/src/app/core/platform/file_dialog.h index 9d58f187..b79a13c4 100644 --- a/src/app/core/platform/file_dialog.h +++ b/src/app/core/platform/file_dialog.h @@ -2,6 +2,7 @@ #define YAZE_APP_CORE_PLATFORM_FILE_DIALOG_H #include +#include #ifdef _WIN32 // Include Windows-specific headers @@ -41,9 +42,83 @@ class FileDialogWrapper { CoUninitialize(); return file_path_windows; } + + static std::string ShowOpenFolderDialog() { + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + + IFileDialog *pfd = NULL; + HRESULT hr = + CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, + IID_IFileDialog, reinterpret_cast(&pfd)); + std::string folder_path_windows; + if (SUCCEEDED(hr)) { + // Show the dialog + DWORD dwOptions; + hr = pfd->GetOptions(&dwOptions); + if (SUCCEEDED(hr)) { + hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS); + if (SUCCEEDED(hr)) { + hr = pfd->Show(NULL); + if (SUCCEEDED(hr)) { + IShellItem *psiResult; + hr = pfd->GetResult(&psiResult); + if (SUCCEEDED(hr)) { + // Get the folder path + PWSTR pszFolderPath; + psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFolderPath); + char str[128]; + wcstombs(str, pszFolderPath, 128); + folder_path_windows = str; + psiResult->Release(); + CoTaskMemFree(pszFolderPath); + } + } + } + } + pfd->Release(); + } + + CoUninitialize(); + return folder_path_windows; + } + + static std::vector GetSubdirectoriesInFolder( + const std::string& folder_path) { + std::vector subdirectories; + WIN32_FIND_DATA findFileData; + HANDLE hFind = FindFirstFile((folder_path + "\\*").c_str(), &findFileData); + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + if (strcmp(findFileData.cFileName, ".") != 0 && + strcmp(findFileData.cFileName, "..") != 0) { + subdirectories.push_back(findFileData.cFileName); + } + } + } while (FindNextFile(hFind, &findFileData) != 0); + FindClose(hFind); + } + return subdirectories; + } + + static std::vector GetFilesInFolder( + const std::string& folder_path) { + std::vector files; + WIN32_FIND_DATA findFileData; + HANDLE hFind = FindFirstFile((folder_path + "\\*").c_str(), &findFileData); + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + files.push_back(findFileData.cFileName); + } + } while (FindNextFile(hFind, &findFileData) != 0); + FindClose(hFind); + } + return files; + } }; -#elif defined(__APPLE__) || defined(__linux__) +#elif defined(__APPLE__) #include #include