You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Merge pull request #10345 from Hinsbart/remove_imported
Removing a Resource also deletes imported files.
This commit is contained in:
@@ -199,6 +199,52 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path)
|
|||||||
return pat.path;
|
return pat.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) {
|
||||||
|
|
||||||
|
Error err;
|
||||||
|
FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
|
||||||
|
|
||||||
|
if (!f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
VariantParser::StreamFile stream;
|
||||||
|
stream.f = f;
|
||||||
|
|
||||||
|
String assign;
|
||||||
|
Variant value;
|
||||||
|
VariantParser::Tag next_tag;
|
||||||
|
|
||||||
|
int lines = 0;
|
||||||
|
String error_text;
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
assign = Variant();
|
||||||
|
next_tag.fields.clear();
|
||||||
|
next_tag.name = String();
|
||||||
|
|
||||||
|
err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
|
||||||
|
if (err == ERR_FILE_EOF) {
|
||||||
|
memdelete(f);
|
||||||
|
return;
|
||||||
|
} else if (err != OK) {
|
||||||
|
ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
|
||||||
|
memdelete(f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assign != String()) {
|
||||||
|
if (assign.begins_with("path.")) {
|
||||||
|
r_paths->push_back(value);
|
||||||
|
} else if (assign == "path") {
|
||||||
|
r_paths->push_back(value);
|
||||||
|
}
|
||||||
|
} else if (next_tag.name != "remap") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memdelete(f);
|
||||||
|
}
|
||||||
|
|
||||||
String ResourceFormatImporter::get_resource_type(const String &p_path) const {
|
String ResourceFormatImporter::get_resource_type(const String &p_path) const {
|
||||||
|
|
||||||
PathAndType pat;
|
PathAndType pat;
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public:
|
|||||||
virtual bool can_be_imported(const String &p_path) const;
|
virtual bool can_be_imported(const String &p_path) const;
|
||||||
|
|
||||||
String get_internal_resource_path(const String &p_path) const;
|
String get_internal_resource_path(const String &p_path) const;
|
||||||
|
void get_internal_resource_path_list(const String &p_path, List<String> *r_paths);
|
||||||
|
|
||||||
void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); }
|
void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); }
|
||||||
void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
|
void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
|
||||||
|
|||||||
@@ -339,6 +339,7 @@ bool EditorFileSystem::_update_scan_actions() {
|
|||||||
|
|
||||||
int idx = ia.dir->find_file_index(ia.file);
|
int idx = ia.dir->find_file_index(ia.file);
|
||||||
ERR_CONTINUE(idx == -1);
|
ERR_CONTINUE(idx == -1);
|
||||||
|
_delete_internal_files(ia.dir->files[idx]->file);
|
||||||
memdelete(ia.dir->files[idx]);
|
memdelete(ia.dir->files[idx]);
|
||||||
ia.dir->files.remove(idx);
|
ia.dir->files.remove(idx);
|
||||||
|
|
||||||
@@ -838,6 +839,19 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||||
|
for (List<String>::Element *E = paths.front(); E; E = E->next()) {
|
||||||
|
da->remove(E->get());
|
||||||
|
}
|
||||||
|
da->remove(p_file + ".import");
|
||||||
|
memdelete(da);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditorFileSystem::_thread_func_sources(void *_userdata) {
|
void EditorFileSystem::_thread_func_sources(void *_userdata) {
|
||||||
|
|
||||||
EditorFileSystem *efs = (EditorFileSystem *)_userdata;
|
EditorFileSystem *efs = (EditorFileSystem *)_userdata;
|
||||||
@@ -1192,6 +1206,7 @@ void EditorFileSystem::update_file(const String &p_file) {
|
|||||||
|
|
||||||
if (!FileAccess::exists(p_file)) {
|
if (!FileAccess::exists(p_file)) {
|
||||||
//was removed
|
//was removed
|
||||||
|
_delete_internal_files(p_file);
|
||||||
memdelete(fs->files[cpos]);
|
memdelete(fs->files[cpos]);
|
||||||
fs->files.remove(cpos);
|
fs->files.remove(cpos);
|
||||||
call_deferred("emit_signal", "filesystem_changed"); //update later
|
call_deferred("emit_signal", "filesystem_changed"); //update later
|
||||||
|
|||||||
@@ -168,6 +168,8 @@ class EditorFileSystem : public Node {
|
|||||||
|
|
||||||
void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress);
|
void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress);
|
||||||
|
|
||||||
|
void _delete_internal_files(String p_file);
|
||||||
|
|
||||||
Set<String> valid_extensions;
|
Set<String> valid_extensions;
|
||||||
Set<String> import_extensions;
|
Set<String> import_extensions;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user