summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/image_loader.cpp2
-rw-r--r--core/io/resource_loader.cpp34
-rw-r--r--core/io/resource_loader.h2
3 files changed, 37 insertions, 1 deletions
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 614fbb771f..b8fd13d67c 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -185,5 +185,5 @@ bool ResourceFormatLoaderImage::handles_type(const String &p_type) const {
String ResourceFormatLoaderImage::get_resource_type(const String &p_path) const {
- return "Image";
+ return p_path.get_extension().to_lower() == "image" ? "Image" : String();
}
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index c44d2597a7..8b0655deb0 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -123,6 +123,10 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const Stri
return ril;
}
+bool ResourceFormatLoader::exists(const String &p_path) const {
+ return FileAccess::exists(p_path); //by default just check file
+}
+
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
String path = p_path;
@@ -239,6 +243,36 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
return res;
}
+bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
+
+ String local_path;
+ if (p_path.is_rel_path())
+ local_path = "res://" + p_path;
+ else
+ local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+
+ if (ResourceCache::has(local_path)) {
+
+ return true; // If cached, it probably exists
+ }
+
+ bool xl_remapped = false;
+ String path = _path_remap(local_path, &xl_remapped);
+
+ // 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(path, p_type_hint)) {
+ continue;
+ }
+
+ if (loader[i]->exists(path))
+ return true;
+ }
+
+ return false;
+}
+
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
if (r_error)
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 9be82abb42..f78464ef0c 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -60,6 +60,7 @@ class ResourceFormatLoader {
public:
virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual bool exists(const String &p_path) const;
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
virtual bool recognize_path(const String &p_path, const String &p_for_type = String()) const;
@@ -106,6 +107,7 @@ class ResourceLoader {
public:
static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL);
static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL);
+ static bool exists(const String &p_path, const String &p_type_hint = "");
static void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions);
static void add_resource_format_loader(ResourceFormatLoader *p_format_loader, bool p_at_front = false);