| 627 | #define FILE_SYSTEM_OVERRIDE FileSystemStd |
| 628 | #else |
| 629 | class FileSystemDirent : public IGFD::IFileSystem { |
| 630 | public: |
| 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] = {}; |
nothing calls this directly
no test coverage detected