summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorsanikoyes <sanikoyes@163.com>2014-04-06 21:52:47 +0800
committersanikoyes <sanikoyes@163.com>2014-04-06 21:52:47 +0800
commit77a840e350668a9c80b1e63b9b73aac44221c53b (patch)
tree40d2115e639bdc72a61811ac4f2fb0f04ec8eb7f /core/io
parent14bbdcb139b35e6d206df1ab3176d34245b72329 (diff)
parentded365031ede27b7a6efef59bc886343f58d310b (diff)
Merge branch 'master' into hotfix-android-unicode-ime-input
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_pack.cpp1
-rw-r--r--core/io/http_client.cpp8
-rw-r--r--core/io/marshalls.cpp148
-rw-r--r--core/io/resource_format_binary.cpp34
-rw-r--r--core/io/resource_format_binary.h2
-rw-r--r--core/io/resource_format_xml.cpp51
-rw-r--r--core/io/resource_format_xml.h5
-rw-r--r--core/io/resource_loader.cpp13
-rw-r--r--core/io/resource_loader.h1
-rw-r--r--core/io/resource_saver.h3
10 files changed, 233 insertions, 33 deletions
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index edecbb6a3e..45e6990ad2 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -172,7 +172,6 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
uint64_t size = f->get_64();
uint8_t md5[16];
f->get_buffer(md5,16);
-
PackedData::get_singleton()->add_path(p_path, path, ofs, size, md5,this);
};
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 1b53ee6104..f9da846844 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -97,8 +97,16 @@ Error HTTPClient::request( Method p_method, const String& p_url, const Vector<St
String request=String(_methods[p_method])+" "+p_url+" HTTP/1.1\r\n";
request+="Host: "+conn_host+":"+itos(conn_port)+"\r\n";
+ bool add_clen=p_body.length()>0;
for(int i=0;i<p_headers.size();i++) {
request+=p_headers[i]+"\r\n";
+ if (add_clen && p_headers[i].find("Content-Length:")==0) {
+ add_clen=false;
+ }
+ }
+ if (add_clen) {
+ request+="Content-Length: "+itos(p_body.utf8().length())+"\r\n";
+ //should it add utf8 encoding? not sure
}
request+="\r\n";
request+=p_body;
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index f5f9d34439..df951c759a 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -264,26 +264,94 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
}
r_variant=img;
- if (r_len)
+ if (r_len) {
+ if (datalen%4)
+ (*r_len)+=4-datalen%4;
+
(*r_len)+=4*5+datalen;
+ }
} break;
case Variant::NODE_PATH: {
- ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t strlen = decode_uint32(buf);
- buf+=4;
- len-=4;
- ERR_FAIL_COND_V((int)strlen>len,ERR_INVALID_DATA);
+ if (strlen&0x80000000) {
+ //new format
+ ERR_FAIL_COND_V(len<12,ERR_INVALID_DATA);
+ Vector<StringName> names;
+ Vector<StringName> subnames;
+ bool absolute;
+ StringName prop;
- String str;
- str.parse_utf8((const char*)buf,strlen);
+ int i=0;
+ uint32_t namecount=strlen&=0x7FFFFFFF;
+ uint32_t subnamecount = decode_uint32(buf+4);
+ uint32_t flags = decode_uint32(buf+8);
- r_variant=NodePath(str);
+ len-=12;
+ buf+=12;
- if (r_len)
- (*r_len)+=4+strlen;
+ int total=namecount+subnamecount;
+ if (flags&2)
+ total++;
+
+ if (r_len)
+ (*r_len)+=12;
+
+
+ for(int i=0;i<total;i++) {
+
+ ERR_FAIL_COND_V((int)len<4,ERR_INVALID_DATA);
+ strlen = decode_uint32(buf);
+
+ int pad=0;
+
+ if (strlen%4)
+ pad+=4-strlen%4;
+
+ buf+=4;
+ len-=4;
+ ERR_FAIL_COND_V((int)strlen+pad>len,ERR_INVALID_DATA);
+
+ String str;
+ str.parse_utf8((const char*)buf,strlen);
+
+
+ if (i<namecount)
+ names.push_back(str);
+ else if (i<namecount+subnamecount)
+ subnames.push_back(str);
+ else
+ prop=str;
+
+ buf+=strlen+pad;
+ len-=strlen+pad;
+
+ if (r_len)
+ (*r_len)+=4+strlen+pad;
+
+ }
+
+ r_variant=NodePath(names,subnames,flags&1,prop);
+
+ } else {
+ //old format, just a string
+
+ buf+=4;
+ len-=4;
+ ERR_FAIL_COND_V((int)strlen>len,ERR_INVALID_DATA);
+
+
+ String str;
+ str.parse_utf8((const char*)buf,strlen);
+
+ r_variant=NodePath(str);
+
+ if (r_len)
+ (*r_len)+=4+strlen;
+ }
} break;
/*case Variant::RESOURCE: {
@@ -713,7 +781,59 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=4;
} break;
- case Variant::NODE_PATH:
+ case Variant::NODE_PATH: {
+
+ NodePath np=p_variant;
+ if (buf) {
+ encode_uint32(uint32_t(np.get_name_count())|0x80000000,buf); //for compatibility with the old format
+ encode_uint32(np.get_subname_count(),buf+4);
+ uint32_t flags=0;
+ if (np.is_absolute())
+ flags|=1;
+ if (np.get_property()!=StringName())
+ flags|=2;
+
+ encode_uint32(flags,buf+8);
+
+ buf+=12;
+ }
+
+ r_len+=12;
+
+ int total = np.get_name_count()+np.get_subname_count();
+ if (np.get_property()!=StringName())
+ total++;
+
+ for(int i=0;i<total;i++) {
+
+ String str;
+
+ if (i<np.get_name_count())
+ str=np.get_name(i);
+ else if (i<np.get_name_count()+np.get_subname_count())
+ str=np.get_subname(i-np.get_subname_count());
+ else
+ str=np.get_property();
+
+ CharString utf8 = str.utf8();
+
+ int pad = 0;
+
+ if (utf8.length()%4)
+ pad=4-utf8.length()%4;
+
+ if (buf) {
+ encode_uint32(utf8.length(),buf);
+ buf+=4;
+ copymem(buf,utf8.get_data(),utf8.length());
+ buf+=pad+utf8.length();
+ }
+
+
+ r_len+=4+utf8.length()+pad;
+ }
+
+ } break;
case Variant::STRING: {
@@ -879,7 +999,11 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
copymem(&buf[20],&r[0],ds);
}
- r_len+=data.size()+5*4;
+ int pad=0;
+ if (data.size()%4)
+ pad=4-data.size()%4;
+
+ r_len+=data.size()+5*4+pad;
} break;
/*case Variant::RESOURCE: {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index c54398935e..33f4cafedd 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -647,7 +647,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
}
stage++;
- return OK;
+ return error;
}
s-=external_resources.size();
@@ -804,7 +804,12 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f,List<Stri
for(int i=0;i<external_resources.size();i++) {
- p_dependencies->push_back(external_resources[i].path);
+ String dep=external_resources[i].path;
+ if (dep.ends_with("*")) {
+ dep=ResourceLoader::guess_full_filename(dep,external_resources[i].type);
+ }
+
+ p_dependencies->push_back(dep);
}
}
@@ -892,6 +897,19 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
}
+ //see if the exporter has different set of external resources for more efficient loading
+ String preload_depts = "deps/"+res_path.md5_text();
+ if (Globals::get_singleton()->has(preload_depts)) {
+ external_resources.clear();
+ //ignore external resources and use these
+ NodePath depts=Globals::get_singleton()->get(preload_depts);
+ external_resources.resize(depts.get_name_count());
+ for(int i=0;i<depts.get_name_count();i++) {
+ external_resources[i].path=depts.get_name(i);
+ }
+ print_line(res_path+" - EXTERNAL RESOURCES: "+itos(external_resources.size()));
+ }
+
print_bl("ext resources: "+itos(ext_resources_size));
uint32_t int_resources_size=f->get_32();
@@ -931,6 +949,7 @@ String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) {
} else if (header[0]!='R' || header[1]!='S' || header[2]!='R' || header[3]!='C') {
//not normal
+ error=ERR_FILE_UNRECOGNIZED;
return "";
}
@@ -1412,8 +1431,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_32(OBJECT_EXTERNAL_RESOURCE);
save_unicode_string(res->get_save_type());
String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path();
- if (no_extensions)
- path=path.basename()+".*";
save_unicode_string(path);
} else {
@@ -1439,7 +1456,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_32(VARIANT_DICTIONARY);
Dictionary d = p_property;
- f->store_32(uint32_t(d.size())|(d.is_shared()?0x80000000:0));
+ f->store_32(uint32_t(d.size())|(d.is_shared()?0x80000000:0));
List<Variant> keys;
d.get_key_list(&keys);
@@ -1734,7 +1751,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
skip_editor=p_flags&ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
bundle_resources=p_flags&ResourceSaver::FLAG_BUNDLE_RESOURCES;
big_endian=p_flags&ResourceSaver::FLAG_SAVE_BIG_ENDIAN;
- no_extensions=p_flags&ResourceSaver::FLAG_NO_EXTENSION;
+
local_path=p_path.get_base_dir();
//bin_meta_idx = get_string_index("__bin_meta__"); //is often used, so create
@@ -1816,8 +1833,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
save_unicode_string(E->get()->get_save_type());
String path = E->get()->get_path();
- if (no_extensions)
- path=path.basename()+".*";
save_unicode_string(path);
}
// save internal resource table
@@ -1861,6 +1876,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
}
f->seek_end();
+ print_line("SAVING: "+p_path);
if (p_resource->get_import_metadata().is_valid()) {
uint64_t md_pos = f->get_pos();
Ref<ResourceImportMetadata> imd=p_resource->get_import_metadata();
@@ -1869,6 +1885,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
for(int i=0;i<imd->get_source_count();i++) {
save_unicode_string(imd->get_source_path(i));
save_unicode_string(imd->get_source_md5(i));
+ print_line("SAVE PATH: "+imd->get_source_path(i));
+ print_line("SAVE MD5: "+imd->get_source_md5(i));
}
List<String> options;
imd->get_options(&options);
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 006148f5a8..bd33fee82c 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -120,7 +120,7 @@ class ResourceFormatSaverBinaryInstance {
String local_path;
- bool no_extensions;
+
bool relative_paths;
bool bundle_resources;
bool skip_editor;
diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp
index fc5aecfd99..f3c0f1cb8b 100644
--- a/core/io/resource_format_xml.cpp
+++ b/core/io/resource_format_xml.cpp
@@ -1357,6 +1357,31 @@ Error ResourceInteractiveLoaderXML::poll() {
if (error!=OK)
return error;
+ if (ext_resources.size()) {
+
+ error=ERR_FILE_CORRUPT;
+ String path=ext_resources.front()->get();
+
+ RES res = ResourceLoader::load(path);
+
+ if (res.is_null()) {
+
+ if (ResourceLoader::get_abort_on_missing_resources()) {
+ ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": editor exported unexisting resource at: "+path);
+ ERR_FAIL_V(error);
+ } else {
+ ResourceLoader::notify_load_error("Resource Not Found: "+path);
+ }
+ } else {
+
+ resource_cache.push_back(res);
+ }
+
+ error=OK;
+ ext_resources.pop_front();
+ resource_current++;
+ return error;
+ }
bool exit;
Tag *tag = parse_tag(&exit);
@@ -1528,7 +1553,7 @@ int ResourceInteractiveLoaderXML::get_stage() const {
}
int ResourceInteractiveLoaderXML::get_stage_count() const {
- return resources_total;
+ return resources_total+ext_resources.size();
}
ResourceInteractiveLoaderXML::~ResourceInteractiveLoaderXML() {
@@ -1573,6 +1598,12 @@ void ResourceInteractiveLoaderXML::get_dependencies(FileAccess *f,List<String> *
path=Globals::get_singleton()->localize_path(local_path.get_base_dir()+"/"+path);
}
+ if (path.ends_with("*")) {
+ ERR_FAIL_COND(!tag->args.has("type"));
+ String type = tag->args["type"];
+ path = ResourceLoader::guess_full_filename(path,type);
+ }
+
p_dependencies->push_back(path);
Error err = close_tag("ext_resource");
@@ -1642,6 +1673,19 @@ void ResourceInteractiveLoaderXML::open(FileAccess *p_f) {
}
+ String preload_depts = "deps/"+local_path.md5_text();
+ if (Globals::get_singleton()->has(preload_depts)) {
+ ext_resources.clear();
+ //ignore external resources and use these
+ NodePath depts=Globals::get_singleton()->get(preload_depts);
+
+ for(int i=0;i<depts.get_name_count();i++) {
+ ext_resources.push_back(depts.get_name(i));
+ }
+ print_line(local_path+" - EXTERNAL RESOURCES: "+itos(ext_resources.size()));
+ }
+
+
}
String ResourceInteractiveLoaderXML::recognize(FileAccess *p_f) {
@@ -1969,8 +2013,6 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V
if (res->get_path().length() && res->get_path().find("::")==-1) {
//external resource
String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path();
- if (no_extension)
- path=path.basename()+".*";
escape(path);
params+=" path=\""+path+"\"";
} else {
@@ -2458,7 +2500,6 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res
relative_paths=p_flags&ResourceSaver::FLAG_RELATIVE_PATHS;
skip_editor=p_flags&ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
bundle_resources=p_flags&ResourceSaver::FLAG_BUNDLE_RESOURCES;
- no_extension=p_flags&ResourceSaver::FLAG_NO_EXTENSION;
depth=0;
// save resources
@@ -2475,8 +2516,6 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res
write_tabs();
String p = E->get()->get_path();
- if (no_extension)
- p=p.basename()+".*";
enter_tag("ext_resource","path=\""+p+"\" type=\""+E->get()->get_save_type()+"\""); //bundled
exit_tag("ext_resource"); //bundled
diff --git a/core/io/resource_format_xml.h b/core/io/resource_format_xml.h
index 05313ffbd7..7874431a38 100644
--- a/core/io/resource_format_xml.h
+++ b/core/io/resource_format_xml.h
@@ -50,6 +50,10 @@ class ResourceInteractiveLoaderXML : public ResourceInteractiveLoader {
_FORCE_INLINE_ Error _parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end);
+
+
+ List<StringName> ext_resources;
+
int resources_total;
int resource_current;
String resource_type;
@@ -113,7 +117,6 @@ class ResourceFormatSaverXMLInstance {
- bool no_extension;
bool relative_paths;
bool bundle_resources;
bool skip_editor;
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 5ee48bae25..d2610d5d4f 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -166,7 +166,7 @@ RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_n
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
if (OS::get_singleton()->is_stdout_verbose())
- print_line("load resource: ");
+ print_line("load resource: "+remapped_path);
String extension=remapped_path.extension();
bool found=false;
@@ -233,6 +233,10 @@ Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p
String ResourceLoader::find_complete_path(const String& p_path,const String& p_type) {
+ //this is an old vestige when the engine saved files without extension.
+ //remains here for compatibility with old projects and only because it
+ //can be sometimes nice to open files using .* from a script and have it guess
+ //the right extension.
String local_path = p_path;
if (local_path.ends_with("*")) {
@@ -353,6 +357,13 @@ void ResourceLoader::get_dependencies(const String& p_path,List<String> *p_depen
}
}
+String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) {
+
+ String local_path = Globals::get_singleton()->localize_path(p_path);
+
+ return find_complete_path(local_path,p_type);
+
+}
String ResourceLoader::get_resource_type(const String &p_path) {
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 70b1a79582..ab23158785 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -102,6 +102,7 @@ public:
static String get_resource_type(const String &p_path);
static void get_dependencies(const String& p_path,List<String> *p_dependencies);
+ static String guess_full_filename(const String &p_path,const String& p_type);
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load=p_timestamp; }
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index 4b794247e0..fd4575c872 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -74,9 +74,6 @@ public:
FLAG_OMIT_EDITOR_PROPERTIES=8,
FLAG_SAVE_BIG_ENDIAN=16,
FLAG_COMPRESS=32,
- FLAG_NO_EXTENSION=64,
-
-
};