# 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


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)
    # if channelSdkInfo['id'] == '549':
        # del_qihoo(decompileDir)
        # gw_apk_tool.yml_remove_uncompress(decompileDir)

def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
   if channelSdkInfo['id'] == '549' or channelSdkInfo['id'] == '591':
       s1 = os.path.join(decompileDir, "smali_classes4","com")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"com")
            list_package = ["onevcat","RenderHeads","seasun","tencent","twobigears","unionpay","unity3d","vmadalin","xsj","yulong"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes4","com")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"com")
            list_package = ["google","nd"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

   if channelSdkInfo['id'] == '597':
       s1 = os.path.join(decompileDir, "smali_classes2","androidx")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["security","tracing","work","appcompat","cardview","coordinatorlayout","drawerlayout","navigation","sqlite","transition","arch","collection","core","emoji2","room","startup","viewpager2"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes3","androidx")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["security","tracing","work","appcompat","cardview","coordinatorlayout","drawerlayout","navigation","sqlite","transition","arch","collection","core","emoji2","room","startup","viewpager2"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes4","androidx")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["security","tracing","work","appcompat","cardview","coordinatorlayout","drawerlayout","navigation","sqlite","transition","arch","collection","core","emoji2","room","startup","viewpager2"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes2","androidx")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["inspection","loader","print","swiperefreshlayout","webkit","asynclayoutinflater","cursoradapter","interpolator","localbroadc","astmanager","recyclerview","vectordrawable","browser","customview","legacy","media","savedstate","versionedparcelable"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes3","androidx")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["inspection","loader","print","swiperefreshlayout","webkit","asynclayoutinflater","cursoradapter","interpolator","localbroadc","astmanager","recyclerview","vectordrawable","browser","customview","legacy","media","savedstate","versionedparcelable"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)
       s1 = os.path.join(decompileDir, "smali_classes4","androidx")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["inspection","loader","print","swiperefreshlayout","webkit","asynclayoutinflater","cursoradapter","interpolator","localbroadc","astmanager","recyclerview","vectordrawable","browser","customview","legacy","media","savedstate","versionedparcelable"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes4")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new)
            list_package = ["androidx"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali","androidx")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["activity","collection","documentfile","legacy","print","startup","viewpager2"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["annotation","concurrent","drawerlayout","lifecycle","recyclerview","swiperefreshlayout","webkit"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["appcompat","constraintlayout","dynamicanimation","loader","resourceinspection","tracing","work"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["appcompat","constraintlayout","dynamicanimation","loader","resourceinspection","tracing","work"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["arch","coordinatorlayout","emoji2","localbroadcastmanager","room","transition"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["asynclayoutinflater","core","fragment","media","savedstate","vectordrawable"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["browser","cursoradapter","inspection","multidex","slidingpanelayout","versionedparcelable"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
            list_package = ["cardview","customview","interpolator","navigation","sqlite","viewpager"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes2","com")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"com")
            list_package = ["lh"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes2","com")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"com")
            list_package = ["lh"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes2","com")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"com")
            list_package = ["nd","tencent"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

       s1 = os.path.join(decompileDir, "smali_classes2","com")
       if os.path.exists(s1):
            smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
            s3 = os.path.join(decompileDir, smali_classes_new,"com")
            list_package = ["kingsoft"]
            if not os.path.exists(s3):
                distutils.dir_util.mkpath(s3)
            gw_apk_tool.move_package(s1, s3, list_package)

   sdk_id = channelSdkInfo['id']
   if sdk_id == "597":
        move(decompileDir)
   else:
       move_smallsheep(decompileDir)

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_smallsheep(decompileDir):
    s1 = os.path.join(decompileDir, "smali_classes12/com")
    smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
    s3 = os.path.join(decompileDir, smali_classes_new)
    list_package = ["onevcat","RenderHeads","tencent"]
    if not os.path.exists(s3):
        distutils.dir_util.mkpath(s3)
    gw_apk_tool.move_package(s1, s3, list_package)

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

def move(decompileDir):
    s1 = os.path.join(decompileDir, "smali_classes3")
    smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
    s3 = os.path.join(decompileDir, smali_classes_new)
    list_package = ["androidx"]
    if not os.path.exists(s3):
        distutils.dir_util.mkpath(s3)
    gw_apk_tool.move_package(s1, s3, list_package)

    s1 = os.path.join(decompileDir, "smali_classes3/com")
    smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
    s3 = os.path.join(decompileDir, smali_classes_new,"com")
    list_package = ["google","nd","onevcat","RenderHeads","tencent"]
    if not os.path.exists(s3):
        distutils.dir_util.mkpath(s3)
    gw_apk_tool.move_package(s1, s3, list_package)

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

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

    s1 = os.path.join(decompileDir, "smali_classes5/androidx")
    smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
    s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
    list_package = ["navigation","room","sqlite","startup","tracing","transition","viewpager2","work"]
    if not os.path.exists(s3):
        distutils.dir_util.mkpath(s3)
    gw_apk_tool.move_package(s1, s3, list_package)

    s1 = os.path.join(decompileDir, "smali_classes6/androidx")
    smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
    s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
    list_package = ["media","print","recyclerview","savedstate","swiperefreshlayout","vectordrawable","versionedparcelable","webkit"]
    if not os.path.exists(s3):
        distutils.dir_util.mkpath(s3)
    gw_apk_tool.move_package(s1, s3, list_package)


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