From a5bcbaf28c7f0c16dabff086efcd873f04be5534 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 26 Mar 2021 10:34:01 +0100 Subject: [PATCH 1/3] 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!") From 439a3d707a21fd5ab2f3166b5402d489b18fbcba Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 26 Mar 2021 10:35:00 +0100 Subject: [PATCH 2/3] add addon de/install errorhandling --- fishy/gui/main_gui.py | 11 ++++++----- fishy/helper/helper.py | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index 6f9fdf1..207d463 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -61,12 +61,13 @@ def _create(gui: 'GUI'): def installer(): if filemenu.entrycget(4, 'label') == "Remove Chalutier": - helper.remove_addon(chalutier[0]) - filemenu.entryconfigure(4, label="Install Chalutier") + if helper.remove_addon(chalutier[0]) == 0: + filemenu.entryconfigure(4, label="Install Chalutier") else: - helper.install_addon(*chalutier) - helper.install_addon(*lam2) - filemenu.entryconfigure(4, label="Remove Chalutier") + 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" filemenu.add_command(label=chaEntry, command=installer) menubar.add_cascade(label="Options", menu=filemenu) diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index f73f154..c772edf 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -176,8 +176,10 @@ def install_addon(name, url, v=None): 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") + return 0 except Exception as ex: logging.error("Could not install Add-On "+name+", try doing it manually") + return 1 def remove_addon(name, url=None, v=None): @@ -186,6 +188,10 @@ def remove_addon(name, url=None, v=None): logging.info("Add-On "+name+" removed!") except FileNotFoundError: pass + except PermissionError as ex: + logging.error("Fishy has no permission to remove "+name+" Add-On") + return 1 + return 0 def get_documents(): From 2ac57c2f369a8c790ae5bb090a32ded6cd4996fc Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 26 Mar 2021 10:38:41 +0100 Subject: [PATCH 3/3] newline at end of constants.py --- fishy/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fishy/constants.py b/fishy/constants.py index 021149a..3080fd0 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", 111) -lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32) \ No newline at end of file +lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32)