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
|
||||
Reference in New Issue
Block a user