summaryrefslogtreecommitdiff
path: root/protocols/Tox/src
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-01-21 12:50:12 +0300
committeraunsane <aunsane@gmail.com>2018-01-21 12:50:54 +0300
commit7177ca3a70807f06746b5f753e786811cd98f90e (patch)
tree6a0360a3353a79f05b8e1ee330f80211ea806d36 /protocols/Tox/src
parent087173d06f4848f19d186b6902d399ce9b7225e1 (diff)
Tox: attempt to fix locked file when transfer is cancelled
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r--protocols/Tox/src/stdafx.h2
-rw-r--r--protocols/Tox/src/tox_contacts.cpp2
-rw-r--r--protocols/Tox/src/tox_messages.cpp2
-rw-r--r--protocols/Tox/src/tox_transfer.cpp4
-rw-r--r--protocols/Tox/src/tox_transfer.h38
5 files changed, 22 insertions, 26 deletions
diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h
index a136f910a7..099e77f46d 100644
--- a/protocols/Tox/src/stdafx.h
+++ b/protocols/Tox/src/stdafx.h
@@ -42,6 +42,8 @@
struct CToxProto;
+#define now() time(nullptr)
+
#include "version.h"
#include "resource.h"
#include "tox_menus.h"
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 08931dee00..d79ca5f61d 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -234,7 +234,7 @@ void CToxProto::OnFriendRequest(Tox*, const uint8_t *pubKey, const uint8_t *mess
DB_AUTH_BLOB blob(hContact, nullptr, nullptr, nullptr, (LPCSTR)address, (LPCSTR)message);
PROTORECVEVENT pre = { 0 };
- pre.timestamp = time(nullptr);
+ pre.timestamp = now();
pre.lParam = blob.size();
pre.szMessage = blob;
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp
index 6ab66e8186..8d39d1d6d7 100644
--- a/protocols/Tox/src/tox_messages.cpp
+++ b/protocols/Tox/src/tox_messages.cpp
@@ -60,7 +60,7 @@ void CToxProto::OnFriendMessage(Tox *tox, uint32_t friendNumber, TOX_MESSAGE_TYP
rawMessage[length] = 0;
PROTORECVEVENT recv = { 0 };
- recv.timestamp = time(nullptr);
+ recv.timestamp = now();
recv.szMessage = rawMessage;
switch (type) {
case TOX_MESSAGE_TYPE_NORMAL:
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index 6becdc1a26..908c54c37a 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -52,7 +52,7 @@ void CToxProto::OnFriendFile(Tox *tox, uint32_t friendNumber, uint32_t fileNumbe
PROTORECVFILET pre = { 0 };
pre.dwFlags = PRFF_UNICODE;
pre.fileCount = 1;
- pre.timestamp = time(nullptr);
+ pre.timestamp = now();
pre.descr.w = L"";
pre.files.w = &name;
pre.lParam = (LPARAM)transfer;
@@ -111,7 +111,7 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const wchar_t **szFil
debugLogA(__FUNCTION__": failed to open file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
tox_file_control(m_toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, nullptr);
transfers.Remove(transfer);
- return NULL;
+ return 0;
}
TOX_ERR_FILE_CONTROL error;
diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h
index 372b047fb3..640a4f1305 100644
--- a/protocols/Tox/src/tox_transfer.h
+++ b/protocols/Tox/src/tox_transfer.h
@@ -13,7 +13,7 @@ struct FileTransferParam
FileTransferParam(uint32_t friendNumber, uint32_t fileNumber, const wchar_t *fileName, uint64_t fileSize)
{
- hFile = NULL;
+ hFile = nullptr;
this->friendNumber = friendNumber;
this->fileNumber = fileNumber;
transferNumber = (((int64_t)friendNumber) << 32) | ((int64_t)fileNumber);
@@ -24,12 +24,12 @@ struct FileTransferParam
pfts.totalFiles = 1;
pfts.ptszFiles = (wchar_t**)mir_alloc(sizeof(wchar_t*)*(pfts.totalFiles + 1));
pfts.ptszFiles[0] = pfts.tszCurrentFile = mir_wstrdup(fileName);
- pfts.ptszFiles[pfts.totalFiles] = NULL;
+ pfts.ptszFiles[pfts.totalFiles] = nullptr;
pfts.totalBytes = pfts.currentFileSize = fileSize;
pfts.totalProgress = pfts.currentFileProgress = 0;
pfts.currentFileNumber = 0;
- pfts.currentFileTime = time(NULL);
- pfts.tszWorkingDir = NULL;
+ pfts.currentFileTime = now();
+ pfts.tszWorkingDir = nullptr;
transferType = TOX_FILE_KIND_DATA;
}
@@ -37,7 +37,7 @@ struct FileTransferParam
bool OpenFile(const wchar_t *mode)
{
hFile = _wfopen(pfts.tszCurrentFile, mode);
- return hFile != NULL;
+ return hFile != nullptr;
}
void ChangeName(const wchar_t *fileName)
@@ -52,14 +52,14 @@ struct FileTransferParam
~FileTransferParam()
{
- if (pfts.tszWorkingDir != NULL)
+ if (pfts.tszWorkingDir != nullptr)
mir_free(pfts.tszWorkingDir);
mir_free(pfts.pszFiles[0]);
mir_free(pfts.pszFiles);
- if (hFile != NULL)
+ if (hFile != nullptr)
{
fclose(hFile);
- hFile = NULL;
+ hFile = nullptr;
}
}
};
@@ -89,39 +89,33 @@ public:
void Add(FileTransferParam *transfer)
{
if (transfers.find(transfer->transferNumber) == transfers.end())
- {
transfers[transfer->transferNumber] = transfer;
- }
}
FileTransferParam* Get(uint32_t friendNumber, uint32_t fileNumber)
{
int64_t transferNumber = (((int64_t)friendNumber) << 32) | ((int64_t)fileNumber);
if (transfers.find(transferNumber) != transfers.end())
- {
return transfers.at(transferNumber);
- }
- return NULL;
+ return nullptr;
}
FileTransferParam* GetAt(size_t index)
{
- if (index < Count())
- {
- std::map<int64_t, FileTransferParam*>::iterator it = transfers.begin();
+ if (index < Count()) {
+ auto it = transfers.begin();
std::advance(it, index);
return it->second;
}
- return NULL;
+ return nullptr;
}
void Remove(FileTransferParam *transfer)
{
- if (transfers.find(transfer->transferNumber) != transfers.end())
- {
- transfers.erase(transfer->transferNumber);
- delete transfer;
- }
+ if (transfer == nullptr)
+ return;
+ transfers.erase(transfer->transferNumber);
+ delete transfer;
}
};