From 9f0974abb3c3ea3b3a641ed6c7ae40325d55546b Mon Sep 17 00:00:00 2001 From: Adam Saudagar Date: Sun, 21 Nov 2021 16:30:41 +0530 Subject: [PATCH] created migration code which is used to migrate data after an update moved version code to constants so that code can access it too changed Install/Remove Chalutier to FIshyQR in options --- fishy/__init__.py | 4 +++- fishy/__main__.py | 10 ++++---- fishy/constants.py | 11 ++++++--- fishy/engine/fullautofisher/engine.py | 6 ----- fishy/gui/main_gui.py | 16 ++++++------- fishy/helper/__init__.py | 2 +- fishy/helper/helper.py | 23 +++++++++++++++++-- fishy/helper/migration.py | 33 +++++++++++++++++++++++++++ 8 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 fishy/helper/migration.py diff --git a/fishy/__init__.py b/fishy/__init__.py index ebc28bf..124b664 100644 --- a/fishy/__init__.py +++ b/fishy/__init__.py @@ -1,2 +1,4 @@ +from fishy import constants + from fishy.__main__ import main -__version__ = "0.5.2" +__version__ = constants.version diff --git a/fishy/__main__.py b/fishy/__main__.py index 8537191..1b66f90 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -9,13 +9,14 @@ import win32gui import fishy from fishy import gui, helper, web -from fishy.constants import chalutier, lam2 +from fishy.constants import chalutier, lam2, fishyqr, libgps from fishy.engine.common.event_handler import EngineEventHandler from fishy.gui import GUI, splash, update_dialog from fishy.helper import hotkey from fishy.helper.active_poll import active from fishy.helper.config import config from fishy.helper.hotkey.hotkey_process import hotkey +from fishy.helper.migration import Migration def check_window_name(title): @@ -28,6 +29,8 @@ def check_window_name(title): # noinspection PyBroadException def initialize(window_to_hide): + Migration.migrate() + helper.create_shortcut_first() helper.initialize_uid() @@ -62,10 +65,7 @@ def initialize(window_to_hide): helper.install_thread_excepthook() sys.excepthook = helper.unhandled_exception_logging - if not config.get("addoninstalled", 0) or helper.get_addonversion(chalutier[0]) < chalutier[2]: - helper.install_addon(*chalutier) - helper.install_addon(*lam2) - config.set("addoninstalled", helper.get_addonversion(chalutier[0])) + helper.install_required_addons() def main(): diff --git a/fishy/constants.py b/fishy/constants.py index ec39bc7..ba0e03c 100644 --- a/fishy/constants.py +++ b/fishy/constants.py @@ -1,6 +1,11 @@ apiversion = 2 -chalutier = ("Chalutier", "https://www.esoui.com/downloads/dl2934/Chalutier_1.1.4.zip", 114) -lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32) -fishyqr = ("FishyQR", "https://github.com/fishyboteso/FishyQR/files/6329586/FishyQR.zip", 100) +# removed since 0.5.3 +chalutier = ("Chalutier", "https://www.esoui.com/downloads/dl2934/Chalutier_1.1.4.zip", 114) + +# addons used +lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32) +fishyqr = ("FishyQR", "https://github.com/fishyboteso/FishyQR/files/7575974/FishyQR.zip", 101) libgps = ("LibGPS", "https://cdn.esoui.com/downloads/file601/LibGPS_3_0_3.zip", 30) + +version = "0.5.3" diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index d929131..9412798 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -46,12 +46,6 @@ class FullAuto(IEngine): self.mode = None def run(self): - - addons_req = [libgps, lam2, fishyqr] - for addon in addons_req: - if not helper.addon_exists(*addon): - helper.install_addon(*addon) - self.gui.bot_started(True) self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug") diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index e52f043..741fe3f 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -9,7 +9,7 @@ from ttkthemes import ThemedTk from fishy import helper from fishy.web import web -from ..constants import chalutier, lam2 +from ..constants import chalutier, lam2, fishyqr from ..helper.config import config from .discord_login import discord_login from ..helper.hotkey.hotkey_process import hotkey @@ -59,15 +59,13 @@ def _create(gui: 'GUI'): filemenu.add_command(label="Update", command=helper.update) def installer(): - if filemenu.entrycget(4, 'label') == "Remove Chalutier": - if helper.remove_addon(chalutier[0]) == 0: - filemenu.entryconfigure(4, label="Install Chalutier") + if filemenu.entrycget(4, 'label') == "Remove FishyQR": + if helper.remove_addon(fishyqr[0]) == 0: + filemenu.entryconfigure(4, label="Install FishyQR") else: - r = helper.install_addon(*chalutier) - r += helper.install_addon(*lam2) - if r == 0: - filemenu.entryconfigure(4, label="Remove Chalutier") - chaEntry = "Remove Chalutier" if helper.addon_exists(chalutier[0]) else "Install Chalutier" + helper.install_required_addons(True) + filemenu.entryconfigure(4, label="Remove FishyQR") + chaEntry = "Remove FishyQR" if helper.addon_exists(fishyqr[0]) else "Install FishyQR" filemenu.add_command(label=chaEntry, command=installer) menubar.add_cascade(label="Options", menu=filemenu) diff --git a/fishy/helper/__init__.py b/fishy/helper/__init__.py index df42062..084d649 100644 --- a/fishy/helper/__init__.py +++ b/fishy/helper/__init__.py @@ -5,5 +5,5 @@ from .helper import (addon_exists, create_shortcut, create_shortcut_first, install_addon, install_thread_excepthook, manifest_file, not_implemented, open_web, playsound_multiple, remove_addon, restart, unhandled_exception_logging, - update) + update, install_required_addons) from .luaparser import sv_color_extract diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index 35ffb16..56a0a93 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -22,6 +22,8 @@ from win32gui import GetForegroundWindow, GetWindowText import fishy from fishy import web +from fishy.constants import libgps, lam2, fishyqr +from fishy.helper.config import config def playsound_multiple(path, count=2): @@ -190,17 +192,34 @@ def get_addonversion(name, url=None, v=None): return 0 +def install_required_addons(force=False): + addons_req = [libgps, lam2, fishyqr] + addon_version = config.get("addon_version", {}) + installed = False + for addon in addons_req: + if force or (addon_exists(*addon) and + (addon[0] not in addon_version or ( + addon[0] in addon_version and addon_version[addon[0]] < addon[2]))): + remove_addon(*addon) + install_addon(*addon) + addon_version[addon[0]] = addon[2] + installed = True + config.set("addon_version", addon_version) + if installed: + logging.info("Please make sure to enable \"Allow outdated addons\" in ESO") + + # noinspection PyBroadException def install_addon(name, url, v=None): try: r = requests.get(url, stream=True) z = ZipFile(BytesIO(r.content)) z.extractall(path=get_addondir()) - logging.info("Add-On " + name + - " installed successfully!\nPlease make sure to enable \"Allow outdated addons\" in ESO") + logging.info("Add-On " + name + " installed successfully!") return 0 except Exception: logging.error("Could not install Add-On " + name + ", try doing it manually") + traceback.print_exc() return 1 diff --git a/fishy/helper/migration.py b/fishy/helper/migration.py new file mode 100644 index 0000000..a11079a --- /dev/null +++ b/fishy/helper/migration.py @@ -0,0 +1,33 @@ +import logging + +from fishy.helper.auto_update import _normalize_version + +from fishy.constants import chalutier, version +from fishy.helper import helper +from .config import config + + +class Migration: + @staticmethod + def up_to_0_5_3(): + helper.remove_addon(*chalutier) + config.delete("addoninstalled") + + @staticmethod + def migrate(): + prev_version = _normalize_version(config.get("prev_version", "0.0.0")) + current_version = _normalize_version(version) + + if current_version > prev_version: + for v, f in migration_code: + if prev_version < _normalize_version(v) <= current_version: + logging.info(f"running migration for {v}") + f() + config.set("prev_version", version) + + + +migration_code = [ + # version, upgrade_code + ("0.5.3", Migration.up_to_0_5_3) +]