Esempio n. 1
0
INT_PTR CToxProto::SetMyAvatar(WPARAM wParam, LPARAM lParam)
{
	TCHAR *path = (TCHAR*)lParam;
	std::tstring avatarPath = GetAvatarFilePath();
	if (path != NULL)
	{
		if (!CopyFile(path, avatarPath.c_str(), FALSE))
		{
			debugLogA("CToxProto::SetMyAvatar: failed to copy new avatar to avatar cache");
			return -1;
		}

		SetToxAvatar(avatarPath, true);
	}
	else
	{
		if (tox_unset_avatar(tox) == TOX_ERROR)
		{
			debugLogA("CToxProto::SetMyAvatar: failed to unset avatar");
			return -1;
		}

		if (IsFileExists(avatarPath))
		{
			DeleteFile(avatarPath.c_str());
		}

		db_unset(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH);
	}

	return 0;
}
Esempio n. 2
0
INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
{
	debugLogA("CToxProto::SetMyAvatar: setting avatar");
	TCHAR *path = (TCHAR*)lParam;
	std::tstring avatarPath = GetAvatarFilePath();
	if (path != NULL)
	{
		debugLogA("CToxProto::SetMyAvatar: copy new avatar");
		if (!CopyFile(path, avatarPath.c_str(), FALSE))
		{
			debugLogA("CToxProto::SetMyAvatar: failed to copy new avatar to avatar cache");
			return 0;
		}

		SetToxAvatar(avatarPath);

		return 0;
	}

	if (IsOnline())
	{
		for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
		{
			if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
				continue;

			int32_t friendNumber = GetToxFriendNumber(hContact);
			if (friendNumber == UINT32_MAX)
				continue;

			TOX_ERR_FILE_SEND error;
			tox_file_send(tox, friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error);
			if (error != TOX_ERR_FILE_SEND_OK)
			{
				debugLogA(__FUNCTION__": failed to unset avatar (%d)", error);
				return 0;
			}
		}
	}

	if (IsFileExists(avatarPath))
		DeleteFile(avatarPath.c_str());

	delSetting(TOX_SETTINGS_AVATAR_HASH);

	return 0;
}