From 525c9d756368aa029069a73f1318c58869ad60f8 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 26 Sep 2025 17:04:13 -0400 Subject: [PATCH] Hopefully improve packaging. This is experimental and may have to be removed. --- move_dirs_hook.py | 41 +++++++++++++++++++++++++++++++++++++++++ wicked_quest.spec | 6 ++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 move_dirs_hook.py diff --git a/move_dirs_hook.py b/move_dirs_hook.py new file mode 100644 index 0000000..00f0ed7 --- /dev/null +++ b/move_dirs_hook.py @@ -0,0 +1,41 @@ +import os +import sys +import shutil + +# Runtime hook to move directories and files from _internal to parent directory +if hasattr(sys, '_MEIPASS'): + # We're running from a PyInstaller bundle + bundle_dir = os.path.dirname(sys.executable) + internal_dir = sys._MEIPASS + + # Directories to move from _internal to parent + dirs_to_move = ['levels', 'sounds', 'libstormgames'] + + # Files to move from _internal to parent + files_to_move = ['files', 'logo.png'] + + # Move directories + for dir_name in dirs_to_move: + internal_path = os.path.join(internal_dir, dir_name) + target_path = os.path.join(bundle_dir, dir_name) + + # Only move if source exists and target doesn't exist + if os.path.exists(internal_path) and not os.path.exists(target_path): + try: + shutil.move(internal_path, target_path) + except Exception as e: + # Silently fail if we can't move - game will still work from _internal + pass + + # Move files + for file_name in files_to_move: + internal_path = os.path.join(internal_dir, file_name) + target_path = os.path.join(bundle_dir, file_name) + + # Only move if source exists and target doesn't exist + if os.path.exists(internal_path) and not os.path.exists(target_path): + try: + shutil.move(internal_path, target_path) + except Exception as e: + # Silently fail if we can't move - game will still work from _internal + pass \ No newline at end of file diff --git a/wicked_quest.spec b/wicked_quest.spec index 0a57a19..cc3a0be 100644 --- a/wicked_quest.spec +++ b/wicked_quest.spec @@ -18,11 +18,13 @@ a = Analysis( datas=level_dirs + [ ('sounds', 'sounds'), ('libstormgames', 'libstormgames'), + ('files', 'files'), + ('logo.png', '.'), ], hiddenimports=[], hookspath=[], hooksconfig={}, - runtime_hooks=[], + runtime_hooks=['move_dirs_hook.py'], excludes=[], noarchive=False, optimize=0, @@ -39,7 +41,7 @@ exe = EXE( bootloader_ignore_signals=False, strip=False, upx=True, - console=True, + console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None,