MCPcopy Create free account
hub / github.com/aiekick/ImGuiFileDialog / FileSystemDirent

Class FileSystemDirent

ImGuiFileDialog.cpp:629–1535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

627#define FILE_SYSTEM_OVERRIDE FileSystemStd
628#else
629class FileSystemDirent : public IGFD::IFileSystem {
630public:
631 bool IsDirectoryCanBeOpened(const std::string& vName) override {
632 if (!vName.empty()) {
633 DIR* pDir = nullptr;
634 // interesting, in the case of a protected dir or for any reason the dir cant be opened
635 // this func will fail
636 pDir = opendir(vName.c_str());
637 if (pDir != nullptr) {
638 (void)closedir(pDir);
639 return true;
640 }
641 }
642 return false;
643 }
644 bool IsDirectoryExist(const std::string& vName) override {
645 bool bExists = false;
646 if (!vName.empty()) {
647 DIR* pDir = nullptr;
648 pDir = opendir(vName.c_str());
649 if (pDir) {
650 bExists = true;
651 closedir(pDir);
652 } else if (ENOENT == errno) {
653 /* Directory does not exist. */
654 // bExists = false;
655 } else {
656 /* opendir() failed for some other reason.
657 like if a dir is protected, or not accessable with user right
658 */
659 bExists = true;
660 }
661 }
662 return bExists;
663 }
664 bool IsFileExist(const std::string& vName) override {
665 std::ifstream docFile(vName, std::ios::in);
666 if (docFile.is_open()) {
667 docFile.close();
668 return true;
669 }
670 return false;
671 }
672 bool CreateDirectoryIfNotExist(const std::string& vName) override {
673 bool res = false;
674 if (!vName.empty()) {
675 if (!IsDirectoryExist(vName)) {
676#ifdef _IGFD_WIN_
677 std::wstring wname = IGFD::Utils::UTF8Decode(vName);
678 if (CreateDirectoryW(wname.c_str(), nullptr)) {
679 res = true;
680 }
681#elif defined(__EMSCRIPTEN__) // _IGFD_WIN_
682 std::string str = std::string("FS.mkdir('") + vName + "');";
683 emscripten_run_script(str.c_str());
684 res = true;
685#elif defined(_IGFD_UNIX_)
686 char buffer[PATH_MAX] = {};

Callers

nothing calls this directly

Calls 12

IGFDExceptionClass · 0.85
emptyMethod · 0.80
sizeMethod · 0.80
clearMethod · 0.80
try_addMethod · 0.80
whatMethod · 0.80
beginMethod · 0.80
SearchForExtMethod · 0.80
isDirMethod · 0.80
isSymLinkMethod · 0.80
isFileMethod · 0.80

Tested by

no test coverage detected