This commit is contained in:
luojian 2025-07-11 00:10:25 +08:00
parent c8fde0d286
commit eac18b1266
2 changed files with 71 additions and 1 deletions

View File

@ -1,12 +1,28 @@
import hashlib import hashlib
import os import os
from pathlib import Path from pathlib import Path
import re
from scripts.context import Context from scripts.context import Context
from scripts.task import Task from scripts.task import Task
from utils import FileUtils from utils import FileUtils
def extract_launcher_ids(xml_content):
"""
修复版提取所有以 "launcher_" 开头的 android:id
"""
pattern = r'android:id\s*=\s*"@\+id/(launcher_\w+)"'
matches = re.findall(pattern, xml_content)
return matches
# def extract_launcher_ids(xml_content):
# """提取所有 android:id 值"""
# pattern = r'android:id\s*=\s*"@\+id/([^"]+)"'
# return re.findall(pattern, xml_content)
def string_to_md5(text): def string_to_md5(text):
# 将字符串编码为UTF-8字节 # 将字符串编码为UTF-8字节
text_bytes = text.encode('utf-8') text_bytes = text.encode('utf-8')
@ -36,6 +52,7 @@ def generate_encryption_key(key: str, s_len: int = -1, target_package_name: str
layout_path = "LauncherCode/res/layout".replace("/", os.sep) layout_path = "LauncherCode/res/layout".replace("/", os.sep)
values_path = "LauncherCode/res/values".replace("/", os.sep)
drawable_xxhdpi_path = "LauncherCode/res/drawable-xxhdpi".replace("/", os.sep) drawable_xxhdpi_path = "LauncherCode/res/drawable-xxhdpi".replace("/", os.sep)
drawable_path = "LauncherCode/res/drawable".replace("/", os.sep) drawable_path = "LauncherCode/res/drawable".replace("/", os.sep)
code_path = "LauncherCode/src".replace("/", os.sep) code_path = "LauncherCode/src".replace("/", os.sep)
@ -46,6 +63,8 @@ launcher_code_path = "lawnchair/src".replace("/", os.sep)
src_code_path = "src".replace("/", os.sep) src_code_path = "src".replace("/", os.sep)
launchercode = "launchercode" launchercode = "launchercode"
lawn_layout = "res/layout".replace("/", os.sep)
class ProjectProguard(Task): class ProjectProguard(Task):
def __init__(self, context: Context): def __init__(self, context: Context):
@ -90,7 +109,44 @@ class ProjectProguard(Task):
self.update(dir_path) self.update(dir_path)
pass pass
def update_id(self, file_path: str):
for root, dirs, files in os.walk(file_path):
for file in files:
xml_file = os.path.join(root, file)
text = open(xml_file, "r", encoding="UTF-8").read()
ids = extract_launcher_ids(text)
for id in ids:
self.add_proguard_key(id)
def write_proguard(self):
file_path = os.path.join(self.context.temp_project_path, "proguard.pro")
lines = open(file_path, "r", encoding="UTF-8").readlines()
lines.append(f"""
-repackageclasses '{self.context.package_name}' # 将所有类移动到 '{self.context.package_name}' 包下
-flattenpackagehierarchy '{self.context.package_name}' # 扁平化包结构
""")
open(file_path, "w", encoding="UTF-8").writelines(lines)
pass
def execute(self): def execute(self):
self.write_proguard()
self.add_proguard_key("LauncherMyNoActionBar")
self.add_proguard_key("LauncherIntroTheme")
self.add_proguard_key("LauncherGameIntroTheme")
self.add_proguard_key("LauncherTransparentTheme")
self.add_proguard_key("launchergamead")
self.add_proguard_key("launcher_help_detail")
self.add_proguard_key("launcher_help")
self.add_proguard_key("launcher_uninstall")
self.add_proguard_key("launcher_onboard")
self.update_id(os.path.join(self.context.temp_project_path, lawn_layout))
self.update_id(os.path.join(self.context.temp_project_path, layout_path))
self.rename_files_in_dir(os.path.join(self.context.temp_project_path, layout_path)) self.rename_files_in_dir(os.path.join(self.context.temp_project_path, layout_path))
self.rename_files_in_dir(os.path.join(self.context.temp_project_path, drawable_xxhdpi_path)) self.rename_files_in_dir(os.path.join(self.context.temp_project_path, drawable_xxhdpi_path))
self.rename_files_in_dir(os.path.join(self.context.temp_project_path, drawable_path)) self.rename_files_in_dir(os.path.join(self.context.temp_project_path, drawable_path))
@ -104,6 +160,7 @@ class ProjectProguard(Task):
) )
} }
self.update_proguard(os.path.join(self.context.temp_project_path, layout_path)) self.update_proguard(os.path.join(self.context.temp_project_path, layout_path))
self.update_proguard(os.path.join(self.context.temp_project_path, values_path))
self.update_proguard(os.path.join(self.context.temp_project_path, drawable_xxhdpi_path)) self.update_proguard(os.path.join(self.context.temp_project_path, drawable_xxhdpi_path))
self.update_proguard(os.path.join(self.context.temp_project_path, drawable_path)) self.update_proguard(os.path.join(self.context.temp_project_path, drawable_path))
self.update_proguard(os.path.join(self.context.temp_project_path, code_path)) self.update_proguard(os.path.join(self.context.temp_project_path, code_path))
@ -111,4 +168,17 @@ class ProjectProguard(Task):
self.update_proguard(os.path.join(self.context.temp_project_path, xml_path)) self.update_proguard(os.path.join(self.context.temp_project_path, xml_path))
self.update_proguard(os.path.join(self.context.temp_project_path, launcher_code_path)) self.update_proguard(os.path.join(self.context.temp_project_path, launcher_code_path))
self.update_proguard(os.path.join(self.context.temp_project_path, src_code_path)) self.update_proguard(os.path.join(self.context.temp_project_path, src_code_path))
self.update_proguard(os.path.join(self.context.temp_project_path, lawn_layout))
pass pass
if __name__ == "__main__":
file = "../project/com_punch_prankster_puzzle_fwaes_free_launcher_fgsaw223908/LauncherCode/res/layout/a60034437eae19e7b00.xml".replace(
"/", os.sep)
text = open(file, "r", encoding="UTF-8").read()
print(text)
temp = extract_launcher_ids(text)
print(temp)
pass

View File

@ -265,7 +265,7 @@ plugins {
text = open(os.path.join(self.context.temp_project_path, ANDROID_MANIFEST_PATH), "r", text = open(os.path.join(self.context.temp_project_path, ANDROID_MANIFEST_PATH), "r",
encoding="utf-8").read() encoding="utf-8").read()
# text = text.replace("WebActivity", "com.unity3d.player.UnityPlayerActivity") text = text.replace("@style/LauncherGameIntroTheme", "@style/UnityThemeSelector")
open(os.path.join(self.context.temp_project_path, ANDROID_MANIFEST_PATH), "w", encoding="utf-8").write(text) open(os.path.join(self.context.temp_project_path, ANDROID_MANIFEST_PATH), "w", encoding="utf-8").write(text)