| 1090 | } |
| 1091 | |
| 1092 | static Result DoReloadResource(HFactory factory, const char* name, HResourceDescriptor* out_descriptor) |
| 1093 | { |
| 1094 | char canonical_path[RESOURCE_PATH_MAX]; |
| 1095 | GetCanonicalPath(name, canonical_path, sizeof(canonical_path)); |
| 1096 | |
| 1097 | uint64_t canonical_path_hash = dmHashBuffer64(canonical_path, strlen(canonical_path)); |
| 1098 | |
| 1099 | ResourceDescriptor* rd = factory->m_Resources->Get(canonical_path_hash); |
| 1100 | |
| 1101 | if (out_descriptor) |
| 1102 | *out_descriptor = rd; |
| 1103 | |
| 1104 | if (rd == 0x0) |
| 1105 | return RESULT_RESOURCE_NOT_FOUND; |
| 1106 | |
| 1107 | ResourceType* resource_type = (ResourceType*) rd->m_ResourceType; |
| 1108 | if (!resource_type->m_RecreateFunction) |
| 1109 | return RESULT_NOT_SUPPORTED; |
| 1110 | |
| 1111 | uint32_t preload_size = RESOURCE_INVALID_PRELOAD_SIZE; |
| 1112 | if (ResourceTypeIsStreaming(resource_type)) |
| 1113 | { |
| 1114 | preload_size = ResourceTypeGetPreloadSize(resource_type); |
| 1115 | } |
| 1116 | |
| 1117 | void* buffer; |
| 1118 | uint32_t buffer_size; |
| 1119 | uint32_t resource_size; |
| 1120 | Result result = LoadResource(factory, canonical_path, name, preload_size, &buffer, &buffer_size, &resource_size); |
| 1121 | if (result != RESULT_OK) |
| 1122 | { |
| 1123 | return result; |
| 1124 | } |
| 1125 | |
| 1126 | assert(buffer == factory->m_Buffer.Begin()); |
| 1127 | |
| 1128 | ResourceRecreateParams params; |
| 1129 | params.m_Factory = factory; |
| 1130 | params.m_Type = resource_type; |
| 1131 | params.m_Context = resource_type->m_Context; |
| 1132 | params.m_Message = 0; |
| 1133 | params.m_Buffer = buffer; |
| 1134 | params.m_BufferSize = buffer_size; |
| 1135 | params.m_FileSize = resource_size; |
| 1136 | params.m_IsBufferPartial= buffer_size != resource_size; |
| 1137 | params.m_Resource = rd; |
| 1138 | params.m_Filename = name; |
| 1139 | rd->m_PrevResource = 0; |
| 1140 | Result create_result = (Result)resource_type->m_RecreateFunction(¶ms); |
| 1141 | if (create_result == RESULT_OK) |
| 1142 | { |
| 1143 | rd->m_Version = IncreaseVersion(factory); |
| 1144 | params.m_Resource->m_ResourceSizeOnDisc = buffer_size; |
| 1145 | if (factory->m_ResourceReloadedCallbacks) |
| 1146 | { |
| 1147 | for (uint32_t i = 0; i < factory->m_ResourceReloadedCallbacks->Size(); ++i) |
| 1148 | { |
| 1149 | ResourceReloadedCallbackPair& pair = (*factory->m_ResourceReloadedCallbacks)[i]; |
no test coverage detected