This commit is contained in:
+104
-95
@@ -20,119 +20,128 @@
|
||||
}
|
||||
"""
|
||||
|
||||
priority = 0
|
||||
|
||||
# imports
|
||||
__author__ = "wowlikon <wowlikon@gmail.com>"
|
||||
__version__ = "1.0.0"
|
||||
import shutil
|
||||
from typing import Any, Dict, List
|
||||
|
||||
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.config import PatchTemplate
|
||||
from utils.public import insert_after_public
|
||||
|
||||
#Config
|
||||
# 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"
|
||||
}
|
||||
]
|
||||
"Мы в социальных сетях": [
|
||||
{
|
||||
"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):
|
||||
|
||||
class Patch(PatchTemplate):
|
||||
priority: int = Field(frozen=True, exclude=True, default=0)
|
||||
version: str = Field(" by wowlikon", description="Суффикс версии")
|
||||
menu: Dict[str, List[Dict[str, str]]] = Field(DEFAULT_MENU, description="Меню")
|
||||
|
||||
# Patch
|
||||
def make_category(ns, name, items):
|
||||
cat = etree.Element("PreferenceCategory", nsmap=ns)
|
||||
cat.set(f"{{{ns['android']}}}title", name)
|
||||
cat.set(f"{{{ns['app']}}}iconSpaceReserved", "false")
|
||||
def make_category(self, ns, name, items):
|
||||
cat = etree.Element("PreferenceCategory", nsmap=ns)
|
||||
cat.set(f"{{{ns['android']}}}title", name)
|
||||
cat.set(f"{{{ns['app']}}}iconSpaceReserved", "false")
|
||||
|
||||
for item in items:
|
||||
pref = etree.SubElement(cat, "Preference", nsmap=ns)
|
||||
pref.set(f"{{{ns['android']}}}title", item["title"])
|
||||
pref.set(f"{{{ns['android']}}}summary", item["description"])
|
||||
pref.set(f"{{{ns['app']}}}icon", item["icon"])
|
||||
pref.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"])
|
||||
for item in items:
|
||||
pref = etree.SubElement(cat, "Preference", nsmap=ns)
|
||||
pref.set(f"{{{ns['android']}}}title", item["title"])
|
||||
pref.set(f"{{{ns['android']}}}summary", item["description"])
|
||||
pref.set(f"{{{ns['app']}}}icon", item["icon"])
|
||||
pref.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"])
|
||||
|
||||
intent = etree.SubElement(pref, "intent", nsmap=ns)
|
||||
intent.set(f"{{{ns['android']}}}action", "android.intent.action.VIEW")
|
||||
intent.set(f"{{{ns['android']}}}data", item["url"])
|
||||
intent.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"])
|
||||
intent = etree.SubElement(pref, "intent", nsmap=ns)
|
||||
intent.set(f"{{{ns['android']}}}action", "android.intent.action.VIEW")
|
||||
intent.set(f"{{{ns['android']}}}data", item["url"])
|
||||
intent.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"])
|
||||
|
||||
return cat
|
||||
return cat
|
||||
|
||||
def apply(config: Config, base: Dict[str, Any]) -> bool:
|
||||
# Добавление кастомных иконок
|
||||
shutil.copy(
|
||||
"./resources/ic_custom_crown.xml",
|
||||
"./decompiled/res/drawable/ic_custom_crown.xml",
|
||||
)
|
||||
insert_after_public("warning_error_counter_background", "ic_custom_crown")
|
||||
def apply(self, base: Dict[str, Any]) -> bool:
|
||||
# Добавление кастомных иконок
|
||||
shutil.copy(
|
||||
"./resources/ic_custom_crown.xml",
|
||||
"./decompiled/res/drawable/ic_custom_crown.xml",
|
||||
)
|
||||
insert_after_public("warning_error_counter_background", "ic_custom_crown")
|
||||
|
||||
shutil.copy(
|
||||
"./resources/ic_custom_telegram.xml",
|
||||
"./decompiled/res/drawable/ic_custom_telegram.xml",
|
||||
)
|
||||
insert_after_public("warning_error_counter_background", "ic_custom_telegram")
|
||||
shutil.copy(
|
||||
"./resources/ic_custom_telegram.xml",
|
||||
"./decompiled/res/drawable/ic_custom_telegram.xml",
|
||||
)
|
||||
insert_after_public("warning_error_counter_background", "ic_custom_telegram")
|
||||
|
||||
file_path = "./decompiled/res/xml/preference_main.xml"
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(file_path, parser)
|
||||
root = tree.getroot()
|
||||
file_path = "./decompiled/res/xml/preference_main.xml"
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(file_path, parser)
|
||||
root = tree.getroot()
|
||||
|
||||
# Вставка новых пунктов перед последним
|
||||
pos = root.index(root[-1])
|
||||
for section, items in config.menu.items():
|
||||
root.insert(pos, make_category(base["xml_ns"], section, items))
|
||||
pos += 1
|
||||
# Вставка новых пунктов перед последним
|
||||
pos = root.index(root[-1])
|
||||
for section, items in self.menu.items():
|
||||
root.insert(pos, self.make_category(base["xml_ns"], section, items))
|
||||
pos += 1
|
||||
|
||||
# Сохранение
|
||||
tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8")
|
||||
# Сохранение
|
||||
tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8")
|
||||
|
||||
# Добавление суффикса версии
|
||||
filepaths = [
|
||||
"./decompiled/smali_classes2/com/swiftsoft/anixartd/ui/activity/UpdateActivity.smali",
|
||||
"./decompiled/smali_classes2/com/swiftsoft/anixartd/ui/fragment/main/preference/MainPreferenceFragment.smali",
|
||||
]
|
||||
for filepath in filepaths:
|
||||
content = ""
|
||||
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('"'):]
|
||||
else:
|
||||
content += line
|
||||
with open(filepath, "w", encoding="utf-8") as file:
|
||||
file.write(content)
|
||||
return True
|
||||
# Добавление суффикса версии
|
||||
filepaths = [
|
||||
"./decompiled/smali_classes2/com/swiftsoft/anixartd/ui/activity/UpdateActivity.smali",
|
||||
"./decompiled/smali_classes2/com/swiftsoft/anixartd/ui/fragment/main/preference/MainPreferenceFragment.smali",
|
||||
]
|
||||
for filepath in filepaths:
|
||||
content = ""
|
||||
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('"')]
|
||||
+ self.version
|
||||
+ line[line.rindex('"') :]
|
||||
)
|
||||
else:
|
||||
content += line
|
||||
with open(filepath, "w", encoding="utf-8") as file:
|
||||
file.write(content)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user