Jump to content

Ultimate MakePack Python Script Helper


Recommended Posts

  • Former Staff

hello guys i wrote this script to help using makepack

import glob, os , shutil, sys
from os import path , system
executefile = "execute.cmd"
logfolder = "logs"
packfile = "D:\Husam\Client\pack/"
packedfolder = "packed/"
text = ".txt"
ivfilename = ""
type = ""
comptype = ""
file_list = []
def yes_no(question, default="yes"):
	valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
	if default is None:
		prompt = " [y/n] "
	elif default == "yes":
		prompt = " [Y/n] "
	elif default == "no":
		prompt = " [y/N] "
	else:
		raise ValueError("invalid default answer: '%s'" % default)

	
	sys.stdout.write(question + prompt)
	choice = raw_input().lower()
	if default is not None and choice == '':
		return valid[default]
	if choice in valid:
		return valid[choice]
	else:
		sys.stdout.write("Please respond with 'yes' or 'no' ", "(or 'y' or 'n').\n")

def get_size(dirname):
	total_size = 0
	for dirpath, dirnames, filenames in os.walk(dirname):
		for f in filenames:
			fp = os.path.join(dirpath, f)
			total_size += os.path.getsize(fp)
	return total_size
	
def createpack(filename, dirname):
	if get_size(dirname) == 0:
		print("This is an empty folder [%s]"% (dirname))
		exit()
	print("Please Chose the type of pack you want to create\n")
	print("1:CompressExtNameList --> type 1")
	print("2:SecurityExtNameList --> type 2")
	print("3:panamaextnamelist --> type 3")
	print("4:cshybridencryptexenamelist --> type 4\n")
	type = raw_input("Your Choice:")
	type = int(type)
	if type < 0 or type > 4:
		print ("Please Type one number Bettwen 1 - 5")
	if type == 1:
		comptype = "CompressExtNameList";
	if type == 2:
		comptype = "SecurityExtNameList";
	if type == 3:
		comptype = "panamaextnamelist";
	if type == 4:
		comptype = "cshybridencryptexenamelist";
	makeit = filename + text
	check(makeit,1,"no")
	x = open(makeit, 'w')
	x.write("FolderName\t\"%s\"\nPackName\t\"%s\"\n"% (packedfolder, filename))
	if type == 3:
		pack = os.path.join(packfile,filename)
		check(pack,0,"yes")
		x.write("IV\t\"%s\"\n"% (pack))
	x.write("\nList\t%s\n{\n" % (comptype))
	chkdict = {}
	setdef = chkdict.setdefault
	for root, dirs, files in os.walk(dirname):
		for file in files:
			ext = path.splitext(file)[1]
			if not ext in chkdict:
				x.write("\t\"%s\"\n" % setdef(ext,ext))
	del chkdict
	x.write("}\n")
	x.write("\nList\tFilelist\n{\n")
	for root, dirs, files in os.walk(dirname):
		for filesname in files :
			filepath = os.path.join(root,filesname)
			if os.stat(filepath).st_size==0:
				continue
			x.write("\t\"%s\"\n" %(filepath))
	x.write("}\n")

def	extract_writer(type, iv):
	global ivfilename , file_list
	check("",0,"no")
	if not os.listdir(packfile): 
		print("Error: %s folder is empty \nsystem will close the script now"%(packfile))
		system("pause")# this is an optinal command if you want to see what is going on
		return
	listofpacks()
	pack = raw_input("Pack Number:")
	pack = int(pack)
	file = file_list[pack]
	index = file + ".eix"
	y = check(index,0,"no")
	if y == True:
		file2 = os.path.join(packfile,file)
		if iv == True:
			ivfilename = file2
		x = open(executefile, 'a') #open extract.cmd
		x.write("MakePack.exe --%s %s %s\t> logs/%s_log.txt\t 2> logs/%s_error.txt\n" % (type,file2, ivfilename, file, file))
		print("MakePack.exe --%s %s %s\n" % (type,file2, ivfilename)) #show you on screen what are the file 
	else:
		return
	x.close()
	executeMakePackfiles(executefile)
	
