# coding:utf8

__author__ = '极无双'

import os
import logging
import xml.dom.minidom
import re
import shutil
import glob


def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
    logging.info('script_second: ' + str(channel_sdk_info))
    # 逆向渠道id
    public_xml = os.path.join(extract_dir, "res/values/public.xml")
    handle_public_xml(public_xml, "progress_text")
    handle_public_xml(public_xml, "lebian_color")
    handle_public_xml(public_xml, "progress_max")
    handle_public_xml(public_xml, "progress_current")
    handle_public_xml(public_xml, "progress_reached")
    handle_public_xml(public_xml, "progress_unreached")

    return


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


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__':
    replace_life_method("D:\\work\\jws")
