# coding:utf8

__author__ = 'dong'

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


def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
    # if channelSdkInfo['id'] == '597':
    #     gw_data_center.pack_small = True
    return


def script_second(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
    return


def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
    # logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
    # if channelSdkInfo['id'] == '597':
    #     logging.info("remove_navigate")
    #     remove_navigate(decompileDir)
    return


def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
    logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
    if channelSdkInfo['id'] == '597':
       return
    else:
        move(decompileDir)

def move(decompileDir):
    s1 = os.path.join(decompileDir, "smali_classes3/androidx")
    smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
    s3 = os.path.join(decompileDir, smali_classes_new, "androidx")
    list_package = ["activity","arch","constraintlayout","cursoradapter","drawerlayout","legacy","localbroadcastmanager","annotation","asynclayoutinflater","coordinatorlayout","customview","fragment","lifecycle","appcompat","collection","core","documentfile","interpolator","loader"]

    if not os.path.exists(s3):
        distutils.dir_util.mkpath(s3)
    gw_apk_tool.move_package(s1, s3, list_package)


def remove_navigate(decompileDir):
    tmp_res = os.path.join(decompileDir, "res", "navigation")
    tmp_public_xml = os.path.join(decompileDir, "res", "values", "public.xml")
    if os.path.exists(tmp_res):
        distutils.dir_util.remove_tree(tmp_res)
    if os.path.exists(tmp_public_xml):
        os.remove(tmp_public_xml)


def move_10_bytedance(decompileDir):
    s1 = os.path.join(decompileDir, "smali_classes10/com/bytedance")
    smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
    s3 = os.path.join(decompileDir, smali_classes_new, "com/bytedance")
    list_package = ["ttgame"]
    if not os.path.exists(s3):
        distutils.dir_util.mkpath(s3)
    gw_apk_tool.move_package(s1, s3, list_package)


def handle_public_xml(public_xml_path, remove_node):
    if not os.path.exists(public_xml_path):
        logging.info('public_xml is null: ' + public_xml_path)
        return
    new_lines = []
    with open(public_xml_path, 'r+') as f:
        for line in f.readlines():
            # l = line.strip()
            if line.find(remove_node) > -1:
                continue
            new_lines.append(line)
        f.seek(0)
        f.truncate()
        f.writelines(new_lines)
    return

if __name__ == '__main__':
    # del_qihoo("C:\\Users\\Administrator\\Desktop\\zt")
    remove_navigate("G:\\autopack2.0_kuaifa\\tool\\workspace\\lrs360\\13651\\extract")
