From 75d27e475943eafbcb52e9a795554358c9348fbd Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 30 Oct 2015 17:58:45 +0000 Subject: Tox: fixed profile creation and import git-svn-id: http://svn.miranda-ng.org/main/trunk@15654 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/docs/tox.ini | 37 ------------------------------------- protocols/Tox/src/tox_core.cpp | 13 ++++++------- protocols/Tox/src/tox_network.cpp | 6 +++--- protocols/Tox/src/tox_options.cpp | 18 ++---------------- protocols/Tox/src/tox_profile.cpp | 6 ++++++ protocols/Tox/src/tox_proto.h | 4 ++-- 6 files changed, 19 insertions(+), 65 deletions(-) (limited to 'protocols') diff --git a/protocols/Tox/docs/tox.ini b/protocols/Tox/docs/tox.ini index 66764036a6..12c57eccf0 100644 --- a/protocols/Tox/docs/tox.ini +++ b/protocols/Tox/docs/tox.ini @@ -18,12 +18,6 @@ IPv6=2604:180:1::3ded:b280 PubKey=A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074 Port=33445 -[Node_astonex] -IPv4=178.62.125.224 -IPv6=2a03:b0c0:1:d0::178:6001 -PubKey=10B20C49ACBD968D7C80F2E8438F92EA51F189F4E70CFBBB2C2C8C799E97F03E -Port=33445 - [Node_SylvieLorxu] IPv4=178.21.112.187 IPv6=2a02:2308::216:3eff:fe82:eaef @@ -41,11 +35,6 @@ IPv4=192.210.149.121 PubKey=F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67 Port=33445 -[Node_bunslow] -IPv4=76.191.23.96 -PubKey=93574A3FAB7D612FEA29FD8D67D3DD10DFD07A075A5D62E8AF3DD9F5D0932E11 -Port=33445 - [Node_MartinSchroder] IPv4=46.38.239.179 PubKey=F5A1A38EFB6BD3C2C8AF8B10D85F0F89E931704D349F1D0720C3C4059AF2440A @@ -57,11 +46,6 @@ IPv6=2a03:b0c0:2:d0::16:1 PubKey=788236D34978D1D5BD822F0A5BEBD2C53C64CC31CD3149350EE27D4D9A2F9B6B Port=33445 -[Node_ThierryThomas] -IPv4=78.225.128.39 -PubKey=7A2306BFBA665E5480AE59B31E116BE9C04DCEFE04D9FE25082316FA34B4DA0C -Port=33445 - [Node_Manolis] IPv4=130.133.110.14 IPv6=2001:6f8:1c3c:babe::14:1 @@ -73,16 +57,6 @@ IPv4=104.167.101.29 PubKey=5918AC3C06955962A75AD7DF4F80A5D7C34F7DB9E1498D2E0495DE35B3FE8A57 Port=33445 -[Node_aceawan] -IPv4=195.154.109.148 -PubKey=391C96CB67AE893D4782B8E4495EB9D89CF1031F48460C06075AA8CE76D50A21 -Port=33445 - -[Node_pastly] -IPv4=192.3.173.88 -PubKey=3E1FFDEB667BFF549F619EC6737834762124F50A89C8D0DBF1DDF64A2DD6CD1B -Port=33445 - [Node_Busindre] IPv4=205.185.116.116 PubKey=A179B09749AC826FF01F37A9613F6B57118AE014D4196A0E1105A98F93A54702 @@ -116,17 +90,6 @@ IPv6=2001:1470:fbfe::109 PubKey=3CEE1F054081E7A011234883BC4FC39F661A55B73637A5AC293DDF1251D9432B Port=33445 -[Node_fluke571] -IPv4=194.249.212.109 -IPv6=2001:1470:fbfe::109 -PubKey=3CEE1F054081E7A011234883BC4FC39F661A55B73637A5AC293DDF1251D9432B -Port=443 - -[Node_zeno.io] -IPv4=103.38.216.87 -PubKey=601AEE6FC8C17E8CD8F8F1FFC4D4AD84E59A73BE451F037194E7A404E3795320 -Port=33445 - [Node_MAH69K] IPv4=185.25.116.107 IPv6=2a00:7a60:0:746b::3 diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index 335743303b..a500d84be9 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -41,21 +41,19 @@ Tox_Options* CToxProto::GetToxOptions() return options; } -bool CToxProto::InitToxCore() +bool CToxProto::InitToxCore(CToxThread *toxThread) { logger->Log(__FUNCTION__": initializing tox core"); + if (toxThread == NULL) + return false; + Tox_Options *options = GetToxOptions(); if (options == NULL) return false; if (LoadToxProfile(options)) { - if (toxThread == NULL) { - tox_options_free(options); - return false; - } - TOX_ERR_NEW initError; toxThread->tox = tox_new(options, &initError); if (initError != TOX_ERR_NEW_OK) @@ -117,7 +115,7 @@ bool CToxProto::InitToxCore() return false; } -void CToxProto::UninitToxCore() +void CToxProto::UninitToxCore(CToxThread *toxThread) { if (toxThread) { if (toxThread->toxAv) @@ -130,6 +128,7 @@ void CToxProto::UninitToxCore() SaveToxProfile(); tox_kill(toxThread->tox); + toxThread->tox = NULL; } toxThread = NULL; } diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 3e1b440595..51b0b13397 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -151,9 +151,9 @@ void CToxProto::PollingThread(void*) logger->Log(__FUNCTION__": entering"); - if (!InitToxCore()) + if (!InitToxCore(&toxThread)) { - UninitToxCore(); + UninitToxCore(&toxThread); SetStatus(ID_STATUS_OFFLINE); ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD); logger->Log(__FUNCTION__": leaving"); @@ -170,7 +170,7 @@ void CToxProto::PollingThread(void*) toxThread.Do(); } - UninitToxCore(); + UninitToxCore(&toxThread); toxThread.isConnected = false; logger->Log(__FUNCTION__": leaving"); diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index fdd5d30a92..007a3d6f74 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -74,25 +74,15 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) return; } CloseHandle(hProfile); - - TOX_ERR_NEW initError; - toxThread.tox = tox_new(NULL, &initError); - if (initError != TOX_ERR_NEW_OK) - { - m_proto->logger->Log(__FUNCTION__": failed to load tox profile (%d)", initError); - return; - } } - if (m_proto->InitToxCore()) + if (m_proto->InitToxCore(&toxThread)) { ptrT group(m_group.GetText()); if (mir_tstrlen(group) > 0 && Clist_GroupExists(group)) Clist_CreateGroup(0, group); - m_proto->LoadFriendList(NULL); - m_proto->SaveToxProfile(); - tox_kill(toxThread.tox); + m_proto->UninitToxCore(&toxThread); m_toxAddress.Enable(); m_toxAddress.SetTextA(ptrA(m_proto->getStringA(TOX_SETTINGS_ID))); @@ -128,15 +118,11 @@ void CToxOptionsMain::ProfileImport_OnClick(CCtrlButton*) ofn.lpstrInitialDir = _T("%APPDATA%\\Tox"); if (!GetOpenFileName(&ofn)) - { return; - } ptrT defaultProfilePath(m_proto->GetToxProfilePath()); if (mir_tstrcmpi(profilePath, defaultProfilePath) != 0) - { CopyFile(profilePath, defaultProfilePath, FALSE); - } m_profileCreate.OnClick(&m_profileCreate); } diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index d103736466..68539952b4 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -42,6 +42,12 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) fclose(profile); return false; } + + if (size == 0) + { + fclose(profile); + return true; + } uint8_t *data = (uint8_t*)mir_calloc(size); if (fread((char*)data, sizeof(char), size, profile) != (size_t)size) diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index a00d512d85..7075a281d1 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -86,8 +86,8 @@ private: // tox core Tox_Options* GetToxOptions(); - bool InitToxCore(); - void UninitToxCore(); + bool InitToxCore(CToxThread *toxThread); + void UninitToxCore(CToxThread *toxThread); // tox network bool IsOnline(); -- cgit v1.2.3