Now FileCache uses the new Directory class.

This commit is contained in:
Relintai 2022-02-04 23:25:26 +01:00
parent 0669bbbe55
commit d71db48661

View File

@ -1,6 +1,6 @@
#include "file_cache.h" #include "file_cache.h"
#include <tinydir/tinydir.h> #include "core/os/directory.h"
#include <iostream> #include <iostream>
@ -27,40 +27,26 @@ void FileCache::wwwroot_refresh_cache() {
} }
void FileCache::wwwroot_evaluate_dir(const char *path, const bool should_exist) { void FileCache::wwwroot_evaluate_dir(const char *path, const bool should_exist) {
tinydir_dir dir; Ref<Directory> dir;
if (tinydir_open(&dir, path) == -1) { dir.instance();
if (should_exist) ERR_FAIL_COND_MSG(!dir->open(path, true), "Error opening wwwroot! folder: " + String(path));
printf("Error opening wwwroot! folder: %s\n", path);
return;
}
while (dir.has_next) { while (dir->has_next()) {
tinydir_file file; dir->next();
if (tinydir_readfile(&dir, &file) == -1) {
tinydir_next(&dir);
continue;
}
if (!file.is_dir) { if (dir->current_is_file()) {
String np = file.path; String np = dir->current_get_path_cstr();
np = np.substr(wwwroot.size(), np.size() - wwwroot.size()); np = np.substr(wwwroot.size(), np.size() - wwwroot.size());
registered_files.insert(np); registered_files.insert(np);
} else { } else {
if (file.name[0] == '.' && file.name[1] == '\0' || file.name[0] == '.' && file.name[1] == '.') { wwwroot_evaluate_dir(dir->current_get_path_cstr());
tinydir_next(&dir); }
continue;
} }
wwwroot_evaluate_dir(file.path); dir->close();
}
tinydir_next(&dir);
}
tinydir_close(&dir);
} }
bool FileCache::get_cached_body(const String &path, String *body) { bool FileCache::get_cached_body(const String &path, String *body) {