| 68 | } |
| 69 | |
| 70 | fs::path promptDirectory(const std::string& title, void* hwnd) |
| 71 | { |
| 72 | fs::path result; |
| 73 | |
| 74 | // Initialize COM and get a pointer to the shell memory allocator |
| 75 | LPMALLOC lpMalloc; |
| 76 | if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)) && SUCCEEDED(SHGetMalloc(&lpMalloc))) |
| 77 | { |
| 78 | auto titleW = Utility::toUtf16(title); |
| 79 | BROWSEINFOW bi{}; |
| 80 | bi.lpszTitle = titleW.c_str(); |
| 81 | bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_NONEWFOLDERBUTTON; |
| 82 | |
| 83 | LPITEMIDLIST pidl = SHBrowseForFolderW(&bi); |
| 84 | if (pidl != nullptr) |
| 85 | { |
| 86 | result = fs::path(SHGetPathFromIDListLongPath(pidl).c_str()); |
| 87 | } |
| 88 | CoTaskMemFree(pidl); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | std::cerr << "Error opening directory browse window"; |
| 93 | } |
| 94 | CoUninitialize(); |
| 95 | |
| 96 | // SHBrowseForFolderW might minimize the main window, |
| 97 | // so make sure that it's visible again. |
| 98 | if (hwnd != nullptr) |
| 99 | { |
| 100 | ShowWindow(static_cast<HWND>(hwnd), SW_RESTORE); |
| 101 | } |
| 102 | |
| 103 | return result; |
| 104 | } |
| 105 | |
| 106 | static fs::path WIN32_GetModuleFileNameW(HMODULE hModule) |
| 107 | { |
nothing calls this directly
no test coverage detected