forked from anixart-mod/patcher
Обновление структуры проекта, использование pydantic для конфигураций, улучшение отчёта о патчах
This commit is contained in:
@@ -26,8 +26,52 @@ priority = 0
|
||||
# imports
|
||||
import shutil
|
||||
from lxml import etree
|
||||
from tqdm import tqdm
|
||||
from typing import Dict, List, Any
|
||||
from pydantic import Field
|
||||
|
||||
from utils.config import PatchConfig
|
||||
from utils.public import insert_after_public
|
||||
|
||||
#Config
|
||||
DEFAULT_MENU = {
|
||||
"Мы в социальных сетях": [
|
||||
{
|
||||
"title": "wowlikon",
|
||||
"description": "Разработчик",
|
||||
"url": "https://t.me/wowlikon",
|
||||
"icon": "@drawable/ic_custom_telegram",
|
||||
"icon_space_reserved": "false"
|
||||
},
|
||||
{
|
||||
"title": "Kentai Radiquum",
|
||||
"description": "Разработчик",
|
||||
"url": "https://t.me/radiquum",
|
||||
"icon": "@drawable/ic_custom_telegram",
|
||||
"icon_space_reserved": "false"
|
||||
},
|
||||
{
|
||||
"title": "Мы в Telegram",
|
||||
"description": "Подпишитесь на канал, чтобы быть в курсе последних новостей.",
|
||||
"url": "https://t.me/http_teapod",
|
||||
"icon": "@drawable/ic_custom_telegram",
|
||||
"icon_space_reserved": "false"
|
||||
}
|
||||
],
|
||||
"Прочее": [
|
||||
{
|
||||
"title": "Помочь проекту",
|
||||
"description": "Вы можете помочь нам в разработке мода, написании кода или тестировании.",
|
||||
"url": "https://git.wowlikon.tech/anixart-mod",
|
||||
"icon": "@drawable/ic_custom_crown",
|
||||
"icon_space_reserved": "false"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
class Config(PatchConfig):
|
||||
version: str = Field(" by wowlikon", description="Суффикс версии")
|
||||
menu: Dict[str, List[Dict[str, str]]] = Field(DEFAULT_MENU, description="Меню")
|
||||
|
||||
# Patch
|
||||
def make_category(ns, name, items):
|
||||
@@ -49,7 +93,7 @@ def make_category(ns, name, items):
|
||||
|
||||
return cat
|
||||
|
||||
def apply(config: dict) -> bool:
|
||||
def apply(config: Config, base: Dict[str, Any]) -> bool:
|
||||
shutil.copy(
|
||||
"./resources/ic_custom_crown.xml",
|
||||
"./decompiled/res/drawable/ic_custom_crown.xml",
|
||||
@@ -70,8 +114,8 @@ def apply(config: dict) -> bool:
|
||||
# Insert new PreferenceCategory before the last element
|
||||
last = root[-1] # last element
|
||||
pos = root.index(last)
|
||||
for section, items in config["menu"].items():
|
||||
root.insert(pos, make_category(config["xml_ns"], section, items))
|
||||
for section, items in config.menu.items():
|
||||
root.insert(pos, make_category(base["xml_ns"], section, items))
|
||||
pos += 1
|
||||
|
||||
# Save back
|
||||
@@ -86,7 +130,7 @@ def apply(config: dict) -> bool:
|
||||
with open(filepath, "r", encoding="utf-8") as file:
|
||||
for line in file.readlines():
|
||||
if '"\u0412\u0435\u0440\u0441\u0438\u044f'.encode("unicode_escape").decode() in line:
|
||||
content += line[:line.rindex('"')] + config["version"] + line[line.rindex('"'):]
|
||||
content += line[:line.rindex('"')] + config.version + line[line.rindex('"'):]
|
||||
else:
|
||||
content += line
|
||||
with open(filepath, "w", encoding="utf-8") as file:
|
||||
|
||||
Reference in New Issue
Block a user