Browse Source

FileSystem: Force update when we delete a folder from the editor and searching changes only if we change the directory successfully in the scan_fs_changes

(cherry picked from commit dc7693867994620c390e619b91d23bdd1f8cba4e)
Mateo Kuruk Miccino 4 năm trước cách đây
mục cha
commit
71a9932f38
3 tập tin đã thay đổi với 15 bổ sung3 xóa
  1. 9 3
      editor/editor_file_system.cpp
  2. 2 0
      editor/editor_file_system.h
  3. 4 0
      editor/filesystem_dock.cpp

+ 9 - 3
editor/editor_file_system.cpp

@@ -68,6 +68,11 @@ int EditorFileSystemDirectory::find_dir_index(const String &p_dir) const {
 	return -1;
 }
 
+void EditorFileSystemDirectory::force_update() {
+	// We set modified_time to 0 to force `EditorFileSystem::_scan_fs_changes` to search changes in the directory
+	modified_time = 0;
+}
+
 int EditorFileSystemDirectory::get_subdir_count() const {
 
 	return subdirs.size();
@@ -870,9 +875,11 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
 
 		//then scan files and directories and check what's different
 
-		DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+		DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+
+		Error ret = da->change_dir(cd);
+		ERR_FAIL_COND_MSG(ret != OK, "Cannot change to '" + cd + "' folder.");
 
-		da->change_dir(cd);
 		da->list_dir_begin();
 		while (true) {
 
@@ -958,7 +965,6 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
 		}
 
 		da->list_dir_end();
-		memdelete(da);
 	}
 
 	for (int i = 0; i < p_dir->files.size(); i++) {

+ 2 - 0
editor/editor_file_system.h

@@ -101,6 +101,8 @@ public:
 	int find_file_index(const String &p_file) const;
 	int find_dir_index(const String &p_dir) const;
 
+	void force_update();
+
 	EditorFileSystemDirectory();
 	~EditorFileSystemDirectory();
 };

+ 4 - 0
editor/filesystem_dock.cpp

@@ -1330,6 +1330,10 @@ void FileSystemDock::_folder_removed(String p_folder) {
 	}
 
 	current_path->set_text(path);
+	EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_filesystem_path(path);
+	if (efd) {
+		efd->force_update();
+	}
 }
 
 void FileSystemDock::_rename_operation_confirm() {