summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_transfer.h
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-03-03 20:36:35 +0300
committeraunsane <aunsane@gmail.com>2018-03-03 20:36:35 +0300
commit51022062562449eb9679a931bdc5cb4d62aca682 (patch)
tree93a56d484b80b0eab1eebef9e1fb067d7ea3e7be /protocols/Tox/src/tox_transfer.h
parentfa58f69fe117640e29cefb1b699bede4d045bc2f (diff)
Tox: #1156
- more accurate transfer management - unlockong file on transfer pause - added additional logs - cleanup
Diffstat (limited to 'protocols/Tox/src/tox_transfer.h')
-rw-r--r--protocols/Tox/src/tox_transfer.h45
1 files changed, 28 insertions, 17 deletions
diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h
index 640a4f1305..8b0a30cb32 100644
--- a/protocols/Tox/src/tox_transfer.h
+++ b/protocols/Tox/src/tox_transfer.h
@@ -34,12 +34,36 @@ struct FileTransferParam
transferType = TOX_FILE_KIND_DATA;
}
- bool OpenFile(const wchar_t *mode)
+ ~FileTransferParam()
{
- hFile = _wfopen(pfts.tszCurrentFile, mode);
+ if (pfts.tszWorkingDir)
+ mir_free(pfts.tszWorkingDir);
+ mir_free(pfts.pszFiles[0]);
+ mir_free(pfts.pszFiles);
+ if (hFile) {
+ fclose(hFile);
+ hFile = nullptr;
+ }
+ }
+
+ bool Resume()
+ {
+ if (hFile)
+ return true;
+ hFile = _wfopen(pfts.tszCurrentFile, L"wb+");
+ if (hFile)
+ _chsize_s(_fileno(hFile), pfts.currentFileSize);
return hFile != nullptr;
}
+ void Pause()
+ {
+ if (hFile) {
+ fclose(hFile);
+ hFile = nullptr;
+ }
+ }
+
void ChangeName(const wchar_t *fileName)
{
pfts.ptszFiles[0] = replaceStrW(pfts.tszCurrentFile, fileName);
@@ -49,19 +73,6 @@ struct FileTransferParam
{
return (pfts.flags & PFTS_SENDING) ? 0 : 1;
}
-
- ~FileTransferParam()
- {
- if (pfts.tszWorkingDir != nullptr)
- mir_free(pfts.tszWorkingDir);
- mir_free(pfts.pszFiles[0]);
- mir_free(pfts.pszFiles);
- if (hFile != nullptr)
- {
- fclose(hFile);
- hFile = nullptr;
- }
- }
};
struct AvatarTransferParam : public FileTransferParam
@@ -114,8 +125,8 @@ public:
{
if (transfer == nullptr)
return;
- transfers.erase(transfer->transferNumber);
- delete transfer;
+ if (transfers.erase(transfer->transferNumber))
+ delete transfer;
}
};