From c2c68d35470d448194aecf3cc4bedee5b1487f5a Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 9 Feb 2015 17:54:33 +0000 Subject: Tox: - enabled profile import dialog - added global lock on file sending - updated tox core git-svn-id: http://svn.miranda-ng.org/main/trunk@12071 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_account.cpp | 15 +++++++-------- protocols/Tox/src/tox_accounts.cpp | 8 ++++---- protocols/Tox/src/tox_contacts.cpp | 2 -- protocols/Tox/src/tox_options.cpp | 3 --- protocols/Tox/src/tox_transfer.cpp | 32 +++++++++++--------------------- protocols/Tox/src/tox_transfer.h | 3 +-- protocols/Tox/src/version.h | 2 +- 7 files changed, 24 insertions(+), 41 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index 7a4d4515ab..6947d4f675 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -118,13 +118,9 @@ void CToxProto::UninitToxCore() for (size_t i = 0; i < transfers->Count(); i++) { FileTransferParam *transfer = transfers->GetAt(i); - { - mir_cslock(transfer->fileLock); - - transfer->status = CANCELED; - tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0); - ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0); - } + transfer->status = CANCELED; + tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0); + ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0); transfers->Remove(transfer); } @@ -154,7 +150,10 @@ void CToxProto::DoBootstrap() void CToxProto::DoTox() { - tox_do(tox); + { + mir_cslock lock(toxLock); + tox_do(tox); + } uint32_t interval = tox_do_interval(tox); Sleep(interval); } diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index 4c3af7bc18..afcac8e4a6 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -7,9 +7,9 @@ int CToxProto::CompareAccounts(const CToxProto *p1, const CToxProto *p2) return _tcscmp(p1->m_tszUserName, p2->m_tszUserName); } -CToxProto* CToxProto::InitAccount(const char* protoName, const wchar_t* userName) +CToxProto* CToxProto::InitAccount(const char *protoName, const wchar_t *userName) { - /*ptrA address(db_get_sa(NULL, protoName, TOX_SETTINGS_ID)); + ptrA address(db_get_sa(NULL, protoName, TOX_SETTINGS_ID)); if (address == NULL) { DialogBoxParam( @@ -18,13 +18,13 @@ CToxProto* CToxProto::InitAccount(const char* protoName, const wchar_t* userName GetActiveWindow(), CToxProto::ToxProfileImportProc, (LPARAM)userName); - }*/ + } CToxProto *proto = new CToxProto(protoName, userName); return proto; } -int CToxProto::UninitAccount(CToxProto* proto) +int CToxProto::UninitAccount(CToxProto *proto) { accounts.remove(proto); delete proto; diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 5fb359100e..29bc67baf7 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -273,8 +273,6 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, const int friendNumber, cons FileTransferParam *transfer = proto->transfers->GetAt(i); if (transfer->friendNumber == friendNumber) { - mir_cslock(transfer->fileLock); - transfer->status = BROKEN; } } diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 33c19a0b50..f19abec6bd 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -30,9 +30,6 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l CheckDlgButton(hwnd, IDC_DISABLE_UDP, proto->getBool("DisableUDP", 0)); CheckDlgButton(hwnd, IDC_DISABLE_IPV6, proto->getBool("DisableIPv6", 0)); - - EnableWindow(GetDlgItem(hwnd, IDC_TOXID), proto->IsOnline()); - EnableWindow(GetDlgItem(hwnd, IDC_CLIPBOARD), proto->IsOnline()); } return TRUE; diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index a8643d16ea..1ae16c2455 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -44,7 +44,7 @@ HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const P // stupid fix TCHAR fullPath[MAX_PATH]; mir_sntprintf(fullPath, SIZEOF(fullPath), _T("%s\\%s"), transfer->pfts.tszWorkingDir, transfer->pfts.tszCurrentFile); - transfer->Rename(fullPath); + transfer->ChangeName(fullPath); if (!ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, (HANDLE)transfer, (LPARAM)&transfer->pfts)) { @@ -78,7 +78,7 @@ int __cdecl CToxProto::FileResume(HANDLE hTransfer, int *action, const PROTOCHAR switch (*action) { case FILERESUME_RENAME: - transfer->Rename(*szFilename); + transfer->ChangeName(*szFilename); result = transfer->OpenFile(_T("wb")); break; @@ -214,8 +214,6 @@ void CToxProto::SendFileAsync(void *arg) while (transfer->status == STARTED && transfer->hFile != NULL && fileProgress < fileSize) { - mir_cslockfull locker(transfer->fileLock); - if (dataSize == 0) { dataSize = min(chunkSize, fileSize - fileProgress); @@ -229,9 +227,13 @@ void CToxProto::SendFileAsync(void *arg) } } - if (tox_file_send_data(tox, transfer->friendNumber, transfer->fileNumber, data, dataSize) == TOX_ERROR) + int sendResult = TOX_ERROR; + { + mir_cslock lock(toxLock); + sendResult = tox_file_send_data(tox, transfer->friendNumber, transfer->fileNumber, data, dataSize); + } + if (sendResult == TOX_ERROR) { - locker.unlock(); Sleep(100); continue; } @@ -300,19 +302,13 @@ void CToxProto::OnFileRequest(Tox *tox, int32_t friendNumber, uint8_t receive_se break; case TOX_FILECONTROL_PAUSE: - { - mir_cslock locker(transfer->fileLock); - transfer->status = PAUSED; - } - break; + break; case TOX_FILECONTROL_RESUME_BROKEN: // receiver asked to resume transfer if (receive_send == 1) { - mir_cslock locker(transfer->fileLock); - uint64_t progress = *(uint64_t*)data; if (progress >= transfer->pfts.currentFileSize || length != sizeof(uint64_t)) { @@ -345,10 +341,7 @@ void CToxProto::OnFileRequest(Tox *tox, int32_t friendNumber, uint8_t receive_se break; case TOX_FILECONTROL_KILL: - { - mir_cslock locker(transfer->fileLock); - transfer->status = CANCELED; - } + transfer->status = CANCELED; proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0); proto->transfers->Remove(transfer); break; @@ -357,10 +350,7 @@ void CToxProto::OnFileRequest(Tox *tox, int32_t friendNumber, uint8_t receive_se { proto->debugLogA("CToxProto::SendFileAsync: finish the transfer of file (%d)", transfer->fileNumber); bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize; - { - mir_cslock locker(transfer->fileLock); - transfer->status = isFileFullyTransfered ? FINISHED : FAILED; - } + transfer->status = isFileFullyTransfered ? FINISHED : FAILED; if (!isFileFullyTransfered) { proto->debugLogA("CToxProto::SendFileAsync: file (%d) is transferred not completely", transfer->fileNumber); diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h index 080d8a2289..9658266191 100644 --- a/protocols/Tox/src/tox_transfer.h +++ b/protocols/Tox/src/tox_transfer.h @@ -18,7 +18,6 @@ struct FileTransferParam PROTOFILETRANSFERSTATUS pfts; FILE_TRANSFER_STATUS status; FILE *hFile; - mir_cs fileLock; int friendNumber; int fileNumber; @@ -47,7 +46,7 @@ struct FileTransferParam return hFile != NULL; } - void Rename(const TCHAR* fileName) + void ChangeName(const TCHAR *fileName) { pfts.ptszFiles[0] = replaceStrT(pfts.tszCurrentFile, fileName); } diff --git a/protocols/Tox/src/version.h b/protocols/Tox/src/version.h index 3edccd9363..e00e04fb2e 100644 --- a/protocols/Tox/src/version.h +++ b/protocols/Tox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 0 -#define __BUILD_NUM 5 +#define __BUILD_NUM 6 #include -- cgit v1.2.3