summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_pack.cpp27
-rw-r--r--core/io/file_access_pack.h6
-rw-r--r--core/io/file_access_zip.cpp23
-rw-r--r--core/io/file_access_zip.h2
-rw-r--r--core/io/image_loader.cpp2
-rw-r--r--core/io/image_loader.h2
-rw-r--r--core/io/resource_format_binary.cpp52
-rw-r--r--core/io/resource_format_binary.h5
-rw-r--r--core/io/resource_importer.cpp4
-rw-r--r--core/io/resource_importer.h2
-rw-r--r--core/io/resource_loader.cpp4
-rw-r--r--core/io/resource_loader.h2
-rw-r--r--core/io/translation_loader_po.cpp2
-rw-r--r--core/io/translation_loader_po.h2
14 files changed, 57 insertions, 78 deletions
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index aa10afe642..0a7dee9444 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -30,16 +30,15 @@
#include "file_access_pack.h"
-#include "core/project_settings.h"
#include "core/version.h"
#include <stdio.h>
-Error PackedData::add_pack(const String &p_path, bool p_replace_files, const String &p_destination) {
+Error PackedData::add_pack(const String &p_path, bool p_replace_files) {
for (int i = 0; i < sources.size(); i++) {
- if (sources[i]->try_open_pack(p_path, p_replace_files, p_destination)) {
+ if (sources[i]->try_open_pack(p_path, p_replace_files)) {
return OK;
};
@@ -90,7 +89,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
}
}
String filename = path.get_file();
- // Don't add as a file if the path points to a directory.
+ // Don't add as a file if the path points to a directory
if (!filename.empty()) {
cd->files.insert(filename);
}
@@ -133,7 +132,7 @@ PackedData::~PackedData() {
//////////////////////////////////////////////////////////////////
-bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, const String &p_destination) {
+bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f)
@@ -199,24 +198,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
String path;
path.parse_utf8(cs.ptr());
- if (p_destination != "") {
- String destination = ProjectSettings::get_singleton()->localize_path(p_destination);
- ERR_FAIL_COND_V_MSG(!destination.begins_with("res://"), false, "The destination path must be within the resource filesystem (res://).");
-
- if (!destination.ends_with("/")) {
- destination += "/";
- }
-
- DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- if (!dir->dir_exists(destination)) {
- memdelete(dir);
-
- ERR_FAIL_V_MSG(false, vformat("The destination path \"%s\" does not exist.", destination));
- }
- memdelete(dir);
-
- path = path.replace_first("res://", destination);
- }
uint64_t ofs = f->get_64();
uint64_t size = f->get_64();
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index 1a46bef0f6..8df6826ac9 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -113,7 +113,7 @@ public:
_FORCE_INLINE_ bool is_disabled() const { return disabled; }
static PackedData *get_singleton() { return singleton; }
- Error add_pack(const String &p_path, bool p_replace_files, const String &p_destination);
+ Error add_pack(const String &p_path, bool p_replace_files);
_FORCE_INLINE_ FileAccess *try_open_path(const String &p_path);
_FORCE_INLINE_ bool has_path(const String &p_path);
@@ -125,7 +125,7 @@ public:
class PackSource {
public:
- virtual bool try_open_pack(const String &p_path, bool p_replace_files, const String &p_destination = "") = 0;
+ virtual bool try_open_pack(const String &p_path, bool p_replace_files) = 0;
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0;
virtual ~PackSource() {}
};
@@ -133,7 +133,7 @@ public:
class PackedSourcePCK : public PackSource {
public:
- virtual bool try_open_pack(const String &p_path, bool p_replace_files, const String &p_destination = "");
+ virtual bool try_open_pack(const String &p_path, bool p_replace_files);
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
};
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index 5696e47193..57de66afaf 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -160,7 +160,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
return pkg;
}
-bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, const String &p_destination) {
+bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) {
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0)
@@ -206,26 +206,7 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, const
f.package = pkg_num;
unzGetFilePos(zfile, &f.file_pos);
- String fname;
- if (p_destination != "") {
- String destination = "res://" + p_destination;
- if (!destination.ends_with("/")) {
- destination += "/";
- }
-
- DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- if (!dir->dir_exists(destination)) {
- memdelete(dir);
-
- return false;
- }
- memdelete(dir);
-
- fname = destination + filename_inzip;
- } else {
- fname = String("res://") + filename_inzip;
- }
-
+ String fname = String("res://") + filename_inzip;
files[fname] = f;
uint8_t md5[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index 5bcaea7ed9..d5ce7d7a8d 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -74,7 +74,7 @@ public:
bool file_exists(String p_name) const;
- virtual bool try_open_pack(const String &p_path, bool p_replace_files, const String &p_destination = "");
+ virtual bool try_open_pack(const String &p_path, bool p_replace_files);
FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
static ZipArchive *get_singleton();
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 2770adbd36..01e6bb5618 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -129,7 +129,7 @@ void ImageLoader::cleanup() {
/////////////////
-RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
+RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 18b4df98f7..15ce6031d7 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -73,7 +73,7 @@ public:
class ResourceFormatLoaderImage : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index a640565ecf..8c7559479b 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -337,12 +337,16 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case OBJECT_INTERNAL_RESOURCE: {
uint32_t index = f->get_32();
- String path = res_path + "::" + itos(index);
- RES res = ResourceLoader::load(path);
- if (res.is_null()) {
- WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data());
+ if (use_nocache) {
+ r_v = internal_resources[index].cache;
+ } else {
+ String path = res_path + "::" + itos(index);
+ RES res = ResourceLoader::load(path);
+ if (res.is_null()) {
+ WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data());
+ }
+ r_v = res;
}
- r_v = res;
} break;
case OBJECT_EXTERNAL_RESOURCE: {
@@ -716,22 +720,24 @@ Error ResourceLoaderBinary::load() {
if (!main) {
- path = internal_resources[i].path;
- if (path.begins_with("local://")) {
- path = path.replace_first("local://", "");
- subindex = path.to_int();
- path = res_path + "::" + path;
- }
+ if (!use_nocache) {
+ path = internal_resources[i].path;
+ if (path.begins_with("local://")) {
+ path = path.replace_first("local://", "");
+ subindex = path.to_int();
+ path = res_path + "::" + path;
+ }
- if (ResourceCache::has(path)) {
- //already loaded, don't do anything
- stage++;
- error = OK;
- continue;
+ if (ResourceCache::has(path)) {
+ //already loaded, don't do anything
+ stage++;
+ error = OK;
+ continue;
+ }
}
} else {
- if (!ResourceCache::has(res_path))
+ if (!use_nocache && !ResourceCache::has(res_path))
path = res_path;
}
@@ -757,9 +763,15 @@ Error ResourceLoaderBinary::load() {
RES res = RES(r);
- r->set_path(path);
+ if (path != String()) {
+ r->set_path(path);
+ }
r->set_subindex(subindex);
+ if (!main) {
+ internal_resources.write[i].cache = res;
+ }
+
int pc = f->get_32();
//set properties
@@ -1013,6 +1025,7 @@ ResourceLoaderBinary::ResourceLoaderBinary() :
importmd_ofs(0),
error(OK) {
+ use_nocache = false;
progress = nullptr;
use_sub_threads = false;
}
@@ -1023,7 +1036,7 @@ ResourceLoaderBinary::~ResourceLoaderBinary() {
memdelete(f);
}
-RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
+RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
if (r_error)
*r_error = ERR_FILE_CANT_OPEN;
@@ -1034,6 +1047,7 @@ RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_origi
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot open file '" + p_path + "'.");
ResourceLoaderBinary loader;
+ loader.use_nocache = p_no_cache;
loader.use_sub_threads = p_use_sub_threads;
loader.progress = r_progress;
String path = p_original_path != "" ? p_original_path : p_path;
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index da67e1e648..0f8fc9445b 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -68,6 +68,7 @@ class ResourceLoaderBinary {
struct IntResource {
String path;
uint64_t offset;
+ RES cache;
};
Vector<IntResource> internal_resources;
@@ -78,6 +79,8 @@ class ResourceLoaderBinary {
Map<String, String> remaps;
Error error;
+ bool use_nocache;
+
friend class ResourceFormatLoaderBinary;
Error parse_variant(Variant &r_v);
@@ -101,7 +104,7 @@ public:
class ResourceFormatLoaderBinary : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index ceb73cab77..643df53f8c 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -117,7 +117,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
return OK;
}
-RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
+RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
@@ -130,7 +130,7 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_
return RES();
}
- RES res = ResourceLoader::_load(pat.path, p_path, pat.type, false, r_error, p_use_sub_threads, r_progress);
+ RES res = ResourceLoader::_load(pat.path, p_path, pat.type, p_no_cache, r_error, p_use_sub_threads, r_progress);
#ifdef TOOLS_ENABLED
if (res.is_valid()) {
diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h
index dbac80599a..6b76912494 100644
--- a/core/io/resource_importer.h
+++ b/core/io/resource_importer.h
@@ -58,7 +58,7 @@ class ResourceFormatImporter : public ResourceFormatLoader {
public:
static ResourceFormatImporter *get_singleton() { return singleton; }
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
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;
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 05a41013c2..d90802d7e2 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -119,7 +119,7 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions)
}
}
-RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
+RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
if (get_script_instance() && get_script_instance()->has_method("load")) {
Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads);
@@ -200,7 +200,7 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c
continue;
}
found = true;
- RES res = loader[i]->load(p_path, p_original_path != String() ? p_original_path : p_path, r_error, p_use_sub_threads, r_progress);
+ RES res = loader[i]->load(p_path, p_original_path != String() ? p_original_path : p_path, r_error, p_use_sub_threads, r_progress, p_no_cache);
if (res.is_null()) {
continue;
}
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index be4adf9091..2d95d5545f 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -43,7 +43,7 @@ protected:
static void _bind_methods();
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual bool exists(const String &p_path) const;
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index 5da236d029..bce5361c76 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -185,7 +185,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
return translation;
}
-RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
+RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
if (r_error)
*r_error = ERR_CANT_OPEN;
diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h
index 9d3117b630..137dfd1768 100644
--- a/core/io/translation_loader_po.h
+++ b/core/io/translation_loader_po.h
@@ -38,7 +38,7 @@
class TranslationLoaderPO : public ResourceFormatLoader {
public:
static RES load_translation(FileAccess *f, Error *r_error = nullptr);
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;