Skip to content

Update ImGuiFileDialog.cpp #2190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions thirdparty/ImGuiFileDialog/ImGuiFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,27 @@ namespace IGFD
//// INLINE FUNCTIONS ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

#ifdef USE_STD_FILESYSTEM
inline bool isDirectoryAccessible(const std::string &path)
{
try
{
const std::filesystem::path fspath(path);
const auto dir_iter = std::filesystem::directory_iterator(fspath);
return true;
}
catch (...)
{
return false;
}
}
#else
inline bool isDirectoryAccessible(const std::string& path)
{
return access(path.c_str(), R_OK | F_OK) == 0;
}
#endif

#ifndef USE_STD_FILESYSTEM
inline int inAlphaSort(const struct dirent** a, const struct dirent** b)
{
Expand Down Expand Up @@ -1738,7 +1759,7 @@ namespace IGFD
newPath = prCurrentPath + std::string(1u, PATH_SEP) + vInfos->fileName;
}

if (IGFD::Utils::IsDirectoryExist(newPath))
if (IGFD::Utils::IsDirectoryExist(newPath) && isDirectoryAccessible(newPath))
{
if (puShowDrives)
{
Expand Down Expand Up @@ -2107,8 +2128,11 @@ namespace IGFD
auto gio = ImGui::GetIO();
if (ImGui::IsKeyReleased(gio.KeyMap[ImGuiKey_Enter]))
{
puFileManager.SetCurrentPath(std::string(puFileManager.puInputPathBuffer));
puFileManager.OpenCurrentPath(*this);
if (isDirectoryAccessible(std::string(puFileManager.puInputPathBuffer)))
{
puFileManager.SetCurrentPath(std::string(puFileManager.puInputPathBuffer));
puFileManager.OpenCurrentPath(*this);
}
puFileManager.puInputPathActivated = false;
}
if (ImGui::IsKeyReleased(gio.KeyMap[ImGuiKey_Escape]))
Expand Down