Skip to content

Instantly share code, notes, and snippets.

@apsun
Created October 19, 2015 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apsun/d969919e0044bf4f07c7 to your computer and use it in GitHub Desktop.
Save apsun/d969919e0044bf4f07c7 to your computer and use it in GitHub Desktop.
import zipfile
import shutil
import os
import errno
import tempfile
# Path containing game files (main.lua should be in this directory)
SRC_PATH = "D:\Files\Documents\IdeaProjects\OpenFire\src"
# Name of the executable file in the output directory/zip file
GAME_EXECUTABLE = "openfire.exe"
# Path to the output directory
DEST_PATH = None
# Path to the output zip file
ZIP_PATH = "D:\Files\Desktop\openfire.zip"
# Path to the love installation directory (without the executable name)
LOVE_PATH = "C:\Program Files\love"
# Name of the love executable file (love.exe)
LOVE_EXECUTABLE = "love.exe"
# Dependencies to copy to the output directory/zip file
DEPENDENCIES = [
"DevIL.dll",
"love.dll",
"lua51.dll",
"mpg123.dll",
"msvcp110.dll",
"msvcr110.dll",
"OpenAL32.dll",
"SDL2.dll",
"license.txt"
]
def main():
global DEST_PATH
if DEST_PATH is None and ZIP_PATH is None:
print("At least one of DEST_PATH or ZIP_PATH must be specified!")
return
# Create destination path
using_temp_path = False
if DEST_PATH is not None:
print("Ensuring destination path exists...")
try:
os.makedirs(DEST_PATH)
except OSError as ex:
if ex.errno != errno.EEXIST:
raise
else:
DEST_PATH = tempfile.mkdtemp()
using_temp_path = True
# Copy love executable
game_exe_path = os.path.join(DEST_PATH, GAME_EXECUTABLE)
print("Copying love executable...")
shutil.copyfile(os.path.join(LOVE_PATH, LOVE_EXECUTABLE), game_exe_path)
# Append ZIP to love executable
print("Appending game archive to executable...")
zf = zipfile.ZipFile(game_exe_path, "a", zipfile.ZIP_DEFLATED)
# Add game files to ZIP file
print("Adding game files...")
for dirname, subdirs, files in os.walk(SRC_PATH):
for filename in files:
full_path = os.path.join(dirname, filename)
relative_path = os.path.relpath(full_path, SRC_PATH)
print("+ " + relative_path)
zf.write(full_path, relative_path)
# Flush changes to disk
print("Saving game executable...")
zf.close()
# Copy other dependencies
if not using_temp_path:
print("Copying dependencies...")
for filename in DEPENDENCIES:
print("* " + filename)
shutil.copy(os.path.join(LOVE_PATH, filename), DEST_PATH)
# Add files to distribution ZIP
if ZIP_PATH is not None:
print("Creating distribution ZIP...")
zf = zipfile.ZipFile(ZIP_PATH, "w", zipfile.ZIP_DEFLATED)
print("Adding game executable to distribution ZIP...")
zf.write(game_exe_path, GAME_EXECUTABLE)
print("Adding dependencies to distribution ZIP...")
for filename in DEPENDENCIES:
print("+ " + filename)
zf.write(os.path.join(LOVE_PATH, filename), filename)
if using_temp_path:
print("Deleting temporary directory...")
shutil.rmtree(DEST_PATH)
print("Done!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment