# coding:utf8

__author__ = 'dong'

import os
import logging
import xml.dom.minidom
import re
import shutil
import glob
import distutils
import gw_data_center
import gw_file_system


def script_init(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
    sdk_id = channel_sdk_info['id']
    gw_data_center.pack_small = False
    logging.info('script_init: ' + str(channel_sdk_info))


def script_first(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
    logging.info("-----debug exec first func-----")
    # game_apk = os.path.join(decompileDir, "game.apk")
    game_apk = decompileDir + "/../game.apk"
    if os.path.exists(game_apk):
        # A3AEECD8
        gw_file_system.delete_apk_file_by_aapt(game_apk, "assets/39285EFA.dex")
    logging.info("-----debug first-----")


def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
    dex = decompileDir + "../39285EFA.dex"
    asserts = os.path.join(decompileDir, "assets/39285EFA.dex")
    if os.path.exists(asserts) and os.path.exists(os.path.join(dex)):
        distutils.dir_util.copy_tree(dex, asserts)

    logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
    if channelSdkInfo['id'] == '549':
        del_qihoo(decompileDir)


def del_qihoo(decompileDir):
    qihoo = os.path.join(decompileDir, 'smali_classes5/com/qihoo')
    if not os.path.exists(qihoo):
        return

    qihoo = os.path.join(decompileDir, 'smali_classes2/com/qihoo')
    if os.path.exists(qihoo):
        shutil.rmtree(qihoo)

    qihoo = os.path.join(decompileDir, 'smali_classes3/com/qihoo')
    if os.path.exists(qihoo):
        shutil.rmtree(qihoo)


if __name__ == '__main__':
    del_qihoo("C:\\Users\\Administrator\\Desktop\\zmq")
