#ifndef YERBACON_EMSCRIPTEN_COMPATIBILITY_H #define YERBACON_EMSCRIPTEN_COMPATIBILITY_H #include #include #include filesystem::path mount(const std::string_view& element_path) { filesystem::path file_path = element_path; #ifdef EMSCRIPTEN if (element_path.size() >= 2 and element_path[1] == ':') { auto path = string(element_path.begin() + 2, element_path.end()); replace(path.begin(), path.end(), '\\', '/'); file_path = path; } const string directory = filesystem::path(file_path).remove_filename(); cout << "Directory: " << directory << endl; for (unsigned int character = 1; character < directory.size(); ++character) { const string sub_directory = directory.substr(0, character); if (is_node and (directory[character] == '/') and not filesystem::is_directory(sub_directory)) { MAIN_THREAD_EM_ASM({ const sub_directory = UTF8ToString($0); if (!FS.isMountpoint(sub_directory)) { try { FS.mkdir(sub_directory); FS.mount(NODEFS, {root: sub_directory}, sub_directory); } catch (exception) {} }; }, sub_directory.c_str()); } } #endif return file_path; } #endif //YERBACON_EMSCRIPTEN_COMPATIBILITY_H