|
@@ -12,14 +12,14 @@
|
|
|
#
|
|
#
|
|
|
##############################################################################
|
|
##############################################################################
|
|
|
|
|
|
|
|
-import sys,os,getopt,compileall
|
|
|
|
|
|
|
+import sys,os,getopt,string,shutil,py_compile
|
|
|
|
|
|
|
|
OPTIONLIST = [
|
|
OPTIONLIST = [
|
|
|
("game", 1, "Name of directory containing game"),
|
|
("game", 1, "Name of directory containing game"),
|
|
|
("version", 1, "Version number to add to game name"),
|
|
("version", 1, "Version number to add to game name"),
|
|
|
("fast", 0, "Use fast compression instead of good compression"),
|
|
("fast", 0, "Use fast compression instead of good compression"),
|
|
|
-("bam", 0, "Convert all EGG files to BAM"),
|
|
|
|
|
-("pyc", 0, "Convert all PY files to PYC"),
|
|
|
|
|
|
|
+("cplegg", 0, "Convert all EGG files to BAM"),
|
|
|
|
|
+("cplpy", 0, "Convert all PY files to PYC"),
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
def ParseFailure():
|
|
def ParseFailure():
|
|
@@ -55,7 +55,27 @@ OPTIONS = ParseOptions(sys.argv[1:])
|
|
|
|
|
|
|
|
##############################################################################
|
|
##############################################################################
|
|
|
#
|
|
#
|
|
|
-# Identify the main parts of the game: GAME, NAME, MAIN, ICON, IMAGE
|
|
|
|
|
|
|
+# Locate the relevant trees.
|
|
|
|
|
+#
|
|
|
|
|
+##############################################################################
|
|
|
|
|
+
|
|
|
|
|
+PANDA=None
|
|
|
|
|
+for dir in sys.path:
|
|
|
|
|
+ if os.path.exists(os.path.join(dir,"direct")) and os.path.exists(os.path.join(dir,"pandac")) and os.path.exists(os.path.join(dir,"python")):
|
|
|
|
|
+ PANDA=os.path.abspath(dir)
|
|
|
|
|
+if (PANDA is None):
|
|
|
|
|
+ sys.exit("Cannot locate the panda root directory in the python path (cannot locate directory containing direct and pandac).")
|
|
|
|
|
+
|
|
|
|
|
+if (os.path.exists(os.path.join("PANDA","..","makepanda","makepanda.py"))) and (os.path.exists(os.path.join("PANDA","..","thirdparty","win-nsis","makensis.exe"))):
|
|
|
|
|
+ PSOURCE=os.path.abspath(os.path.join(PANDA,".."))
|
|
|
|
|
+ NSIS=os.path.abspath(os.path.join(PANDA,"..","thirdparty","win-nsis"))
|
|
|
|
|
+else:
|
|
|
|
|
+ PSOURCE=PANDA
|
|
|
|
|
+ NSIS=os.path.join(PANDA,"nsis")
|
|
|
|
|
+
|
|
|
|
|
+##############################################################################
|
|
|
|
|
+#
|
|
|
|
|
+# Identify the main parts of the game: GAME, NAME, MAIN, ICON, BITMAP, etc
|
|
|
#
|
|
#
|
|
|
##############################################################################
|
|
##############################################################################
|
|
|
|
|
|
|
@@ -66,16 +86,18 @@ if (GAME==""):
|
|
|
ParseFailure()
|
|
ParseFailure()
|
|
|
GAME=os.path.abspath(GAME)
|
|
GAME=os.path.abspath(GAME)
|
|
|
NAME=os.path.basename(GAME)
|
|
NAME=os.path.basename(GAME)
|
|
|
-STARTMENU=os.path.basename(GAME)
|
|
|
|
|
-if (VER!=""): STARTMENU=STARTMENU+" "+VER
|
|
|
|
|
-MAIN=NAME+".py"
|
|
|
|
|
|
|
+SMDIRECTORY=os.path.basename(GAME)
|
|
|
|
|
+if (VER!=""): SMDIRECTORY=SMDIRECTORY+" "+VER
|
|
|
|
|
+if (OPTIONS["cplpy"]): MAIN=NAME+".pyc"
|
|
|
|
|
+else: MAIN=NAME+".py"
|
|
|
ICON=os.path.join(GAME,NAME+".ico")
|
|
ICON=os.path.join(GAME,NAME+".ico")
|
|
|
-IMAGE=os.path.join(GAME,NAME+".bmp")
|
|
|
|
|
-OUTPUT=os.path.basename(GAME)
|
|
|
|
|
-if (VER!=""): OUTPUT=OUTPUT+"-"+VER
|
|
|
|
|
-OUTPUT=os.path.abspath(OUTPUT+".exe")
|
|
|
|
|
-INSTALLTO='C:\\'+os.path.basename(GAME)
|
|
|
|
|
-if (VER!=""): INSTALLTO=INSTALLTO+"-"+VER
|
|
|
|
|
|
|
+BITMAP=os.path.join(GAME,NAME+".bmp")
|
|
|
|
|
+LICENSE=os.path.join(GAME,"LICENSE.TXT")
|
|
|
|
|
+OUTFILE=os.path.basename(GAME)
|
|
|
|
|
+if (VER!=""): OUTFILE=OUTFILE+"-"+VER
|
|
|
|
|
+OUTFILE=os.path.abspath(OUTFILE+".exe")
|
|
|
|
|
+INSTALLDIR='C:\\'+os.path.basename(GAME)
|
|
|
|
|
+if (VER!=""): INSTALLDIR=INSTALLDIR+"-"+VER
|
|
|
COMPRESS="lzma"
|
|
COMPRESS="lzma"
|
|
|
if (OPTIONS["fast"]): COMPRESS="zlib"
|
|
if (OPTIONS["fast"]): COMPRESS="zlib"
|
|
|
|
|
|
|
@@ -87,38 +109,76 @@ def PrintFileStatus(label, file):
|
|
|
|
|
|
|
|
PrintFileStatus("Game",GAME)
|
|
PrintFileStatus("Game",GAME)
|
|
|
print "%-15s: %s"%("Name",NAME)
|
|
print "%-15s: %s"%("Name",NAME)
|
|
|
-print "%-15s: %s"%("Start Menu",STARTMENU)
|
|
|
|
|
|
|
+print "%-15s: %s"%("Start Menu",SMDIRECTORY)
|
|
|
PrintFileStatus("Main",os.path.join(GAME,MAIN))
|
|
PrintFileStatus("Main",os.path.join(GAME,MAIN))
|
|
|
PrintFileStatus("Icon",ICON)
|
|
PrintFileStatus("Icon",ICON)
|
|
|
-PrintFileStatus("Image",IMAGE)
|
|
|
|
|
-print "%-15s: %s"%("Output",OUTPUT)
|
|
|
|
|
-print "%-15s: %s"%("Install To",INSTALLTO)
|
|
|
|
|
|
|
+PrintFileStatus("Bitmap",BITMAP)
|
|
|
|
|
+PrintFileStatus("License",LICENSE)
|
|
|
|
|
+print "%-15s: %s"%("Output",OUTFILE)
|
|
|
|
|
+print "%-15s: %s"%("Install Dir",INSTALLDIR)
|
|
|
|
|
|
|
|
if (os.path.isdir(GAME)==0):
|
|
if (os.path.isdir(GAME)==0):
|
|
|
sys.exit("Difficulty reading "+GAME+". Cannot continue.")
|
|
sys.exit("Difficulty reading "+GAME+". Cannot continue.")
|
|
|
|
|
|
|
|
-if (os.path.isfile(os.path.join(GAME,MAIN))==0):
|
|
|
|
|
- sys.exit("Difficulty reading "+MAIN+". Cannot continue.")
|
|
|
|
|
|
|
+if (os.path.isfile(os.path.join(GAME,NAME+".py"))==0):
|
|
|
|
|
+ sys.exit("Difficulty reading "+NAME+".py. Cannot continue.")
|
|
|
|
|
+
|
|
|
|
|
+if (os.path.isfile(LICENSE)==0):
|
|
|
|
|
+ LICENSE=os.path.join(PANDA,"LICENSE")
|
|
|
|
|
+
|
|
|
|
|
+if (os.path.isfile(BITMAP)==0):
|
|
|
|
|
+ BITMAP=os.path.join(NSIS,"Contrib","Modern UI","Graphics","Wizard","nsis.bmp")
|
|
|
|
|
|
|
|
##############################################################################
|
|
##############################################################################
|
|
|
#
|
|
#
|
|
|
-# Locate the relevant trees.
|
|
|
|
|
|
|
+# If necessary, make a copy of the game for compilation purposes.
|
|
|
#
|
|
#
|
|
|
##############################################################################
|
|
##############################################################################
|
|
|
|
|
|
|
|
-PANDA=None
|
|
|
|
|
-for dir in sys.path:
|
|
|
|
|
- if os.path.exists(os.path.join(dir,"direct")) and os.path.exists(os.path.join(dir,"pandac")) and os.path.exists(os.path.join(dir,"python")):
|
|
|
|
|
- PANDA=os.path.abspath(dir)
|
|
|
|
|
-if (PANDA is None):
|
|
|
|
|
- sys.exit("Cannot locate the panda root directory in the python path (cannot locate directory containing direct and pandac).")
|
|
|
|
|
-
|
|
|
|
|
-if (os.path.exists(os.path.join("PANDA","..","makepanda","makepanda.py"))) and (os.path.exists(os.path.join("PANDA","..","thirdparty","win-nsis","makensis.exe"))):
|
|
|
|
|
- PSOURCE=os.path.abspath(os.path.join(PANDA,".."))
|
|
|
|
|
- NSIS=os.path.abspath(os.path.join(PANDA,"..","thirdparty","win-nsis"))
|
|
|
|
|
|
|
+EGG2BAM=os.path.join(PANDA,"bin","egg2bam.exe")
|
|
|
|
|
+
|
|
|
|
|
+def egg2bam(file):
|
|
|
|
|
+ orig = os.getcwd()
|
|
|
|
|
+ dir = os.path.dirname(file)
|
|
|
|
|
+ base = os.path.basename(file)
|
|
|
|
|
+ pre = base[:-4]
|
|
|
|
|
+ cmd = 'egg2bam -noabs "'+base+'" -o "'+pre+'.bam"'
|
|
|
|
|
+ print "Executing: "+cmd
|
|
|
|
|
+ os.chdir(dir)
|
|
|
|
|
+ res = os.spawnl(os.P_WAIT, EGG2BAM, cmd)
|
|
|
|
|
+ if (res != 0): sys.exit("Cannot convert egg to bam")
|
|
|
|
|
+ os.chdir(orig)
|
|
|
|
|
+ os.unlink(file)
|
|
|
|
|
+
|
|
|
|
|
+def py2pyc(file):
|
|
|
|
|
+ print "Compiling python "+file
|
|
|
|
|
+ try: py_compile.compile(file)
|
|
|
|
|
+ except: sys.exit("Cannot compile "+file)
|
|
|
|
|
+ os.unlink(file)
|
|
|
|
|
+
|
|
|
|
|
+def CompileFiles(file):
|
|
|
|
|
+ if (os.path.isfile(file)):
|
|
|
|
|
+ if OPTIONS["cplegg"] and (string.lower(file[-4:])==".egg"):
|
|
|
|
|
+ egg2bam(file)
|
|
|
|
|
+ elif OPTIONS["cplpy"] and (string.lower(file[-3:])==".py"):
|
|
|
|
|
+ py2pyc(file)
|
|
|
|
|
+ else: pass
|
|
|
|
|
+ elif (os.path.isdir(file)):
|
|
|
|
|
+ for x in os.listdir(file):
|
|
|
|
|
+ CompileFiles(os.path.join(file,x))
|
|
|
|
|
+
|
|
|
|
|
+if (OPTIONS["cplpy"] or OPTIONS["cplegg"]):
|
|
|
|
|
+ TMPDIR=os.path.abspath("packpanda-TMP")
|
|
|
|
|
+ print "Copying the game to "+TMPDIR+"..."
|
|
|
|
|
+ if (os.path.exists(TMPDIR)):
|
|
|
|
|
+ try: shutil.rmtree(TMPDIR)
|
|
|
|
|
+ except: sys.exit("Cannot delete "+TMPDIR)
|
|
|
|
|
+ try: shutil.copytree(GAME, TMPDIR)
|
|
|
|
|
+ except: sys.exit("Cannot copy game to "+TMPDIR)
|
|
|
|
|
+ print "Searching for files to compile in "+TMPDIR+"..."
|
|
|
|
|
+ CompileFiles(TMPDIR)
|
|
|
else:
|
|
else:
|
|
|
- PSOURCE=PANDA
|
|
|
|
|
- NSIS=os.path.join(PANDA,"nsis")
|
|
|
|
|
|
|
+ TMPDIR=GAME
|
|
|
|
|
|
|
|
##############################################################################
|
|
##############################################################################
|
|
|
#
|
|
#
|
|
@@ -128,18 +188,24 @@ else:
|
|
|
|
|
|
|
|
CMD=NSIS+"\\makensis.exe /V2 "
|
|
CMD=NSIS+"\\makensis.exe /V2 "
|
|
|
CMD=CMD+'/DCOMPRESSOR="'+COMPRESS+'" '
|
|
CMD=CMD+'/DCOMPRESSOR="'+COMPRESS+'" '
|
|
|
-CMD=CMD+'/DFULLNAME="'+NAME+'" '
|
|
|
|
|
-CMD=CMD+'/DSMDIRECTORY="'+STARTMENU+'" '
|
|
|
|
|
-CMD=CMD+'/DINSTALLDIR="'+INSTALLTO+'" '
|
|
|
|
|
|
|
+CMD=CMD+'/DNAME="'+NAME+'" '
|
|
|
|
|
+CMD=CMD+'/DSMDIRECTORY="'+SMDIRECTORY+'" '
|
|
|
|
|
+CMD=CMD+'/DINSTALLDIR="'+INSTALLDIR+'" '
|
|
|
|
|
+CMD=CMD+'/DOUTFILE="'+OUTFILE+'" '
|
|
|
|
|
+CMD=CMD+'/DLICENSE="'+LICENSE+'" '
|
|
|
|
|
+CMD=CMD+'/DLANGUAGE="English" '
|
|
|
|
|
+CMD=CMD+'/DRUNTEXT="Play '+NAME+'" '
|
|
|
|
|
+CMD=CMD+'/DIBITMAP="'+BITMAP+'" '
|
|
|
|
|
+CMD=CMD+'/DUBITMAP="'+BITMAP+'" '
|
|
|
CMD=CMD+'/DPANDA="'+PANDA+'" '
|
|
CMD=CMD+'/DPANDA="'+PANDA+'" '
|
|
|
CMD=CMD+'/DPSOURCE="'+PSOURCE+'" '
|
|
CMD=CMD+'/DPSOURCE="'+PSOURCE+'" '
|
|
|
-CMD=CMD+'/DOUTFILE="'+OUTPUT+'" '
|
|
|
|
|
-CMD=CMD+'/DPPGAMEID="'+NAME+'" '
|
|
|
|
|
-CMD=CMD+'/DPPGAMEPATH="'+GAME+'" '
|
|
|
|
|
-CMD=CMD+'/DPPGAMEPY="'+MAIN+'" '
|
|
|
|
|
|
|
+CMD=CMD+'/DPPGAME="'+TMPDIR+'" '
|
|
|
|
|
+CMD=CMD+'/DPPMAIN="'+MAIN+'" '
|
|
|
CMD=CMD+'"'+PSOURCE+'\\direct\\src\\directscripts\\packpanda.nsi"'
|
|
CMD=CMD+'"'+PSOURCE+'\\direct\\src\\directscripts\\packpanda.nsi"'
|
|
|
|
|
|
|
|
print ""
|
|
print ""
|
|
|
print CMD
|
|
print CMD
|
|
|
print "packing..."
|
|
print "packing..."
|
|
|
os.system(CMD)
|
|
os.system(CMD)
|
|
|
|
|
+
|
|
|
|
|
+
|