avatar cancelling fixed
This commit is contained in:
parent
4cda4ed4a1
commit
12d2ee52dc
2 changed files with 10 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
from toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL
|
from toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL
|
||||||
from os.path import basename, getsize, exists
|
from os.path import basename, getsize, exists
|
||||||
from os import remove
|
from os import remove, chdir
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
from tox import Tox
|
from tox import Tox
|
||||||
import settings
|
import settings
|
||||||
|
@ -149,8 +149,8 @@ class ReceiveTransfer(FileTransfer):
|
||||||
|
|
||||||
def __init__(self, path, tox, friend_number, size, file_number):
|
def __init__(self, path, tox, friend_number, size, file_number):
|
||||||
super(ReceiveTransfer, self).__init__(path, tox, friend_number, size, file_number)
|
super(ReceiveTransfer, self).__init__(path, tox, friend_number, size, file_number)
|
||||||
self._file = open(self._path, 'wb')
|
|
||||||
if type(self) is not ReceiveAvatar:
|
if type(self) is not ReceiveAvatar:
|
||||||
|
self._file = open(self._path, 'wb')
|
||||||
self._file.truncate(0)
|
self._file.truncate(0)
|
||||||
self._file_size = 0
|
self._file_size = 0
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ class ReceiveAvatar(ReceiveTransfer):
|
||||||
MAX_AVATAR_SIZE = 512 * 1024
|
MAX_AVATAR_SIZE = 512 * 1024
|
||||||
|
|
||||||
def __init__(self, tox, friend_number, size, file_number):
|
def __init__(self, tox, friend_number, size, file_number):
|
||||||
path = settings.ProfileHelper.get_path() + '/avatars/{}.png'.format(tox.friend_get_public_key(friend_number))
|
path = settings.ProfileHelper.get_path() + 'avatars/{}.png'.format(tox.friend_get_public_key(friend_number))
|
||||||
super(ReceiveAvatar, self).__init__(path, tox, friend_number, size, file_number)
|
super(ReceiveAvatar, self).__init__(path, tox, friend_number, size, file_number)
|
||||||
if size > self.MAX_AVATAR_SIZE:
|
if size > self.MAX_AVATAR_SIZE:
|
||||||
self.send_control(TOX_FILE_CONTROL['CANCEL'])
|
self.send_control(TOX_FILE_CONTROL['CANCEL'])
|
||||||
|
@ -231,14 +231,17 @@ class ReceiveAvatar(ReceiveTransfer):
|
||||||
remove(path)
|
remove(path)
|
||||||
else:
|
else:
|
||||||
hash = self.get_file_id()
|
hash = self.get_file_id()
|
||||||
with open(path, 'rb') as fl:
|
with open(path) as fl:
|
||||||
existing_hash = Tox.hash(fl.read())
|
data = fl.read()
|
||||||
|
existing_hash = Tox.hash(data)
|
||||||
if hash == existing_hash:
|
if hash == existing_hash:
|
||||||
self.send_control(TOX_FILE_CONTROL['CANCEL'])
|
self.send_control(TOX_FILE_CONTROL['CANCEL'])
|
||||||
self.state = TOX_FILE_TRANSFER_STATE['CANCELED']
|
self.state = TOX_FILE_TRANSFER_STATE['CANCELED']
|
||||||
else:
|
else:
|
||||||
|
self._file = open(self._path, 'wb')
|
||||||
self._file.truncate(0)
|
self._file.truncate(0)
|
||||||
self.send_control(TOX_FILE_CONTROL['RESUME'])
|
self.send_control(TOX_FILE_CONTROL['RESUME'])
|
||||||
else:
|
else:
|
||||||
|
self._file = open(self._path, 'wb')
|
||||||
self._file.truncate(0)
|
self._file.truncate(0)
|
||||||
self.send_control(TOX_FILE_CONTROL['RESUME'])
|
self.send_control(TOX_FILE_CONTROL['RESUME'])
|
||||||
|
|
|
@ -1017,7 +1017,7 @@ class Tox(object):
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def hash(data, size, hash=None):
|
def hash(data, hash=None):
|
||||||
"""
|
"""
|
||||||
Generates a cryptographic hash of the given data.
|
Generates a cryptographic hash of the given data.
|
||||||
|
|
||||||
|
@ -1034,7 +1034,7 @@ class Tox(object):
|
||||||
"""
|
"""
|
||||||
if hash is None:
|
if hash is None:
|
||||||
hash = create_string_buffer(TOX_HASH_LENGTH)
|
hash = create_string_buffer(TOX_HASH_LENGTH)
|
||||||
Tox.libtoxcore.tox_hash(hash, c_void_p(data), c_size_t(size))
|
Tox.libtoxcore.tox_hash(hash, c_char_p(data), len(data))
|
||||||
return bin_to_string(hash, TOX_HASH_LENGTH)
|
return bin_to_string(hash, TOX_HASH_LENGTH)
|
||||||
|
|
||||||
def file_control(self, friend_number, file_number, control):
|
def file_control(self, friend_number, file_number, control):
|
||||||
|
|
Loading…
Reference in a new issue