Exemplo n.º 1
0
    def projectConfigRead(self):
        """Read funcellconfig.xml file and save to a dictionary"""
        try:
            configfile = file_operate.getCommonXmlPath()

            config = ET.parse(configfile)
            root = config.getroot()
            apk = root.find("apk")
            self._apkPath = apk.get("path")
            keystore = root.find("keystore")
            self._keystoreFile = keystore.get("path")
            self._keystorepassword = keystore.get("password")
            self._alias = keystore.get("alias")
            self._aliasPassword = keystore.get("aliaspassword")

            configfile = file_operate.getConfigXmlPath()
            config = ET.parse(configfile)
            root = config.getroot()
            app = root.find("app")
            self._packageName = app.get("packageName")
            platform = root.find("platform")
            self._appVersion = platform.get("appVersion")
            self._gameId = platform.get("gameId")
            self._platformId = platform.get("platformId")
            self._platformType = platform.get("platformType")
            channel = root.find("channel")
            self._resVersion = channel.get("resVersion")

        except Exception, e:
            print e
            print "Error: cannot parse file: funcellconfig.xml."
            return -1
def addSplashScreen(splashSDKName, decompileDir):
    """ add splash screen
        channel hasn't Splash if channel["bHasSplash"] = 0
        otherwise channel["bHasSplash"] express orientation and color
    """
    channelHasSplash = "0"
    try:
        #read has splash to funcellconfig.xml
        config = ET.parse(file_operate.getConfigXmlPath())
        root = config.getroot()
        splash = root.find("splash")
        channelHasSplash = splash.get('hasSplash')

    except Exception, e:
        print e
        print "Error: cannot parse file: funcellconfig.xml."
def modifyGameName(channel, decompileDir):
    config = ET.parse(file_operate.getConfigXmlPath())
    root = config.getroot()
    apktoolYmlPath = decompileDir + '/apktool.yml'
    newapktoolYmlPath = decompileDir + '/apktool.yml.new'
    try:
        game = root.find("game")
        appName = game.get("appName")
        if appName != None:
            StringConfig = ET.parse(decompileDir + '/res/values/strings.xml')
            StringConfigRoot = StringConfig.getroot()
            for StringConfigNode in StringConfigRoot:
                if StringConfigNode.attrib['name'] == "app_name":
                    StringConfigNode.text = unicode(appName)
            StringConfig.write(decompileDir + '/res/values/strings.xml',
                               "utf-8")
    except Exception, e:
        print e
def appendChannelIconMark(iconName, decompileDir):
    """
        自动给游戏图标加上渠道SDK的角标
    """
    #     gameIconPath = file_operate.getFullPath(constant.sdkRelatePath+ConfigParse.shareInstance().getChannelName()) + '/icon/icon.png'
    gameIconPath = file_operate.getFullPath(
        constant.sdkRelatePath) + '/game_icon/icon.png'
    if not os.path.exists(gameIconPath):
        return 1

    useMark = True
    try:
        config = ET.parse(file_operate.getConfigXmlPath())
        root = config.getroot()
        icon = root.find("icon")
        markType = icon.get("markType")
    except Exception, e:
        print e
        useMark = False
def produceNewRFile(packName,
                    decompileFullDir,
                    androidManiFest='AndroidManifest.xml'):
    """
        According to the merger of resources to create new R file
    """
    fullPath = decompileFullDir
    tempPath = os.path.dirname(decompileFullDir)
    tempPath = tempPath + '/tempRFile'
    if os.path.exists(tempPath):
        file_operate.delete_file_folder(tempPath)
    if not os.path.exists(tempPath):
        os.makedirs(tempPath)
    resPath = os.path.join(decompileFullDir, 'res')
    targetResPath = os.path.join(tempPath, 'res')
    file_operate.copyFiles(resPath, targetResPath)
    genPath = os.path.join(tempPath, 'gen')
    if not os.path.exists(genPath):
        os.mkdir(genPath)
    androidPath = file_operate.getToolPath('android.jar')
    srcManifest = os.path.join(fullPath, androidManiFest)
    aaptPath = file_operate.getToolPath('aapt')
    cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (
        aaptPath, genPath, targetResPath, androidPath, srcManifest)
    ret = file_operate.execFormatCmd(cmd)
    if ret:
        error_operate.error(102)
        return 1
    RPath = packName.replace('.', '/')
    RPath = os.path.join(genPath, RPath)
    RFile = os.path.join(RPath, 'R.java')
    cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (
        file_operate.getJavaBinDir(), RFile)
    ret = file_operate.execFormatCmd(cmd)
    if ret:
        error_operate.error(103)
        return 1

    #针对某系渠道通过R。xx来获取资源,在指定包名下添加R文件
    try:
        config = ET.parse(file_operate.getConfigXmlPath())
        root = config.getroot()
        Manifest = root.find("Manifest")
        num = int(Manifest.get('num'))
        for i in range(0, num):
            srcManifest_i = os.path.join(
                file_operate.getFullPath(constant.tmpPath),
                'Manifest/' + str(i) + '/AndroidManifest.xml')
            cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (
                aaptPath, genPath, targetResPath, androidPath, srcManifest_i)
            ret = file_operate.execFormatCmd(cmd)
            if ret:
                error_operate.error(102)
                return 1
            packageNameArray = Manifest.get('packageNameArray')
            packageNameNode = packageNameArray.split(',')[i]
            RPath = packageNameNode.replace('.', '/')
            RPath = os.path.join(genPath, RPath)
            RFile = os.path.join(RPath, 'R.java')
            cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (
                file_operate.getJavaBinDir(), RFile)
            ret = file_operate.execFormatCmd(cmd)
            if ret:
                error_operate.error(103)
                return 1
    except Exception, e:
        print e
        print "Error: cannot parse file: funcellconfig.xml."