summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_transfer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Tox/src/tox_transfer.cpp')
-rw-r--r--protocols/Tox/src/tox_transfer.cpp301
1 files changed, 133 insertions, 168 deletions
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index 7b5a011786..c2cbad33cd 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -3,40 +3,56 @@
/* FILE RECEIVING */
// incoming file flow
-void CToxProto::OnFriendFile(Tox *, int32_t friendNumber, uint8_t fileNumber, uint64_t fileSize, const uint8_t *fileName, uint16_t, void *arg)
+void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, uint32_t kind, uint64_t fileSize, const uint8_t *fileName, size_t filenameLength, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact)
{
- TCHAR *name = mir_utf8decodeT((char*)fileName);
- if (name == NULL)
+ switch (kind)
{
- // uTox send file name in ansi
- name = mir_a2u((char*)fileName);
+ case TOX_FILE_KIND_AVATAR:
+ case TOX_FILE_KIND_DATA:
+ {
+ ptrA rawName((char*)mir_alloc(filenameLength + 1));
+ memcpy(rawName, fileName, filenameLength);
+ rawName[filenameLength] = 0;
+ TCHAR *name = mir_utf8decodeT(rawName);
+
+ FileTransferParam *transfer = new FileTransferParam(friendNumber, fileNumber, name, fileSize);
+ transfer->pfts.hContact = hContact;
+ transfer->pfts.flags |= PFTS_RECEIVING;
+ proto->transfers.Add(transfer);
+
+ if (kind == TOX_FILE_KIND_AVATAR)
+ {
+ proto->OnGotFriendAvatarInfo(transfer, fileName);
+ return;
+ }
+
+ PROTORECVFILET pre = { 0 };
+ pre.flags = PREF_TCHAR;
+ pre.fileCount = 1;
+ pre.timestamp = time(NULL);
+ pre.tszDescription = _T("");
+ pre.ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*) * 2);
+ pre.ptszFiles[0] = name;
+ pre.ptszFiles[1] = NULL;
+ pre.lParam = (LPARAM)transfer;
+ ProtoChainRecvFile(hContact, &pre);
}
+ break;
- FileTransferParam *transfer = new FileTransferParam(friendNumber, fileNumber, name, fileSize);
- transfer->pfts.hContact = hContact;
- transfer->pfts.flags |= PFTS_RECEIVING;
- proto->transfers.Add(transfer);
-
- PROTORECVFILET pre = { 0 };
- pre.flags = PREF_TCHAR;
- pre.fileCount = 1;
- pre.timestamp = time(NULL);
- pre.tszDescription = _T("");
- pre.ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*)*2);
- pre.ptszFiles[0] = name;
- pre.ptszFiles[1] = NULL;
- pre.lParam = (LPARAM)transfer;
- ProtoChainRecvFile(hContact, &pre);
+ default:
+ proto->debugLogA(__FUNCTION__": unknown file kind (%d)", kind);
+ return;
+ }
}
}
// file request is allowed
-HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR *tszPath)
+HANDLE CToxProto::OnFileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR *tszPath)
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
transfer->pfts.tszWorkingDir = mir_tstrdup(tszPath);
@@ -52,17 +68,18 @@ HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const P
{
debugLogA("CToxProto::FileAllow: failed to open file (%d)", transfer->fileNumber);
transfer->status = FAILED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
return NULL;
}
debugLogA("CToxProto::FileAllow: start receiving file (%d)", transfer->fileNumber);
transfer->status = STARTED;
- if (tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_ACCEPT, NULL, 0) == TOX_ERROR)
+ TOX_ERR_FILE_CONTROL error;
+ if (!tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
{
- debugLogA("CToxProto::FileAllow: failed to start the transfer of file (%d)", transfer->fileNumber);
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ debugLogA("CToxProto::FileAllow: failed to start the transfer (%d)", error);
+ tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
}
}
@@ -70,7 +87,7 @@ HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const P
}
// if file is exists
-int __cdecl CToxProto::FileResume(HANDLE hTransfer, int *action, const PROTOCHAR **szFilename)
+int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const PROTOCHAR **szFilename)
{
bool result = false;
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
@@ -92,20 +109,21 @@ int __cdecl CToxProto::FileResume(HANDLE hTransfer, int *action, const PROTOCHAR
break;
}
+ TOX_ERR_FILE_CONTROL error;
if (result)
{
debugLogA("CToxProto::FileResume: start receiving file (%d)", transfer->fileNumber);
transfer->status = STARTED;
- if (tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_ACCEPT, NULL, 0) == TOX_ERROR)
+ if (!tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
{
- debugLogA("CToxProto::FileResume: failed to start the transfer of file (%d)", transfer->fileNumber);
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ debugLogA("CToxProto::FileResume: failed to start the transfer (%d)", error);
+ tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, &error);
}
}
else
{
transfer->status = CANCELED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, &error);
transfers.Remove(transfer);
}
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, result ? ACKRESULT_CONNECTED : ACKRESULT_DENIED, (HANDLE)transfer, 0);
@@ -114,50 +132,60 @@ int __cdecl CToxProto::FileResume(HANDLE hTransfer, int *action, const PROTOCHAR
}
// getting the file data
-void CToxProto::OnFileData(Tox *tox, int32_t friendNumber, uint8_t fileNumber, const uint8_t *data, uint16_t size, void *arg)
+void CToxProto::OnFileReceiveData(Tox*, uint32_t friendNumber, uint32_t fileNumber, uint64_t position, const uint8_t *data, size_t length, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
- MCONTACT hContact = proto->GetContact(friendNumber);
- if (hContact == NULL)
+ FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
+ if (transfer == NULL)
{
- proto->debugLogA("CToxProto::OnFileData: cannot find contact by number (%d)", friendNumber);
- tox_file_send_control(tox, friendNumber, 1, fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
}
- FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
- if (transfer == NULL)
+ if (length == 0 || (length == 0 && position == UINT64_MAX))
{
- proto->debugLogA("CToxProto::OnFileData: cannot find transfer by number (%d)", fileNumber);
- transfer->status = FAILED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ //receiving is finished
+ proto->debugLogA(__FUNCTION__": finised the transfer of file (%d)", fileNumber);
+ bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
+ transfer->status = isFileFullyTransfered ? FINISHED : FAILED;
+ if (!isFileFullyTransfered)
+ {
+ proto->debugLogA(__FUNCTION__": file (%d) is transferred not completely", fileNumber);
+ }
+ proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, isFileFullyTransfered ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)transfer, 0);
+ proto->transfers.Remove(transfer);
+ }
+
+ MCONTACT hContact = proto->GetContact(friendNumber);
+ if (hContact == NULL)
+ {
+ proto->debugLogA("CToxProto::OnFileData: cannot find contact by number (%d)", friendNumber);
+ tox_file_control(proto->tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
}
- if (fwrite(data, sizeof(uint8_t), size, transfer->hFile) != size)
+ if (fwrite(data, sizeof(uint8_t), length, transfer->hFile) != length)
{
- proto->debugLogA("CToxProto::OnFileData: cannot write to file (%d)", fileNumber);
+ proto->debugLogA(__FUNCTION__": failed write to file (%d)", fileNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
transfer->status = FAILED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ tox_file_control(proto->tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
}
- transfer->pfts.totalProgress = transfer->pfts.currentFileProgress += size;
+ transfer->pfts.totalProgress = transfer->pfts.currentFileProgress += length;
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)transfer, (LPARAM)&transfer->pfts);
}
/* FILE SENDING */
// outcoming file flow
-HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHAR **ppszFiles)
+HANDLE CToxProto::OnSendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHAR **ppszFiles)
{
int32_t friendNumber = GetToxFriendNumber(hContact);
- if (friendNumber == TOX_ERROR)
- {
+ if (friendNumber == UINT32_MAX)
return NULL;
- }
TCHAR *fileName = _tcsrchr(ppszFiles[0], '\\') + 1;
@@ -169,7 +197,7 @@ HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHA
FILE *hFile = _tfopen(ppszFiles[0], _T("rb"));
if (hFile == NULL)
{
- debugLogA("CToxProto::SendFilesAsync: cannot open file");
+ debugLogA(__FUNCTION__": cannot open file");
return NULL;
}
@@ -178,10 +206,11 @@ HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHA
rewind(hFile);
char *name = mir_utf8encodeW(fileName);
- int fileNumber = tox_new_file_sender(tox, friendNumber, fileSize, (uint8_t*)name, (uint16_t)mir_strlen(name));
- if (fileNumber == TOX_ERROR)
+ TOX_ERR_FILE_SEND sendError;
+ uint32_t fileNumber = tox_file_send(tox, friendNumber, TOX_FILE_KIND_DATA, fileSize, NULL, (uint8_t*)name, mir_strlen(name), &sendError);
+ if (sendError != TOX_ERR_FILE_SEND_OK)
{
- debugLogA("CToxProto::SendFilesAsync: cannot send file");
+ debugLogA(__FUNCTION__": failed to send file (%d)", sendError);
return NULL;
}
@@ -195,85 +224,76 @@ HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHA
return (HANDLE)transfer;
}
-// start sending
-void CToxProto::SendFileAsync(void *arg)
+void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, uint64_t position, size_t length, void *arg)
{
- FileTransferParam *transfer = (FileTransferParam*)arg;
- transfer->status = STARTED;
+ CToxProto *proto = (CToxProto*)arg;
- size_t dataSize = 0;
- uint64_t fileProgress = transfer->pfts.currentFileProgress;
- uint64_t fileSize = transfer->pfts.currentFileSize;
- int chunkSize = min(tox_file_data_size(tox, transfer->friendNumber), fileSize);
- uint8_t *data = (uint8_t*)mir_alloc(chunkSize);
+ FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
+ if (transfer == NULL)
+ {
+ tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ return;
+ }
- while (transfer->status == STARTED && transfer->hFile != NULL && fileProgress < fileSize)
+ if (length == 0)
{
- if (dataSize == 0)
+ // file sending is finished
+ proto->debugLogA(__FUNCTION__": finised the transfer of file (%d)", fileNumber);
+ bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
+ transfer->status = isFileFullyTransfered ? FINISHED : FAILED;
+ if (!isFileFullyTransfered)
{
- dataSize = min(chunkSize, fileSize - fileProgress);
- size_t read = fread(data, sizeof(uint8_t), dataSize, transfer->hFile);
- if (read != dataSize)
- {
- debugLogA("CToxProto::SendFileAsync: failed to read from file (%d)", transfer->fileNumber);
- debugLogA("CToxProto::SendFileAsync: read %d of %d (%d)", read, dataSize, transfer->fileNumber);
- debugLogA("CToxProto::SendFileAsync: sent %llu of %llu of file (%d)", transfer->pfts.currentFileProgress, transfer->pfts.currentFileSize, transfer->fileNumber);
- ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
- transfer->status = FAILED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
- return;
- }
+ proto->debugLogA(__FUNCTION__": file (%d) is transferred not completely", fileNumber);
}
+ proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, isFileFullyTransfered ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)transfer, 0);
+ proto->transfers.Remove(transfer);
+ return;
+ }
- int sendResult = TOX_ERROR;
- {
- mir_cslock lock(toxLock);
- sendResult = tox_file_send_data(tox, transfer->friendNumber, transfer->fileNumber, data, (uint16_t)dataSize);
- }
- if (sendResult == TOX_ERROR)
- {
- Sleep(100);
- continue;
- }
+ uint64_t sentBytes = _ftelli64(transfer->hFile);
+ if (sentBytes != position)
+ _fseeki64(transfer->hFile, position, SEEK_SET);
- transfer->pfts.totalProgress = transfer->pfts.currentFileProgress = fileProgress += dataSize;
- ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)transfer, (LPARAM)&transfer->pfts);
- dataSize = 0;
+ uint8_t *data = (uint8_t*)mir_alloc(length);
+ if (fread(data, sizeof(uint8_t), length, transfer->hFile) != length)
+ {
+ proto->debugLogA(__FUNCTION__": failed to read from file (%d)", transfer->fileNumber);
+ proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
+ transfer->status = FAILED;
+ tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ return;
}
- mir_free(data);
-
- if (transfer->status == STARTED && fileProgress == fileSize)
+ TOX_ERR_FILE_SEND_CHUNK error;
+ if (!tox_file_send_chunk(proto->tox, friendNumber, fileNumber, position, data, length, &error))
{
- transfer->status = FINISHED;
- if (tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_FINISHED, NULL, 0) == TOX_ERROR)
- {
- debugLogA("CToxProto::SendFileAsync: failed to finish the transfer of file (%d)", transfer->fileNumber);
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
- }
+ proto->debugLogA(__FUNCTION__": failed to send file chunk (%d)", error);
+ proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
+ transfer->status = FAILED;
+ tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ mir_free(data);
+ return;
}
+
+ transfer->pfts.totalProgress = transfer->pfts.currentFileProgress = length;
+
+ mir_free(data);
}
/* COMMON */
// file request is cancelled
-int __cdecl CToxProto::FileCancel(MCONTACT, HANDLE hTransfer)
+int CToxProto::OnFileCancel(MCONTACT, HANDLE hTransfer)
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
transfer->status = CANCELED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
return 0;
}
-// file request is denied
-int __cdecl CToxProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR*)
-{
- return FileCancel(hContact, hTransfer);
-}
-
-void CToxProto::OnFileRequest(Tox *tox, int32_t friendNumber, uint8_t receive_send, uint8_t fileNumber, uint8_t type, const uint8_t *data, uint16_t length, void *arg)
+void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber, TOX_FILE_CONTROL control, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
@@ -283,81 +303,26 @@ void CToxProto::OnFileRequest(Tox *tox, int32_t friendNumber, uint8_t receive_se
FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- tox_file_send_control(tox, friendNumber, receive_send, fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
}
- switch (type)
+ switch (control)
{
- case TOX_FILECONTROL_ACCEPT:
- // receiver allowed the transfer
- if (receive_send == 1)
- {
- proto->debugLogA("CToxProto::OnFileRequest: start the transfer of file (%d)", transfer->fileNumber);
- // start file sending
- proto->ForkThread(&CToxProto::SendFileAsync, transfer);
- }
- break;
-
- case TOX_FILECONTROL_PAUSE:
+ case TOX_FILE_CONTROL_PAUSE:
transfer->status = PAUSED;
break;
- case TOX_FILECONTROL_RESUME_BROKEN:
- // receiver asked to resume transfer
- if (receive_send == 1)
- {
- uint64_t progress = *(uint64_t*)data;
- if (progress >= transfer->pfts.currentFileSize || length != sizeof(uint64_t))
- {
- transfer->status = FAILED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
- }
- if (tox_file_send_control(tox, friendNumber, transfer->GetDirection(), fileNumber, TOX_FILECONTROL_ACCEPT, NULL, 0) == TOX_ERROR)
- {
- proto->debugLogA("CToxProto::OnFileRequest: failed to resume the transfer of file (%d)", transfer->fileNumber);
- proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
- transfer->status = FAILED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
- break;
- }
- if (transfer->pfts.currentFileProgress != progress)
- {
- transfer->pfts.totalProgress = transfer->pfts.currentFileProgress = progress;
- if (_fseeki64(transfer->hFile, progress, SEEK_SET))
- {
- proto->debugLogA("CToxProto::OnFileRequest: failed to change file position from %llu to %llu of file (%d)",
- transfer->pfts.currentFileProgress, progress, transfer->fileNumber);
- transfer->status = FAILED;
- tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
- }
- }
- proto->debugLogA("CToxProto::SendFileAsync: resume the transfer of file (%d)", transfer->fileNumber);
- // resume file sending
- proto->ForkThread(&CToxProto::SendFileAsync, transfer);
- }
+ case TOX_FILE_CONTROL_RESUME:
+ transfer->status = STARTED;
+ proto->debugLogA("CToxProto::OnFileRequest: start/resume the transfer of file (%d)", transfer->fileNumber);
break;
- case TOX_FILECONTROL_KILL:
+ case TOX_FILE_CONTROL_CANCEL:
transfer->status = CANCELED;
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0);
proto->transfers.Remove(transfer);
break;
-
- case TOX_FILECONTROL_FINISHED:
- {
- proto->debugLogA("CToxProto::SendFileAsync: finish the transfer of file (%d)", transfer->fileNumber);
- bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
- transfer->status = isFileFullyTransfered ? FINISHED : FAILED;
- if (!isFileFullyTransfered)
- {
- proto->debugLogA("CToxProto::SendFileAsync: file (%d) is transferred not completely", transfer->fileNumber);
- }
- tox_file_send_control(tox, friendNumber, transfer->GetDirection(), fileNumber, isFileFullyTransfered ? TOX_FILECONTROL_FINISHED : TOX_FILECONTROL_KILL, NULL, 0);
- proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, isFileFullyTransfered ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)transfer, 0);
- proto->transfers.Remove(transfer);
- }
- break;
}
}
} \ No newline at end of file