def check(filename,remove,IVa="no"):
	if filename == ""  and remove == 0:
		if os.path.isfile(executefile):
			os.remove(executefile)
		if not os.path.isdir(logfolder):
			os.system("mkdir %s" % (logfolder))
		if not os.path.isdir(packfile):
			os.system("mkdir pack")
		return True
	elif os.path.splitext(filename)[1] == ".eix":
		filename = os.path.join(packfile,filename)
		if os.path.isfile(filename):
			return True
		print("[%s] Is missing"%(filename))
		return False
	if filename != "":
		if os.path.isfile(filename) or os.path.isdir(filename):
			if remove == 1:
				os.remove(filename)
			if IVa == "yes":
				os.system("MakePack.exe --createiv %s"%(filename))

#run extract.cmd to execute the commands
def	executeMakePackfiles(filename):
	answer = yes_no("Do you Want to run %s?" %(filename),"yes")
	if True == answer:
		if filename == executefile:
			os.system(executefile)
		else:
			os.system("MakePack.exe %s" %(filename))
	else:
		system("pause")# this is an optinal command if you want to see what is going on
	main()

def listofpacks():
	global file_list
	i = 0
	file_count = len(glob.glob("%s*.epk"%(packfile)))
	for file in glob.glob("%s*.epk"%(packfile)): #search for any file with the (.epk) extention
		file = path.basename(file)
		file = path.splitext(file)[0] #removeing extention [xxx.epk ---> xxx (without (.epk))]
		file_list.append(file)
		#
	while i < file_count:
		filo = file_list[i]
		filo = ("%d:%s" % (i,filo))
		print filo
		i += 1

def cls():
	os.system("cls")

def main():
	print ("Hello This is Make Pack pythn tool")
	print ("type the number of the command you want to execute")
	print ("1:Create-iv\n2:Open-iv\n3:Extract\n4:Extract With Iv\n5:Make Pack\n6:Exit")
	choice = raw_input("Your Choice:")
	choice = int(choice)
	if choice < 1 or choice > 6:
		print ("Please Type one number Bettwen 1 - 6")
	if choice >= 1 and choice <= 4:
		if choice == 1:
			executetype = "createiv"
			iv = bool(False)
		elif choice == 2:
			executetype = "openiv"
			iv = bool(False)
		elif choice == 3:
			executetype = "extract"
			iv = bool(False)
		elif choice == 4:
			executetype = "extract"
			iv = bool(True)
		cls()
		extract_writer(executetype, iv)
	if choice == 5:
		packname = raw_input("Pack Name:")
		path = raw_input("Path:")
		createpack(packname,path)
		packname2 = packname + text
		executeMakePackfiles(packname2)
		system("pause")# this is an optinal command if you want to see what is going on
		main()
	if choice == 6:
		exit()
main()

 

now I'm not a python expert so if any expert here can tell me some notes on how to write better code it would very nice

plus if any one want my version of make pack just tell me to upload it

now my only problem here is that thae script writes only one type of compressing types using by the binary

i you can't use the script to write something like this fro example  YET

List	SecurityExtNameList
{
	".dds"
	".tga"
	".jpg"
}
List	Panamaextnamelist
{
	".msenv"
	".sub"
}

but anyway the script generates something look like this

FolderName	"packed"
PackName	"etc"

List	SecurityExtNameList
{
	".msenv"
	".dds"
	".tga"
	".sub"
	".jpg"
}

List	Filelist
{
	"ymir work\environment\a1.msenv"
	"....."
}

#Updated with IV file check for panama type .. thanks to metin2team for noticing the mistake 

#updated with file size check ... ---> make pack wont pack 0 sized  file  so the script ignores the 0 file :)

#updated ... now after any command you do the script restarts from the beginning ...because the python window closes after the code is done

#update --> now you can specify the pack

Edited by flygun
  • Good 1
  • Love 4
Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.