diff --git a/game_engine_save_as_runtime.py b/game_engine_save_as_runtime.py index f55e2f6de385e3683c78ed57fc4e30e385a6fe58..588b0904a1e7c2d5bdf8727bf5fca8879153ba1a 100644 --- a/game_engine_save_as_runtime.py +++ b/game_engine_save_as_runtime.py @@ -17,7 +17,7 @@ # ##### END GPL LICENSE BLOCK ##### bl_info = { - 'name': 'Save As Runtime', + 'name': 'Save As Game Engine Runtime', 'author': 'Mitchell Stokes (Moguri)', 'version': (0, 3, 1), "blender": (2, 5, 8), @@ -37,6 +37,25 @@ import sys import shutil +def CopyPythonLibs(dst, overwrite_lib): + import sysconfig + src = sysconfig.get_paths()['platstdlib'] + # X.XX/python/lib --> X.XX/python/lib/pythonX.X + dst = os.path.join(dst, os.path.basename(src)) + if os.path.exists(src): + write = False + if os.path.exists(dst): + if overwrite_lib: + shutil.rmtree(dst) + write = True + else: + write = True + if write: + shutil.copytree(src, dst, ignore=lambda dir, contents: [i for i in contents if i == '__pycache__']) + else: + print("Python not found in %r, skipping pythn copy." % src) + + def WriteAppleRuntime(player_path, output_path, copy_python, overwrite_lib): # Enforce the extension if not output_path.endswith('.app'): @@ -52,16 +71,8 @@ def WriteAppleRuntime(player_path, output_path, copy_python, overwrite_lib): if copy_python: print("Copying Python files...", end=" ") - src = os.path.join(blender_dir, "%d.%d" % bpy.app.version[:2], "python", "lib") dst = os.path.join(output_path, "..") - - if os.path.exists(dst): - if overwrite_lib: - shutil.rmtree(dst) - shutil.copytree(src, dst, ignore=lambda dir, contents: [i for i in contents if i.endswith('.pyc')]) - else: - shutil.copytree(src, dst, ignore=lambda dir, contents: [i for i in contents if i.endswith('.pyc')]) - + CopyPythonLibs(dst, overwrite_lib) print("done") @@ -132,25 +143,14 @@ def WriteRuntime(player_path, output_path, copy_python, overwrite_lib, copy_dlls if copy_python: print("Copying Python files...", end=" ") py_folder = os.path.join(bpy.app.version_string.split()[0], "python", "lib") - src = os.path.join(blender_dir, py_folder) dst = os.path.join(runtime_dir, py_folder) - - if os.path.exists(src): - if os.path.exists(dst): - if overwrite_lib: - shutil.rmtree(dst) - shutil.copytree(src, dst, ignore=lambda dir, contents: [i for i in contents if i == '__pycache__']) - else: - shutil.copytree(src, dst, ignore=lambda dir, contents: [i for i in contents if i == '__pycache__']) - else: - print("Python not found in %r, skipping pythn copy." % src) - + CopyPythonLibs(dst, overwrite_lib) print("done") # And DLLs if copy_dlls: print("Copying DLLs...", end=" ") - for file in [i for i in os.listdir(blender_dir) if i.endswith('.dll')]: + for file in [i for i in os.listdir(blender_dir) if i.lower().endswith('.dll')]: src = os.path.join(blender_dir, file) dst = os.path.join(runtime_dir, file) shutil.copy2(src, dst) @@ -162,7 +162,7 @@ from bpy.props import * class SaveAsRuntime(bpy.types.Operator): bl_idname = "wm.save_as_runtime" - bl_label = "Save As Runtime" + bl_label = "Save As Game Engine Runtime" bl_options = {'REGISTER'} if sys.platform == 'darwin': @@ -171,7 +171,7 @@ class SaveAsRuntime(bpy.types.Operator): else: blender_bin_path = bpy.app.binary_path blender_bin_dir = os.path.dirname(blender_bin_path) - ext = os.path.splitext(blender_bin_path)[-1] + ext = os.path.splitext(blender_bin_path)[-1].lower() default_player_path = os.path.join(blender_bin_dir, 'blenderplayer' + ext) player_path = StringProperty(name="Player Path", description="The path to the player to use", default=default_player_path)