void CToxProto::OnGotFriendAvatarData(Tox *tox, int32_t number, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t length, void *arg) { CToxProto *proto = (CToxProto*)arg; MCONTACT hContact = proto->FindContact(number); if (hContact) { db_set_blob(hContact, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, hash, TOX_HASH_LENGTH); std::tstring path = proto->GetAvatarFilePath(hContact); FILE *hFile = _tfopen(path.c_str(), L"wb"); if (hFile) { if (fwrite(data, sizeof(uint8_t), length, hFile) == length) { PROTO_AVATAR_INFORMATIONW pai = { sizeof(pai) }; pai.format = PA_FORMAT_PNG; pai.hContact = hContact; _tcscpy(pai.filename, path.c_str()); proto->ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0); } fclose(hFile); } } }
void CToxProto::OnGotFriendAvatarInfo(Tox *tox, int32_t number, uint8_t format, uint8_t *hash, void *arg) { CToxProto *proto = (CToxProto*)arg; MCONTACT hContact = proto->FindContact(number); if (hContact) { std::tstring path = proto->GetAvatarFilePath(hContact); if (format == TOX_AVATAR_FORMAT_NONE) { proto->delSetting(hContact, TOX_SETTINGS_AVATAR_HASH); proto->ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, 0, 0); if (IsFileExists(path)) { DeleteFile(path.c_str()); } } else { DBVARIANT dbv; if (!db_get(hContact, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv)) { if (memcmp(hash, dbv.pbVal, TOX_HASH_LENGTH) != 0) { tox_request_avatar_data(proto->tox, number); } db_free(&dbv); } else { tox_request_avatar_data(proto->tox, number); } } } }