| 2166 | } |
| 2167 | |
| 2168 | Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags) { |
| 2169 | Resource::seed_scene_unique_id(p_path.hash()); |
| 2170 | |
| 2171 | Error err; |
| 2172 | Ref<FileAccess> f; |
| 2173 | if (p_flags & ResourceSaver::FLAG_COMPRESS) { |
| 2174 | Ref<FileAccessCompressed> fac; |
| 2175 | fac.instantiate(); |
| 2176 | fac->configure("RSCC"); |
| 2177 | f = fac; |
| 2178 | err = fac->open_internal(p_path, FileAccess::WRITE); |
| 2179 | } else { |
| 2180 | f = FileAccess::open(p_path, FileAccess::WRITE, &err); |
| 2181 | } |
| 2182 | |
| 2183 | ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Cannot create file '%s'.", p_path)); |
| 2184 | |
| 2185 | relative_paths = p_flags & ResourceSaver::FLAG_RELATIVE_PATHS; |
| 2186 | skip_editor = p_flags & ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES; |
| 2187 | bundle_resources = p_flags & ResourceSaver::FLAG_BUNDLE_RESOURCES; |
| 2188 | big_endian = p_flags & ResourceSaver::FLAG_SAVE_BIG_ENDIAN; |
| 2189 | takeover_paths = p_flags & ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; |
| 2190 | |
| 2191 | if (!p_path.begins_with("res://")) { |
| 2192 | takeover_paths = false; |
| 2193 | } |
| 2194 | |
| 2195 | local_path = p_path.get_base_dir(); |
| 2196 | path = ProjectSettings::get_singleton()->localize_path(p_path); |
| 2197 | |
| 2198 | _find_resources(p_resource, true); |
| 2199 | |
| 2200 | if (!(p_flags & ResourceSaver::FLAG_COMPRESS)) { |
| 2201 | //save header compressed |
| 2202 | static const uint8_t header[4] = { 'R', 'S', 'R', 'C' }; |
| 2203 | f->store_buffer(header, 4); |
| 2204 | } |
| 2205 | |
| 2206 | if (big_endian) { |
| 2207 | f->store_32(1); |
| 2208 | } else { |
| 2209 | f->store_32(0); |
| 2210 | } |
| 2211 | f->store_32(0); //64 bits file, false for now |
| 2212 | f->set_big_endian(big_endian); |
| 2213 | |
| 2214 | f->store_32(REDOT_VERSION_MAJOR); |
| 2215 | f->store_32(REDOT_VERSION_MINOR); |
| 2216 | f->store_32(FORMAT_VERSION); |
| 2217 | |
| 2218 | if (f->get_error() != OK && f->get_error() != ERR_FILE_EOF) { |
| 2219 | return ERR_CANT_CREATE; |
| 2220 | } |
| 2221 | |
| 2222 | save_unicode_string(f, _resource_get_class(p_resource)); |
| 2223 | f->store_64(0); //offset to import metadata |
| 2224 | |
| 2225 | String script_class; |
no test coverage detected