summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_buffered.cpp2
-rw-r--r--core/io/file_access_buffered.h2
-rw-r--r--core/io/file_access_compressed.cpp4
-rw-r--r--core/io/file_access_compressed.h2
-rw-r--r--core/io/file_access_encrypted.cpp4
-rw-r--r--core/io/file_access_encrypted.h2
-rw-r--r--core/io/file_access_memory.cpp2
-rw-r--r--core/io/file_access_memory.h2
-rw-r--r--core/io/file_access_network.cpp2
-rw-r--r--core/io/file_access_network.h2
-rw-r--r--core/io/file_access_pack.cpp8
-rw-r--r--core/io/file_access_pack.h2
-rw-r--r--core/io/file_access_zip.cpp6
-rw-r--r--core/io/file_access_zip.h2
-rw-r--r--core/io/pck_packer.cpp8
-rw-r--r--core/io/resource_format_binary.cpp8
-rw-r--r--core/io/resource_import.cpp29
-rw-r--r--core/io/resource_import.h7
-rw-r--r--core/io/resource_loader.cpp25
-rw-r--r--core/io/resource_loader.h2
-rw-r--r--core/io/stream_peer.cpp6
-rw-r--r--core/io/stream_peer.h2
-rw-r--r--core/io/xml_parser.cpp2
-rw-r--r--core/io/zip_io.h4
24 files changed, 95 insertions, 40 deletions
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index 859f2e3f8c..9ec03bf32b 100644
--- a/core/io/file_access_buffered.cpp
+++ b/core/io/file_access_buffered.cpp
@@ -76,7 +76,7 @@ void FileAccessBuffered::seek_end(int64_t p_position) {
file.offset = file.size + p_position;
};
-size_t FileAccessBuffered::get_pos() const {
+size_t FileAccessBuffered::get_position() const {
return file.offset;
};
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
index d3137058fb..70aaeb8ae0 100644
--- a/core/io/file_access_buffered.h
+++ b/core/io/file_access_buffered.h
@@ -72,7 +72,7 @@ protected:
int get_cache_size();
public:
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual void seek(size_t p_position); ///< seek to a given position
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 70430ca5d3..4750945854 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -62,7 +62,7 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
block_size = f->get_32();
read_total = f->get_32();
int bc = (read_total / block_size) + 1;
- int acc_ofs = f->get_pos() + bc * 4;
+ int acc_ofs = f->get_position() + bc * 4;
int max_bs = 0;
for (int i = 0; i < bc; i++) {
@@ -232,7 +232,7 @@ void FileAccessCompressed::seek_end(int64_t p_position) {
seek(read_total + p_position);
}
}
-size_t FileAccessCompressed::get_pos() const {
+size_t FileAccessCompressed::get_position() const {
ERR_FAIL_COND_V(!f, 0);
if (writing) {
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index ba84c9767c..1a57e2d4ee 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -74,7 +74,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 12503f3be4..461c5bafe2 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -71,7 +71,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
unsigned char md5d[16];
p_base->get_buffer(md5d, 16);
length = p_base->get_64();
- base = p_base->get_pos();
+ base = p_base->get_position();
ERR_FAIL_COND_V(p_base->get_len() < base + length, ERR_FILE_CORRUPT);
uint32_t ds = length;
if (ds % 16) {
@@ -199,7 +199,7 @@ void FileAccessEncrypted::seek_end(int64_t p_position) {
seek(data.size() + p_position);
}
-size_t FileAccessEncrypted::get_pos() const {
+size_t FileAccessEncrypted::get_position() const {
return pos;
}
diff --git a/core/io/file_access_encrypted.h b/core/io/file_access_encrypted.h
index 74d00a5a8f..82f60ac654 100644
--- a/core/io/file_access_encrypted.h
+++ b/core/io/file_access_encrypted.h
@@ -61,7 +61,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index 5b186b7798..b948394385 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -120,7 +120,7 @@ void FileAccessMemory::seek_end(int64_t p_position) {
pos = length + p_position;
}
-size_t FileAccessMemory::get_pos() const {
+size_t FileAccessMemory::get_position() const {
ERR_FAIL_COND_V(!data, 0);
return pos;
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index 7feb16461b..b7b8430089 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -51,7 +51,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 58ca2d4c58..8c624226a1 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -350,7 +350,7 @@ void FileAccessNetwork::seek_end(int64_t p_position) {
seek(total_size + p_position);
}
-size_t FileAccessNetwork::get_pos() const {
+size_t FileAccessNetwork::get_position() const {
ERR_FAIL_COND_V(!opened, 0);
return pos;
diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h
index cd5046f007..abbe378b60 100644
--- a/core/io/file_access_network.h
+++ b/core/io/file_access_network.h
@@ -145,7 +145,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index e511085ac5..ff4c28ec39 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -140,17 +140,17 @@ bool PackedSourcePCK::try_open_pack(const String &p_path) {
if (magic != 0x43504447) {
//maybe at he end.... self contained exe
f->seek_end();
- f->seek(f->get_pos() - 4);
+ f->seek(f->get_position() - 4);
magic = f->get_32();
if (magic != 0x43504447) {
memdelete(f);
return false;
}
- f->seek(f->get_pos() - 12);
+ f->seek(f->get_position() - 12);
uint64_t ds = f->get_64();
- f->seek(f->get_pos() - ds - 8);
+ f->seek(f->get_position() - ds - 8);
magic = f->get_32();
if (magic != 0x43504447) {
@@ -236,7 +236,7 @@ void FileAccessPack::seek_end(int64_t p_position) {
seek(pf.size + p_position);
}
-size_t FileAccessPack::get_pos() const {
+size_t FileAccessPack::get_position() const {
return pos;
}
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index 758e9afa8e..3deb0d2bd3 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -148,7 +148,7 @@ public:
virtual void seek(size_t p_position);
virtual void seek_end(int64_t p_position = 0);
- virtual size_t get_pos() const;
+ virtual size_t get_position() const;
virtual size_t get_len() const;
virtual bool eof_reached() const;
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index 8c99ef2983..73b23ac702 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -65,7 +65,7 @@ static uLong godot_write(voidpf opaque, voidpf stream, const void *buf, uLong si
static long godot_tell(voidpf opaque, voidpf stream) {
FileAccess *f = (FileAccess *)opaque;
- return f->get_pos();
+ return f->get_position();
};
static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
@@ -76,7 +76,7 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
- pos = f->get_pos() + offset;
+ pos = f->get_position() + offset;
break;
case ZLIB_FILEFUNC_SEEK_END:
pos = f->get_len() + offset;
@@ -301,7 +301,7 @@ void FileAccessZip::seek_end(int64_t p_position) {
unzSeekCurrentFile(zfile, get_len() + p_position);
};
-size_t FileAccessZip::get_pos() const {
+size_t FileAccessZip::get_position() const {
ERR_FAIL_COND_V(!zfile, 0);
return unztell(zfile);
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index 2a8ec3fca5..a40e1a753d 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -98,7 +98,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index f1f5b6f538..23e86580d1 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -119,7 +119,7 @@ Error PCKPacker::flush(bool p_verbose) {
for (int i = 0; i < files.size(); i++) {
file->store_pascal_string(files[i].path);
- files[i].offset_offset = file->get_pos();
+ files[i].offset_offset = file->get_position();
file->store_64(0); // offset
file->store_64(files[i].size); // size
@@ -130,10 +130,10 @@ Error PCKPacker::flush(bool p_verbose) {
file->store_32(0);
};
- uint64_t ofs = file->get_pos();
+ uint64_t ofs = file->get_position();
ofs = _align(ofs, alignment);
- _pad(file, ofs - file->get_pos());
+ _pad(file, ofs - file->get_position());
const uint32_t buf_max = 65536;
uint8_t *buf = memnew_arr(uint8_t, buf_max);
@@ -150,7 +150,7 @@ Error PCKPacker::flush(bool p_verbose) {
to_write -= read;
};
- uint64_t pos = file->get_pos();
+ uint64_t pos = file->get_position();
file->seek(files[i].offset_offset); // go back to store the file's offset
file->store_64(ofs);
file->seek(pos);
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 16ec6cd3c5..900db7c2dc 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -1179,7 +1179,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
save_ustring(fw, get_ustring(f)); //type
- size_t md_ofs = f->get_pos();
+ size_t md_ofs = f->get_position();
size_t importmd_ofs = f->get_64();
fw->store_64(0); //metadata offset
@@ -1227,7 +1227,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
save_ustring(fw, path);
}
- int64_t size_diff = (int64_t)fw->get_pos() - (int64_t)f->get_pos();
+ int64_t size_diff = (int64_t)fw->get_position() - (int64_t)f->get_position();
//internal resources
uint32_t int_resources_size = f->get_32();
@@ -1880,7 +1880,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
} else {
save_unicode_string(r->get_path()); //actual external
}
- ofs_pos.push_back(f->get_pos());
+ ofs_pos.push_back(f->get_position());
f->store_64(0); //offset in 64 bits
}
@@ -1891,7 +1891,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
ResourceData &rd = E->get();
- ofs_table.push_back(f->get_pos());
+ ofs_table.push_back(f->get_position());
save_unicode_string(rd.type);
f->store_32(rd.properties.size());
diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp
index be486a86a3..bc7ea47762 100644
--- a/core/io/resource_import.cpp
+++ b/core/io/resource_import.cpp
@@ -87,6 +87,8 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
path_found = true; //first match must have priority
} else if (assign == "type") {
r_path_and_type.type = value;
+ } else if (assign == "importer") {
+ r_path_and_type.importer = value;
} else if (assign == "valid") {
if (r_valid) {
*r_valid = value;
@@ -184,6 +186,29 @@ bool ResourceFormatImporter::can_be_imported(const String &p_path) const {
return ResourceFormatLoader::recognize_path(p_path);
}
+int ResourceFormatImporter::get_import_order(const String &p_path) const {
+
+ Ref<ResourceImporter> importer;
+
+ if (FileAccess::exists(p_path + ".import")) {
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path, pat);
+
+ if (err == OK) {
+ importer = get_importer_by_name(pat.importer);
+ }
+ } else {
+
+ importer = get_importer_by_extension(p_path.get_extension().to_lower());
+ }
+
+ if (importer.is_valid())
+ return importer->get_import_order();
+
+ return 0;
+}
+
bool ResourceFormatImporter::handles_type(const String &p_type) const {
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
@@ -291,7 +316,7 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String>
return ResourceLoader::get_dependencies(pat.path, p_dependencies, p_add_types);
}
-Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) {
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const {
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
if (E->get()->get_importer_name() == p_name) {
@@ -315,7 +340,7 @@ void ResourceFormatImporter::get_importers_for_extension(const String &p_extensi
}
}
-Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) {
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const {
Ref<ResourceImporter> importer;
float priority = 0;
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
index b10255fbab..28489b5d34 100644
--- a/core/io/resource_import.h
+++ b/core/io/resource_import.h
@@ -38,6 +38,7 @@ class ResourceFormatImporter : public ResourceFormatLoader {
struct PathAndType {
String path;
String type;
+ String importer;
};
Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = NULL) const;
@@ -58,14 +59,15 @@ public:
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
virtual bool can_be_imported(const String &p_path) const;
+ virtual int get_import_order(const String &p_path) const;
String get_internal_resource_path(const String &p_path) const;
void get_internal_resource_path_list(const String &p_path, List<String> *r_paths);
void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); }
void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
- Ref<ResourceImporter> get_importer_by_name(const String &p_name);
- Ref<ResourceImporter> get_importer_by_extension(const String &p_extension);
+ Ref<ResourceImporter> get_importer_by_name(const String &p_name) const;
+ Ref<ResourceImporter> get_importer_by_extension(const String &p_extension) const;
void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers);
String get_import_base_path(const String &p_for_file) const;
@@ -82,6 +84,7 @@ public:
virtual String get_save_extension() const = 0;
virtual String get_resource_type() const = 0;
virtual float get_priority() const { return 1.0; }
+ virtual int get_import_order() const { return 0; }
struct ImportOption {
PropertyInfo option;
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 4f266df43e..89cb4a22c2 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -308,6 +308,31 @@ void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_l
}
}
+int ResourceLoader::get_import_order(const String &p_path) {
+
+ String path = _path_remap(p_path);
+
+ String local_path;
+ if (path.is_rel_path())
+ local_path = "res://" + path;
+ else
+ local_path = ProjectSettings::get_singleton()->localize_path(path);
+
+ for (int i = 0; i < loader_count; i++) {
+
+ if (!loader[i]->recognize_path(local_path))
+ continue;
+ /*
+ if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ continue;
+ */
+
+ return loader[i]->get_import_order(p_path);
+ }
+
+ return 0;
+}
+
bool ResourceLoader::is_import_valid(const String &p_path) {
String path = _path_remap(p_path);
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index a71a568569..5deffbca1a 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -67,6 +67,7 @@ public:
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
virtual Error rename_dependencies(const String &p_path, const Map<String, String> &p_map) { return OK; }
virtual bool is_import_valid(const String &p_path) const { return true; }
+ virtual int get_import_order(const String &p_path) const { return 0; }
virtual ~ResourceFormatLoader() {}
};
@@ -110,6 +111,7 @@ public:
static void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
static Error rename_dependencies(const String &p_path, const Map<String, String> &p_map);
static bool is_import_valid(const String &p_path);
+ static int get_import_order(const String &p_path);
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; }
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index f4f81f0807..2583eb369d 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -405,9 +405,9 @@ void StreamPeer::_bind_methods() {
void StreamPeerBuffer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("seek", "pos"), &StreamPeerBuffer::seek);
+ ClassDB::bind_method(D_METHOD("seek", "position"), &StreamPeerBuffer::seek);
ClassDB::bind_method(D_METHOD("get_size"), &StreamPeerBuffer::get_size);
- ClassDB::bind_method(D_METHOD("get_pos"), &StreamPeerBuffer::get_pos);
+ ClassDB::bind_method(D_METHOD("get_position"), &StreamPeerBuffer::get_position);
ClassDB::bind_method(D_METHOD("resize", "size"), &StreamPeerBuffer::resize);
ClassDB::bind_method(D_METHOD("set_data_array", "data"), &StreamPeerBuffer::set_data_array);
ClassDB::bind_method(D_METHOD("get_data_array"), &StreamPeerBuffer::get_data_array);
@@ -484,7 +484,7 @@ int StreamPeerBuffer::get_size() const {
return data.size();
}
-int StreamPeerBuffer::get_pos() const {
+int StreamPeerBuffer::get_position() const {
return pointer;
}
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index 1ee997c123..b120d18501 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -111,7 +111,7 @@ public:
void seek(int p_pos);
int get_size() const;
- int get_pos() const;
+ int get_position() const;
void resize(int p_size);
void set_data_array(const PoolVector<uint8_t> &p_data);
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index 3a4be7cd13..8ae68183d7 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -369,7 +369,7 @@ void XMLParser::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_empty"), &XMLParser::is_empty);
ClassDB::bind_method(D_METHOD("get_current_line"), &XMLParser::get_current_line);
ClassDB::bind_method(D_METHOD("skip_section"), &XMLParser::skip_section);
- ClassDB::bind_method(D_METHOD("seek", "pos"), &XMLParser::seek);
+ ClassDB::bind_method(D_METHOD("seek", "position"), &XMLParser::seek);
ClassDB::bind_method(D_METHOD("open", "file"), &XMLParser::open);
ClassDB::bind_method(D_METHOD("open_buffer", "buffer"), &XMLParser::open_buffer);
diff --git a/core/io/zip_io.h b/core/io/zip_io.h
index 8cf971ee08..ce3c919b77 100644
--- a/core/io/zip_io.h
+++ b/core/io/zip_io.h
@@ -72,7 +72,7 @@ static uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong si
static long zipio_tell(voidpf opaque, voidpf stream) {
FileAccess *f = *(FileAccess **)opaque;
- return f->get_pos();
+ return f->get_position();
};
static long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
@@ -83,7 +83,7 @@ static long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
- pos = f->get_pos() + offset;
+ pos = f->get_position() + offset;
break;
case ZLIB_FILEFUNC_SEEK_END:
pos = f->get_len() + offset;