1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

FileChooser: Show desktop folder if requested folder does not exist

This change affects the PostVista version of the Windows FileChooser.
This commit is contained in:
reuk 2020-12-14 13:26:49 +00:00
parent e403e330ef
commit 41ec486dd0
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -167,6 +167,11 @@ private:
Atomic<HWND> nativeDialogRef;
Atomic<int> shouldCancel;
struct FreeLPWSTR
{
void operator() (LPWSTR ptr) const noexcept { CoTaskMemFree (ptr); }
};
bool showDialog (IFileDialog& dialog, bool async) const
{
FILEOPENDIALOGOPTIONS flags = {};
@ -193,7 +198,17 @@ private:
PIDLIST_ABSOLUTE pidl = {};
if (FAILED (SHParseDisplayName (initialPath.toWideCharPointer(), nullptr, &pidl, SFGAO_FOLDER, nullptr)))
return false;
{
LPWSTR ptr = nullptr;
auto result = SHGetKnownFolderPath (FOLDERID_Desktop, 0, nullptr, &ptr);
std::unique_ptr<WCHAR, FreeLPWSTR> desktopPath (ptr);
if (FAILED (result))
return false;
if (FAILED (SHParseDisplayName (desktopPath.get(), nullptr, &pidl, SFGAO_FOLDER, nullptr)))
return false;
}
const auto item = [&]
{
@ -228,17 +243,12 @@ private:
{
const auto getUrl = [] (IShellItem& item)
{
struct Free
{
void operator() (LPWSTR ptr) const noexcept { CoTaskMemFree (ptr); }
};
LPWSTR ptr = nullptr;
if (item.GetDisplayName (SIGDN_FILESYSPATH, &ptr) != S_OK)
return URL();
const auto path = std::unique_ptr<WCHAR, Free> { ptr };
const auto path = std::unique_ptr<WCHAR, FreeLPWSTR> { ptr };
return URL (File (String (path.get())));
};