229 lines
6.5 KiB
Python
229 lines
6.5 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import json
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
import zipfile
|
||
|
|
import platform
|
||
|
|
from versionIssue import versionIssue
|
||
|
|
from ffEncrypt import ffEncrypt
|
||
|
|
import shutil
|
||
|
|
|
||
|
|
|
||
|
|
from tkinter import *
|
||
|
|
|
||
|
|
resSubFix = "../updateVersion/org_res/"
|
||
|
|
encryptSubFix = "../updateVersion/encrypt_res/"
|
||
|
|
hisSubFix = "../updateVersion/{}/version/history"
|
||
|
|
ediSubFix = "../updateVersion/{}/version/edition"
|
||
|
|
zipSubFix = "../updateVersion/{}/zip/"
|
||
|
|
|
||
|
|
start_version = ""
|
||
|
|
end_version = ""
|
||
|
|
enableEncrypt = False
|
||
|
|
|
||
|
|
|
||
|
|
skipFile = [ ".gitignore" ]
|
||
|
|
skipSuffix = [ ".meta" ]
|
||
|
|
skipFloder = [ ".svn", ".gradle", ".nomedia", ".idea", ".vscode", ".wing", "__pycache__" ]
|
||
|
|
|
||
|
|
systemName = platform.system().lower()
|
||
|
|
if( "darwin" == systemName ):
|
||
|
|
skipFile.append( ".DS_Store" )
|
||
|
|
|
||
|
|
|
||
|
|
def validName( name, isFloder ):
|
||
|
|
if isFloder:
|
||
|
|
return name not in skipFloder
|
||
|
|
else:
|
||
|
|
if name in skipFile:
|
||
|
|
return False
|
||
|
|
for suffix in skipSuffix:
|
||
|
|
if name.endswith( suffix ):
|
||
|
|
return False
|
||
|
|
return True
|
||
|
|
|
||
|
|
|
||
|
|
def get_pf_target():
|
||
|
|
return sys.argv[1]
|
||
|
|
|
||
|
|
def make_zip(start, end, xmls_dir, tmp, export):
|
||
|
|
stStartVersion = versionIssue( start )
|
||
|
|
stEndVersion = versionIssue( end )
|
||
|
|
for i in os.listdir(xmls_dir):
|
||
|
|
curBeginV = versionIssue(i.split('-')[0])
|
||
|
|
curEndV = versionIssue(i.split('-')[1].split('.')[0])
|
||
|
|
|
||
|
|
if not stStartVersion.biggerThen( curBeginV ) and not curEndV.biggerThen( stEndVersion ) :
|
||
|
|
copy_by_json(os.path.join(xmls_dir, i), tmp, export)
|
||
|
|
|
||
|
|
|
||
|
|
def copy_by_json(xml_file, tmp_dir, export_dir):
|
||
|
|
|
||
|
|
jsonString = ""
|
||
|
|
with open( xml_file, 'r', encoding='utf-8' ) as f:
|
||
|
|
jsonString = f.read()
|
||
|
|
|
||
|
|
fileList = []
|
||
|
|
if 0 < len(jsonString):
|
||
|
|
jsonRoot = json.loads( jsonString )
|
||
|
|
jsonList = jsonRoot.get("files")
|
||
|
|
for fileItem in jsonList:
|
||
|
|
fileList.append( fileItem.get("path") )
|
||
|
|
|
||
|
|
|
||
|
|
xml_name = os.path.basename(xml_file)
|
||
|
|
myzipfile = os.path.join(export_dir, xml_name.split('.json')[0]+'.zip')
|
||
|
|
f = zipfile.ZipFile(myzipfile, 'w', zipfile.ZIP_DEFLATED,True)
|
||
|
|
|
||
|
|
print('zip file: %s' % myzipfile)
|
||
|
|
|
||
|
|
for filename in fileList:
|
||
|
|
if os.path.exists(os.path.join(tmp_dir, filename)):
|
||
|
|
zip_write(filename, f, tmp_dir)
|
||
|
|
else:
|
||
|
|
print('missing file : %s' % filename)
|
||
|
|
f.close()
|
||
|
|
|
||
|
|
def zip_write(filename, zipobj, tmp_dir):
|
||
|
|
mydir = os.path.dirname(filename)
|
||
|
|
if mydir + '/' not in zipobj.namelist():
|
||
|
|
if filename.find('/') != -1 or filename.find('\\') != -1:
|
||
|
|
zip_write(mydir, zipobj, tmp_dir)
|
||
|
|
if filename not in zipobj.namelist():
|
||
|
|
zipobj.write(os.path.join(tmp_dir, filename), arcname=filename)
|
||
|
|
|
||
|
|
|
||
|
|
def do_gen_check_xml():
|
||
|
|
|
||
|
|
jsonObj = { "res":end_version }
|
||
|
|
|
||
|
|
xml_string = json.dumps( jsonObj, ensure_ascii=False) #encoding='utf-8'
|
||
|
|
|
||
|
|
path_check = os.path.join(zipSubFix, 'version.json')
|
||
|
|
|
||
|
|
with open(path_check, 'w', encoding='utf-8' ) as f:
|
||
|
|
f.write(xml_string)
|
||
|
|
|
||
|
|
print(u"生成热更新文件内容如下:")
|
||
|
|
print(xml_string)
|
||
|
|
print("==============================")
|
||
|
|
|
||
|
|
print(u"""生成热更新文件地址:""")
|
||
|
|
print(zipSubFix)
|
||
|
|
print("==============================")
|
||
|
|
|
||
|
|
|
||
|
|
def encryptFolder( floder, target, encryptObj ):
|
||
|
|
|
||
|
|
if not os.path.exists(target):
|
||
|
|
os.makedirs(target)
|
||
|
|
|
||
|
|
files = os.listdir(floder)
|
||
|
|
for file in files:
|
||
|
|
childPath = os.path.join(floder, file)
|
||
|
|
if os.path.isdir(childPath):
|
||
|
|
if validName( file, True ):
|
||
|
|
encryptFolder( childPath, os.path.join(target, file), encryptObj )
|
||
|
|
else:
|
||
|
|
if validName( file, False ):
|
||
|
|
encryptObj.build( childPath, os.path.join(target, file) )
|
||
|
|
|
||
|
|
def setPlatform(platform):
|
||
|
|
global resSubFix
|
||
|
|
global encryptSubFix
|
||
|
|
global hisSubFix
|
||
|
|
global ediSubFix
|
||
|
|
global zipSubFix
|
||
|
|
global start_version
|
||
|
|
global end_version
|
||
|
|
|
||
|
|
encryptSubFix = os.path.join( sys.path[0], encryptSubFix )
|
||
|
|
resSubFix = os.path.join( sys.path[0], resSubFix )
|
||
|
|
hisSubFix = os.path.join( sys.path[0], hisSubFix.format(platform) )
|
||
|
|
ediSubFix = os.path.join( sys.path[0], ediSubFix.format(platform) )
|
||
|
|
zipSubFix = os.path.join( sys.path[0], zipSubFix.format(platform) )
|
||
|
|
|
||
|
|
viStart = None
|
||
|
|
viEnd = None
|
||
|
|
|
||
|
|
files = os.listdir( hisSubFix )
|
||
|
|
for file in files:
|
||
|
|
if file.endswith( ".json" ):
|
||
|
|
curItem = versionIssue(os.path.basename(file)[8:-5])
|
||
|
|
if curItem.valid() :
|
||
|
|
if None == viStart or viStart.biggerThen( curItem ):
|
||
|
|
viStart = curItem
|
||
|
|
if None == viEnd or curItem.biggerThen( viEnd ):
|
||
|
|
viEnd = curItem
|
||
|
|
|
||
|
|
if None != viStart:
|
||
|
|
start_version = viStart.getVersion()
|
||
|
|
|
||
|
|
if None != viEnd:
|
||
|
|
end_version = viEnd.getVersion()
|
||
|
|
|
||
|
|
def main():
|
||
|
|
|
||
|
|
global enableEncrypt
|
||
|
|
|
||
|
|
platformValue = "default"
|
||
|
|
encryptKey = ""
|
||
|
|
|
||
|
|
if None != sys.argv:
|
||
|
|
argvLength = len(sys.argv)
|
||
|
|
for i in range(1, argvLength):
|
||
|
|
findPos = sys.argv[i].find( 'Encrypt=1' )
|
||
|
|
if -1 != findPos:
|
||
|
|
enableEncrypt = True
|
||
|
|
continue
|
||
|
|
|
||
|
|
findPos = sys.argv[i].find('Platform=')
|
||
|
|
if -1 != findPos:
|
||
|
|
platformValue = sys.argv[i][findPos+9:]
|
||
|
|
continue
|
||
|
|
|
||
|
|
findPos = sys.argv[i].find('EncryptKey=')
|
||
|
|
if -1 != findPos:
|
||
|
|
encryptKey = sys.argv[i][findPos + 11:]
|
||
|
|
continue
|
||
|
|
|
||
|
|
setPlatform( platformValue )
|
||
|
|
|
||
|
|
xml_dir = os.path.join( ediSubFix, end_version) # 包含打包文件信息的xml文件
|
||
|
|
export_dir = os.path.join( zipSubFix, 'zipsource') # 输出目录
|
||
|
|
version_dir = os.path.join( zipSubFix, 'zipsource', end_version) # 版本目录
|
||
|
|
|
||
|
|
if not os.path.exists(export_dir):
|
||
|
|
os.makedirs(export_dir)
|
||
|
|
|
||
|
|
if not os.path.exists(version_dir):
|
||
|
|
os.makedirs(version_dir)
|
||
|
|
|
||
|
|
print( "Encrypt:" + str(enableEncrypt) )
|
||
|
|
|
||
|
|
# clear old encrypt cache
|
||
|
|
if enableEncrypt :
|
||
|
|
print(u"""加密文件中""")
|
||
|
|
if os.path.exists(encryptSubFix):
|
||
|
|
shutil.rmtree(encryptSubFix)
|
||
|
|
os.makedirs(encryptSubFix)
|
||
|
|
|
||
|
|
encryptObj = ffEncrypt(encryptKey)
|
||
|
|
encryptFolder( resSubFix, encryptSubFix, encryptObj )
|
||
|
|
|
||
|
|
print("==============================")
|
||
|
|
|
||
|
|
|
||
|
|
print(u"""生成zip文件:""")
|
||
|
|
print("==============================")
|
||
|
|
if enableEncrypt :
|
||
|
|
make_zip(start_version, end_version, xml_dir, encryptSubFix, version_dir)
|
||
|
|
else:
|
||
|
|
make_zip(start_version, end_version, xml_dir, resSubFix, version_dir)
|
||
|
|
print("==============================")
|
||
|
|
|
||
|
|
do_gen_check_xml()
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|