From 3d0d603b5159effa974dc587ee77312d8929c969 Mon Sep 17 00:00:00 2001 From: BarsTiger Date: Thu, 5 May 2022 20:52:37 +0300 Subject: [PATCH] new self update method --- horsy.py | 22 ++++++++++++++++------ horsygui.py | 30 +++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/horsy.py b/horsy.py index 33105cf..0cf68a4 100644 --- a/horsy.py +++ b/horsy.py @@ -34,6 +34,9 @@ if not os.path.isfile(horsy_vars.horsypath + 'config.cfg'): if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'): with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f: f.write('{}') +if os.path.isfile(horsy_vars.horsypath + 'horsy.old'): + os.remove(horsy_vars.horsypath + 'horsy.old') + print('Removed old horsy') # Checking version try: @@ -44,15 +47,22 @@ except: 'If you installed it just now, please restart PC.') if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version: + from modules.download import dl + import urllib.request print('New version available!') - print('If you see this message again, or horsy doesn\'t launch itself for long time, please type ' - 'horsy_updater in your terminal to update it manually.') input('Press enter to update...') print('Updating...') - print('Please wait, if process seems closed, its OK, just wait a bit.') - with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f: - f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content) - subprocess.Popen('horsy_updater.exe horsy', shell=True, close_fds=True) + print('Please wait...') + os.rename(horsy_vars.horsypath + "horsy.exe", horsy_vars.horsypath + "horsy.old") + print('Renamed horsy.exe to horsy.old') + dl(['https://github.com/horsy-ml/horsy/raw/master/bin/horsy.exe', + 'https://github.com/horsy-ml/horsy/raw/master/bin/horsygui.exe'] + if os.path.isfile(horsy_vars.horsypath + 'horsygui.exe') else + ['https://github.com/horsy-ml/horsy/raw/master/bin/horsy.exe'], + horsy_vars.horsypath) + urllib.request.urlretrieve("https://github.com/horsy-ml/horsy/raw/master/web_vars/version", + horsy_vars.horsypath + '/apps/version') + subprocess.Popen(str(horsy_vars.horsypath + 'horsy.exe'), shell=True, close_fds=True) sys.exit(0) diff --git a/horsygui.py b/horsygui.py index fb1b797..f704799 100644 --- a/horsygui.py +++ b/horsygui.py @@ -250,6 +250,9 @@ if __name__ == "__main__": if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'): with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f: f.write('{}') + if os.path.isfile(horsy_vars.horsypath + 'horsygui.old'): + os.remove(horsy_vars.horsypath + 'horsygui.old') + gui.popup('Success', 'Removed old horsygui') # Checking version try: @@ -261,20 +264,29 @@ if __name__ == "__main__": if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version: gui.popup('Update', 'New version available! \nWe appreciate your safety, so you need to update horsy.' '\nPress OK and updater will download the latest version.\n' - 'If you see this message again, or horsy doesn\'t launch \n' - 'itself for long time, please type horsy_updater in your terminal.') + 'If you see this message again, or horsy doesn\'t launch, \n' + 'download updater manually from GitHub.\n\n' + 'Window will hide while updating.') try: - with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f: - f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content) + import urllib.request + UiMainWindow.close() + os.rename(horsy_vars.horsypath + "horsygui.exe", horsy_vars.horsypath + "horsygui.old") + with open(os.path.join(horsy_vars.horsypath) + 'horsygui.exe', 'wb') as f: + f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsygui.exe').content) + with open(os.path.join(horsy_vars.horsypath) + 'horsy.exe', 'wb') as f: + f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy.exe').content) + urllib.request.urlretrieve("https://github.com/horsy-ml/horsy/raw/master/web_vars/version", + horsy_vars.horsypath + '/apps/version') except: - gui.popup('Error', 'Could not download updater. \nMaybe installation folder is not writable ' + gui.popup('Error', 'Could not download horsy. \nMaybe installation folder is not writable ' '(only for admins).\n Please reinstall horsy or update it manually. \n' - 'Click OK, download file that will open browser and launch it.\n' + 'Click OK, download file that will be opened in browser copy it to horsy \n' + 'folder and launch it.\n' 'Afterwards, delete updater file and launch horsy again.') webbrowser.open('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe') - UiMainWindow.close() - subprocess.Popen('horsy_updater.exe horsygui', shell=True, close_fds=True) - sys.exit() + + subprocess.Popen(str(horsy_vars.horsypath + 'horsygui.exe'), shell=True, close_fds=True) + sys.exit(0) get_users_apps() installed_apps()