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 = ['sounds', 'libstormgames'] # Directories to copy (keep in both locations) dirs_to_copy = ['levels'] # 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 # Copy directories (keep in both locations) for dir_name in dirs_to_copy: internal_path = os.path.join(internal_dir, dir_name) target_path = os.path.join(bundle_dir, dir_name) # Only copy if source exists and target doesn't exist if os.path.exists(internal_path) and not os.path.exists(target_path): try: shutil.copytree(internal_path, target_path) except Exception as e: # Silently fail if we can't copy - 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 at least enough to exit. pass