summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_transfers.cpp
blob: 51bab8aac33d4221a73755ba5d62bd5bf2ae87c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "common.h"

void CToxProto::SendFileAsync(void* arg)
{
	CFile *file = (CFile*)arg;
	const CFileTransfer *transfer = file->GetTransfer();
	CToxProto *proto = (CToxProto*)transfer->GetProtoInstance();
}

void CToxProto::SendFilesAsync(void* arg)
{
	CFileTransfer *transfer = (CFileTransfer*)arg;

	std::string toxId(getStringA(transfer->GetContactHandle(), TOX_SETTINGS_ID));
	std::vector<uint8_t> clientId = HexStringToData(toxId);

	uint32_t number = tox_get_friend_number(tox, clientId.data());

	for (int i = 0; transfer->GetFileCount(); i++)
	{
		CFile *file = transfer->GetFileAt(i);

		int hFile = tox_new_file_sender(tox, number, file->GetSize(), (uint8_t*)file->GetName(), strlen(file->GetName()));
		if (hFile < 0)
		{
			debugLogA("CToxProto::SendFilesAsync: cannot send file");
		}
		file->SetNumber(hFile);

		transfer->Wait();
	}
}

CFileTransfer *CToxProto::GetFileTransferByFileNumber(int fileNumber)
{
	for (int i = 0; fileTransfers.getCount(); i++)
	{
		if (fileTransfers[i]->HasFile(fileNumber))
		{
			return fileTransfers[i];
		}
	}
	return NULL;
}