mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 06:11:29 +03:00
Merge pull request #96590 from reduz/list-directory
Provide a reliable way to see original resources in a directory
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/core_bind.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/resource_importer.h"
|
||||
#include "core/object/script_language.h"
|
||||
@@ -40,6 +41,7 @@
|
||||
#include "core/os/safe_binary_mutex.h"
|
||||
#include "core/string/print_string.h"
|
||||
#include "core/string/translation_server.h"
|
||||
#include "core/templates/rb_set.h"
|
||||
#include "core/variant/variant_parser.h"
|
||||
#include "servers/rendering_server.h"
|
||||
|
||||
@@ -1474,6 +1476,60 @@ bool ResourceLoader::is_cleaning_tasks() {
|
||||
return cleaning_tasks;
|
||||
}
|
||||
|
||||
Vector<String> ResourceLoader::list_directory(const String &p_directory) {
|
||||
RBSet<String> files_found;
|
||||
Ref<DirAccess> dir = DirAccess::open(p_directory);
|
||||
if (dir.is_null()) {
|
||||
return Vector<String>();
|
||||
}
|
||||
|
||||
Error err = dir->list_dir_begin();
|
||||
if (err != OK) {
|
||||
return Vector<String>();
|
||||
}
|
||||
|
||||
String d = dir->get_next();
|
||||
while (!d.is_empty()) {
|
||||
bool recognized = false;
|
||||
if (dir->current_is_dir()) {
|
||||
if (d != "." && d != "..") {
|
||||
d += "/";
|
||||
recognized = true;
|
||||
}
|
||||
} else {
|
||||
if (d.ends_with(".import") || d.ends_with(".remap") || d.ends_with(".uid")) {
|
||||
d = d.substr(0, d.rfind("."));
|
||||
}
|
||||
|
||||
if (d.ends_with(".gdc")) {
|
||||
d = d.substr(0, d.rfind("."));
|
||||
d += ".gd";
|
||||
}
|
||||
|
||||
const String full_path = p_directory.path_join(d);
|
||||
// Try all loaders and pick the first match for the type hint.
|
||||
for (int i = 0; i < loader_count; i++) {
|
||||
if (loader[i]->recognize_path(full_path)) {
|
||||
recognized = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recognized) {
|
||||
files_found.insert(d);
|
||||
}
|
||||
d = dir->get_next();
|
||||
}
|
||||
|
||||
Vector<String> ret;
|
||||
for (const String &f : files_found) {
|
||||
ret.push_back(f);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ResourceLoader::initialize() {}
|
||||
|
||||
void ResourceLoader::finalize() {}
|
||||
|
||||
Reference in New Issue
Block a user