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
70
71
72
73
74
75
76
|
#include "stdafx.h"
LIST<FileTransferParam> Transfers(1, HandleKeySortT);
INT_PTR CCloudService::SendFileInterceptor(WPARAM, LPARAM lParam)
{
CCSDATA *pccsd = (CCSDATA*)lParam;
for (auto &service : Services) {
auto it = service->InterceptedContacts.find(pccsd->hContact);
if (it == service->InterceptedContacts.end())
continue;
service->InterceptedContacts.erase(it);
return (INT_PTR)service->SendFile(pccsd->hContact, (wchar_t*)pccsd->wParam, (wchar_t**)pccsd->lParam);
}
return CALLSERVICE_NOTFOUND;
}
int CCloudService::FileCancel(MCONTACT, HANDLE hTransfer)
{
FileTransferParam *ftp = Transfers.find((FileTransferParam*)&hTransfer);
if (ftp)
ftp->Terminate();
return 0;
}
HANDLE CCloudService::SendFile(MCONTACT hContact, const wchar_t *description, wchar_t **paths)
{
FileTransferParam *ftp = new FileTransferParam(hContact);
ftp->SetDescription(description);
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, this, ftp);
return (HANDLE)ftp->GetId();
}
void CCloudService::OpenUploadDialog(MCONTACT hContact)
{
char *proto = GetContactProto(hContact);
if (!mir_strcmpi(proto, META_PROTO))
hContact = CallService(MS_MC_GETMOSTONLINECONTACT, hContact);
auto it = InterceptedContacts.find(hContact);
if (it == InterceptedContacts.end())
{
HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, hContact, 0);
InterceptedContacts[hContact] = hwnd;
}
else
SetActiveWindow(it->second);
}
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->GetContact(), ftp->GetData());
Transfers.remove(ftp);
delete ftp;
return res;
}
|