2019-06-01 11:29:46 +00:00
|
|
|
#include <windows.h>
|
2020-12-26 13:10:11 +00:00
|
|
|
#include <shlobj.h>
|
2022-07-08 16:51:10 +00:00
|
|
|
#include <stdio.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;
|
|
|
|
|
2022-05-21 15:18:34 +00:00
|
|
|
if (GetOpenFileNameW(&dialog)) {
|
2022-04-14 17:43:45 +00:00
|
|
|
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
|
|
|
}
|
2022-05-21 15:18:34 +00:00
|
|
|
|
|
|
|
char *do_save_recording_dialog(unsigned frequency)
|
|
|
|
{
|
|
|
|
OPENFILENAMEW dialog;
|
2022-07-02 19:41:07 +00:00
|
|
|
wchar_t filename[MAX_PATH + 5] = L"recording.wav";
|
2022-07-08 16:51:10 +00:00
|
|
|
static wchar_t filter[] = L"RIFF WAVE\0*.wav\0Apple AIFF\0*.aiff;*.aif;*.aifc\0Raw PCM (Stereo _______Hz, 16-bit LE)\0*.raw;*.pcm;\0All files\0*.*\0\0";
|
2022-07-02 19:41:07 +00:00
|
|
|
|
2022-05-21 15:18:34 +00:00
|
|
|
memset(&dialog, 0, sizeof(dialog));
|
|
|
|
dialog.lStructSize = sizeof(dialog);
|
|
|
|
dialog.lpstrFile = filename;
|
|
|
|
dialog.nMaxFile = MAX_PATH;
|
2022-07-08 16:51:10 +00:00
|
|
|
dialog.lpstrFilter = filter;
|
|
|
|
swprintf(filter + sizeof("RIFF WAVE\0*.wav\0Apple AIFF\0*.aiff;*.aif;*.aifc\0Raw PCM (Stereo ") - 1,
|
|
|
|
sizeof("_______Hz, 16-bit LE)"),
|
|
|
|
L"%dHz, 16-bit LE) ",
|
|
|
|
frequency);
|
|
|
|
|
2022-05-21 15:18:34 +00:00
|
|
|
dialog.nFilterIndex = 1;
|
|
|
|
dialog.lpstrInitialDir = NULL;
|
|
|
|
dialog.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
|
|
|
|
|
|
|
|
if (GetSaveFileNameW(&dialog)) {
|
|
|
|
if (dialog.nFileExtension == 0) {
|
|
|
|
switch (dialog.nFilterIndex) {
|
|
|
|
case 1:
|
|
|
|
wcscat(filename, L".wav");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
wcscat(filename, L".aiff");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
wcscat(filename, L".raw");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wc_to_utf8_alloc(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|