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/bin/x64/libtox.dll | Bin 3959539 -> 3961142 bytes protocols/Tox/bin/x86/libtox.dll | Bin 3301804 -> 3301873 bytes protocols/Tox/res/resource.rc | 8 ++++---- 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 +- 10 files changed, 28 insertions(+), 45 deletions(-) (limited to 'protocols') diff --git a/protocols/Tox/bin/x64/libtox.dll b/protocols/Tox/bin/x64/libtox.dll index c3464e820c..df8c69fb0a 100644 Binary files a/protocols/Tox/bin/x64/libtox.dll and b/protocols/Tox/bin/x64/libtox.dll differ diff --git a/protocols/Tox/bin/x86/libtox.dll b/protocols/Tox/bin/x86/libtox.dll index 1c7b9e98a6..85cb42935a 100644 Binary files a/protocols/Tox/bin/x86/libtox.dll and b/protocols/Tox/bin/x86/libtox.dll differ diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc index 3b12e9d37d..0ad27956f3 100644 --- a/protocols/Tox/res/resource.rc +++ b/protocols/Tox/res/resource.rc @@ -87,10 +87,10 @@ BEGIN LTEXT "Name:",IDC_STATIC,12,24,54,12 EDITTEXT IDC_NAME,66,23,120,12,ES_AUTOHSCROLL LTEXT "Password:",IDC_STATIC,12,40,54,12,NOT WS_VISIBLE - EDITTEXT IDC_TOXID,66,7,100,12,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED + EDITTEXT IDC_TOXID,66,7,100,12,ES_AUTOHSCROLL | ES_READONLY LTEXT "Default group:",IDC_STATIC,12,56,54,12 EDITTEXT IDC_GROUP,66,54,120,12,ES_AUTOHSCROLL - PUSHBUTTON "C",IDC_CLIPBOARD,170,7,16,13,WS_DISABLED + PUSHBUTTON "C",IDC_CLIPBOARD,170,7,16,13 LTEXT "Tox ID:",IDC_STATIC,12,9,54,8 EDITTEXT IDC_PASSWORD,66,38,120,12,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE END @@ -103,7 +103,7 @@ BEGIN LTEXT "Name:",IDC_STATIC,12,35,69,11 EDITTEXT IDC_NAME,81,33,219,12,ES_AUTOHSCROLL LTEXT "Tox ID:",IDC_STATIC,12,19,69,11 - EDITTEXT IDC_TOXID,81,17,199,12,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED + EDITTEXT IDC_TOXID,81,17,199,12,ES_AUTOHSCROLL | ES_READONLY GROUPBOX "Connection settings",IDC_STATIC,7,89,298,45 CONTROL "Disable UDP (force Tox to use TCP)",IDC_DISABLE_UDP, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,101,288,10 @@ -111,7 +111,7 @@ BEGIN GROUPBOX "Tox",IDC_STATIC,7,7,298,77 LTEXT "Default group:",IDC_STATIC,12,68,69,12 EDITTEXT IDC_GROUP,81,65,219,12,ES_AUTOHSCROLL - PUSHBUTTON "C",IDC_CLIPBOARD,284,17,16,13,WS_DISABLED + PUSHBUTTON "C",IDC_CLIPBOARD,284,17,16,13 LTEXT "Password:",IDC_STATIC,12,51,69,8,NOT WS_VISIBLE EDITTEXT IDC_PASSWORD,81,49,219,12,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE END 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