diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-08-18 20:31:18 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-08-18 20:31:18 +0000 |
commit | e39da35942db7d2bd7c192336f4d3c33e44d0ba4 (patch) | |
tree | 15b58062f133790fa75b1e37f2a6302a4f2326d1 /protocols/Tox/src/tox_utils.cpp | |
parent | 87204c540590feeba783f40319d4a503b9f325f5 (diff) |
Tox: code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@10232 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_utils.cpp')
-rw-r--r-- | protocols/Tox/src/tox_utils.cpp | 63 |
1 files changed, 23 insertions, 40 deletions
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);
}
|