From 90cabe1a4585eb1d3da809c3bccf29d46bcd905f Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 17 Mar 2016 18:55:18 +0300 Subject: [PATCH] receiving (test mode) --- src/callbacks.py | 7 ++++++- src/file_transfers.py | 14 +++++++------- src/tox.py | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index efdcc33..c1ca6e4 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -4,6 +4,7 @@ from settings import Settings from profile import Profile from toxcore_enums_and_consts import * from tox import bin_to_string +from ctypes import c_char_p, cast, pointer class InvokeEvent(QtCore.QEvent): @@ -158,7 +159,11 @@ def tox_file_recv(window, tray): def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, user_data): - Profile.get_instance().incoming_chunk(friend_number, file_number, position, chunk if length else None) + print 'Len:', type(length) + print 'Chunk', type(chunk) + print 'Pos', type(position) + #chunk = cast(pointer(chunk), c_char_p)[0] + Profile.get_instance().incoming_chunk(friend_number, file_number, position, chunk[:length] if length else None) # ----------------------------------------------------------------------------------------------------------------- # Callbacks - initialization # ----------------------------------------------------------------------------------------------------------------- diff --git a/src/file_transfers.py b/src/file_transfers.py index b52795d..7352140 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -35,13 +35,13 @@ class ReceiveTransfer(FileTransfer): self._file = open(self._path, 'wb') def write_chunk(self, position, data): - size = getsize(self._path) - if size < position + len(data): - self._file.write('\0' * (position + len(data) - size)) + if data is not None: + size = getsize(self._path) + if size < position: + self._file.seek(0, 2) + self._file.write('\0' * (position - size)) self._file.seek(position) - self._file.write(data) + self._file.write(''.join(chr(x) for x in data)) self._file.flush() else: - self._file.seek(position) - self._file.write(data) - self._file.flush() + self._file.close() diff --git a/src/tox.py b/src/tox.py index 3ec7bed..2767660 100644 --- a/src/tox.py +++ b/src/tox.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from ctypes import c_char_p, Structure, CDLL, c_bool, addressof, c_int, c_size_t, POINTER, c_uint16, c_void_p, c_uint64 -from ctypes import create_string_buffer, ArgumentError, CFUNCTYPE, c_uint32, sizeof +from ctypes import create_string_buffer, ArgumentError, CFUNCTYPE, c_uint32, sizeof, c_uint8 from platform import system from toxcore_enums_and_consts import * @@ -1351,7 +1351,7 @@ class Tox(object): pointer (c_void_p) to user_data :param user_data: pointer (c_void_p) to user data """ - c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_uint64, c_char_p, c_size_t, c_void_p) + c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_uint64, POINTER(c_uint8), c_size_t, c_void_p) self.file_recv_chunk_cb = c_callback(callback) self.libtoxcore.tox_callback_file_recv_chunk(self._tox_pointer, self.file_recv_chunk_cb, user_data)