From 97958dd9636d6db2e7c4d851ff6e39b9f96febb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Thu, 22 Feb 2024 05:55:18 +0900 Subject: [PATCH 1/5] add Path existence check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- DMMGamePlayerFastLauncher/static/loder.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DMMGamePlayerFastLauncher/static/loder.py b/DMMGamePlayerFastLauncher/static/loder.py index e9d69db..3ae6e66 100644 --- a/DMMGamePlayerFastLauncher/static/loder.py +++ b/DMMGamePlayerFastLauncher/static/loder.py @@ -10,6 +10,11 @@ def config_loder(): + if not DataPathConfig.DATA.exists(): + raise FileNotFoundError(f"{DataPathConfig.DATA} not found") + if not AssetsPathConfig.PATH.exists(): + raise FileNotFoundError(f"{AssetsPathConfig.PATH} not found") + if DataPathConfig.APP_CONFIG.exists(): with open(DataPathConfig.APP_CONFIG, "r", encoding="utf-8") as f: AppConfig.DATA = SettingData.from_dict(json.load(f)) From a05e6654be94127c52ef027cf994c2da94a9d283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Thu, 22 Feb 2024 11:59:40 +0900 Subject: [PATCH 2/5] fix syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- DMMGamePlayerFastLauncher/lib/process_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DMMGamePlayerFastLauncher/lib/process_manager.py b/DMMGamePlayerFastLauncher/lib/process_manager.py index 51c0374..ddad641 100644 --- a/DMMGamePlayerFastLauncher/lib/process_manager.py +++ b/DMMGamePlayerFastLauncher/lib/process_manager.py @@ -15,7 +15,7 @@ class ProcessManager: @staticmethod def admin_run(args: list[str], cwd: Optional[str] = None) -> int: - file, *args = args + file, args = args[0], args[1:] logging.info({"cwd": cwd, "args": args, "file": file}) return ctypes.windll.shell32.ShellExecuteW(None, "runas", file, " ".join([f"{arg}" for arg in args]), cwd, 1) From 06b722dc5462af26f9803956e98a0fef3253ff0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Thu, 22 Feb 2024 15:35:34 +0900 Subject: [PATCH 3/5] fix error handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- DMMGamePlayerFastLauncher/tab/shortcut.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/DMMGamePlayerFastLauncher/tab/shortcut.py b/DMMGamePlayerFastLauncher/tab/shortcut.py index 0915411..a729797 100644 --- a/DMMGamePlayerFastLauncher/tab/shortcut.py +++ b/DMMGamePlayerFastLauncher/tab/shortcut.py @@ -105,6 +105,10 @@ def save(self): with open(path, "w", encoding="utf-8") as f: f.write(json.dumps(self.data.to_dict())) + def failed_save(self): + path = DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json") + path.unlink() + @error_toast def bypass_callback(self): self.save() @@ -123,7 +127,7 @@ def bypass_callback(self): Shortcut().create(sorce=sorce, target=Env.SCHTASKS, args=args, icon=icon) self.toast.info(i18n.t("app.shortcut.save_success")) except Exception: - DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() + self.failed_save() raise @error_toast @@ -141,7 +145,7 @@ def uac_callback(self): Shortcut().create(sorce=sorce, args=args, icon=icon) self.toast.info(i18n.t("app.shortcut.save_success")) except Exception: - DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() + self.failed_save() raise @error_toast @@ -162,7 +166,7 @@ def save_callback(self): Shortcut().create(sorce=sorce, args=args, icon=icon) self.toast.info(i18n.t("app.shortcut.save_success")) except Exception: - DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() + self.failed_save() raise @error_toast @@ -238,9 +242,13 @@ def save(self): self.selected.set(self.filename.get()) self.option_callback("_") except Exception: - selected.with_suffix(".json.bak").rename(selected.with_suffix(".json")) + self.failed_save() raise + def failed_save(self): + selected = DataPathConfig.SHORTCUT.joinpath(self.selected.get()).with_suffix(".json") + selected.with_suffix(".json.bak").rename(selected.with_suffix(".json")) + @error_toast def delete_callback(self): path = DataPathConfig.SHORTCUT.joinpath(self.selected.get()).with_suffix(".json") From 482e1ab0b36745efa81d9a4108bb4a20c49a6d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Sat, 24 Feb 2024 02:16:33 +0900 Subject: [PATCH 4/5] fix error handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- .../lib/process_manager.py | 4 +- DMMGamePlayerFastLauncher/tab/shortcut.py | 96 ++++++++++--------- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/DMMGamePlayerFastLauncher/lib/process_manager.py b/DMMGamePlayerFastLauncher/lib/process_manager.py index ddad641..e10f18b 100644 --- a/DMMGamePlayerFastLauncher/lib/process_manager.py +++ b/DMMGamePlayerFastLauncher/lib/process_manager.py @@ -15,9 +15,9 @@ class ProcessManager: @staticmethod def admin_run(args: list[str], cwd: Optional[str] = None) -> int: - file, args = args[0], args[1:] + file = args.pop(0) logging.info({"cwd": cwd, "args": args, "file": file}) - return ctypes.windll.shell32.ShellExecuteW(None, "runas", file, " ".join([f"{arg}" for arg in args]), cwd, 1) + return ctypes.windll.shell32.ShellExecuteW(None, "runas", str(file), " ".join([f"{arg}" for arg in args]), cwd, 1) @staticmethod def admin_check() -> bool: diff --git a/DMMGamePlayerFastLauncher/tab/shortcut.py b/DMMGamePlayerFastLauncher/tab/shortcut.py index a729797..711f806 100644 --- a/DMMGamePlayerFastLauncher/tab/shortcut.py +++ b/DMMGamePlayerFastLauncher/tab/shortcut.py @@ -1,6 +1,7 @@ import json from pathlib import Path from tkinter import Frame, StringVar +from typing import Callable import customtkinter as ctk import i18n @@ -105,14 +106,12 @@ def save(self): with open(path, "w", encoding="utf-8") as f: f.write(json.dumps(self.data.to_dict())) - def failed_save(self): - path = DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json") - path.unlink() + def save_handler(self, fn: Callable[[], None]): + pass @error_toast def bypass_callback(self): - self.save() - try: + def fn(): task = Schtasks(self.filename.get()) if task.check(): task.set() @@ -121,53 +120,52 @@ def bypass_callback(self): except Exception: name, icon = self.filename.get(), None self.toast.error(i18n.t("app.shortcut.game_info_error")) - sorce = Env.DESKTOP.joinpath(name).with_suffix(".lnk") args = ["/run", "/tn", task.name] Shortcut().create(sorce=sorce, target=Env.SCHTASKS, args=args, icon=icon) self.toast.info(i18n.t("app.shortcut.save_success")) - except Exception: - self.failed_save() - raise + + self.save_handler(fn) @error_toast def uac_callback(self): - self.save() - try: + def fn(): try: - name, icon, admin = self.get_game_info() + try: + name, icon, admin = self.get_game_info() + except Exception: + name, icon = self.filename.get(), None + self.toast.error(i18n.t("app.shortcut.game_info_error")) + sorce = Env.DESKTOP.joinpath(name).with_suffix(".lnk") + args = [self.filename.get()] + Shortcut().create(sorce=sorce, args=args, icon=icon) + self.toast.info(i18n.t("app.shortcut.save_success")) except Exception: - name, icon = self.filename.get(), None - self.toast.error(i18n.t("app.shortcut.game_info_error")) + DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() + raise - sorce = Env.DESKTOP.joinpath(name).with_suffix(".lnk") - args = [self.filename.get()] - Shortcut().create(sorce=sorce, args=args, icon=icon) - self.toast.info(i18n.t("app.shortcut.save_success")) - except Exception: - self.failed_save() - raise + self.save_handler(fn) @error_toast def save_callback(self): - self.save() - try: + def fn(): try: - name, icon, admin = self.get_game_info() + try: + name, icon, admin = self.get_game_info() + except Exception: + name, icon, admin = self.filename.get(), None, False + self.toast.error(i18n.t("app.shortcut.game_info_error")) + if admin: + raise Exception(i18n.t("app.shortcut.administrator_error")) except Exception: - name, icon, admin = self.filename.get(), None, False - self.toast.error(i18n.t("app.shortcut.game_info_error")) - - if admin: - raise Exception(i18n.t("app.shortcut.administrator_error")) - + DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() + raise sorce = Env.DESKTOP.joinpath(name).with_suffix(".lnk") args = [self.filename.get()] Shortcut().create(sorce=sorce, args=args, icon=icon) self.toast.info(i18n.t("app.shortcut.save_success")) - except Exception: - self.failed_save() - raise + + self.save_handler(fn) @error_toast def save_only_callback(self): @@ -207,6 +205,10 @@ def create(self): super().create() return self + def save_handler(self, fn: Callable[[], None]): + self.save() + fn() + class ShortcutEdit(ShortcutBase): selected: StringVar @@ -231,23 +233,23 @@ def create(self): return self - def save(self): - selected = DataPathConfig.SHORTCUT.joinpath(self.selected.get()).with_suffix(".json") - selected.rename(selected.with_suffix(".json.bak")) + def save_handler(self, fn: Callable[[], None]): + selected = DataPathConfig.SHORTCUT.joinpath(self.selected.get()) + selected.with_suffix(".json").rename(selected.with_suffix(".json.bak")) try: - super().save() - selected.with_suffix(".json.bak").unlink() - self.values.remove(self.selected.get()) - self.values.append(self.filename.get()) - self.selected.set(self.filename.get()) - self.option_callback("_") + self.save() + try: + fn() + except Exception: + DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() except Exception: - self.failed_save() + selected.with_suffix(".json.bak").rename(selected.with_suffix(".json")) raise - - def failed_save(self): - selected = DataPathConfig.SHORTCUT.joinpath(self.selected.get()).with_suffix(".json") - selected.with_suffix(".json.bak").rename(selected.with_suffix(".json")) + selected.with_suffix(".json.bak").unlink() + self.values.remove(self.selected.get()) + self.values.append(self.filename.get()) + self.selected.set(self.filename.get()) + self.option_callback("_") @error_toast def delete_callback(self): From 97cd066d2e5aa10d331bd0e64162c0e8760076bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Sat, 24 Feb 2024 02:28:22 +0900 Subject: [PATCH 5/5] update version 5.5.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- DMMGamePlayerFastLauncher/static/env.py | 2 +- DMMGamePlayerFastLauncher/static/loder.py | 2 +- setup.iss | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DMMGamePlayerFastLauncher/static/env.py b/DMMGamePlayerFastLauncher/static/env.py index 8041508..ee6860a 100644 --- a/DMMGamePlayerFastLauncher/static/env.py +++ b/DMMGamePlayerFastLauncher/static/env.py @@ -8,7 +8,7 @@ class Env(Dump): - VERSION = "v5.5.1" + VERSION = "v5.5.2" RELEASE_VERSION = requests.get(UrlConfig.RELEASE_API).json().get("tag_name", VERSION) DEVELOP: bool = os.environ.get("ENV") == "DEVELOP" diff --git a/DMMGamePlayerFastLauncher/static/loder.py b/DMMGamePlayerFastLauncher/static/loder.py index 3ae6e66..298a04f 100644 --- a/DMMGamePlayerFastLauncher/static/loder.py +++ b/DMMGamePlayerFastLauncher/static/loder.py @@ -40,7 +40,7 @@ def config_migrate(): version = Version(AppConfig.DATA.last_version.get() or "v0.0.0") logging.info(f"Migration from {version} to {Env.VERSION}") - if version < Version("v5.5.0"): + if version < Version("v5.5.2"): logging.info("Migration from v5.5.0 to v5.5.1") Path(AssetsPathConfig.I18N).joinpath("app.ja.yml").unlink(missing_ok=True) Path(AssetsPathConfig.I18N).joinpath("app.en.yml").unlink(missing_ok=True) diff --git a/setup.iss b/setup.iss index 2e96b63..955cb06 100644 --- a/setup.iss +++ b/setup.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "DMMGamePlayerFastLauncher" -#define MyAppVersion "5.5.1" +#define MyAppVersion "5.5.2" #define MyAppPublisher "yuki" #define MyAppURL "https://github.com/fa0311/DMMGamePlayerFastLauncher" #define MyAppExeName "DMMGamePlayerFastLauncher.exe"