2019-06-01 11:29:46 +00:00
|
|
|
#include <windows.h>
|
2020-12-26 13:10:11 +00:00
|
|
|
#include <shlobj.h>
|
2019-06-01 11:29:46 +00:00
|
|
|
#include "open_dialog.h"
|
|
|
|
|
2022-04-14 17:43:45 +00:00
|
|
|
static char *wc_to_utf8_alloc(const wchar_t *wide)
|
|
|
|
{
|
|
|
|
unsigned int cb = WideCharToMultiByte(CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (cb) {
|
|
|
|
char *buffer = (char*) malloc(cb);
|
|
|
|
if (buffer) {
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wide, -1, buffer, cb, NULL, NULL);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-01 11:29:46 +00:00
|
|
|
char *do_open_rom_dialog(void)
|
|
|
|
{
|
|
|
|
OPENFILENAMEW dialog;
|
2022-04-14 17:43:45 +00:00
|
|
|
wchar_t filename[MAX_PATH];
|
|
|
|
|
|
|
|
filename[0] = '\0';
|
2019-06-01 11:29:46 +00:00
|
|
|
memset(&dialog, 0, sizeof(dialog));
|
|
|
|
dialog.lStructSize = sizeof(dialog);
|
|
|
|
dialog.lpstrFile = filename;
|
2022-04-14 17:43:45 +00:00
|
|
|
dialog.nMaxFile = MAX_PATH;
|
2020-04-25 19:48:48 +00:00
|
|
|
dialog.lpstrFilter = L"Game Boy ROMs\0*.gb;*.gbc;*.sgb;*.isx\0All files\0*.*\0\0";
|
2019-06-01 11:29:46 +00:00
|
|
|
dialog.nFilterIndex = 1;
|
|
|
|
dialog.lpstrFileTitle = NULL;
|
|
|
|
dialog.nMaxFileTitle = 0;
|
|
|
|
dialog.lpstrInitialDir = NULL;
|
2022-04-14 17:43:45 +00:00
|
|
|
dialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
|
|
|
|
|
|
|
if (GetOpenFileNameW(&dialog) == TRUE) {
|
|
|
|
return wc_to_utf8_alloc(filename);
|
2019-06-01 11:29:46 +00:00
|
|
|
}
|
2022-04-14 17:43:45 +00:00
|
|
|
|
2019-06-01 11:29:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-12-26 13:10:11 +00:00
|
|
|
|
|
|
|
char *do_open_folder_dialog(void)
|
|
|
|
{
|
2022-04-14 17:43:45 +00:00
|
|
|
char *ret = NULL;
|
2020-12-26 13:10:11 +00:00
|
|
|
BROWSEINFOW dialog;
|
2022-04-14 17:43:45 +00:00
|
|
|
|
2020-12-26 13:10:11 +00:00
|
|
|
memset(&dialog, 0, sizeof(dialog));
|
2022-04-14 17:43:45 +00:00
|
|
|
dialog.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS;
|
2020-12-26 13:10:11 +00:00
|
|
|
dialog.lpszTitle = L"Select Boot ROMs Folder";
|
|
|
|
|
2022-04-14 17:43:45 +00:00
|
|
|
HRESULT hrOleInit = OleInitialize(NULL);
|
|
|
|
LPITEMIDLIST list = SHBrowseForFolderW(&dialog);
|
2020-12-26 13:10:11 +00:00
|
|
|
if (list) {
|
2022-04-14 17:43:45 +00:00
|
|
|
wchar_t filename[MAX_PATH];
|
|
|
|
if (SHGetPathFromIDListW(list, filename)) {
|
|
|
|
ret = wc_to_utf8_alloc(filename);
|
2020-12-26 13:10:11 +00:00
|
|
|
}
|
|
|
|
CoTaskMemFree(list);
|
|
|
|
}
|
2022-04-14 17:43:45 +00:00
|
|
|
|
|
|
|
if (SUCCEEDED(hrOleInit)) OleUninitialize();
|
|
|
|
return ret;
|
2020-12-26 13:10:11 +00:00
|
|
|
}
|