summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_compressed.cpp16
-rw-r--r--core/io/file_access_compressed.h3
-rw-r--r--core/io/file_access_network.cpp6
-rw-r--r--core/io/resource_format_binary.cpp122
-rw-r--r--core/io/resource_format_binary.h2
-rw-r--r--core/io/resource_importer.cpp16
-rw-r--r--core/io/resource_importer.h8
-rw-r--r--core/io/resource_saver.cpp24
-rw-r--r--core/io/resource_saver.h4
9 files changed, 195 insertions, 6 deletions
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index c9e0c2c638..c256668af0 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -184,6 +184,22 @@ bool FileAccessCompressed::is_open() const {
return f.is_valid();
}
+String FileAccessCompressed::get_path() const {
+ if (f.is_valid()) {
+ return f->get_path();
+ } else {
+ return "";
+ }
+}
+
+String FileAccessCompressed::get_path_absolute() const {
+ if (f.is_valid()) {
+ return f->get_path_absolute();
+ } else {
+ return "";
+ }
+}
+
void FileAccessCompressed::seek(uint64_t p_position) {
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index 53b4887b90..136fcede06 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -73,6 +73,9 @@ public:
virtual Error open_internal(const String &p_path, int p_mode_flags) override; ///< open a file
virtual bool is_open() const override; ///< true when file is open
+ virtual String get_path() const override; /// returns the path for the current open file
+ virtual String get_path_absolute() const override; /// returns the absolute path for the current open file
+
virtual void seek(uint64_t p_position) override; ///< seek to a given position
virtual void seek_end(int64_t p_position = 0) override; ///< seek from the end of file
virtual uint64_t get_position() const override; ///< get position in the file
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index c442cd04ca..e765eb2d42 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -465,10 +465,8 @@ Error FileAccessNetwork::_set_unix_permissions(const String &p_file, uint32_t p_
}
void FileAccessNetwork::configure() {
- GLOBAL_DEF("network/remote_fs/page_size", 65536);
- ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_size", PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater")); //is used as denominator and can't be zero
- GLOBAL_DEF("network/remote_fs/page_read_ahead", 4);
- ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_read_ahead", PropertyInfo(Variant::INT, "network/remote_fs/page_read_ahead", PROPERTY_HINT_RANGE, "0,8,1,or_greater"));
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater"), 65536); // Is used as denominator and can't be zero
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "network/remote_fs/page_read_ahead", PROPERTY_HINT_RANGE, "0,8,1,or_greater"), 4);
}
FileAccessNetwork::FileAccessNetwork() {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index ba6ad16ca8..45e1301930 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -1045,10 +1045,10 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
#ifdef TOOLS_ENABLED
// Silence a warning that can happen during the initial filesystem scan due to cache being regenerated.
if (ResourceLoader::get_resource_uid(res_path) != er.uid) {
- WARN_PRINT(String(res_path + ": In external resource #" + itos(i) + ", invalid UUID: " + ResourceUID::get_singleton()->id_to_text(er.uid) + " - using text path instead: " + er.path).utf8().get_data());
+ WARN_PRINT(String(res_path + ": In external resource #" + itos(i) + ", invalid UID: " + ResourceUID::get_singleton()->id_to_text(er.uid) + " - using text path instead: " + er.path).utf8().get_data());
}
#else
- WARN_PRINT(String(res_path + ": In external resource #" + itos(i) + ", invalid UUID: " + ResourceUID::get_singleton()->id_to_text(er.uid) + " - using text path instead: " + er.path).utf8().get_data());
+ WARN_PRINT(String(res_path + ": In external resource #" + itos(i) + ", invalid UID: " + ResourceUID::get_singleton()->id_to_text(er.uid) + " - using text path instead: " + er.path).utf8().get_data());
#endif
}
}
@@ -2209,12 +2209,130 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re
return OK;
}
+Error ResourceFormatSaverBinaryInstance::set_uid(const String &p_path, ResourceUID::ID p_uid) {
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
+ ERR_FAIL_COND_V_MSG(f.is_null(), ERR_CANT_OPEN, "Cannot open file '" + p_path + "'.");
+
+ Ref<FileAccess> fw;
+
+ local_path = p_path.get_base_dir();
+
+ uint8_t header[4];
+ f->get_buffer(header, 4);
+ if (header[0] == 'R' && header[1] == 'S' && header[2] == 'C' && header[3] == 'C') {
+ // Compressed.
+ Ref<FileAccessCompressed> fac;
+ fac.instantiate();
+ Error err = fac->open_after_magic(f);
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'.");
+ f = fac;
+
+ Ref<FileAccessCompressed> facw;
+ facw.instantiate();
+ facw->configure("RSCC");
+ err = facw->open_internal(p_path + ".uidren", FileAccess::WRITE);
+ ERR_FAIL_COND_V_MSG(err, ERR_FILE_CORRUPT, "Cannot create file '" + p_path + ".uidren'.");
+
+ fw = facw;
+
+ } else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
+ // Not a binary resource.
+ return ERR_FILE_UNRECOGNIZED;
+ } else {
+ fw = FileAccess::open(p_path + ".uidren", FileAccess::WRITE);
+ ERR_FAIL_COND_V_MSG(fw.is_null(), ERR_CANT_CREATE, "Cannot create file '" + p_path + ".uidren'.");
+
+ uint8_t magich[4] = { 'R', 'S', 'R', 'C' };
+ fw->store_buffer(magich, 4);
+ }
+
+ big_endian = f->get_32();
+ bool use_real64 = f->get_32();
+ f->set_big_endian(big_endian != 0); //read big endian if saved as big endian
+#ifdef BIG_ENDIAN_ENABLED
+ fw->store_32(!big_endian);
+#else
+ fw->store_32(big_endian);
+#endif
+ fw->set_big_endian(big_endian != 0);
+ fw->store_32(use_real64); //use real64
+
+ uint32_t ver_major = f->get_32();
+ uint32_t ver_minor = f->get_32();
+ uint32_t ver_format = f->get_32();
+
+ if (ver_format < FORMAT_VERSION_CAN_RENAME_DEPS) {
+ fw.unref();
+
+ {
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ da->remove(p_path + ".uidren");
+ }
+
+ // Use the old approach.
+
+ WARN_PRINT("This file is old, so it does not support UIDs, opening and resaving '" + p_path + "'.");
+ return ERR_UNAVAILABLE;
+ }
+
+ if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
+ ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED,
+ vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).",
+ local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH));
+ }
+
+ // Since we're not actually converting the file contents, leave the version
+ // numbers in the file untouched.
+ fw->store_32(ver_major);
+ fw->store_32(ver_minor);
+ fw->store_32(ver_format);
+
+ save_ustring(fw, get_ustring(f)); //type
+
+ fw->store_64(f->get_64()); //metadata offset
+
+ uint32_t flags = f->get_32();
+ flags |= ResourceFormatSaverBinaryInstance::FORMAT_FLAG_UIDS;
+ f->get_64(); // Skip previous UID
+
+ fw->store_32(flags);
+ fw->store_64(p_uid);
+
+ //rest of file
+ uint8_t b = f->get_8();
+ while (!f->eof_reached()) {
+ fw->store_8(b);
+ b = f->get_8();
+ }
+
+ f.unref();
+
+ bool all_ok = fw->get_error() == OK;
+
+ if (!all_ok) {
+ return ERR_CANT_CREATE;
+ }
+
+ fw.unref();
+
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ da->remove(p_path);
+ da->rename(p_path + ".uidren", p_path);
+ return OK;
+}
+
Error ResourceFormatSaverBinary::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) {
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
ResourceFormatSaverBinaryInstance saver;
return saver.save(local_path, p_resource, p_flags);
}
+Error ResourceFormatSaverBinary::set_uid(const String &p_path, ResourceUID::ID p_uid) {
+ String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ ResourceFormatSaverBinaryInstance saver;
+ return saver.set_uid(local_path, p_uid);
+}
+
bool ResourceFormatSaverBinary::recognize(const Ref<Resource> &p_resource) const {
return true; //all recognized
}
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 36613dbd58..2e8988005f 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -170,6 +170,7 @@ public:
RESERVED_FIELDS = 11
};
Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags = 0);
+ Error set_uid(const String &p_path, ResourceUID::ID p_uid);
static void write_variant(Ref<FileAccess> f, const Variant &p_property, HashMap<Ref<Resource>, int> &resource_map, HashMap<Ref<Resource>, int> &external_resources, HashMap<StringName, int> &string_map, const PropertyInfo &p_hint = PropertyInfo());
};
@@ -177,6 +178,7 @@ class ResourceFormatSaverBinary : public ResourceFormatSaver {
public:
static ResourceFormatSaverBinary *singleton;
virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0);
+ virtual Error set_uid(const String &p_path, ResourceUID::ID p_uid);
virtual bool recognize(const Ref<Resource> &p_resource) const;
virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const;
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index a4f4d705ee..dc1de6b9ce 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -31,6 +31,7 @@
#include "resource_importer.h"
#include "core/config/project_settings.h"
+#include "core/io/config_file.h"
#include "core/os/os.h"
#include "core/variant/variant_parser.h"
@@ -484,3 +485,18 @@ void ResourceFormatImporter::add_importer(const Ref<ResourceImporter> &p_importe
importers.push_back(p_importer);
}
}
+
+/////
+
+Error ResourceFormatImporterSaver::set_uid(const String &p_path, ResourceUID::ID p_uid) {
+ Ref<ConfigFile> cf;
+ cf.instantiate();
+ Error err = cf->load(p_path + ".import");
+ if (err != OK) {
+ return err;
+ }
+ cf->set_value("remap", "uid", ResourceUID::get_singleton()->id_to_text(p_uid));
+ cf->save(p_path + ".import");
+
+ return OK;
+}
diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h
index b104a9dffe..0089544caa 100644
--- a/core/io/resource_importer.h
+++ b/core/io/resource_importer.h
@@ -32,6 +32,7 @@
#define RESOURCE_IMPORTER_H
#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
class ResourceImporter;
@@ -149,4 +150,11 @@ public:
VARIANT_ENUM_CAST(ResourceImporter::ImportOrder);
+class ResourceFormatImporterSaver : public ResourceFormatSaver {
+ GDCLASS(ResourceFormatImporterSaver, ResourceFormatSaver)
+
+public:
+ virtual Error set_uid(const String &p_path, ResourceUID::ID p_uid) override;
+};
+
#endif // RESOURCE_IMPORTER_H
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index de450a8420..9809b9a48f 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -47,6 +47,12 @@ Error ResourceFormatSaver::save(const Ref<Resource> &p_resource, const String &p
return (Error)res;
}
+Error ResourceFormatSaver::set_uid(const String &p_path, ResourceUID::ID p_uid) {
+ Error err = ERR_FILE_UNRECOGNIZED;
+ GDVIRTUAL_CALL(_set_uid, p_path, p_uid, err);
+ return err;
+}
+
bool ResourceFormatSaver::recognize(const Ref<Resource> &p_resource) const {
bool success = false;
GDVIRTUAL_CALL(_recognize, p_resource, success);
@@ -85,6 +91,7 @@ bool ResourceFormatSaver::recognize_path(const Ref<Resource> &p_resource, const
void ResourceFormatSaver::_bind_methods() {
GDVIRTUAL_BIND(_save, "resource", "path", "flags");
+ GDVIRTUAL_BIND(_set_uid, "path", "uid");
GDVIRTUAL_BIND(_recognize, "resource");
GDVIRTUAL_BIND(_get_recognized_extensions, "resource");
GDVIRTUAL_BIND(_recognize_path, "resource", "path");
@@ -146,6 +153,23 @@ Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path,
return err;
}
+Error ResourceSaver::set_uid(const String &p_path, ResourceUID::ID p_uid) {
+ String path = p_path;
+
+ ERR_FAIL_COND_V_MSG(path.is_empty(), ERR_INVALID_PARAMETER, "Can't update UID to empty path. Provide non-empty path.");
+
+ Error err = ERR_FILE_UNRECOGNIZED;
+
+ for (int i = 0; i < saver_count; i++) {
+ err = saver[i]->set_uid(path, p_uid);
+ if (err == OK) {
+ break;
+ }
+ }
+
+ return err;
+}
+
void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) {
save_callback = p_callback;
}
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index f25463d71f..2043947963 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -42,12 +42,14 @@ protected:
static void _bind_methods();
GDVIRTUAL3R(int64_t, _save, Ref<Resource>, String, uint32_t)
+ GDVIRTUAL2R(Error, _set_uid, String, ResourceUID::ID)
GDVIRTUAL1RC(bool, _recognize, Ref<Resource>)
GDVIRTUAL1RC(Vector<String>, _get_recognized_extensions, Ref<Resource>)
GDVIRTUAL2RC(bool, _recognize_path, Ref<Resource>, String)
public:
virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0);
+ virtual Error set_uid(const String &p_path, ResourceUID::ID p_uid);
virtual bool recognize(const Ref<Resource> &p_resource) const;
virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const;
virtual bool recognize_path(const Ref<Resource> &p_resource, const String &p_path) const;
@@ -88,6 +90,8 @@ public:
static void add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front = false);
static void remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver);
+ static Error set_uid(const String &p_path, ResourceUID::ID p_uid);
+
static void set_timestamp_on_save(bool p_timestamp) { timestamp_on_save = p_timestamp; }
static bool get_timestamp_on_save() { return timestamp_on_save; }