diff --git a/DMMGamePlayerFastLauncher/lib/process_manager.py b/DMMGamePlayerFastLauncher/lib/process_manager.py index 51c0374..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 + 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/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 e9d69db..298a04f 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)) @@ -35,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/DMMGamePlayerFastLauncher/tab/shortcut.py b/DMMGamePlayerFastLauncher/tab/shortcut.py index 0915411..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,10 +106,12 @@ def save(self): with open(path, "w", encoding="utf-8") as f: f.write(json.dumps(self.data.to_dict())) + 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() @@ -117,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: - DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() - 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: - DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() - 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: - DataPathConfig.SHORTCUT.joinpath(self.filename.get()).with_suffix(".json").unlink() - raise + + self.save_handler(fn) @error_toast def save_only_callback(self): @@ -203,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 @@ -227,19 +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: selected.with_suffix(".json.bak").rename(selected.with_suffix(".json")) raise + 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): 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"