Advertisement
charparodar

MakePack Python Script - Credits: flygun - metin2dev.org

May 16th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.90 KB | None | 0 0
  1. import glob, os , shutil, sys
  2. from os import path , system
  3. executefile = "execute.cmd"
  4. logfolder = "logs"
  5. packfile = "D:\Client 40250\pack/"
  6. packedfolder = "packed/"
  7. text = ".txt"
  8. ivfilename = ""
  9. type = ""
  10. comptype = ""
  11. file_list = []
  12. def yes_no(question, default="yes"):
  13.     valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
  14.     if default is None:
  15.         prompt = " [y/n] "
  16.     elif default == "yes":
  17.         prompt = " [Y/n] "
  18.     elif default == "no":
  19.         prompt = " [y/N] "
  20.     else:
  21.         raise ValueError("invalid default answer: '%s'" % default)
  22.  
  23.    
  24.     sys.stdout.write(question + prompt)
  25.     choice = raw_input().lower()
  26.     if default is not None and choice == '':
  27.         return valid[default]
  28.     if choice in valid:
  29.         return valid[choice]
  30.     else:
  31.         sys.stdout.write("Please respond with 'yes' or 'no' ", "(or 'y' or 'n').\n")
  32.  
  33. def get_size(dirname):
  34.     total_size = 0
  35.     for dirpath, dirnames, filenames in os.walk(dirname):
  36.         for f in filenames:
  37.             fp = os.path.join(dirpath, f)
  38.             total_size += os.path.getsize(fp)
  39.     return total_size
  40.    
  41. def createpack(filename, dirname):
  42.     if get_size(dirname) == 0:
  43.         print("This is an empty folder [%s]"% (dirname))
  44.         exit()
  45.     print("Please Chose the type of pack you want to create\n")
  46.     print("1:CompressExtNameList --> type 1")
  47.     print("2:SecurityExtNameList --> type 2")
  48.     print("3:panamaextnamelist --> type 3")
  49.     print("4:cshybridencryptexenamelist --> type 4\n")
  50.     type = raw_input("Your Choice:")
  51.     type = int(type)
  52.     if type < 0 or type > 4:
  53.         print ("Please Type one number Bettwen 1 - 5")
  54.     if type == 1:
  55.         comptype = "CompressExtNameList";
  56.     if type == 2:
  57.         comptype = "SecurityExtNameList";
  58.     if type == 3:
  59.         comptype = "panamaextnamelist";
  60.     if type == 4:
  61.         comptype = "cshybridencryptexenamelist";
  62.     makeit = filename + text
  63.     check(makeit,1,"no")
  64.     x = open(makeit, 'w')
  65.     x.write("FolderName\t\"%s\"\nPackName\t\"%s\"\n"% (packedfolder, filename))
  66.     if type == 3:
  67.         pack = os.path.join(packfile,filename)
  68.         check(pack,0,"yes")
  69.         x.write("IV\t\"%s\"\n"% (pack))
  70.     x.write("\nList\t%s\n{\n" % (comptype))
  71.     chkdict = {}
  72.     setdef = chkdict.setdefault
  73.     for root, dirs, files in os.walk(dirname):
  74.         for file in files:
  75.             ext = path.splitext(file)[1]
  76.             if not ext in chkdict:
  77.                 x.write("\t\"%s\"\n" % setdef(ext,ext))
  78.     del chkdict
  79.     x.write("}\n")
  80.     x.write("\nList\tFilelist\n{\n")
  81.     for root, dirs, files in os.walk(dirname):
  82.         for filesname in files :
  83.             filepath = os.path.join(root,filesname)
  84.             if os.stat(filepath).st_size==0:
  85.                 continue
  86.             x.write("\t\"%s\"\n" %(filepath))
  87.     x.write("}\n")
  88.  
  89. def extract_writer(type, iv):
  90.     global ivfilename , file_list
  91.     check("",0,"no")
  92.     if not os.listdir(packfile):
  93.         print("Error: %s folder is empty \nsystem will close the script now"%(packfile))
  94.         system("pause")# this is an optinal command if you want to see what is going on
  95.         return
  96.     listofpacks()
  97.     pack = raw_input("Pack Number:")
  98.     pack = int(pack)
  99.     file = file_list[pack]
  100.     index = file + ".eix"
  101.     y = check(index,0,"no")
  102.     if y == True:
  103.         file2 = os.path.join(packfile,file)
  104.         if iv == True:
  105.             ivfilename = file2
  106.         x = open(executefile, 'a') #open extract.cmd
  107.         x.write("PackMaker.exe --%s %s %s\t> logs/%s_log.txt\t 2> logs/%s_error.txt\n" % (type,file2, ivfilename, file, file))
  108.         print("PackMaker.exe --%s %s %s\n" % (type,file2, ivfilename)) #show you on screen what are the file
  109.     else:
  110.         return
  111.     x.close()
  112.     executePackMakerfiles(executefile)
  113.    
  114. def check(filename,remove,IVa="no"):
  115.     if filename == ""  and remove == 0:
  116.         if os.path.isfile(executefile):
  117.             os.remove(executefile)
  118.         if not os.path.isdir(logfolder):
  119.             os.system("mkdir %s" % (logfolder))
  120.         if not os.path.isdir(packfile):
  121.             os.system("mkdir pack")
  122.         return True
  123.     elif os.path.splitext(filename)[1] == ".eix":
  124.         filename = os.path.join(packfile,filename)
  125.         if os.path.isfile(filename):
  126.             return True
  127.         print("[%s] Is missing"%(filename))
  128.         return False
  129.     if filename != "":
  130.         if os.path.isfile(filename) or os.path.isdir(filename):
  131.             if remove == 1:
  132.                 os.remove(filename)
  133.             if IVa == "yes":
  134.                 os.system("PackMaker.exe --createiv %s"%(filename))
  135.  
  136. #run extract.cmd to execute the commands
  137. def executePackMakerfiles(filename):
  138.     answer = yes_no("Do you Want to run %s?" %(filename),"yes")
  139.     if True == answer:
  140.         if filename == executefile:
  141.             os.system(executefile)
  142.         else:
  143.             os.system("PackMaker.exe %s" %(filename))
  144.     else:
  145.         system("pause")# this is an optinal command if you want to see what is going on
  146.     main()
  147.  
  148. def listofpacks():
  149.     global file_list
  150.     i = 0
  151.     file_count = len(glob.glob("%s*.epk"%(packfile)))
  152.     for file in glob.glob("%s*.epk"%(packfile)): #search for any file with the (.epk) extention
  153.         file = path.basename(file)
  154.         file = path.splitext(file)[0] #removeing extention [xxx.epk ---> xxx (without (.epk))]
  155.         file_list.append(file)
  156.         #
  157.     while i < file_count:
  158.         filo = file_list[i]
  159.         filo = ("%d:%s" % (i,filo))
  160.         print filo
  161.         i += 1
  162.  
  163. def cls():
  164.     os.system("cls")
  165.  
  166. def main():
  167.     print ("Hello This is Make Pack pythn tool")
  168.     print ("type the number of the command you want to execute")
  169.     print ("1:Create-iv\n2:Open-iv\n3:Extract\n4:Extract With Iv\n5:Make Pack\n6:Exit")
  170.     choice = raw_input("Your Choice:")
  171.     choice = int(choice)
  172.     if choice < 1 or choice > 6:
  173.         print ("Please Type one number Bettwen 1 - 6")
  174.     if choice >= 1 and choice <= 4:
  175.         if choice == 1:
  176.             executetype = "createiv"
  177.             iv = bool(False)
  178.         elif choice == 2:
  179.             executetype = "openiv"
  180.             iv = bool(False)
  181.         elif choice == 3:
  182.             executetype = "extract"
  183.             iv = bool(False)
  184.         elif choice == 4:
  185.             executetype = "extract"
  186.             iv = bool(True)
  187.         cls()
  188.         extract_writer(executetype, iv)
  189.     if choice == 5:
  190.         packname = raw_input("Pack Name:")
  191.         path = raw_input("Path:")
  192.         createpack(packname,path)
  193.         packname2 = packname + text
  194.         executePackMakerfiles(packname2)
  195.         system("pause")# this is an optinal command if you want to see what is going on
  196.         main()
  197.     if choice == 6:
  198.         exit()
  199. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement