From 6f678ec0a48415e93b7910a45376786dd22a0d26 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 9 Sep 2026 00:19:35 +0200 Subject: [PATCH] feat(assets): support PyInstaller sys._MEIPASS frozen asset bundle path --- catser/assets_manager.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/catser/assets_manager.py b/catser/assets_manager.py index 94e08a9..fa355ff 100644 --- a/catser/assets_manager.py +++ b/catser/assets_manager.py @@ -14,6 +14,7 @@ Assets managed: """ import os +import sys import re import json import math @@ -48,9 +49,12 @@ def _download_file(url: str, dest_path: Path) -> bool: Downloads a file with custom User-Agent to avoid Cloudflare 403 blocks. Returns True on success, False otherwise. """ - dest_path.parent.mkdir(parents=True, exist_ok=True) if dest_path.exists() and dest_path.stat().st_size > 0: return True + try: + dest_path.parent.mkdir(parents=True, exist_ok=True) + except Exception: + pass try: req = urllib.request.Request(url, headers={"User-Agent": USER_AGENT}) @@ -84,7 +88,14 @@ class AssetsManager: """ def __init__(self, assets_dir: Optional[Path] = None, cat_width: int = 144, config: Optional[Config] = None): - self.assets_dir = assets_dir or (Path(__file__).parent / "assets") + if assets_dir: + self.assets_dir = assets_dir + elif getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): + mei_catser = Path(sys._MEIPASS) / "catser" / "assets" + self.assets_dir = mei_catser if mei_catser.exists() else (Path(sys._MEIPASS) / "assets") + else: + self.assets_dir = Path(__file__).parent / "assets" + self.config = config or Config(cat_width=cat_width) self.cat_width = self.config.cat_width self.cat_height = self.config.cat_height @@ -106,7 +117,10 @@ class AssetsManager: def initialize(self) -> None: """Downloads all missing assets and prepares raw frames.""" - self.assets_dir.mkdir(parents=True, exist_ok=True) + try: + self.assets_dir.mkdir(parents=True, exist_ok=True) + except Exception: + pass self._ensure_assets_downloaded() self._load_raw_assets()