# encoding: utf-8
import logging
import os
import yaml
import xml.etree.ElementTree as ET
import re
__author__ = 'billyyoyo'

ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'

def change_application_id(extra_dir, packageName):
    fname = extra_dir + '/AndroidManifest.xml'
    with open(fname, 'r+') as f:
        cont = f.read()
        findstr = '#applicationId#'
        rStr = packageName+'.smallsheep'
        cont = cont.replace(findstr, rStr)
        f.seek(0)
        f.truncate(len(cont))
        f.write(cont)
        f.close()


def script(work_sdk_dir, extra_dir, channel_sdk_info, new_game_channel_info, game_info):
    logging.info("---------------channel_sdk_info-------------")
    logging.info(channel_sdk_info)
    logging.info("---------------new_game_channel_info-------------")
    logging.info(new_game_channel_info)
    logging.info("---------------game_info-------------")
    logging.info(game_info)
    applicationId = channel_sdk_info["packNameSuffix"]
    change_application_id(extra_dir, applicationId)
    fix_kf_kuyun(extra_dir)

def fix_kf_kuyun(decompile_dir):
    for dirpath, dirnames, filenames in os.walk(decompile_dir):
        # if ur'com\yog\kothoth\\utils' in dirpath and u'RealnameCheckor.smali' in filenames:
            auth_listener_path = os.path.join(decompile_dir,"smali","com","yog","kothoth","utils",'RealnameCheckor.smali')
            with open(auth_listener_path, 'r') as f:
                content = f.read()
            new_content = content.replace('com.kf.framework', 'com.kuyun.framewor')

            if new_content == content:
                print "no found"
                return
            with open(auth_listener_path, 'w') as f:
                f.write(new_content)

if __name__ == '__main__':
    # script("", ".", {'package_name':'com.netease.dwrg.yl.ludashi'}, {}, {})
    fix_kf_kuyun("D:/work/autopack3/tool/outputGame/admin@163.com/nslm2/nslm2_311")
