| 187 | } |
| 188 | |
| 189 | bool CSkins7::LoadSkin(const char *pName, int DirType) |
| 190 | { |
| 191 | char aFilename[IO_MAX_PATH_LENGTH]; |
| 192 | str_format(aFilename, sizeof(aFilename), SKINS_DIR "/%s", pName); |
| 193 | void *pFileData; |
| 194 | unsigned JsonFileSize; |
| 195 | if(!Storage()->ReadFile(aFilename, DirType, &pFileData, &JsonFileSize)) |
| 196 | { |
| 197 | log_error("skins7", "Failed to read skin json file '%s'", aFilename); |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | CSkin Skin; |
| 202 | str_copy(Skin.m_aName, pName, 1 + str_length(pName) - str_length(".json")); |
| 203 | const bool SpecialSkin = IsSpecialSkin(Skin.m_aName); |
| 204 | Skin.m_Flags = 0; |
| 205 | if(SpecialSkin) |
| 206 | { |
| 207 | Skin.m_Flags |= SKINFLAG_SPECIAL; |
| 208 | } |
| 209 | if(DirType != IStorage::TYPE_SAVE) |
| 210 | { |
| 211 | Skin.m_Flags |= SKINFLAG_STANDARD; |
| 212 | } |
| 213 | |
| 214 | json_settings JsonSettings{}; |
| 215 | char aError[256]; |
| 216 | json_value *pJsonData = json_parse_ex(&JsonSettings, static_cast<const json_char *>(pFileData), JsonFileSize, aError); |
| 217 | free(pFileData); |
| 218 | if(pJsonData == nullptr) |
| 219 | { |
| 220 | log_error("skins7", "Failed to parse skin json file '%s': %s", aFilename, aError); |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | const json_value &Start = (*pJsonData)["skin"]; |
| 225 | if(Start.type != json_object) |
| 226 | { |
| 227 | log_error("skins7", "Failed to parse skin json file '%s': root must be an object", aFilename); |
| 228 | json_value_free(pJsonData); |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | for(int PartIndex = 0; PartIndex < protocol7::NUM_SKINPARTS; ++PartIndex) |
| 233 | { |
| 234 | Skin.m_aUseCustomColors[PartIndex] = 0; |
| 235 | Skin.m_aPartColors[PartIndex] = (PartIndex == protocol7::SKINPART_MARKING ? 0xFF000000u : 0u) + 0x00FF80u; |
| 236 | |
| 237 | const json_value &Part = Start[(const char *)ms_apSkinPartNames[PartIndex]]; |
| 238 | if(Part.type == json_none) |
| 239 | { |
| 240 | Skin.m_apParts[PartIndex] = FindDefaultSkinPart(PartIndex); |
| 241 | continue; |
| 242 | } |
| 243 | if(Part.type != json_object) |
| 244 | { |
| 245 | log_error("skins7", "Failed to parse skin json file '%s': attribute '%s' must specify an object", aFilename, ms_apSkinPartNames[PartIndex]); |
| 246 | json_value_free(pJsonData); |
no test coverage detected