From c4843148e44e3af453e6f175af264c67d2bb7658 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 22 Oct 2016 20:31:34 +0300 Subject: [PATCH] check if updater exists --- toxygen/main.py | 10 ++++------ toxygen/menu.py | 10 ++++++++++ toxygen/updater.py | 9 +++++++++ toxygen/util.py | 4 ++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/toxygen/main.py b/toxygen/main.py index 436b5d3..2405199 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -9,7 +9,7 @@ except ImportError: from bootstrap import node_generator from mainscreen import MainWindow from callbacks import init_callbacks, stop, start -from util import curr_directory, program_version +from util import curr_directory, program_version, remove import styles.style import platform import toxencryptsave @@ -22,7 +22,7 @@ class Toxygen: def __init__(self, path_or_uri=None): super(Toxygen, self).__init__() - self.tox = self.ms = self.init = self.mainloop = self.avloop = None + self.tox = self.ms = self.init = self.app = self.tray = self.mainloop = self.avloop = None if path_or_uri is None: self.uri = self.path = None elif path_or_uri.startswith('tox:'): @@ -260,7 +260,7 @@ class Toxygen: self.tray.activated.connect(tray_activated) updating = False - if settings['update'] and updater.connection_available(): # auto update + if settings['update'] and updater.updater_available() and updater.connection_available(): # auto update version = updater.check_for_updates() if version is not None: if settings['update'] == 2: @@ -440,9 +440,7 @@ class Toxygen: def clean(): """Removes all windows libs from libs folder""" d = curr_directory() + '/libs/' - for fl in ('libtox64.dll', 'libtox.dll', 'libsodium64.a', 'libsodium.a'): - if os.path.exists(d + fl): - os.remove(d + fl) + remove(d) def configure(): diff --git a/toxygen/menu.py b/toxygen/menu.py index 5102e9b..4220c70 100644 --- a/toxygen/menu.py +++ b/toxygen/menu.py @@ -960,6 +960,16 @@ class UpdateSettings(CenteredWidget): msgBox.setText(text) msgBox.exec_() return + if not updater.updater_available(): + msgBox = QtGui.QMessageBox() + msgBox.setWindowTitle( + QtGui.QApplication.translate("updateSettingsForm", "Error", None, + QtGui.QApplication.UnicodeUTF8)) + text = (QtGui.QApplication.translate("updateSettingsForm", 'Updater not found', None, + QtGui.QApplication.UnicodeUTF8)) + msgBox.setText(text) + msgBox.exec_() + return version = updater.check_for_updates() if version is not None: updater.download(version) diff --git a/toxygen/updater.py b/toxygen/updater.py index 7587b8b..c25cadf 100644 --- a/toxygen/updater.py +++ b/toxygen/updater.py @@ -18,6 +18,15 @@ def connection_available(): return False +def updater_available(): + if is_from_sources(): + return os.path.exists(util.curr_directory() + '/toxygen_updater.py') + elif platform.system() == 'Windows': + return os.path.exists(util.curr_directory() + '/toxygen_updater.exe') + else: + return os.path.exists(util.curr_directory() + '/toxygen_updater') + + def check_for_updates(): current_version = util.program_version major, minor, patch = list(map(lambda x: int(x), current_version.split('.'))) diff --git a/toxygen/util.py b/toxygen/util.py index 0d1a48f..925127f 100644 --- a/toxygen/util.py +++ b/toxygen/util.py @@ -30,6 +30,10 @@ def copy(src, dest): copy(full_file_name, os.path.join(dest, file_name)) +def remove(folder): + shutil.rmtree(folder) + + def convert_time(t): offset = time.timezone - time.daylight * 3600 sec = int(t) - offset