Mercurial > repos > blastem
diff nuklear_ui/filechooser_win.c @ 2355:94cf5cc89227
Add an option to use the system file picker on Linux and Windows
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 21 Oct 2023 19:22:01 -0700 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuklear_ui/filechooser_win.c Sat Oct 21 19:22:01 2023 -0700 @@ -0,0 +1,34 @@ +#include <windows.h> +#include <stdint.h> + +uint8_t native_filechooser_available(void) +{ + return 1; +} + +char* native_filechooser_pick(const char *title, const char *start_directory) +{ + char file_name[MAX_PATH] = ""; + OPENFILENAMEA ofn = { + .lStructSize = sizeof(ofn), + .hwndOwner = NULL, //TODO: should probably get the HWND of the main window + .lpstrFilter = + "All Files\0*.*\0" + "All Supported Types\0*.zip;*.bin;*.bin.gz;*.gen;*.gen.gz;*.md;*.md.gz;*.sms;*.sms.gz;*.gg;*.gg.gz;*.sg;*.sg.gz;*.cue;*.toc;*.flac;*.vgm;*.vgz;*.vgm.gz\0" + "Genesis/MD\0.zip;*.bin;*.bin.gz;*.gen;*.gen*.gz;*.md;*.md.gz\0" + "Sega/Mega CD\0*.cue;*.toc\0" + "Sega 8-bit\0*.sms;*.sms.gz;*.gg;*.gg.gz;*.sg;*.sg.gz\0" + "Audio/VGM\0*.flac;*.vgm;*.vgz;*.vgm.gz\0", + .nFilterIndex = 2, + .lpstrFile = file_name, + .nMaxFile = sizeof(file_name), + .lpstrInitialDir = start_directory, + .lpstrTitle = title, + .Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_LONGNAMES, + }; + char *ret = NULL; + if (GetOpenFileNameA(&ofn)) { + ret = strdup(file_name); + } + return ret; +}