From 010e3e0ac7edb93c83ac807438548d9b4b26605f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 5 Jan 2016 10:36:24 -0300 Subject: [PATCH] -completely rewritten filesystem dock and internal editor filesystem management, fixes #1926 -filesystem dock now tracks objects and directories in real-time, fixes #2009 --- bin/tests/test_containers.cpp | 2 +- bin/tests/test_containers.h | 2 +- bin/tests/test_detailer.cpp | 2 +- bin/tests/test_detailer.h | 2 +- bin/tests/test_gdscript.cpp | 2 +- bin/tests/test_gdscript.h | 2 +- bin/tests/test_gui.cpp | 2 +- bin/tests/test_gui.h | 2 +- bin/tests/test_image.cpp | 2 +- bin/tests/test_image.h | 2 +- bin/tests/test_io.cpp | 2 +- bin/tests/test_io.h | 2 +- bin/tests/test_main.cpp | 2 +- bin/tests/test_main.h | 2 +- bin/tests/test_math.cpp | 2 +- bin/tests/test_math.h | 2 +- bin/tests/test_misc.cpp | 2 +- bin/tests/test_misc.h | 2 +- bin/tests/test_particles.cpp | 2 +- bin/tests/test_particles.h | 2 +- bin/tests/test_physics.cpp | 2 +- bin/tests/test_physics.h | 2 +- bin/tests/test_physics_2d.cpp | 2 +- bin/tests/test_physics_2d.h | 2 +- bin/tests/test_python.cpp | 2 +- bin/tests/test_python.h | 2 +- bin/tests/test_render.cpp | 2 +- bin/tests/test_render.h | 2 +- bin/tests/test_shader_lang.cpp | 2 +- bin/tests/test_shader_lang.h | 2 +- bin/tests/test_sound.cpp | 2 +- bin/tests/test_sound.h | 2 +- bin/tests/test_string.cpp | 2 +- bin/tests/test_string.h | 2 +- tools/editor/editor_file_system.cpp | 958 ++++++++++++++++------------ tools/editor/editor_file_system.h | 91 ++- 36 files changed, 646 insertions(+), 471 deletions(-) diff --git a/bin/tests/test_containers.cpp b/bin/tests/test_containers.cpp index f8cc8ccd412..db877fcc1cc 100644 --- a/bin/tests/test_containers.cpp +++ b/bin/tests/test_containers.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_containers.h b/bin/tests/test_containers.h index 72d5c0ff7a3..3bfdef301be 100644 --- a/bin/tests/test_containers.h +++ b/bin/tests/test_containers.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_detailer.cpp b/bin/tests/test_detailer.cpp index 616356077e2..ce318632ddb 100644 --- a/bin/tests/test_detailer.cpp +++ b/bin/tests/test_detailer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_detailer.h b/bin/tests/test_detailer.h index 597e088caf2..a410f6a67af 100644 --- a/bin/tests/test_detailer.h +++ b/bin/tests/test_detailer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_gdscript.cpp b/bin/tests/test_gdscript.cpp index 683191fba2e..68209ecb540 100644 --- a/bin/tests/test_gdscript.cpp +++ b/bin/tests/test_gdscript.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_gdscript.h b/bin/tests/test_gdscript.h index 225654e2a8e..f599b9c9e13 100644 --- a/bin/tests/test_gdscript.h +++ b/bin/tests/test_gdscript.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_gui.cpp b/bin/tests/test_gui.cpp index cba488a3daa..c404623872e 100644 --- a/bin/tests/test_gui.cpp +++ b/bin/tests/test_gui.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_gui.h b/bin/tests/test_gui.h index 5526320b0c8..556b45462ae 100644 --- a/bin/tests/test_gui.h +++ b/bin/tests/test_gui.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_image.cpp b/bin/tests/test_image.cpp index bf9851cf01e..b378755dfe0 100644 --- a/bin/tests/test_image.cpp +++ b/bin/tests/test_image.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_image.h b/bin/tests/test_image.h index 09b33e799e7..8812658464a 100644 --- a/bin/tests/test_image.h +++ b/bin/tests/test_image.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_io.cpp b/bin/tests/test_io.cpp index a1eb2be19b9..4c211a1b0d2 100644 --- a/bin/tests/test_io.cpp +++ b/bin/tests/test_io.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_io.h b/bin/tests/test_io.h index c839590ab9e..27a5118cf0d 100644 --- a/bin/tests/test_io.h +++ b/bin/tests/test_io.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_main.cpp b/bin/tests/test_main.cpp index 8143a95d669..5567145aa04 100644 --- a/bin/tests/test_main.cpp +++ b/bin/tests/test_main.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_main.h b/bin/tests/test_main.h index c8d571a7dd6..d1898387ebc 100644 --- a/bin/tests/test_main.h +++ b/bin/tests/test_main.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_math.cpp b/bin/tests/test_math.cpp index b5041b265f2..d340515c65c 100644 --- a/bin/tests/test_math.cpp +++ b/bin/tests/test_math.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_math.h b/bin/tests/test_math.h index 492c3a18378..3209ebcef6f 100644 --- a/bin/tests/test_math.h +++ b/bin/tests/test_math.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_misc.cpp b/bin/tests/test_misc.cpp index 68564c62b05..d6ea1938535 100644 --- a/bin/tests/test_misc.cpp +++ b/bin/tests/test_misc.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_misc.h b/bin/tests/test_misc.h index 55608f6a0e4..ac751e5cc9b 100644 --- a/bin/tests/test_misc.h +++ b/bin/tests/test_misc.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_particles.cpp b/bin/tests/test_particles.cpp index bafd78eda07..18b52444d89 100644 --- a/bin/tests/test_particles.cpp +++ b/bin/tests/test_particles.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_particles.h b/bin/tests/test_particles.h index e95637a4e6e..e5e3cfab15c 100644 --- a/bin/tests/test_particles.h +++ b/bin/tests/test_particles.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_physics.cpp b/bin/tests/test_physics.cpp index ce96f37f3f5..e3fd96ff9d7 100644 --- a/bin/tests/test_physics.cpp +++ b/bin/tests/test_physics.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_physics.h b/bin/tests/test_physics.h index 5b6a54f2d48..f62806bf5e0 100644 --- a/bin/tests/test_physics.h +++ b/bin/tests/test_physics.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_physics_2d.cpp b/bin/tests/test_physics_2d.cpp index c5fb7349998..70a7d868be2 100644 --- a/bin/tests/test_physics_2d.cpp +++ b/bin/tests/test_physics_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_physics_2d.h b/bin/tests/test_physics_2d.h index e2eb1f40234..eadd5ebcb48 100644 --- a/bin/tests/test_physics_2d.h +++ b/bin/tests/test_physics_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_python.cpp b/bin/tests/test_python.cpp index 575caf2513c..a89e4a7eeed 100644 --- a/bin/tests/test_python.cpp +++ b/bin/tests/test_python.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_python.h b/bin/tests/test_python.h index 77e9603fe27..9dafbd545d4 100644 --- a/bin/tests/test_python.h +++ b/bin/tests/test_python.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_render.cpp b/bin/tests/test_render.cpp index 568699e5e6a..97a52b16c1b 100644 --- a/bin/tests/test_render.cpp +++ b/bin/tests/test_render.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_render.h b/bin/tests/test_render.h index 6993e75b9fe..dc71a32978a 100644 --- a/bin/tests/test_render.h +++ b/bin/tests/test_render.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_shader_lang.cpp b/bin/tests/test_shader_lang.cpp index e55ad3074f2..df826e489d7 100644 --- a/bin/tests/test_shader_lang.cpp +++ b/bin/tests/test_shader_lang.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_shader_lang.h b/bin/tests/test_shader_lang.h index f129fb224af..85d379bc43c 100644 --- a/bin/tests/test_shader_lang.h +++ b/bin/tests/test_shader_lang.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_sound.cpp b/bin/tests/test_sound.cpp index 44cc117e02b..63c6edd9c9b 100644 --- a/bin/tests/test_sound.cpp +++ b/bin/tests/test_sound.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_sound.h b/bin/tests/test_sound.h index 91b87a2261c..32b66c8bbad 100644 --- a/bin/tests/test_sound.h +++ b/bin/tests/test_sound.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_string.cpp b/bin/tests/test_string.cpp index fe7bf4d9cf7..93b1835b785 100644 --- a/bin/tests/test_string.cpp +++ b/bin/tests/test_string.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/bin/tests/test_string.h b/bin/tests/test_string.h index 7b3cd9a019c..b04eccb0059 100644 --- a/bin/tests/test_string.h +++ b/bin/tests/test_string.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/tools/editor/editor_file_system.cpp b/tools/editor/editor_file_system.cpp index 673607706a6..c7c1a48e34e 100644 --- a/tools/editor/editor_file_system.cpp +++ b/tools/editor/editor_file_system.cpp @@ -37,6 +37,31 @@ EditorFileSystem *EditorFileSystem::singleton=NULL; +void EditorFileSystemDirectory::sort_files() { + + files.sort_custom(); +} + +int EditorFileSystemDirectory::find_file_index(const String& p_file) const { + + for(int i=0;ifile==p_file) + return i; + } + return -1; + +} +int EditorFileSystemDirectory::find_dir_index(const String& p_dir) const{ + + + for(int i=0;iname==p_dir) + return i; + } + + return -1; +} + int EditorFileSystemDirectory::get_subdir_count() const { @@ -59,7 +84,7 @@ String EditorFileSystemDirectory::get_file(int p_idx) const{ ERR_FAIL_INDEX_V(p_idx,files.size(),""); - return files[p_idx].file; + return files[p_idx]->file; } String EditorFileSystemDirectory::get_path() const { @@ -91,22 +116,22 @@ String EditorFileSystemDirectory::get_file_path(int p_idx) const { bool EditorFileSystemDirectory::get_file_meta(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,files.size(),""); - return files[p_idx].meta.enabled; + return files[p_idx]->meta.enabled; } Vector EditorFileSystemDirectory::get_file_deps(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,files.size(),Vector()); - return files[p_idx].meta.deps; + return files[p_idx]->meta.deps; } Vector EditorFileSystemDirectory::get_missing_sources(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,files.size(),Vector()); Vector missing; - for(int i=0;imeta.sources.size();i++) { + if (files[p_idx]->meta.sources[i].missing) + missing.push_back(files[p_idx]->meta.sources[i].path); } return missing; @@ -116,8 +141,8 @@ Vector EditorFileSystemDirectory::get_missing_sources(int p_idx) const { bool EditorFileSystemDirectory::is_missing_sources(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,files.size(),false); - for(int i=0;imeta.sources.size();i++) { + if (files[p_idx]->meta.sources[i].missing) return true; } @@ -127,7 +152,7 @@ bool EditorFileSystemDirectory::is_missing_sources(int p_idx) const { StringName EditorFileSystemDirectory::get_file_type(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,files.size(),""); - return files[p_idx].type; + return files[p_idx]->type; } String EditorFileSystemDirectory::get_name() { @@ -157,11 +182,17 @@ void EditorFileSystemDirectory::_bind_methods() { EditorFileSystemDirectory::EditorFileSystemDirectory() { + modified_time=0; parent=NULL; } EditorFileSystemDirectory::~EditorFileSystemDirectory() { + for(int i=0;i imd = ResourceLoader::load_import_metadata(p_path); @@ -214,160 +232,16 @@ EditorFileSystemDirectory::ImportMeta EditorFileSystem::_get_meta(const String& return m; } -EditorFileSystem::DirItem* EditorFileSystem::_scan_dir(DirAccess *da,Set &extensions,String p_name,float p_from,float p_range,const String& p_path,HashMap &file_cache,HashMap &dir_cache,EditorProgressBG& p_prog) { - if (abort_scan) - return NULL; +void EditorFileSystem::_scan_filesystem() { - if (p_path!=String()) { - if (FileAccess::exists(("res://"+p_path).plus_file("engine.cfg"))) { - return NULL; - } - } - - List dirs; - List files; - Set pngs; - - String path=p_path; - if (path.ends_with("/")) - path=path.substr(0,path.length()-1); - String global_path = Globals::get_singleton()->get_resource_path().plus_file(path); - - path="res://"+path; - uint64_t mtime = FileAccess::get_modified_time(global_path); - - DirCache *dc = dir_cache.getptr(path); - - - if (false && dc && dc->modification_time==mtime) { - //use the cached files, since directory did not change - for (Set::Element *E=dc->subdirs.front();E;E=E->next()) { - dirs.push_back(E->get()); - } - for (Set::Element *E=dc->files.front();E;E=E->next()) { - files.push_back(E->get()); - } - - } else { - //use the filesystem, some files may have changed - Error err = da->change_dir(global_path); - if (err!=OK) { - print_line("Can't change to: "+path); - ERR_FAIL_COND_V(err!=OK,NULL); - } - - - da->list_dir_begin(); - while (true) { - - bool isdir; - String f = da->get_next(&isdir); - if (f=="") - break; - if (isdir) { - dirs.push_back(f); - } else { - String ext = f.extension().to_lower(); - if (extensions.has(ext)) - files.push_back(f); - - } - - } - - da->list_dir_end(); - files.sort(); - dirs.sort(); - - } - - - - //print_line(da->get_current_dir()+": dirs: "+itos(dirs.size())+" files:"+itos(files.size()) ); - - //find subdirs - Vector subdirs; - - //String current = da->get_current_dir(); - float idx=0; - for (List::Element *E=dirs.front();E;E=E->next(),idx+=1.0) { - - String d = E->get(); - if (d.begins_with(".")) //ignore hidden and . / .. - continue; - - //ERR_CONTINUE( da->change_dir(d)!= OK ); - DirItem *sdi = _scan_dir(da,extensions,d,p_from+(idx/dirs.size())*p_range,p_range/dirs.size(),p_path+d+"/",file_cache,dir_cache,p_prog); - if (sdi) { - subdirs.push_back(sdi); - } - //da->change_dir(current); - } - - - if (subdirs.empty() && files.empty()) { - total=p_from+p_range; - p_prog.step(total*100); - return NULL; //give up, nothing to do here - } - - DirItem *di = memnew( DirItem ); - di->path=path; - di->name=p_name; - di->dirs=subdirs; - di->modified_time=mtime; - - //add files - for (List::Element *E=files.front();E;E=E->next()) { - - SceneItem * si = memnew( SceneItem ); - si->file=E->get(); - si->path="res://"+p_path+si->file; - FileCache *fc = file_cache.getptr(si->path); - uint64_t mt = FileAccess::get_modified_time(si->path); - - if (fc && fc->modification_time == mt) { - - si->meta=fc->meta; - si->type=fc->type; - si->modified_time=fc->modification_time; - } else { - si->meta=_get_meta(si->path); - si->type=ResourceLoader::get_resource_type(si->path); - si->modified_time=mt; - - } - - if (si->meta.enabled) { - md_count++; - if (_check_meta_sources(si->meta)) { - sources_changed.push_back(si->path); - } - } - di->files.push_back(si); - } - - total=p_from+p_range; - p_prog.step(total*100); - - return di; -} - - -void EditorFileSystem::_scan_scenes() { - - ERR_FAIL_COND(!scanning || scandir); + ERR_FAIL_COND(!scanning || new_filesystem); //read .fscache - HashMap file_cache; - HashMap dir_cache; - DirCache *dc=NULL; String cpath; sources_changed.clear(); - - + file_cache.clear(); String project=Globals::get_singleton()->get_resource_path(); @@ -387,26 +261,7 @@ void EditorFileSystem::_scan_scenes() { ERR_CONTINUE( split.size() != 3); String name = split[1]; - dir_cache[name]=DirCache(); - dc=&dir_cache[name]; - dc->modification_time=split[2].to_int64(); - - if (name!="res://") { - - cpath=name+"/"; - - int sp=name.find_last("/"); - if (sp==5) - sp=6; - String pd = name.substr(0,sp); - DirCache *dcp = dir_cache.getptr(pd); - ERR_CONTINUE(!dcp); - dcp->subdirs.insert(name.get_file()); - } else { - - cpath=name; - } - + cpath=name; } else { Vector split = l.split("::"); @@ -414,12 +269,8 @@ void EditorFileSystem::_scan_scenes() { String name = split[0]; String file; - if (!name.begins_with("res://")) { - file=name; - name=cpath+name; - } else { - file=name.get_file(); - } + file=name; + name=cpath.plus_file(name); FileCache fc; fc.type=split[1]; @@ -453,8 +304,6 @@ void EditorFileSystem::_scan_scenes() { file_cache[name]=fc; - ERR_CONTINUE(!dc); - dc->files.insert(file); } } @@ -465,39 +314,31 @@ void EditorFileSystem::_scan_scenes() { + EditorProgressBG scan_progress("efs","ScanFS",1000); + + ScanProgress sp; + sp.low=0; + sp.hi=1; + sp.progress=&scan_progress; + new_filesystem = memnew( EditorFileSystemDirectory ); + new_filesystem->parent=NULL; - total=0; - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - //da->change_dir( Globals::get_singleton()->get_resource_path() ); + 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 - List extensionsl; - ResourceLoader::get_recognized_extensions_for_type("",&extensionsl); - Set extensions; - for(List::Element *E = extensionsl.front();E;E=E->next()) { - - extensions.insert(E->get()); - } - - EditorProgressBG scan_progress("efs","ScanFS",100); - - md_count=0; - scandir=_scan_dir(da,extensions,"",0,1,"",file_cache,dir_cache,scan_progress); - memdelete(da); - if (abort_scan && scandir) { - memdelete(scandir); - scandir=NULL; - - } + memdelete(d); //save back the findings // String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("file_cache"); f=FileAccess::open(fscache,FileAccess::WRITE); - _save_type_cache_fs(scandir,f); + _save_filesystem_cache(new_filesystem,f); f->close(); memdelete(f); @@ -510,7 +351,95 @@ void EditorFileSystem::_scan_scenes() { void EditorFileSystem::_thread_func(void *_userdata) { EditorFileSystem *sd = (EditorFileSystem*)_userdata; - sd->_scan_scenes(); + sd->_scan_filesystem(); + +} + +bool EditorFileSystem::_update_scan_actions() { + + sources_changed.clear(); + + bool fs_changed=false; + + for (List::Element *E=scan_actions.front();E;E=E->next()) { + + ItemAction&ia = E->get(); + + switch(ia.action) { + case ItemAction::ACTION_NONE: { + + } break; + case ItemAction::ACTION_DIR_ADD: { + + //print_line("*ACTION ADD DIR: "+ia.new_dir->get_name()); + int idx=0; + for(int i=0;isubdirs.size();i++) { + + if (ia.new_dir->namesubdirs[i]->name) + break; + idx++; + } + if (idx==ia.dir->subdirs.size()) { + ia.dir->subdirs.push_back(ia.new_dir); + } else { + ia.dir->subdirs.insert(idx,ia.new_dir); + } + + fs_changed=true; + } break; + case ItemAction::ACTION_DIR_REMOVE: { + + ERR_CONTINUE(!ia.dir->parent); + //print_line("*ACTION REMOVE DIR: "+ia.dir->get_name()); + ia.dir->parent->subdirs.erase(ia.dir); + memdelete( ia.dir ); + fs_changed=true; + } break; + case ItemAction::ACTION_FILE_ADD: { + + int idx=0; + for(int i=0;ifiles.size();i++) { + + if (ia.new_file->filefiles[i]->file) + break; + idx++; + } + if (idx==ia.dir->files.size()) { + ia.dir->files.push_back(ia.new_file); + } else { + ia.dir->files.insert(idx,ia.new_file); + } + + fs_changed=true; + //print_line("*ACTION ADD FILE: "+ia.new_file->file); + + } break; + case ItemAction::ACTION_FILE_REMOVE: { + + int idx = ia.dir->find_file_index(ia.file); + ERR_CONTINUE(idx==-1); + memdelete( ia.dir->files[idx] ); + ia.dir->files.remove(idx); + + fs_changed=true; + //print_line("*ACTION REMOVE FILE: "+ia.file); + + } break; + case ItemAction::ACTION_FILE_SOURCES_CHANGED: { + + int idx = ia.dir->find_file_index(ia.file); + ERR_CONTINUE(idx==-1); + String full_path = ia.dir->get_file_path(idx); + sources_changed.push_back(full_path); + + } break; + + } + } + + scan_actions.clear(); + + return fs_changed; } @@ -526,19 +455,15 @@ void EditorFileSystem::scan() { abort_scan=false; if (!use_threads) { scanning=true; - _scan_scenes(); - if (rootdir) - memdelete(rootdir); - rootdir=scandir; + scan_total=0; + _scan_filesystem(); if (filesystem) memdelete(filesystem); // file_type_cache.clear(); - filesystem=_update_tree(rootdir); - - if (rootdir) - memdelete(rootdir); - rootdir=NULL; - scanning=false; + filesystem=new_filesystem; + new_filesystem=NULL; + _update_scan_actions(); + scanning=false; emit_signal("filesystem_changed"); emit_signal("sources_changed",sources_changed.size()>0); @@ -548,6 +473,7 @@ void EditorFileSystem::scan() { set_process(true); Thread::Settings s; scanning=true; + scan_total=0; s.priority=Thread::PRIORITY_LOW; thread = Thread::create(_thread_func,this,s); //tree->hide(); @@ -559,14 +485,10 @@ void EditorFileSystem::scan() { } -bool EditorFileSystem::_check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta,EditorProgressBG *ep) { +bool EditorFileSystem::_check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta) { if (p_meta.enabled) { - if (ep) { - ep->step(ss_amount++); - } - for(int j=0;jstep(ratio*1000); + EditorFileSystem::singleton->scan_total=ratio; +} + +EditorFileSystem::ScanProgress EditorFileSystem::ScanProgress::get_sub(int p_current,int p_total) const{ + + ScanProgress sp=*this; + float slice = (sp.hi-sp.low)/p_total; + sp.low+=slice*p_current; + sp.hi=slice; + return sp; + + +} + + +void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess *da,const ScanProgress& p_progress) { + + List dirs; + List files; + + String cd = da->get_current_dir(); + + p_dir->modified_time = FileAccess::get_modified_time(cd); + + + da->list_dir_begin(); + while (true) { + + bool isdir; + String f = da->get_next(&isdir); + if (f=="") + break; + + if (isdir) { + + if (f.begins_with(".")) //ignore hidden and . / .. + continue; + + if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this + continue; + + dirs.push_back(f); + + } else { + + files.push_back(f); + } + + } + + da->list_dir_end(); + + dirs.sort(); + files.sort(); + + int total = dirs.size()+files.size(); + int idx=0; + + for (List::Element *E=dirs.front();E;E=E->next(),idx++) { + + if (da->change_dir(E->get())==OK) { + + EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory ); + + efd->parent=p_dir; + efd->name=E->get(); + + _scan_new_dir(efd,da,p_progress.get_sub(idx,total)); + + int idx=0; + for(int i=0;isubdirs.size();i++) { + + if (efd->namesubdirs[i]->name) + break; + idx++; + } + if (idx==p_dir->subdirs.size()) { + p_dir->subdirs.push_back(efd); + } else { + p_dir->subdirs.insert(idx,efd); + } + + da->change_dir(".."); + } else { + ERR_PRINTS("Can't go into subdir: "+E->get()); + } + + p_progress.update(idx,total); + + } + + for (List::Element*E=files.front();E;E=E->next(),idx++) { + + String ext = E->get().extension().to_lower(); + if (!valid_extensions.has(ext)) + continue; //invalid + + EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); + fi->file=E->get(); + + String path = cd.plus_file(fi->file); + + FileCache *fc = file_cache.getptr(path); + uint64_t mt = FileAccess::get_modified_time(path); + + if (fc && fc->modification_time == mt) { + + fi->meta=fc->meta; + fi->type=fc->type; + fi->modified_time=fc->modification_time; + } else { + fi->meta=_get_meta(path); + fi->type=ResourceLoader::get_resource_type(path); + fi->modified_time=mt; + + } + + if (fi->meta.enabled) { + if (_check_meta_sources(fi->meta)) { + ItemAction ia; + ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; + ia.dir=p_dir; + ia.file=E->get(); + scan_actions.push_back(ia); + } + } + + p_dir->files.push_back(fi); + p_progress.update(idx,total); + } + +} + + +void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const ScanProgress& p_progress) { + + uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path()); + + bool updated_dir=false; + + //print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime)); + + if (current_mtime!=p_dir->modified_time) { + + updated_dir=true; + p_dir->modified_time=current_mtime; + //ooooops, dir changed, see what's going on + + //first mark everything as veryfied + + for(int i=0;ifiles.size();i++) { + + p_dir->files[i]->verified=false; + } + + for(int i=0;isubdirs.size();i++) { + + p_dir->get_subdir(i)->verified=false; + } + + //then scan files and directories and check what's different + + DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + String cd = p_dir->get_path(); + da->change_dir(cd); + da->list_dir_begin(); + while (true) { + + bool isdir; + String f = da->get_next(&isdir); + if (f=="") + break; + + if (isdir) { + + if (f.begins_with(".")) //ignore hidden and . / .. + continue; + + int idx = p_dir->find_dir_index(f); + if (idx==-1) { + + if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this + continue; + + EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory ); + + efd->parent=p_dir; + efd->name=f; + 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; + ia.dir=p_dir; + ia.file=f; + ia.new_dir=efd; + scan_actions.push_back(ia); + } else { + p_dir->subdirs[idx]->verified=true; + } + + + } else { + String ext = f.extension().to_lower(); + if (!valid_extensions.has(ext)) + continue; //invalid + + int idx = p_dir->find_file_index(f); + + if (idx==-1) { + //never seen this file, add actition to add it + EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); + fi->file=f; + + String path = cd.plus_file(fi->file); + fi->modified_time=FileAccess::get_modified_time(path); + fi->meta=_get_meta(path); + fi->type=ResourceLoader::get_resource_type(path); + + { + ItemAction ia; + ia.action=ItemAction::ACTION_FILE_ADD; + ia.dir=p_dir; + ia.file=f; + ia.new_file=fi; + scan_actions.push_back(ia); + } + + //take the chance and scan sources + if (_check_meta_sources(fi->meta)) { + + ItemAction ia; + ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; + ia.dir=p_dir; + ia.file=f; + scan_actions.push_back(ia); + } + + } else { + p_dir->files[idx]->verified=true; + } + + + } + + } + da->list_dir_end(); + memdelete(da); + + + + + } for(int i=0;ifiles.size();i++) { - if (_check_meta_sources(p_dir->files[i].meta,ep)) { - sources_changed.push_back(p_dir->get_file_path(i)); + if (updated_dir && !p_dir->files[i]->verified) { + //this file was removed, add action to remove it + ItemAction ia; + ia.action=ItemAction::ACTION_FILE_REMOVE; + ia.dir=p_dir; + ia.file=p_dir->files[i]->file; + scan_actions.push_back(ia); + continue; + + } + if (_check_meta_sources(p_dir->files[i]->meta)) { + ItemAction ia; + ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; + ia.dir=p_dir; + ia.file=p_dir->files[i]->file; + scan_actions.push_back(ia); } } for(int i=0;isubdirs.size();i++) { - _scan_sources(p_dir->get_subdir(i),ep); + if (updated_dir && !p_dir->subdirs[i]->verified) { + //this directory was removed, add action to remove it + ItemAction ia; + ia.action=ItemAction::ACTION_DIR_REMOVE; + ia.dir=p_dir->subdirs[i]; + scan_actions.push_back(ia); + continue; + + } + _scan_fs_changes(p_dir->get_subdir(i),p_progress); } } @@ -619,9 +823,12 @@ void EditorFileSystem::_thread_func_sources(void *_userdata) { EditorFileSystem *efs = (EditorFileSystem*)_userdata; if (efs->filesystem) { - EditorProgressBG pr("sources","ScanSources",efs->md_count); - efs->ss_amount=0; - efs->_scan_sources(efs->filesystem,&pr); + EditorProgressBG pr("sources","ScanSources",1000); + ScanProgress sp; + sp.progress=≺ + sp.hi=1; + sp.low=0; + efs->_scan_fs_changes(efs->filesystem,sp); } efs->scanning_sources_done=true; } @@ -643,8 +850,17 @@ void EditorFileSystem::scan_sources() { abort_scan=false; if (!use_threads) { - if (filesystem) - _scan_sources(filesystem,NULL); + if (filesystem) { + EditorProgressBG pr("sources","ScanSources",1000); + ScanProgress sp; + sp.progress=≺ + sp.hi=1; + sp.low=0; + scan_total=0; + _scan_fs_changes(filesystem,sp); + if (_update_scan_actions()) + emit_signal("filesystem_changed"); + } scanning_sources=false; scanning_sources_done=true; emit_signal("sources_changed",sources_changed.size()>0); @@ -652,8 +868,8 @@ void EditorFileSystem::scan_sources() { ERR_FAIL_COND(thread_sources); set_process(true); + scan_total=0; Thread::Settings s; - ss_amount=0; s.priority=Thread::PRIORITY_LOW; thread_sources = Thread::create(_thread_func_sources,this,s); //tree->hide(); @@ -665,53 +881,14 @@ void EditorFileSystem::scan_sources() { } -EditorFileSystemDirectory* EditorFileSystem::_update_tree(DirItem *p_item) { - - EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory ); - - if (!p_item) - return efd; //empty likely - efd->name=p_item->name; - - for(int i=0;ifiles.size();i++) { - - String s = p_item->files[i]->type; - //if (p_item->files[i]->meta) - // s="*"+s; - -// file_type_cache[p_item->files[i]->path]=s; - if (p_item->files[i]->type=="") - continue; //ignore because it's invalid - EditorFileSystemDirectory::FileInfo fi; - fi.file=p_item->files[i]->file; - fi.type=p_item->files[i]->type; - fi.meta=p_item->files[i]->meta; - fi.modified_time=p_item->files[i]->modified_time; - - efd->files.push_back(fi); - - } - - for(int i=0;idirs.size();i++) { - - EditorFileSystemDirectory *efsd =_update_tree(p_item->dirs[i]); - efsd->parent=efd; - efd->subdirs.push_back( efsd ); - - } - - - return efd; -} - void EditorFileSystem::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_TREE: { - _load_type_cache(); - scan(); + + scan(); } break; case NOTIFICATION_EXIT_TREE: { if (use_threads && thread) { @@ -727,13 +904,13 @@ void EditorFileSystem::_notification(int p_what) { set_process(false); } - if (rootdir) - memdelete(rootdir); - rootdir=NULL; if (filesystem) memdelete(filesystem); + if (new_filesystem) + memdelete(new_filesystem); filesystem=NULL; + new_filesystem=NULL; } break; case NOTIFICATION_PROCESS: { @@ -751,6 +928,8 @@ void EditorFileSystem::_notification(int p_what) { Thread::wait_to_finish(thread_sources); memdelete(thread_sources); thread_sources=NULL; + if (_update_scan_actions()) + emit_signal("filesystem_changed"); //print_line("sources changed: "+itos(sources_changed.size())); emit_signal("sources_changed",sources_changed.size()>0); } @@ -758,21 +937,14 @@ void EditorFileSystem::_notification(int p_what) { set_process(false); - if (rootdir) - memdelete(rootdir); if (filesystem) memdelete(filesystem); - rootdir=scandir; - scandir=NULL; -// file_type_cache.clear(); - filesystem=_update_tree(rootdir); - - if (rootdir) - memdelete(rootdir); - rootdir=NULL; + filesystem=new_filesystem; + new_filesystem=NULL; Thread::wait_to_finish(thread); memdelete(thread); thread=NULL; + _update_scan_actions(); emit_signal("filesystem_changed"); emit_signal("sources_changed",sources_changed.size()>0); //print_line("initial sources changed: "+itos(sources_changed.size())); @@ -794,7 +966,7 @@ bool EditorFileSystem::is_scanning() const { } float EditorFileSystem::get_scanning_progress() const { - return total; + return scan_total; } EditorFileSystemDirectory *EditorFileSystem::get_filesystem() { @@ -802,12 +974,12 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem() { return filesystem; } -void EditorFileSystem::_save_type_cache_fs(DirItem *p_dir,FileAccess *p_file) { +void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory*p_dir,FileAccess *p_file) { if (!p_dir) return; //none - p_file->store_line("::"+p_dir->path+"::"+String::num(p_dir->modified_time)); + p_file->store_line("::"+p_dir->get_path()+"::"+String::num(p_dir->modified_time)); for(int i=0;ifiles.size();i++) { @@ -832,126 +1004,96 @@ void EditorFileSystem::_save_type_cache_fs(DirItem *p_dir,FileAccess *p_file) { p_file->store_line(s); } - for(int i=0;idirs.size();i++) { + for(int i=0;isubdirs.size();i++) { - _save_type_cache_fs(p_dir->dirs[i],p_file); + _save_filesystem_cache(p_dir->subdirs[i],p_file); } } -void EditorFileSystem::_load_type_cache(){ - - GLOBAL_LOCK_FUNCTION - - -#if 0 - //this is not good, removed for now as it interferes with metadata stored in files - - String project=Globals::get_singleton()->get_resource_path(); - FileAccess *f =FileAccess::open(project+"/types.cache",FileAccess::READ); - - if (!f) { - - WARN_PRINT("Can't open types.cache."); - return; - } - - file_type_cache.clear(); - while(!f->eof_reached()) { - - String path=f->get_line(); - if (f->eof_reached()) - break; - String type=f->get_line(); - file_type_cache[path]=type; - } - - memdelete(f); -#endif -} bool EditorFileSystem::_find_file(const String& p_file,EditorFileSystemDirectory ** r_d, int &r_file_pos) const { //todo make faster - if (!filesystem || scanning) - return false; + if (!filesystem || scanning) + return false; - String f = Globals::get_singleton()->localize_path(p_file); + String f = Globals::get_singleton()->localize_path(p_file); - if (!f.begins_with("res://")) - return false; - f=f.substr(6,f.length()); - f=f.replace("\\","/"); + if (!f.begins_with("res://")) + return false; + f=f.substr(6,f.length()); + f=f.replace("\\","/"); - Vector path = f.split("/"); + Vector path = f.split("/"); - if (path.size()==0) - return false; - String file=path[path.size()-1]; - path.resize(path.size()-1); + if (path.size()==0) + return false; + String file=path[path.size()-1]; + path.resize(path.size()-1); - EditorFileSystemDirectory *fs=filesystem; + EditorFileSystemDirectory *fs=filesystem; - for(int i=0;iget_subdir_count();j++) { + int idx=-1; + for(int j=0;jget_subdir_count();j++) { - if (fs->get_subdir(j)->get_name()==path[i]) { - idx=j; - break; - } + if (fs->get_subdir(j)->get_name()==path[i]) { + idx=j; + break; + } + } + + if (idx==-1) { + //does not exist, create i guess? + EditorFileSystemDirectory *efsd = memnew( EditorFileSystemDirectory ); + efsd->name=path[i]; + int idx2=0; + for(int j=0;jget_subdir_count();j++) { + + if (efsd->nameget_subdir(j)->get_name()) + break; + idx2++; + } + + if (idx2==fs->get_subdir_count()) + fs->subdirs.push_back(efsd); + else + fs->subdirs.insert(idx2,efsd); + fs=efsd; + } else { + + fs=fs->get_subdir(idx); + } } - if (idx==-1) { - //does not exist, create i guess? - EditorFileSystemDirectory *efsd = memnew( EditorFileSystemDirectory ); - efsd->name=path[i]; - int idx2=0; - for(int j=0;jget_subdir_count();j++) { - if (efsd->nameget_subdir(j)->get_name()) - break; - idx2++; - } + int cpos=-1; + for(int i=0;ifiles.size();i++) { - if (idx2==fs->get_subdir_count()) - fs->subdirs.push_back(efsd); - else - fs->subdirs.insert(idx2,efsd); - fs=efsd; - } else { - - fs=fs->get_subdir(idx); + if (fs->files[i]->file==file) { + cpos=i; + break; + } } - } - - - int cpos=-1; - for(int i=0;ifiles.size();i++) { - - if (fs->files[i].file==file) { - cpos=i; - break; - } - } r_file_pos=cpos; *r_d=fs; - if (cpos!=-1) { + if (cpos!=-1) { - return true; - } else { + return true; + } else { - return false; - } + return false; + } } @@ -967,7 +1109,7 @@ String EditorFileSystem::get_file_type(const String& p_file) const { } - return fs->files[cpos].type; + return fs->files[cpos]->type; } @@ -1024,16 +1166,16 @@ EditorFileSystemDirectory *EditorFileSystem::get_path(const String& p_path) { void EditorFileSystem::_resource_saved(const String& p_path){ - print_line("resource saved: "+p_path); + //print_line("resource saved: "+p_path); EditorFileSystem::get_singleton()->update_file(p_path); } String EditorFileSystem::_find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const { for(int i=0;ifiles.size();i++) { - for(int j=0;jfiles[i].meta.sources.size();j++) { + for(int j=0;jfiles[i]->meta.sources.size();j++) { - if (p_dir->files[i].meta.sources[j].path==p_src) + if (p_dir->files[i]->meta.sources[j].path==p_src) return p_dir->get_file_path(i); } } @@ -1070,6 +1212,7 @@ void EditorFileSystem::update_file(const String& p_file) { if (!FileAccess::exists(p_file)) { //was removed + memdelete( fs->files[cpos] ); fs->files.remove(cpos); call_deferred("emit_signal","filesystem_changed"); //update later return; @@ -1083,13 +1226,13 @@ void EditorFileSystem::update_file(const String& p_file) { int idx=0; for(int i=0;ifiles.size();i++) { - if (p_filefiles[i].file) + if (p_filefiles[i]->file) break; idx++; } - EditorFileSystemDirectory::FileInfo fi; - fi.file=p_file.get_file(); + EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); + fi->file=p_file.get_file(); if (idx==fs->files.size()) { fs->files.push_back(fi); @@ -1102,10 +1245,10 @@ void EditorFileSystem::update_file(const String& p_file) { } - print_line("UPDATING: "+p_file); - fs->files[cpos].type=type; - fs->files[cpos].modified_time=FileAccess::get_modified_time(p_file); - fs->files[cpos].meta=_get_meta(p_file); + //print_line("UPDATING: "+p_file); + fs->files[cpos]->type=type; + fs->files[cpos]->modified_time=FileAccess::get_modified_time(p_file); + fs->files[cpos]->meta=_get_meta(p_file); call_deferred("emit_signal","filesystem_changed"); //update later @@ -1128,15 +1271,22 @@ EditorFileSystem::EditorFileSystem() { thread = NULL; scanning=false; - scandir=NULL; - rootdir=NULL; use_threads=true; thread_sources=NULL; + new_filesystem=NULL; scanning_sources=false; ResourceSaver::set_save_callback(_resource_saved); + List extensionsl; + ResourceLoader::get_recognized_extensions_for_type("",&extensionsl); + for(List::Element *E = extensionsl.front();E;E=E->next()) { + valid_extensions.insert(E->get()); + } + + + scan_total=0; } EditorFileSystem::~EditorFileSystem() { diff --git a/tools/editor/editor_file_system.h b/tools/editor/editor_file_system.h index 0db2dc150e5..d11fa0cfb1a 100644 --- a/tools/editor/editor_file_system.h +++ b/tools/editor/editor_file_system.h @@ -42,6 +42,8 @@ class EditorFileSystemDirectory : public Object { OBJ_TYPE( EditorFileSystemDirectory,Object ); String name; + uint64_t modified_time; + bool verified; //used for checking changes EditorFileSystemDirectory *parent; Vector subdirs; @@ -68,11 +70,20 @@ class EditorFileSystemDirectory : public Object { String file; StringName type; uint64_t modified_time; - ImportMeta meta; + bool verified; //used for checking changes + }; - Vector files; + struct FileInfoSort { + bool operator()(const FileInfo *p_a,const FileInfo *p_b) const { + return p_a->filefile; + } + }; + + void sort_files(); + + Vector files; static void _bind_methods(); @@ -96,6 +107,9 @@ public: EditorFileSystemDirectory *get_parent(); + int find_file_index(const String& p_file) const; + int find_dir_index(const String& p_dir) const; + EditorFileSystemDirectory(); ~EditorFileSystemDirectory(); @@ -107,45 +121,47 @@ class EditorFileSystem : public Node { _THREAD_SAFE_CLASS_ - struct SceneItem { + + struct ItemAction { + + enum Action { + ACTION_NONE, + ACTION_DIR_ADD, + ACTION_DIR_REMOVE, + ACTION_FILE_ADD, + ACTION_FILE_REMOVE, + ACTION_FILE_SOURCES_CHANGED + }; + + Action action; + EditorFileSystemDirectory *dir; String file; - String path; - String type; - uint64_t modified_time; - EditorFileSystemDirectory::ImportMeta meta; + EditorFileSystemDirectory *new_dir; + EditorFileSystemDirectory::FileInfo *new_file; + + ItemAction() { action=ACTION_NONE; dir=NULL; new_dir=NULL; new_file=NULL; } + }; - struct DirItem { - - uint64_t modified_time; - String path; - String name; - Vector dirs; - Vector files; - ~DirItem(); - }; - - float total; bool use_threads; Thread *thread; static void _thread_func(void *_userdata); - DirItem *scandir; - DirItem *rootdir; + EditorFileSystemDirectory *new_filesystem; bool abort_scan; bool scanning; + float scan_total; - EditorFileSystemDirectory* _update_tree(DirItem *p_item); - void _scan_scenes(); - void _load_type_cache(); + void _scan_filesystem(); EditorFileSystemDirectory *filesystem; static EditorFileSystem *singleton; + /* Used for reading the filesystem cache file */ struct FileCache { String type; @@ -154,34 +170,43 @@ class EditorFileSystem : public Node { Vector deps; }; - struct DirCache { + HashMap file_cache; - uint64_t modification_time; - Set files; - Set subdirs; + struct ScanProgress { + + float low; + float hi; + mutable EditorProgressBG *progress; + void update(int p_current,int p_total) const; + ScanProgress get_sub(int p_current,int p_total) const; }; - static EditorFileSystemDirectory::ImportMeta _get_meta(const String& p_path); - bool _check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta,EditorProgressBG *ep=NULL); + bool _check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta); - DirItem* _scan_dir(DirAccess *da,Set &extensions,String p_name,float p_from,float p_range,const String& p_path,HashMap &file_cache,HashMap &dir_cache,EditorProgressBG& p_prog); - void _save_type_cache_fs(DirItem *p_dir,FileAccess *p_file); + void _save_filesystem_cache(EditorFileSystemDirectory *p_dir,FileAccess *p_file); bool _find_file(const String& p_file,EditorFileSystemDirectory ** r_d, int &r_file_pos) const; - void _scan_sources(EditorFileSystemDirectory *p_dir,EditorProgressBG *ep); + void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress); int md_count; + Set valid_extensions; + + void _scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess *da,const ScanProgress& p_progress); Thread *thread_sources; bool scanning_sources; bool scanning_sources_done; - int ss_amount; + static void _thread_func_sources(void *_userdata); + List sources_changed; + List scan_actions; + + bool _update_scan_actions(); static void _resource_saved(const String& p_path); String _find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const;