Hopefully improve packaging. This is experimental and may have to be removed.

This commit is contained in:
Storm Dragon
2025-09-26 17:04:13 -04:00
parent 10f859136b
commit 525c9d7563
2 changed files with 45 additions and 2 deletions

41
move_dirs_hook.py Normal file
View File

@@ -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

View File

@@ -18,11 +18,13 @@ a = Analysis(
datas=level_dirs + [ datas=level_dirs + [
('sounds', 'sounds'), ('sounds', 'sounds'),
('libstormgames', 'libstormgames'), ('libstormgames', 'libstormgames'),
('files', 'files'),
('logo.png', '.'),
], ],
hiddenimports=[], hiddenimports=[],
hookspath=[], hookspath=[],
hooksconfig={}, hooksconfig={},
runtime_hooks=[], runtime_hooks=['move_dirs_hook.py'],
excludes=[], excludes=[],
noarchive=False, noarchive=False,
optimize=0, optimize=0,
@@ -39,7 +41,7 @@ exe = EXE(
bootloader_ignore_signals=False, bootloader_ignore_signals=False,
strip=False, strip=False,
upx=True, upx=True,
console=True, console=False,
disable_windowed_traceback=False, disable_windowed_traceback=False,
argv_emulation=False, argv_emulation=False,
target_arch=None, target_arch=None,