|
48 | 48 | #include "scene/resources/packed_scene.h"
|
49 | 49 |
|
50 | 50 | EditorFileSystem *EditorFileSystem::singleton = nullptr;
|
| 51 | +int EditorFileSystem::nb_files_total = 0; |
| 52 | +EditorFileSystem::ScannedDirectory *EditorFileSystem::first_scan_root_dir = nullptr; |
| 53 | + |
51 | 54 | //the name is the version, to keep compatibility with different versions of Godot
|
52 | 55 | #define CACHE_FILE_NAME "filesystem_cache10"
|
53 | 56 |
|
@@ -237,16 +240,72 @@ EditorFileSystem::ScannedDirectory::~ScannedDirectory() {
|
237 | 240 | }
|
238 | 241 | }
|
239 | 242 |
|
240 |
| -void EditorFileSystem::_first_scan_filesystem() { |
241 |
| - EditorProgress ep = EditorProgress("first_scan_filesystem", TTR("Project initialization"), 5); |
| 243 | +void EditorFileSystem::_load_first_scan_root_dir() { |
242 | 244 | Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
243 | 245 | first_scan_root_dir = memnew(ScannedDirectory);
|
244 | 246 | first_scan_root_dir->full_path = "res://";
|
| 247 | + |
| 248 | + nb_files_total = _scan_new_dir(first_scan_root_dir, d); |
| 249 | +} |
| 250 | + |
| 251 | +void EditorFileSystem::scan_for_uid() { |
| 252 | + // Load file structure into memory. |
| 253 | + _load_first_scan_root_dir(); |
| 254 | + |
| 255 | + // Load extensions for which an .import should exists. |
| 256 | + List<String> extensionsl; |
| 257 | + HashSet<String> import_extensions; |
| 258 | + ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl); |
| 259 | + for (const String &E : extensionsl) { |
| 260 | + import_extensions.insert(E); |
| 261 | + } |
| 262 | + |
| 263 | + // Scan the file system to load uid. |
| 264 | + _scan_for_uid_directory(first_scan_root_dir, import_extensions); |
| 265 | + |
| 266 | + // It's done, resetting the callback method to prevent a second scan. |
| 267 | + ResourceUID::scan_for_uid_on_startup = nullptr; |
| 268 | +} |
| 269 | + |
| 270 | +void EditorFileSystem::_scan_for_uid_directory(const ScannedDirectory *p_scan_dir, const HashSet<String> &p_import_extensions) { |
| 271 | + for (ScannedDirectory *scan_sub_dir : p_scan_dir->subdirs) { |
| 272 | + _scan_for_uid_directory(scan_sub_dir, p_import_extensions); |
| 273 | + } |
| 274 | + |
| 275 | + for (const String &scan_file : p_scan_dir->files) { |
| 276 | + const String ext = scan_file.get_extension().to_lower(); |
| 277 | + |
| 278 | + if (ext == "uid" || ext == "import") { |
| 279 | + continue; |
| 280 | + } |
| 281 | + |
| 282 | + const String path = p_scan_dir->full_path.path_join(scan_file); |
| 283 | + ResourceUID::ID uid = ResourceUID::INVALID_ID; |
| 284 | + if (p_import_extensions.has(ext)) { |
| 285 | + if (FileAccess::exists(path + ".import")) { |
| 286 | + uid = ResourceFormatImporter::get_singleton()->get_resource_uid(path); |
| 287 | + } |
| 288 | + } else { |
| 289 | + uid = ResourceLoader::get_resource_uid(path); |
| 290 | + } |
| 291 | + |
| 292 | + if (uid != ResourceUID::INVALID_ID) { |
| 293 | + if (!ResourceUID::get_singleton()->has_id(uid)) { |
| 294 | + ResourceUID::get_singleton()->add_id(uid, path); |
| 295 | + } |
| 296 | + } |
| 297 | + } |
| 298 | +} |
| 299 | + |
| 300 | +void EditorFileSystem::_first_scan_filesystem() { |
| 301 | + EditorProgress ep = EditorProgress("first_scan_filesystem", TTR("Project initialization"), 5); |
245 | 302 | HashSet<String> existing_class_names;
|
246 | 303 | HashSet<String> extensions;
|
247 | 304 |
|
248 |
| - ep.step(TTR("Scanning file structure..."), 0, true); |
249 |
| - nb_files_total = _scan_new_dir(first_scan_root_dir, d); |
| 305 | + if (!first_scan_root_dir) { |
| 306 | + ep.step(TTR("Scanning file structure..."), 0, true); |
| 307 | + _load_first_scan_root_dir(); |
| 308 | + } |
250 | 309 |
|
251 | 310 | // Preloading GDExtensions file extensions to prevent looping on all the resource loaders
|
252 | 311 | // for each files in _first_scan_process_scripts.
|
@@ -440,6 +499,7 @@ void EditorFileSystem::_scan_filesystem() {
|
440 | 499 | sd = first_scan_root_dir;
|
441 | 500 | // Will be updated on scan.
|
442 | 501 | ResourceUID::get_singleton()->clear();
|
| 502 | + ResourceUID::scan_for_uid_on_startup = nullptr; |
443 | 503 | processed_files = memnew(HashSet<String>());
|
444 | 504 | } else {
|
445 | 505 | Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
0 commit comments