# -*- coding:utf-8 -*-
__author__ = 'ALIXie'

import os
import logging
import gw_data_center
import gw_apk_tool


def script_init(workspace_sdk_dir, extract_dir, channelSdkInfo, new_game_channel_info, game_info):
    gw_data_center.pack_small = False
    gw_apk_tool.__apk_tool__ = 'apktool_2.6.0.jar'
    return


def script_last(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
    logging.info('channel_sdk_info: ' + str(channel_sdk_info))
    if channel_sdk_info['id'] == '549':
        add_life_cycle(extract_dir)


def add_life_cycle(extract_dir):
    tfile = os.path.join(extract_dir, 'smali/com/unity3d/player/UnityPlayerActivity.smali')
    print tfile
    logging.info(tfile)
    if os.path.isfile(tfile):
        with open(tfile, 'r+') as f:
            cont = f.readlines()
            for lin in cont:
                if lin.replace('\n', '').strip(' ') == '.method protected onPause()V':
                    a = cont.index(lin)
                    cont.insert(a + 2, '    invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onPause()V')
                if lin.replace('\n', '').strip(' ') == '.method protected onResume()V':
                    b = cont.index(lin)
                    cont.insert(b + 2, '    invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onResume()V')
        with open(tfile, 'w') as tf:
            tf.write(''.join(cont))


if __name__ == "__main__":
    add_life_cycle("C:\\Users\\Administrator\\Desktop\\longzhu")
