forked from anixart-mod/patcher
Обновление структуры проекта, использование pydantic для конфигураций, улучшение отчёта о патчах
This commit is contained in:
@@ -12,36 +12,43 @@ priority = 0
|
||||
# imports
|
||||
from lxml import etree
|
||||
from tqdm import tqdm
|
||||
from typing import Dict, List, Any
|
||||
from pydantic import Field
|
||||
|
||||
from utils.config import PatchConfig
|
||||
|
||||
#Config
|
||||
class Config(PatchConfig):
|
||||
items: List[str] = Field(["home", "discover", "feed", "bookmarks", "profile"], description="Список элементов в панели навигации")
|
||||
|
||||
# Patch
|
||||
def apply(config: dict) -> bool:
|
||||
def apply(config: Config, base: Dict[str, Any]) -> bool:
|
||||
file_path = "./decompiled/res/menu/bottom.xml"
|
||||
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(file_path, parser)
|
||||
root = tree.getroot()
|
||||
|
||||
items = root.findall("item", namespaces=config['xml_ns'])
|
||||
items = root.findall("item", namespaces=base['xml_ns'])
|
||||
|
||||
def get_id_suffix(item):
|
||||
full_id = item.get(f"{{{config['xml_ns']['android']}}}id")
|
||||
full_id = item.get(f"{{{base['xml_ns']['android']}}}id")
|
||||
return full_id.split("tab_")[-1] if full_id else None
|
||||
|
||||
items_by_id = {get_id_suffix(item): item for item in items}
|
||||
existing_order = [get_id_suffix(item) for item in items]
|
||||
|
||||
ordered_items = []
|
||||
for key in config['items']:
|
||||
for key in config.items:
|
||||
if key in items_by_id:
|
||||
ordered_items.append(items_by_id[key])
|
||||
|
||||
extra = [i for i in items if get_id_suffix(i) not in config['items']]
|
||||
extra = [i for i in items if get_id_suffix(i) not in config.items]
|
||||
if extra:
|
||||
tqdm.write("⚠Найдены лишние элементы: " + str([get_id_suffix(i) for i in extra]))
|
||||
ordered_items.extend(extra)
|
||||
|
||||
for i in root.findall("item", namespaces=config['xml_ns']):
|
||||
for i in root.findall("item", namespaces=base['xml_ns']):
|
||||
root.remove(i)
|
||||
|
||||
for item in ordered_items:
|
||||
|
||||
Reference in New Issue
Block a user