receiving (test mode)
This commit is contained in:
parent
4ce7f6c6a5
commit
90cabe1a45
3 changed files with 15 additions and 10 deletions
|
@ -4,6 +4,7 @@ from settings import Settings
|
||||||
from profile import Profile
|
from profile import Profile
|
||||||
from toxcore_enums_and_consts import *
|
from toxcore_enums_and_consts import *
|
||||||
from tox import bin_to_string
|
from tox import bin_to_string
|
||||||
|
from ctypes import c_char_p, cast, pointer
|
||||||
|
|
||||||
|
|
||||||
class InvokeEvent(QtCore.QEvent):
|
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):
|
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
|
# Callbacks - initialization
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -35,13 +35,13 @@ class ReceiveTransfer(FileTransfer):
|
||||||
self._file = open(self._path, 'wb')
|
self._file = open(self._path, 'wb')
|
||||||
|
|
||||||
def write_chunk(self, position, data):
|
def write_chunk(self, position, data):
|
||||||
|
if data is not None:
|
||||||
size = getsize(self._path)
|
size = getsize(self._path)
|
||||||
if size < position + len(data):
|
if size < position:
|
||||||
self._file.write('\0' * (position + len(data) - size))
|
self._file.seek(0, 2)
|
||||||
|
self._file.write('\0' * (position - size))
|
||||||
self._file.seek(position)
|
self._file.seek(position)
|
||||||
self._file.write(data)
|
self._file.write(''.join(chr(x) for x in data))
|
||||||
self._file.flush()
|
self._file.flush()
|
||||||
else:
|
else:
|
||||||
self._file.seek(position)
|
self._file.close()
|
||||||
self._file.write(data)
|
|
||||||
self._file.flush()
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- 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 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 platform import system
|
||||||
from toxcore_enums_and_consts import *
|
from toxcore_enums_and_consts import *
|
||||||
|
|
||||||
|
@ -1351,7 +1351,7 @@ class Tox(object):
|
||||||
pointer (c_void_p) to user_data
|
pointer (c_void_p) to user_data
|
||||||
:param user_data: 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.file_recv_chunk_cb = c_callback(callback)
|
||||||
self.libtoxcore.tox_callback_file_recv_chunk(self._tox_pointer, self.file_recv_chunk_cb, user_data)
|
self.libtoxcore.tox_callback_file_recv_chunk(self._tox_pointer, self.file_recv_chunk_cb, user_data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue