windows bug fixes

This commit is contained in:
ingvar1995 2016-06-22 16:09:44 +03:00
parent 5a0843d98b
commit b9cbf809b5
2 changed files with 8 additions and 6 deletions

View file

@ -230,7 +230,7 @@ class ReceiveTransfer(FileTransfer):
data = bytearray(data) data = bytearray(data)
if self._file_size < position: if self._file_size < position:
self._file.seek(0, 2) self._file.seek(0, 2)
self._file.write('\0' * (position - self._file_size)) self._file.write(b'\0' * (position - self._file_size))
self._file.seek(position) self._file.seek(position)
self._file.write(data) self._file.write(data)
l = len(data) l = len(data)
@ -281,12 +281,14 @@ class ReceiveAvatar(ReceiveTransfer):
super(ReceiveAvatar, self).__init__(path + '.tmp', tox, friend_number, size, file_number) super(ReceiveAvatar, self).__init__(path + '.tmp', 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'])
self._file.close()
remove(path + '.tmp') remove(path + '.tmp')
elif not size: elif not size:
self.send_control(TOX_FILE_CONTROL['CANCEL']) self.send_control(TOX_FILE_CONTROL['CANCEL'])
self._file.close() self._file.close()
if exists(path): if exists(path):
remove(path) remove(path)
self._file.close()
remove(path + '.tmp') remove(path + '.tmp')
elif exists(path): elif exists(path):
hash = self.get_file_id() hash = self.get_file_id()
@ -295,6 +297,7 @@ class ReceiveAvatar(ReceiveTransfer):
existing_hash = Tox.hash(data) 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._file.close()
remove(path + '.tmp') remove(path + '.tmp')
else: else:
self.send_control(TOX_FILE_CONTROL['RESUME']) self.send_control(TOX_FILE_CONTROL['RESUME'])
@ -309,5 +312,3 @@ class ReceiveAvatar(ReceiveTransfer):
chdir(dirname(avatar_path)) chdir(dirname(avatar_path))
remove(avatar_path) remove(avatar_path)
rename(self._path, avatar_path) rename(self._path, avatar_path)

View file

@ -1,5 +1,6 @@
from platform import system from platform import system
from ctypes import CDLL from ctypes import CDLL
import util
class LibToxCore: class LibToxCore:
@ -9,7 +10,7 @@ class LibToxCore:
# libtoxcore and libsodium must be installed in your os # libtoxcore and libsodium must be installed in your os
self._libtoxcore = CDLL('libtoxcore.so') self._libtoxcore = CDLL('libtoxcore.so')
elif system() == 'Windows': elif system() == 'Windows':
self._libtoxcore = CDLL('libs/libtox.dll') self._libtoxcore = CDLL(util.curr_directory() + '/libs/libtox.dll')
else: else:
raise OSError('Unknown system.') raise OSError('Unknown system.')
@ -25,7 +26,7 @@ class LibToxAV:
self._libtoxav = CDLL('libtoxav.so') self._libtoxav = CDLL('libtoxav.so')
elif system() == 'Windows': elif system() == 'Windows':
# on Windows av api is in libtox.dll # on Windows av api is in libtox.dll
self._libtoxav = CDLL('libs/libtox.dll') self._libtoxav = CDLL(util.curr_directory() + '/libs/libtox.dll')
else: else:
raise OSError('Unknown system.') raise OSError('Unknown system.')
@ -41,7 +42,7 @@ class LibToxEncryptSave:
self._lib_tox_encrypt_save = CDLL('libtoxencryptsave.so') self._lib_tox_encrypt_save = CDLL('libtoxencryptsave.so')
elif system() == 'Windows': elif system() == 'Windows':
# on Windows profile encryption api is in libtox.dll # on Windows profile encryption api is in libtox.dll
self._lib_tox_encrypt_save = CDLL('libs/libtox.dll') self._lib_tox_encrypt_save = CDLL(util.curr_directory() + '/libs/libtox.dll')
else: else:
raise OSError('Unknown system.') raise OSError('Unknown system.')