diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-10-30 17:58:45 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-10-30 17:58:45 +0000 |
commit | 75d27e475943eafbcb52e9a795554358c9348fbd (patch) | |
tree | c809bfe3d298f81633e22cea62a9336b22e99237 /protocols/Tox/src | |
parent | c0bf2d57a2b9ed3bb11eb6a4c499629b7ce8ba98 (diff) |
Tox: fixed profile creation and import
git-svn-id: http://svn.miranda-ng.org/main/trunk@15654 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r-- | protocols/Tox/src/tox_core.cpp | 13 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 6 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 18 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.cpp | 6 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 4 |
5 files changed, 19 insertions, 28 deletions
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();
|