summaryrefslogtreecommitdiff
path: root/editor/editor_file_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r--editor/editor_file_system.cpp79
1 files changed, 29 insertions, 50 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index 2b98a4b02a..98bf5d3234 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -218,10 +218,10 @@ void EditorFileSystem::_scan_filesystem() {
String project = ProjectSettings::get_singleton()->get_resource_path();
String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(CACHE_FILE_NAME);
- FileAccess *f = FileAccess::open(fscache, FileAccess::READ);
+ Ref<FileAccess> f = FileAccess::open(fscache, FileAccess::READ);
bool first = true;
- if (f) {
+ if (f.is_valid()) {
//read the disk cache
while (!f->eof_reached()) {
String l = f->get_line().strip_edges();
@@ -283,16 +283,13 @@ void EditorFileSystem::_scan_filesystem() {
file_cache[name] = fc;
}
}
-
- f->close();
- memdelete(f);
}
String update_cache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_update4");
if (FileAccess::exists(update_cache)) {
{
- FileAccessRef f2 = FileAccess::open(update_cache, FileAccess::READ);
+ Ref<FileAccess> f2 = FileAccess::open(update_cache, FileAccess::READ);
String l = f2->get_line().strip_edges();
while (!l.is_empty()) {
file_cache.erase(l); //erase cache for this, so it gets updated
@@ -300,7 +297,7 @@ void EditorFileSystem::_scan_filesystem() {
}
}
- DirAccessRef d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
d->remove(update_cache); //bye bye update cache
}
@@ -314,14 +311,12 @@ void EditorFileSystem::_scan_filesystem() {
new_filesystem = memnew(EditorFileSystemDirectory);
new_filesystem->parent = nullptr;
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
d->change_dir("res://");
_scan_new_dir(new_filesystem, d, sp);
file_cache.clear(); //clear caches, no longer needed
- memdelete(d);
-
if (!first_scan) {
//on the first scan this is done from the main thread after re-importing
_save_filesystem_cache();
@@ -335,13 +330,11 @@ void EditorFileSystem::_save_filesystem_cache() {
String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(CACHE_FILE_NAME);
- FileAccess *f = FileAccess::open(fscache, FileAccess::WRITE);
- ERR_FAIL_COND_MSG(!f, "Cannot create file '" + fscache + "'. Check user write permissions.");
+ Ref<FileAccess> f = FileAccess::open(fscache, FileAccess::WRITE);
+ ERR_FAIL_COND_MSG(f.is_null(), "Cannot create file '" + fscache + "'. Check user write permissions.");
f->store_line(filesystem_settings_version_for_import);
_save_filesystem_cache(filesystem, f);
- f->close();
- memdelete(f);
}
void EditorFileSystem::_thread_func(void *_userdata) {
@@ -364,9 +357,9 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
}
Error err;
- FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
+ Ref<FileAccess> f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
- if (!f) { //no import file, do reimport
+ if (f.is_null()) { //no import file, do reimport
return true;
}
@@ -400,7 +393,6 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
break;
} else if (err != OK) {
ERR_PRINT("ResourceFormatImporter::load - '" + p_path + ".import:" + itos(lines) + "' error '" + error_text + "'.");
- memdelete(f);
return false; //parse error, try reimport manually (Avoid reimport loop on broken file)
}
@@ -431,8 +423,6 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
}
}
- memdelete(f);
-
if (importer_name == "keep") {
return false; //keep mode, do not reimport
}
@@ -453,8 +443,8 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
// Read the md5's from a separate file (so the import parameters aren't dependent on the file version
String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(p_path);
- FileAccess *md5s = FileAccess::open(base_path + ".md5", FileAccess::READ, &err);
- if (!md5s) { // No md5's stored for this resource
+ Ref<FileAccess> md5s = FileAccess::open(base_path + ".md5", FileAccess::READ, &err);
+ if (md5s.is_null()) { // No md5's stored for this resource
return true;
}
@@ -472,7 +462,6 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
break;
} else if (err != OK) {
ERR_PRINT("ResourceFormatImporter::load - '" + p_path + ".import.md5:" + itos(lines) + "' error '" + error_text + "'.");
- memdelete(md5s);
return false; // parse error
}
if (!assign.is_empty()) {
@@ -485,7 +474,6 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
}
}
}
- memdelete(md5s);
//imported files are gone, reimport
for (const String &E : to_check) {
@@ -742,7 +730,7 @@ EditorFileSystem::ScanProgress EditorFileSystem::ScanProgress::get_sub(int p_cur
return sp;
}
-void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess *da, const ScanProgress &p_progress) {
+void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAccess> &da, const ScanProgress &p_progress) {
List<String> dirs;
List<String> files;
@@ -967,7 +955,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
//then scan files and directories and check what's different
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
Error ret = da->change_dir(cd);
ERR_FAIL_COND_MSG(ret != OK, "Cannot change to '" + cd + "' folder.");
@@ -998,10 +986,9 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
efd->parent = p_dir;
efd->name = f;
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
d->change_dir(cd.plus_file(f));
_scan_new_dir(efd, d, p_progress.get_sub(1, 1));
- memdelete(d);
ItemAction ia;
ia.action = ItemAction::ACTION_DIR_ADD;
@@ -1137,7 +1124,7 @@ void EditorFileSystem::_delete_internal_files(String p_file) {
if (FileAccess::exists(p_file + ".import")) {
List<String> paths;
ResourceFormatImporter::get_singleton()->get_internal_resource_path_list(p_file, &paths);
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
for (const String &E : paths) {
da->remove(E);
}
@@ -1282,7 +1269,7 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem() {
return filesystem;
}
-void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, FileAccess *p_file) {
+void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, Ref<FileAccess> p_file) {
if (!p_dir) {
return; //none
}
@@ -1467,8 +1454,8 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p
void EditorFileSystem::_save_late_updated_files() {
//files that already existed, and were modified, need re-scanning for dependencies upon project restart. This is done via saving this special file
String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_update4");
- FileAccessRef f = FileAccess::open(fscache, FileAccess::WRITE);
- ERR_FAIL_COND_MSG(!f, "Cannot create file '" + fscache + "'. Check user write permissions.");
+ Ref<FileAccess> f = FileAccess::open(fscache, FileAccess::WRITE);
+ ERR_FAIL_COND_MSG(f.is_null(), "Cannot create file '" + fscache + "'. Check user write permissions.");
for (Set<String>::Element *E = late_update_files.front(); E; E = E->next()) {
f->store_line(E->get());
}
@@ -1713,8 +1700,8 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
for (const KeyValue<String, Map<StringName, Variant>> &E : source_file_options) {
const String &file = E.key;
String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(file);
- FileAccessRef f = FileAccess::open(file + ".import", FileAccess::WRITE);
- ERR_FAIL_COND_V_MSG(!f, ERR_FILE_CANT_OPEN, "Cannot open import file '" + file + ".import'.");
+ Ref<FileAccess> f = FileAccess::open(file + ".import", FileAccess::WRITE);
+ ERR_FAIL_COND_V_MSG(f.is_null(), ERR_FILE_CANT_OPEN, "Cannot open import file '" + file + ".import'.");
//write manually, as order matters ([remap] has to go first for performance).
f->store_line("[remap]");
@@ -1774,17 +1761,14 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
f->store_line(base + "=" + value);
}
- f->close();
-
// Store the md5's of the various files. These are stored separately so that the .import files can be version controlled.
- FileAccessRef md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE);
- ERR_FAIL_COND_V_MSG(!md5s, ERR_FILE_CANT_OPEN, "Cannot open MD5 file '" + base_path + ".md5'.");
+ Ref<FileAccess> md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE);
+ ERR_FAIL_COND_V_MSG(md5s.is_null(), ERR_FILE_CANT_OPEN, "Cannot open MD5 file '" + base_path + ".md5'.");
md5s->store_line("source_md5=\"" + FileAccess::get_md5(file) + "\"");
if (dest_paths.size()) {
md5s->store_line("dest_md5=\"" + FileAccess::get_multiple_md5(dest_paths) + "\"\n");
}
- md5s->close();
EditorFileSystemDirectory *fs = nullptr;
int cpos = -1;
@@ -1930,8 +1914,8 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
//as import is complete, save the .import file
- FileAccess *f = FileAccess::open(p_file + ".import", FileAccess::WRITE);
- ERR_FAIL_COND_MSG(!f, "Cannot open file from path '" + p_file + ".import'.");
+ Ref<FileAccess> f = FileAccess::open(p_file + ".import", FileAccess::WRITE);
+ ERR_FAIL_COND_MSG(f.is_null(), "Cannot open file from path '" + p_file + ".import'.");
//write manually, as order matters ([remap] has to go first for performance).
f->store_line("[remap]");
@@ -2017,19 +2001,14 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
f->store_line(base + "=" + value);
}
- f->close();
- memdelete(f);
-
// Store the md5's of the various files. These are stored separately so that the .import files can be version controlled.
- FileAccess *md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE);
- ERR_FAIL_COND_MSG(!md5s, "Cannot open MD5 file '" + base_path + ".md5'.");
+ Ref<FileAccess> md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE);
+ ERR_FAIL_COND_MSG(md5s.is_null(), "Cannot open MD5 file '" + base_path + ".md5'.");
md5s->store_line("source_md5=\"" + FileAccess::get_md5(p_file) + "\"");
if (dest_paths.size()) {
md5s->store_line("dest_md5=\"" + FileAccess::get_multiple_md5(dest_paths) + "\"\n");
}
- md5s->close();
- memdelete(md5s);
//update modified times, to avoid reimport
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
@@ -2342,14 +2321,14 @@ bool EditorFileSystem::_scan_extensions() {
String extension_list_config_file = NativeExtension::get_extension_list_config_file();
if (extensions.size()) {
if (extensions_added.size() || extensions_removed.size()) { //extensions were added or removed
- FileAccessRef f = FileAccess::open(extension_list_config_file, FileAccess::WRITE);
+ Ref<FileAccess> f = FileAccess::open(extension_list_config_file, FileAccess::WRITE);
for (const String &E : extensions) {
f->store_line(E);
}
}
} else {
if (loaded_extensions.size() || FileAccess::exists(extension_list_config_file)) { //extensions were removed
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
da->remove(extension_list_config_file);
}
}
@@ -2438,7 +2417,7 @@ EditorFileSystem::EditorFileSystem() {
new_filesystem = nullptr;
// This should probably also work on Unix and use the string it returns for FAT32 or exFAT
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
using_fat32_or_exfat = (da->get_filesystem_type() == "FAT32" || da->get_filesystem_type() == "exFAT");
scan_total = 0;