| 455 | } |
| 456 | |
| 457 | class FileSystemStd : public IGFD::IFileSystem { |
| 458 | public: |
| 459 | bool IsDirectoryCanBeOpened(const std::string& vName) override { |
| 460 | bool bExists = false; |
| 461 | if (!vName.empty()) { |
| 462 | namespace fs = std::filesystem; |
| 463 | auto pathName = stringToPath(vName); |
| 464 | try { |
| 465 | // interesting, in the case of a protected dir or for any reason the dir cant be opened |
| 466 | // this func will work but will say nothing more . not like the dirent version |
| 467 | bExists = fs::is_directory(pathName); |
| 468 | // test if can be opened, this function can thrown an exception if there is an issue with this dir |
| 469 | // here, the dir_iter is need else not exception is thrown.. |
| 470 | const auto dir_iter = fs::directory_iterator(pathName); |
| 471 | (void)dir_iter; // for avoid unused warnings |
| 472 | } catch (const std::exception& /*ex*/) { |
| 473 | // fail so this dir cant be opened |
| 474 | bExists = false; |
| 475 | } |
| 476 | } |
| 477 | return bExists; // this is not a directory! |
| 478 | } |
| 479 | bool IsDirectoryExist(const std::string& vName) override { |
| 480 | if (!vName.empty()) { |
| 481 | namespace fs = std::filesystem; |
| 482 | return fs::is_directory(stringToPath(vName)); |
| 483 | } |
| 484 | return false; // this is not a directory! |
| 485 | } |
| 486 | bool IsFileExist(const std::string& vName) override { |
| 487 | namespace fs = std::filesystem; |
| 488 | return fs::is_regular_file(stringToPath(vName)); |
| 489 | } |
| 490 | bool CreateDirectoryIfNotExist(const std::string& vName) override { |
| 491 | if (vName.empty()) return false; |
| 492 | if (IsDirectoryExist(vName)) return true; |
| 493 | |
| 494 | #if defined(__EMSCRIPTEN__) |
| 495 | std::string str = std::string("FS.mkdir('") + vName + "');"; |
| 496 | emscripten_run_script(str.c_str()); |
| 497 | bool res = true; |
| 498 | #else |
| 499 | namespace fs = std::filesystem; |
| 500 | bool res = fs::create_directory(stringToPath(vName)); |
| 501 | #endif // _IGFD_WIN_ |
| 502 | if (!res) { |
| 503 | std::cout << "Error creating directory " << vName << std::endl; |
| 504 | } |
| 505 | return res; |
| 506 | } |
| 507 | |
| 508 | std::vector<IGFD::PathDisplayedName> GetDevicesList() override { |
| 509 | std::vector<IGFD::PathDisplayedName> res; |
| 510 | #ifdef _IGFD_WIN_ |
| 511 | const DWORD mydevices = 2048; |
| 512 | char lpBuffer[2048]; |
| 513 | #define mini(a, b) (((a) < (b)) ? (a) : (b)) |
| 514 | const DWORD countChars = mini(GetLogicalDriveStringsA(mydevices, lpBuffer), 2047); |
nothing calls this directly
no outgoing calls
no test coverage detected