classPackagePc(object):def __init__(self, args):
self.workPath=WORK_PATH
self.vsDevCmd= "VsDevCmd.bat"self.compileCommand= ""self.compilePath= ""self.issPath= ""self.packConfig= utils.parse_json(os.path.join(self.workPath, "package.json"))
self.projectName= self.packConfig.get("projectName")
self.projectSlnPath= utils.flat_path(os.path.join(self.workPath, ‘../../../frameworks/runtime-src/proj.win32/‘))
self.compilePath= "{}{}".format(self.packConfig.get("compileType"), ".win32")
self.assetsPath= "{}{}{}".format(self.projectSlnPath, "\\", self.compilePath)
self.useLessFileList= [‘.pdb‘, ‘.ilk‘, ‘.lib‘, ‘.log‘, ‘.obj‘, ‘.exp‘, ‘.js‘, ‘.idb‘, ".res"]defbuildPcPack(self):#初始化项目Sln
self.initProjectSln()#编译C++工程
self.compileCPlus()#压缩图片资源
self.doPngQuant()#js转化jsc
self.compileJsFile()#删除VS生成多余文件
self.removeUselessFile(self.useLessFileList)#加密
self.doEncrypt()#删除jsc
self.removeUselessFile([‘.jsc‘])#生成exe安装包
self.setUpISS()#初始化编译命令
definitProjectSln(self):
slnName= self.packConfig.get("sln")if notslnName:
raise_known_error(‘没有配置项目sln名‘, KnownError.ERROR_WRONG_CONFIG)
self.compileCommand= "{}{}{}{}{}{}".format("devenv", self.projectSlnPath , "\\" , slnName, ".sln", "/rebuild release")#编译C++工程
defcompileCPlus(self):print(u"----------开始编译C++工程----------")
utils.run_shell("%s & %s" %(self.vsDevCmd, self.compileCommand))#压缩图片资源
defdoPngQuant(self):print(u"----------开始压缩图片资源----------")
excludeDict= {"exclude_files": ["gg_s9_res"], "exclude_folders": ["games", "src/libs/images/native/native_s9_res"]}
quant=png_quant.PngQuant(self.assetsPath, excludeDict)
quant.compress_images_in_path()#压缩js文件
defcompileJsFile(self):print(u"----------开始js转化jsc----------")if notos.path.exists(self.assetsPath):print("compileJsFile path not found =" +self.assetsPath)returncompilePath= utils.flat_path(os.path.join(self.workPath, ‘../../../frameworks/cocos2d-x/tools/cocos2d-console/bin/cocos‘))
compileCmd= "%s jscompile -s %s -d %s" %(compilePath, self.assetsPath, self.assetsPath)
utils.run_shell(compileCmd)#资源加密
defdoEncrypt(self):print(u"----------开始资源加密----------")
ASSETS_ENCRYPT_EXCLUDE_CFG= ["games/mj_common/images/card_packer/*.png"]
encrypt=ResEncrypt(self.assetsPath, self.assetsPath, False, ASSETS_ENCRYPT_EXCLUDE_CFG, True, False)
encrypt.do_encrypt()#删除项目中无用的文件
defremoveUselessFile(self, fileList):print(u"----------开始删除VS生成多余文件----------")for parent, dirNames, fileNames inos.walk(self.assetsPath):for fileFullName infileNames:if os.path.splitext(fileFullName)[1] infileList:print("file %s"%(os.path.join(parent, fileFullName)))
os.remove(os.path.join(parent, fileFullName))#生成exe安装包
defsetUpISS(self):print(u"----------开始生成exe安装包----------")
issPath= utils.flat_path(os.path.join(self.workPath, ‘../../../tools/hall/PackPC/‘))
devCmd= "{}{}".format("cd", os.path.join(issPath, "InnoSetup"))
issCmd= "{}{}".format("iscc", os.path.join(issPath, "build.iss"))
self.issPath= os.path.join(issPath, "build.iss")if notos.path.exists(self.issPath):
raise_known_error("找不到ISS文件", KnownError.ERROR_OTHERS)
self.modifyISS(issPath, False)
utils.run_shell("%s & %s & %s" % (devCmd, "ISCC.exe", issCmd))
self.modifyISS(issPath, True)#修改、还原Inno Setup打包配置
defmodifyISS(self, issPath, isReduction):
with open(self.issPath,"rb") as f:
data=f.read()
f.close()
cfgVersion= self.packConfig.get("version").decode(‘utf8‘).encode(‘gb2312‘)ifisReduction:
data= data.replace(cfgVersion, "GameVersion")
data= data.replace(self.assetsPath, "PCProjectPath")
data= data.replace(issPath, "IcoPath")
data= data.replace("xxxxxPC" + cfgVersion + "-Setup", "OutputFilename")else:
data= data.replace("GameVersion", cfgVersion)#修改版本号
data = data.replace("PCProjectPath", self.assetsPath)#修改项目路径名
data = data.replace("IcoPath", issPath)#修改ICO路径
data = data.replace("OutputFilename","xxxxxPC" + cfgVersion + "-Setup")
with open(self.issPath,"wb") as f:
f.write(data)
f.close()