SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit a39445e63bd73cb36375032ce8cbe8f80f7d2952 parent 0f6299edfc6bc4ee89457c2c607f25d52f84791f Author: Lior Halphon <LIJI32@gmail.com> Date: Fri, 5 Apr 2024 13:47:17 +0300 Merge pull request #600 from CasualPokePlayer/new_folder_dialog Add support for the newer Vista style select folder dialog Diffstat:
| M | OpenDialog/windows.c | 46 | +++++++++++++++++++++++++++++++--------------- |
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/OpenDialog/windows.c b/OpenDialog/windows.c @@ -1,3 +1,4 @@ +#define COBJMACROS #include <windows.h> #include <shlobj.h> #include <stdio.h> @@ -42,24 +43,39 @@ char *do_open_rom_dialog(void) char *do_open_folder_dialog(void) { + HRESULT hr, hrCoInit; char *ret = NULL; - BROWSEINFOW dialog; + IFileOpenDialog *dialog = NULL; + IShellItem *result = NULL; + wchar_t *path = NULL; - memset(&dialog, 0, sizeof(dialog)); - dialog.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS; - dialog.lpszTitle = L"Select Boot ROMs Folder"; - - HRESULT hrOleInit = OleInitialize(NULL); - LPITEMIDLIST list = SHBrowseForFolderW(&dialog); - if (list) { - wchar_t filename[MAX_PATH]; - if (SHGetPathFromIDListW(list, filename)) { - ret = wc_to_utf8_alloc(filename); - } - CoTaskMemFree((void *)list); - } + hrCoInit = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + + hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_ALL, &IID_IFileOpenDialog, (LPVOID *)&dialog); + if (FAILED(hr)) goto end; + + hr = IFileOpenDialog_SetOptions(dialog, FOS_NOCHANGEDIR | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_NOREADONLYRETURN); + if (FAILED(hr)) goto end; + + hr = IFileOpenDialog_SetTitle(dialog, L"Select Boot ROMs Folder"); + if (FAILED(hr)) goto end; + + hr = IFileOpenDialog_Show(dialog, NULL); + if (FAILED(hr)) goto end; + + hr = IFileOpenDialog_GetResult(dialog, &result); + if (FAILED(hr)) goto end; + + hr = IShellItem_GetDisplayName(result, SIGDN_FILESYSPATH, &path); + if (FAILED(hr)) goto end; + + ret = wc_to_utf8_alloc(path); - if (SUCCEEDED(hrOleInit)) OleUninitialize(); +end: + if (path) CoTaskMemFree((void *)path); + if (result) IShellItem_Release(result); + if (dialog) IFileOpenDialog_Release(dialog); + if (SUCCEEDED(hrCoInit)) CoUninitialize(); return ret; }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.