From e39da35942db7d2bd7c192336f4d3c33e44d0ba4 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 18 Aug 2014 20:31:18 +0000 Subject: Tox: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@10232 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_proto.h | 4 +-- protocols/Tox/src/tox_utils.cpp | 63 +++++++++++++++-------------------------- 2 files changed, 25 insertions(+), 42 deletions(-) (limited to 'protocols/Tox') diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index af596b689c..0be0115561 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -147,8 +147,8 @@ private: std::tstring GetToxProfilePath(); - int LoadToxData(); - int SaveToxData(); + void LoadToxData(); + void SaveToxData(); // dialogs static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 60dd7e6233..018774c910 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -155,54 +155,46 @@ std::tstring CToxProto::GetToxProfilePath() return profilePath; } -int CToxProto::LoadToxData() +void CToxProto::LoadToxData() { std::tstring toxProfilePath = GetToxProfilePath(); FILE *hFile = _wfopen(toxProfilePath.c_str(), _T("rb")); - if (hFile) + if (!hFile) { - fseek(hFile, 0, SEEK_END); - size_t size = ftell(hFile); - rewind(hFile); - - uint8_t *data = (uint8_t*)mir_alloc(size); + debugLogA("CToxProto::LoadToxData: could not open tox profile"); + return; + } - if (fread(data, sizeof(uint8_t), size, hFile) != size) - { - mir_free(data); - //fputs("[!] could not read data file!\n", stderr); - fclose(hFile); - return 0; - } + fseek(hFile, 0, SEEK_END); + uint32_t size = ftell(hFile); + rewind(hFile); - tox_load(tox, data, size); + uint8_t *data = (uint8_t*)mir_alloc(size); + if (fread(data, sizeof(uint8_t), size, hFile) != size) + { + debugLogA("CToxProto::LoadToxData: could not read tox profile"); + fclose(hFile); mir_free(data); - - if (fclose(hFile) < 0) - { - //perror("[!] fclose failed"); - /* we got it open and the expected data read... let it be ok */ - /* return 0; */ - } - - return 1; + return; } - return 0; + tox_load(tox, data, size); + + mir_free(data); + fclose(hFile); } -int CToxProto::SaveToxData() +void CToxProto::SaveToxData() { std::tstring toxProfilePath = GetToxProfilePath(); FILE *hFile = _wfopen(toxProfilePath.c_str(), _T("wb")); if (!hFile) { - //perror("[!] load_key"); - return 0; + debugLogA("CToxProto::LoadToxData: could not open tox profile"); + return; } - int res = 1; uint32_t size = tox_size(tox); uint8_t *data = (uint8_t*)mir_alloc(size); @@ -210,18 +202,9 @@ int CToxProto::SaveToxData() if (fwrite(data, sizeof(uint8_t), size, hFile) != size) { - mir_free(data); - //fputs("[!] could not write data file (1)!", stderr); - res = 0; + debugLogA("CToxProto::LoadToxData: could not write tox profile"); } mir_free(data); - - if (fclose(hFile) < 0) - { - //perror("[!] could not write data file (2)"); - res = 0; - } - - return res; + fclose(hFile); } -- cgit v1.2.3