Error ResourceFormatLoaderBinary::load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const {


	FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
	if (!f) {
		return ERR_FILE_CANT_OPEN;
	}

	Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
	ria->local_path=Globals::get_singleton()->localize_path(p_path);
	ria->res_path=ria->local_path;
//	ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
	ria->recognize(f);
	if(ria->error!=OK)
		return ERR_FILE_UNRECOGNIZED;
	f=ria->f;
	uint64_t imp_ofs = f->get_64();

	if (imp_ofs==0)
		return ERR_UNAVAILABLE;

	f->seek(imp_ofs);
	Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
	imd->set_editor(ria->get_unicode_string());
	int sc = f->get_32();
	for(int i=0;i<sc;i++) {

		String src = ria->get_unicode_string();
		String md5 = ria->get_unicode_string();
		imd->add_source(src,md5);
	}
	int pc = f->get_32();

	for(int i=0;i<pc;i++) {

		String name = ria->get_unicode_string();
		Variant val;
		ria->parse_variant(val);
		imd->set_option(name,val);
	}

	r_var=imd;

	return OK;

}
示例#2
0
bool PackedSourcePCK::try_open_pack(const String& p_path) {

	FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
	if (!f)
		return false;

	uint32_t magic= f->get_32();

	if (magic != 0x4b435047) {
		//maybe at he end.... self contained exe
		f->seek_end();
		f->seek( f->get_pos() -4 );
		magic = f->get_32();
		if (magic != 0x4b435047) {

			memdelete(f);
			return false;
		}
		f->seek( f->get_pos() -12 );


		uint64_t ds = f->get_64();
		f->seek( f->get_pos() -ds-8 );

		magic = f->get_32();
		if (magic != 0x4b435047) {

			memdelete(f);
			return false;
		}

	}

	uint32_t ver_major = f->get_32();
	uint32_t ver_minor = f->get_32();
	uint32_t ver_rev = f->get_32();

	ERR_EXPLAIN("Pack created with a newer version of the engine: "+itos(ver_major)+"."+itos(ver_minor)+"."+itos(ver_rev));
	ERR_FAIL_COND_V( ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), ERR_INVALID_DATA);

	for(int i=0;i<16;i++) {
		//reserved
		f->get_32();
	}

	int file_count = f->get_32();

	for(int i=0;i<file_count;i++) {

		uint32_t sl = f->get_32();
		CharString cs;
		cs.resize(sl+1);
		f->get_buffer((uint8_t*)cs.ptr(),sl);
		cs[sl]=0;

		String path;
		path.parse_utf8(cs.ptr());

		uint64_t ofs = f->get_64();
		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);
	};

	return true;
};