| 1082 | } |
| 1083 | |
| 1084 | Error ImportInfoModern::save_md5_file(const String &output_dir) { |
| 1085 | Vector<String> dest_files = get_dest_files(); |
| 1086 | if (dest_files.size() == 0) { |
| 1087 | return ERR_PRINTER_ON_FIRE; |
| 1088 | } |
| 1089 | |
| 1090 | String actual_source = get_source_file(); |
| 1091 | if (export_dest != actual_source) { |
| 1092 | return ERR_PRINTER_ON_FIRE; |
| 1093 | } |
| 1094 | // check if each exists |
| 1095 | for (int64_t i = 0; i < dest_files.size(); i++) { |
| 1096 | if (!FileAccess::exists(dest_files[i])) { |
| 1097 | //WARN_PRINT("Cannot find " + dest_files[i] + ", cannot compute dest_md5."); |
| 1098 | return ERR_PRINTER_ON_FIRE; |
| 1099 | } |
| 1100 | } |
| 1101 | // dest_md5 is the md5 of all the destination files together |
| 1102 | String dst_md5 = FileAccess::get_multiple_md5(dest_files); |
| 1103 | ERR_FAIL_COND_V_MSG(dst_md5.is_empty(), ERR_FILE_BAD_PATH, "Can't open import resources to check md5!"); |
| 1104 | |
| 1105 | if (src_md5.is_empty()) { |
| 1106 | String exported_src_path = output_dir.path_join(actual_source.replace_first("res://", "")); |
| 1107 | src_md5 = FileAccess::get_md5(exported_src_path); |
| 1108 | if (src_md5.is_empty()) { |
| 1109 | ERR_FAIL_COND_V_MSG(src_md5.is_empty(), ERR_FILE_BAD_PATH, "Can't open exported resource to check md5!"); |
| 1110 | } |
| 1111 | } |
| 1112 | String md5_file_path = output_dir.path_join(get_md5_file_path().trim_prefix("res://")); |
| 1113 | gdre::ensure_dir(md5_file_path.get_base_dir()); |
| 1114 | Ref<FileAccess> md5_file = FileAccess::open(md5_file_path, FileAccess::WRITE); |
| 1115 | ERR_FAIL_COND_V_MSG(md5_file.is_null(), ERR_FILE_CANT_OPEN, "Can't open exported resource to check md5!"); |
| 1116 | md5_file->store_string("source_md5=\"" + src_md5 + "\"\ndest_md5=\"" + dst_md5 + "\"\n\n"); |
| 1117 | md5_file->flush(); |
| 1118 | return OK; |
| 1119 | } |
| 1120 | |
| 1121 | void ImportInfoModern::_set_from_json(const Dictionary &p_json) { |
| 1122 | ImportInfo::_set_from_json(p_json); |
no test coverage detected