def getAppIconName(decompileDir):
"""
从AndroidManifest.xml中获取游戏图标的名称
"""
manifestFile = decompileDir + "/AndroidManifest.xml"
manifestFile = file_utils.getFullPath(manifestFile)
ET.register_namespace('android', androidNS)
tree = ET.parse(manifestFile)
root = tree.getroot()
applicationNode = root.find('application')
if not applicationNode:
return "ic_launcher"
key = '{'+androidNS+'}icon'
iconName = applicationNode.get(key)
if not iconName:
return "ic_launcher"
name = iconName[10:]
file_utils.printF("The game icon name is now "+name)
return name
def appendChannelIconMark(game, channel, decompileDir):
"""
自动给游戏图标加上渠道SDK的角标
"""
gameIconPath = 'config/games/' + game['appName'] + '/icon/icon.png'
gameIconPath = file_utils.getFullPath(gameIconPath)
if not os.path.exists(gameIconPath):
file_utils.printF("The game %s icon path is not exists:%s", game['appName'], gameIconPath)
return 1
if 'icon' not in channel:
file_utils.printF("The channel %s of game %s not config icon in config.xml", channel['name'], game['appName'])
return 1
markType = channel['icon']
markName = 'right-bottom'
if markType == 'rb':
markName = 'right-bottom'
elif markType == 'rt':
markName = 'right-top'
elif markType == 'lt':
markName = 'left-top'
elif markType == 'lb':
markName = 'left-bottom'
elif markType == 'mb':
markName = 'mini-icon'
markPath = 'config/sdk/' + channel['name'] + '/icon_marks/' + markName + '.png'
if not os.path.exists(markPath):
file_utils.printF("The icon mark %s is not exists of channel %s ", markPath, channel['name'])
return 1
gameIcon = Image.open(gameIconPath)
markIcon = Image.open(markPath)
rlImg = image_utils.appendIconMark(gameIcon, markIcon, (0, 0))
rlImg.show()
ldpiSize = (36, 36)
mdpiSize = (48, 48)
hdpiSize = (72, 72)
xhdpiSize = (96, 96)
xxhdpiSize = (144,144)
ldpiIcon = rlImg.resize(ldpiSize, Image.ANTIALIAS)
mdpiIcon = rlImg.resize(mdpiSize, Image.ANTIALIAS)
hdpiIcon = rlImg.resize(hdpiSize, Image.ANTIALIAS)
xhdpiIcon = rlImg.resize(xhdpiSize, Image.ANTIALIAS)
xxhdpiIcon = rlImg.resize(xxhdpiSize, Image.ANTIALIAS)
ldpiPath = file_utils.getFullPath(decompileDir + '/res/drawable-ldpi')
mdpiPath = file_utils.getFullPath(decompileDir + '/res/drawable-mdpi')
hdpiPath = file_utils.getFullPath(decompileDir + '/res/drawable-hdpi')
xhdpiPath = file_utils.getFullPath(decompileDir + '/res/drawable-xhdpi')
xxhdpiPath = file_utils.getFullPath(decompileDir + '/res/drawable-xxhdpi')
if not os.path.exists(ldpiPath):
os.makedirs(ldpiPath)
if not os.path.exists(mdpiPath):
os.makedirs(mdpiPath)
if not os.path.exists(hdpiPath):
os.makedirs(hdpiPath)
if not os.path.exists(xhdpiPath):
os.makedirs(xhdpiPath)
if not os.path.exists(xxhdpiPath):
os.makedirs(xxhdpiPath)
gameIconName = getAppIconName(decompileDir) + '.png'
file_utils.printF("The game icon name is "+gameIconName)
ldpiIcon.save(os.path.join(ldpiPath, gameIconName), 'PNG' ,quality = 95)
mdpiIcon.save(os.path.join(mdpiPath, gameIconName), 'PNG' ,quality = 95)
hdpiIcon.save(os.path.join(hdpiPath, gameIconName), 'PNG' ,quality = 95)
xhdpiIcon.save(os.path.join(xhdpiPath, gameIconName), 'PNG' ,quality = 95)
xxhdpiIcon.save(os.path.join(xxhdpiPath, gameIconName), 'PNG' ,quality = 95)
return 0
def appendIconMark(imgIcon, imgMark, position):
"""
将两张同样大小的图片叠加在一起
"""
if imgIcon.mode != 'RGBA':
imgIcon = imgIcon.convert('RGBA')
markLayer = Image.new('RGBA', imgIcon.size, (0,0,0,0))
markLayer.paste(imgMark, position)
return Image.composite(markLayer, imgIcon, markLayer)