Open windows file dialog.\n * dialogType 0 = Open file dialog\n * dialogType 1 = Save file dialog\n */
| 366 | * dialogType 1 = Save file dialog\n |
| 367 | */ |
| 368 | static const std::string fileDialog(int dialogType, |
| 369 | const std::string &initialDir, |
| 370 | const std::string &filter) |
| 371 | { |
| 372 | std::string initDir = normalizePath(initialDir); |
| 373 | std::replace(initDir.begin(), initDir.end(), '/', '\\'); |
| 374 | |
| 375 | OPENFILENAME ofn; // common dialog box structure |
| 376 | char fileNameBuffer[512]; |
| 377 | fileNameBuffer[0] = '\0'; |
| 378 | |
| 379 | const std::string filterWithEscape = filter + '\0'; |
| 380 | |
| 381 | ZeroMemory(&ofn, sizeof(ofn)); |
| 382 | ofn.lStructSize = sizeof(ofn); |
| 383 | ofn.lpstrFile = fileNameBuffer; |
| 384 | ofn.nMaxFile = sizeof(fileNameBuffer); |
| 385 | ofn.lpstrFilter = filterWithEscape.c_str(); |
| 386 | ofn.nFilterIndex = 1; |
| 387 | ofn.lpstrInitialDir = (LPSTR)initDir.c_str(); |
| 388 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; |
| 389 | |
| 390 | if (dialogType == 0) |
| 391 | { |
| 392 | if (GetOpenFileName(&ofn)) |
| 393 | return std::string(fileNameBuffer); |
| 394 | } |
| 395 | else |
| 396 | { |
| 397 | if (GetSaveFileName(&ofn)) |
| 398 | return std::string(fileNameBuffer); |
| 399 | } |
| 400 | return ""; |
| 401 | } |
| 402 | #endif |
| 403 | }; |
| 404 | } |