| 303 | } |
| 304 | |
| 305 | Ref<ImportInfo> ImportInfo::load_from_file(const String &p_path, int ver_major, int ver_minor) { |
| 306 | Ref<ImportInfo> iinfo; |
| 307 | Error err = OK; |
| 308 | if (p_path.get_extension() == "import") { |
| 309 | iinfo = Ref<ImportInfo>(memnew(ImportInfoModern)); |
| 310 | err = iinfo->_load(p_path); |
| 311 | if (err == OK && iinfo.is_valid() && iinfo->ver_major == 0 && ver_major != 0) { |
| 312 | iinfo->ver_major = ver_major; |
| 313 | iinfo->ver_minor = ver_minor; |
| 314 | } |
| 315 | } else if (p_path.get_extension() == "remap") { |
| 316 | // .remap file for an autoconverted export |
| 317 | iinfo = Ref<ImportInfoRemap>(memnew(ImportInfoRemap)); |
| 318 | err = iinfo->_load(p_path); |
| 319 | } else if (p_path.get_extension() == "gdnlib" || p_path.get_extension() == "gdextension") { |
| 320 | iinfo = Ref<ImportInfoGDExt>(memnew(ImportInfoGDExt)); |
| 321 | err = iinfo->_load(p_path); |
| 322 | if (err == OK && iinfo.is_valid() && iinfo->ver_major == 0 && ver_major != 0) { |
| 323 | iinfo->ver_major = ver_major; |
| 324 | iinfo->ver_minor = ver_minor; |
| 325 | } |
| 326 | } else { |
| 327 | if (ver_major == 0 && ResourceCompatLoader::handles_resource(p_path)) { |
| 328 | Ref<ResourceInfo> res_info; |
| 329 | err = get_resource_info(p_path, res_info); |
| 330 | ERR_FAIL_COND_V_MSG(err != OK, Ref<ImportInfo>(), "Could not load resource info for " + p_path); |
| 331 | ver_major = res_info->ver_major; |
| 332 | } |
| 333 | if (err == OK) { |
| 334 | if (ver_major <= 2) { |
| 335 | iinfo = Ref<ImportInfo>(memnew(ImportInfov2)); |
| 336 | err = iinfo->_load(p_path); |
| 337 | } else if (ResourceCompatLoader::handles_resource(p_path)) { |
| 338 | iinfo = Ref<ImportInfo>(memnew(ImportInfoDummy)); |
| 339 | err = iinfo->_load(p_path); |
| 340 | } else { |
| 341 | ERR_FAIL_V_MSG(Ref<ImportInfo>(), "Could not load import info; not a resource: " + p_path); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | if (err != OK) { |
| 346 | return Ref<ImportInfo>(); |
| 347 | } |
| 348 | return iinfo; |
| 349 | } |
| 350 | |
| 351 | Ref<ImportInfo> ImportInfo::from_json(const Dictionary &p_json) { |
| 352 | Ref<ImportInfo> iinfo; |