1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import file_utils
- import common_utils
- import xml_utils
- import os.path
- import xml.etree.ElementTree as ET
- import zipfile
- namespaces = {'android' : 'http://schemas.android.com/apk/res/android'}
- encoding = 'UTF-8'
- def execute(game, sdk, config):
- if not checkConfig(config):
- return 1
- subChannel = config['subChannel']
- createJmhyProperties(game, sdk, subChannel, config)
- common_utils.changeApplication(game, sdk, subChannel, config, 'com.tygame.tianyu.TYApplication')
- changePlaceholders(game, sdk, subChannel, config)
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
- manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
- xml_utils.deleteActivityByName(manifest,'com.jmhy.sdk.activity.JmpayActivity')
- return 0
- def checkConfig(config):
- '''
- 检查配置
- '''
- if 'properties' not in config:
- print('properties not exists in config')
- return False
- properties = config['properties']
-
- if 'agent' not in properties or 'version' not in properties:
- print('agent or version not exists in properties')
- return False
- return True
- def createJmhyProperties(game, sdk, subChannel, config):
- '''
- 创建jmhy.properties
- '''
- print('create jmhy.properties')
- propValue = config['properties']
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
- properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
- content = ''
- for key in propValue:
- content = '%s%s=%s\n' % (content, key, propValue[key])
- file_utils.createFile(properties, content)
- return 0
- def changePlaceholders(game, sdk, subChannel, config):
- '''
- 处理掉占位符
- '''
- if 'placeholders' not in config:
- return 0
- decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
- json = os.path.join(decompliePath, 'assets','tycollect.json')
- placeholders = config['placeholders']
- for placeholder in placeholders:
- oldText = '${%s}' % placeholder
- newText = placeholders[placeholder]
- print('change placeholder %s -> %s' % (oldText, newText))
- file_utils.replaceContent(json, oldText, newText)
- return 0
|