summaryrefslogtreecommitdiff
path: root/plugins/CloudFile/src/transfers.cpp
blob: 0f79f970d9f2168504eab7d56fd69c84743d5844 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "stdafx.h"

LIST<FileTransferParam> Transfers(1, HandleKeySortT);

INT_PTR ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
{
	CCSDATA *pccsd = (CCSDATA*)lParam;
	CCloudService *service = (CCloudService*)obj;

	FileTransferParam *ftp = new FileTransferParam(pccsd->hContact);

	const wchar_t *description = (wchar_t*)pccsd->wParam;
	if (description && description[0])
		ftp->AppendFormatData(L"%s\r\n", (wchar_t*)pccsd->wParam);

	wchar_t **paths = (wchar_t**)pccsd->lParam;
	ftp->SetWorkingDirectory(paths[0]);
	for (int i = 0; paths[i]; i++) {
		if (PathIsDirectory(paths[i]))
			continue;
		ftp->AddFile(paths[i]);
	}

	Transfers.insert(ftp);

	mir_forkthreadowner(UploadAndReportProgressThread, service, ftp);

	return ftp->GetId();
}

INT_PTR ProtoSendFileInterceptor(void *obj, WPARAM wParam, LPARAM lParam)
{
	CCSDATA *pccsd = (CCSDATA*)lParam;
	CCloudService *service = (CCloudService*)obj;

	auto it = service->InterceptedContacts.find(pccsd->hContact);
	if (it == service->InterceptedContacts.end())
		return CALLSERVICE_NOTFOUND;
	service->InterceptedContacts.erase(it);

	return ProtoSendFile(obj, wParam, lParam);
}

INT_PTR ProtoCancelFile(WPARAM, LPARAM lParam)
{
	CCSDATA *pccsd = (CCSDATA*)lParam;

	HANDLE hTransfer = (HANDLE)pccsd->wParam;
	FileTransferParam *ftp = Transfers.find((FileTransferParam*)&hTransfer);
	if (ftp)
		ftp->Terminate();

	return 0;
}

UINT UploadAndReportProgressThread(void *owner, void *arg)
{
	CCloudService *service = (CCloudService*)owner;
	FileTransferParam *ftp = (FileTransferParam*)arg;

	int res = service->Upload(ftp);
	if (res == ACKRESULT_SUCCESS)
		service->Report(ftp->GetHContact(), ftp->GetData());

	Transfers.remove(ftp);
	delete ftp;

	return res;
}