Hopefully improve packaging. This is experimental and may have to be removed.
This commit is contained in:
41
move_dirs_hook.py
Normal file
41
move_dirs_hook.py
Normal 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
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user