script.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # coding:utf8
  2. __author__ = 'dong'
  3. import os
  4. import logging
  5. import xml.dom.minidom
  6. import re
  7. import shutil
  8. import glob
  9. from xml.etree.ElementTree import ElementTree, Element
  10. import distutils.dir_util
  11. from xml.etree import ElementTree as ET
  12. import gw_file_system
  13. import os
  14. import shutil
  15. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  16. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  17. return
  18. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  19. logging.info("-----debug-----")
  20. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  21. if channelSdkInfo['id'] == '521':
  22. # res = os.path.join(decompileDir, "res")
  23. # copy_ic_launcher(res)
  24. v26 = os.path.join(decompileDir, "res", "mipmap-anydpi-v26", "ic_launcher.xml")
  25. if os.path.exists(v26):
  26. os.remove(v26)
  27. return
  28. def find_and_replace(directory):
  29. # 遍历目录及其子目录
  30. for root, dirs, files in os.walk(directory):
  31. # 检查当前目录名是否以drawable、mipmap开头或其是drawable-xxx、mipmap-xxx类型的目录
  32. if any(dir_name.startswith(('drawable', 'mipmap')) or dir_name.startswith(('drawable-', 'mipmap-')) for dir_name
  33. in dirs):
  34. # 检查ic_launcher_foreground.png文件是否存在
  35. # 如果存在,则复制同目录下的ic_launcher.png文件,覆盖ic_launcher_foreground.png文件
  36. source_file = os.path.join(dirs, 'ic_launcher.png')
  37. destination_file = os.path.join(dirs, 'ic_launcher_foreground.png')
  38. # 检查ic_launcher.png文件是否存在
  39. if os.path.exists(source_file) and os.path.exists(destination_file):
  40. shutil.copy(source_file, destination_file)
  41. print("Copied ic_launcher.png to ic_launcher_foreground.png in", root)
  42. else:
  43. print("ic_launcher.png not found in", root)
  44. # 使用示例:将'res'替换为你的目标目录路径
  45. def copy_ic_launcher(directory):
  46. for root, dirs, files in os.walk(directory):
  47. for dirname in dirs:
  48. if dirname.startswith('drawable') or dirname.startswith('mipmap'):
  49. folder_path = os.path.join(root, dirname)
  50. foreground_path = os.path.join(folder_path, 'ic_launcher_foreground.png')
  51. launcher_path = os.path.join(folder_path, 'ic_launcher.png')
  52. if os.path.isfile(foreground_path):
  53. shutil.copy(launcher_path, foreground_path)
  54. print("Copied '{}' to '{}'".format(launcher_path, foreground_path))
  55. # 调用函数并传入需要递归遍历的目录路径
  56. if __name__ == '__main__':
  57. # replace_super_application("D:\work\wzdq")
  58. # modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")
  59. ""