channel_action.py
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import os.path
from xml.etree import ElementTree as ET
from xml.etree.ElementTree import SubElement
from xml.etree.ElementTree import Element
from xml.etree.ElementTree import ElementTree
import os
import os.path
import zipfile
import re
import subprocess
import platform
from xml.dom import minidom
import codecs
import sys
androidNS = 'http://schemas.android.com/apk/res/android'
def execute(channel, decompileDir, packageName):
sdkDir = decompileDir + '/../sdk/' + channel['sdk']
if not os.path.exists(sdkDir):
file_utils.printF("The sdk temp folder is not exists. path:"+sdkDir)
return 1
replace_applicationId_to_AndroidManifest(decompileDir, packageName)
write_params_to_config(channel, decompileDir)
return 0
def replace_applicationId_to_AndroidManifest(decompileDir, packageName):
manifestPath = decompileDir + '/AndroidManifest.xml'
manifest_file = open(manifestPath, 'r+', encoding='Utf-8')
manifestContent = str(manifest_file.read())
manifest_file.close()
# 4、replace "${applicationId}" "${JPUSH_PKGNAME}" with packname in AndroidManifest.xml
manifestContent = manifestContent.replace('${applicationId}', packageName)
manifest_new_file = open(manifestPath, 'w', encoding='Utf-8')
manifest_new_file.write(manifestContent)
manifest_new_file.close()
return 0
def write_params_to_config(channel, decompileDir):
if channel['params'] != None and len(channel['params']) > 0:
gameid = ''
gamename = ''
gameappid = ''
access_key = ''
gameurl = ''
for param in channel['params']:
if param['name'] == 'gameid':
gameid = param['value']
elif param['name'] == 'gamename':
gamename = param['value']
elif param['name'] == 'gameappid':
gameappid = param['value']
elif param['name'] == 'access_key':
access_key = param['value']
elif param['name'] == 'gameurl':
gameurl = param['value']
"""
xggameinfo_content = '{"gameid":' + gameid + ',"gamename":"' + gamename + '","gameappid":"' + gameappid + '","access_key":"' + access_key + '","gameurl":"' + gameurl + '"}'
xggameinfoPath = decompileDir + '/assets/xggameinfo.txt'
xggameinfo_file = open(xggameinfoPath, 'w', encoding='Utf-8')
xggameinfo_file.write(xggameinfo_content)
xggameinfo_file.close()
"""
developer_config_path = decompileDir + '/assets/xggameinfo.txt'
euConfigFile = open(developer_config_path, 'r+', encoding='Utf-8')
configContent = str(euConfigFile.read())
euConfigFile.close()
configContent = configContent.replace('gameid_83', gameid)
configContent = configContent.replace('gamename_上古情歌之笑傲江湖(安卓版)', gamename)
configContent = configContent.replace('gameappid_821E8134E6658DC91', gameappid)
configContent = configContent.replace('access_key_KghYMFALElcVFSQUKTMY', access_key)
configContent = configContent.replace('gameurl_https://vip.leiniu.com', gameurl)
developer_config_file = open(developer_config_path, 'w', encoding='Utf-8')
developer_config_file.write(configContent)
developer_config_file.close()
return 0