From a5bcbaf28c7f0c16dabff086efcd873f04be5534 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 26 Mar 2021 10:34:01 +0100 Subject: [PATCH] add Add-On versioncheck --- fishy/__main__.py | 6 +++--- fishy/constants.py | 4 ++-- fishy/helper/__init__.py | 2 +- fishy/helper/helper.py | 19 ++++++++++++++++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/fishy/__main__.py b/fishy/__main__.py index 67820da..4c8d711 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -59,11 +59,11 @@ def initialize(window_to_hide): helper.install_thread_excepthook() sys.excepthook = helper.unhandled_exception_logging - if not config.get("addoninstalled", False): + if not config.get("addoninstalled", 0) or helper.get_addonversion(chalutier[0]) < chalutier[2]: helper.install_addon(*chalutier) helper.install_addon(*lam2) - helper.remove_addon("ProvisionsChalutier") - config.set("addoninstalled", True) + helper.remove_addon("ProvisionsChalutier") #TODO delete with fishy 0.4.6 + config.set("addoninstalled", helper.get_addonversion(chalutier[0])) def main(): diff --git a/fishy/constants.py b/fishy/constants.py index e03e92b..021149a 100644 --- a/fishy/constants.py +++ b/fishy/constants.py @@ -1,3 +1,3 @@ apiversion = 1 -chalutier = ("Chalutier", "https://www.esoui.com/downloads/dl2934/1616505502-Chalutier_1.1.1.zip") -lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip") \ No newline at end of file +chalutier = ("Chalutier", "https://www.esoui.com/downloads/dl2934/1616505502-Chalutier_1.1.1.zip", 111) +lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32) \ No newline at end of file diff --git a/fishy/helper/__init__.py b/fishy/helper/__init__.py index 9a0750f..dabfc52 100644 --- a/fishy/helper/__init__.py +++ b/fishy/helper/__init__.py @@ -1,4 +1,4 @@ from .auto_update import auto_upgrade, upgrade_avail, versions from .config import Config from .helper import open_web, initialize_uid, install_thread_excepthook, unhandled_exception_logging, manifest_file, \ - create_shortcut_first, addon_exists, install_addon, remove_addon, restart, create_shortcut, not_implemented, update + create_shortcut_first, addon_exists, get_addonversion, install_addon, remove_addon, restart, create_shortcut, not_implemented, update diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index 6f50f7a..f73f154 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -152,12 +152,25 @@ def get_addondir(): return os.path.join(documents, "Elder Scrolls Online", "live", "Addons") -def addon_exists(name): +def addon_exists(name, url=None, v=None): return os.path.exists(os.path.join(get_addondir(), name)) +def get_addonversion(name, url=None, v=None): + if addon_exists(name): + txt = name + ".txt" + try: + with open(os.path.join(get_addondir(), name, txt)) as f: + for line in f: + if "AddOnVersion" in line: + return int(line.split(' ')[2]) + except Exception: + pass + return 0 + + # noinspection PyBroadException -def install_addon(name, url): +def install_addon(name, url, v=None): try: r = requests.get(url, stream=True) z = ZipFile(BytesIO(r.content)) @@ -167,7 +180,7 @@ def install_addon(name, url): logging.error("Could not install Add-On "+name+", try doing it manually") -def remove_addon(name): +def remove_addon(name, url=None, v=None): try: shutil.rmtree(os.path.join(get_addondir(), name)) logging.info("Add-On "+name+" removed!")