-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileDialogs.cpp
More file actions
70 lines (67 loc) · 2.12 KB
/
Copy pathFileDialogs.cpp
File metadata and controls
70 lines (67 loc) · 2.12 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "FileDialogs.h"
#include <GLFW/glfw3.h>
#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#include <commdlg.h>
#include <shlobj.h>
// expose native API for glfw before including native header
#ifndef GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WIN32
#endif
#include <GLFW/glfw3native.h>
#endif
std::string FileDialogs::OpenFile(GLFWwindow* window, const char* filter) {
#ifdef _WIN32
OPENFILENAMEA ofn;
char szFile[260] = { 0 };
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = glfwGetWin32Window(window);
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (GetOpenFileNameA(&ofn) == TRUE) return std::string(ofn.lpstrFile);
#endif
return std::string();
}
std::string FileDialogs::SaveFile(GLFWwindow* window, const char* filter, const std::string& initialDir) {
#ifdef _WIN32
OPENFILENAMEA ofn;
char szFile[260] = { 0 };
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = glfwGetWin32Window(window);
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR;
if (!initialDir.empty()) {
ofn.lpstrInitialDir = initialDir.c_str();
}
strncpy(szFile, "scene.nos", sizeof(szFile) - 1);
if (GetSaveFileNameA(&ofn) == TRUE) return std::string(ofn.lpstrFile);
#endif
return std::string();
}
std::string FileDialogs::SelectFolder(GLFWwindow* window) {
#ifdef _WIN32
char path[MAX_PATH];
BROWSEINFOA bi = { 0 };
bi.lpszTitle = "Select Default Export Folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.hwndOwner = glfwGetWin32Window(window);
LPITEMIDLIST pidl = SHBrowseForFolderA(&bi);
if (pidl != 0) {
if (SHGetPathFromIDListA(pidl, path)) {
CoTaskMemFree(pidl);
return std::string(path);
}
CoTaskMemFree(pidl);
}
#endif
return std::string();
}