-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopen_file_dialog.cc
More file actions
38 lines (30 loc) · 1.03 KB
/
open_file_dialog.cc
File metadata and controls
38 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "open_file_dialog.h"
#include <cstdio>
#include <string>
#include <vector>
#ifdef __APPLE__
#include "../macos/src/file_dialog.h"
#endif
#ifdef _WIN32
#include "../windows/src/file_dialog.h"
#endif
#ifdef __linux__
#include "../linux/src/file_dialog.h"
#endif
/* Returns 0 on success, 1 on error (or user hit cancel) */
int open_file_dialog(char *rom_name) {
#if defined(__APPLE__) || defined(__linux__)
// Common flow for Apple and Linux: both return a vector<string>
std::vector<std::string> fileTypes = {"ch8", "CH8", "chip-8", "CHIP-8", "Chip-8"};
const char* defaultDir = ""; // unify behavior: let OS choose last-used/home
std::vector<std::string> files = open_file_dialog("Chip8", defaultDir, fileTypes);
if (files.empty()) return 1;
snprintf(rom_name, 256, "%s", files[0].c_str());
return 0;
#elif defined(_WIN32)
// Windows API variant writes directly into buffer and returns int
return open_file_dialog(rom_name, "Chip8\0*.ch8\0All\0*.*\0");
#else
return 1;
#endif
}