1
0
Fork 0
mirror of https://github.com/Radiquum/anixart-patcher.git synced 2025-09-07 19:53:50 +05:00

feat: [R] Include enabled patches, developer and more info in settings

Fixes #4
This commit is contained in:
Kentai Radiquum 2025-09-04 14:12:41 +05:00
parent 67a45a9ac6
commit 7cae88c2ef
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
5 changed files with 117 additions and 8 deletions

View file

@ -1,3 +1,24 @@
{
"add_patch_info": true
"add_patch_info": true,
"main_settings_categories": [
{
"title": "anixart-patcher",
"items": [
{
"title": "Radiquum",
"summary": "Разработчик",
"url": "https://radiquum.wah.su/",
"icon": "@drawable/solar_code_2_bold",
"icon_space_reserved": false
},
{
"title": "Репозиторий",
"summary": "https://github.com/Radiquum/anixart-patcher",
"url": "https://github.com/Radiquum/anixart-patcher",
"icon": "@drawable/github_mark",
"icon_space_reserved": false
}
]
}
]
}

View file

@ -1,4 +1,5 @@
"""Adds used patches and custom menu items to app settings"""
# Developer: Radiquum
# URL:
@ -9,6 +10,7 @@ priority = -95
# imports
## bundled
import os
import shutil
import random
import string
from typing import TypedDict
@ -21,9 +23,23 @@ from config import config, log
# Patch
class PatchConfig_AddSettingsMenuItemsCategoryItem(TypedDict):
title: str
summary: str | None
url: str | None
icon: str | None
icon_space_reserved: bool
class PatchConfig_AddSettingsMenuItemsCategory(TypedDict):
title: str
items: list[PatchConfig_AddSettingsMenuItemsCategoryItem]
class PatchConfig_AddSettingsMenuItems(TypedDict):
_internal_all_patch_statuses: list
add_patch_info: bool
main_settings_categories: list[PatchConfig_AddSettingsMenuItemsCategory]
def random_key():
@ -53,14 +69,14 @@ def create_intent(
def create_Preference(
title: str,
description: str | None = None,
summary: str | None = None,
icon: str | None = None,
icon_space_reserved: bool = False,
):
ns = config["xml_ns"]
item = etree.Element("Preference", nsmap=ns)
item.set(f"{{{ns['android']}}}title", title)
item.set(f"{{{ns['android']}}}summary", description or "")
item.set(f"{{{ns['android']}}}summary", summary or "")
if icon:
item.set(f"{{{ns['app']}}}icon", icon)
item.set(f"{{{ns['app']}}}iconSpaceReserved", str(icon_space_reserved).lower())
@ -77,6 +93,23 @@ def create_PreferenceCategory(title: str):
return category
def add_icons():
src_icon_path = f"{config["folders"]["patches"]}/resources/icons"
src_icon_night_path = f"{config["folders"]["patches"]}/resources/icons-night"
dst_icon_path = f"{config["folders"]["decompiled"]}/res/drawable"
dst_icon_night_path = f"{config["folders"]["decompiled"]}/res/drawable-night"
icons = os.listdir(src_icon_path)
if len(icons) == 0:
return
for icon in icons:
shutil.copy(f"{src_icon_path}/{icon}", f"{dst_icon_path}/{icon}")
if os.path.exists(f"{src_icon_night_path}/{icon}"):
shutil.copy(
f"{src_icon_night_path}/{icon}", f"{dst_icon_night_path}/{icon}"
)
def add_patch_info(patch_statuses: list):
category = create_PreferenceCategory("Использованные патчи")
for patch in patch_statuses:
@ -91,23 +124,48 @@ def add_patch_info(patch_statuses: list):
) as f:
line = f.readline()
if line.startswith('"""'):
description.append(line.strip().removeprefix('"""').removesuffix('"""').strip())
description.append(
line.strip().removeprefix('"""').removesuffix('"""').strip()
)
line = f.readline()
if line.startswith("# Developer:"):
description.append("by")
description.append(line.strip().removeprefix("# Developer:").strip())
description.append(
line.strip().removeprefix("# Developer:").strip()
)
line = f.readline()
if line.startswith("# URL:"):
url = line.strip().removeprefix("# URL:").strip()
item = create_Preference(patch["name"].replace("_", " ").strip().title(), description=" ".join(description))
item = create_Preference(
patch["name"].replace("_", " ").strip().title(),
description=" ".join(description),
)
if url:
item.append(create_intent(data = url))
item.append(create_intent(data=url))
category.append(item)
return category
def add_custom_category(
title: str, items: list[PatchConfig_AddSettingsMenuItemsCategoryItem]
):
category = create_PreferenceCategory(title)
for item in items:
new_item = create_Preference(
item["title"],
item["summary"],
item["icon"],
item["icon_space_reserved"],
)
if item["url"]:
new_item.append(create_intent(data=item["url"]))
category.append(new_item)
return category
def apply(patch_conf: PatchConfig_AddSettingsMenuItems) -> bool:
parser = etree.XMLParser(remove_blank_text=True)
preference_main_xml = (
f"{config['folders']['decompiled']}/res/xml/preference_main.xml"
)
@ -115,7 +173,22 @@ def apply(patch_conf: PatchConfig_AddSettingsMenuItems) -> bool:
f"{config['folders']['decompiled']}/res/xml/preference_additional.xml"
)
parser = etree.XMLParser(remove_blank_text=True)
add_icons()
if os.path.exists(preference_main_xml):
tree = etree.parse(preference_main_xml, parser)
root = tree.getroot()
last = root[-1]; pos = root.index(last)
for item in patch_conf["main_settings_categories"]:
root.insert(pos, add_custom_category(item["title"], item["items"])); pos += 1
tree.write(
preference_main_xml,
pretty_print=True,
xml_declaration=True,
encoding="utf-8",
)
if os.path.exists(preference_additional_xml):
tree = etree.parse(preference_additional_xml, parser)

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt" android:viewportWidth="96.0" android:viewportHeight="96.0" android:width="24.0dip" android:height="24.0dip">
<path android:pathData="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427 0.49 3.316 -1.059 3.316 -2.362 0 -1.141 -0.08 -5.052 -0.08 -9.127 -13.59 2.934 -16.42 -5.867 -16.42 -5.867 -2.184 -5.704 -5.42 -7.17 -5.42 -7.17 -4.448 -3.015 0.324 -3.015 0.324 -3.015 4.934 0.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074 0.404 -3.178 1.699 -5.378 3.074 -6.6 -10.839 -1.141 -22.243 -5.378 -22.243 -24.283 0 -5.378 1.94 -9.778 5.014 -13.2 -0.485 -1.222 -2.184 -6.275 0.486 -13.038 0 0 4.125 -1.304 13.426 5.052a46.97 46.97 0 0 1 12.214 -1.63c4.125 0 8.33 0.571 12.213 1.63 9.302 -6.356 13.427 -5.052 13.427 -5.052 2.67 6.763 0.97 11.816 0.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905 -11.404 23.06 -22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6 -0.08 11.897 -0.08 13.526 0 1.304 0.89 2.853 3.316 2.364 19.412 -6.52 33.405 -24.935 33.405 -46.691C97.707 22 75.788 0 48.854 0z" android:fillType="evenOdd" android:fillColor="#FFFFFF" />
</vector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt" android:viewportWidth="96.0" android:viewportHeight="96.0" android:width="24.0dip" android:height="24.0dip">
<path android:pathData="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427 0.49 3.316 -1.059 3.316 -2.362 0 -1.141 -0.08 -5.052 -0.08 -9.127 -13.59 2.934 -16.42 -5.867 -16.42 -5.867 -2.184 -5.704 -5.42 -7.17 -5.42 -7.17 -4.448 -3.015 0.324 -3.015 0.324 -3.015 4.934 0.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074 0.404 -3.178 1.699 -5.378 3.074 -6.6 -10.839 -1.141 -22.243 -5.378 -22.243 -24.283 0 -5.378 1.94 -9.778 5.014 -13.2 -0.485 -1.222 -2.184 -6.275 0.486 -13.038 0 0 4.125 -1.304 13.426 5.052a46.97 46.97 0 0 1 12.214 -1.63c4.125 0 8.33 0.571 12.213 1.63 9.302 -6.356 13.427 -5.052 13.427 -5.052 2.67 6.763 0.97 11.816 0.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905 -11.404 23.06 -22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6 -0.08 11.897 -0.08 13.526 0 1.304 0.89 2.853 3.316 2.364 19.412 -6.52 33.405 -24.935 33.405 -46.691C97.707 22 75.788 0 48.854 0z" android:fillType="evenOdd" android:fillColor="#24292F" />
</vector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt" android:viewportWidth="24.0" android:viewportHeight="24.0" android:width="24.0dip" android:height="24.0dip">
<path android:pathData="M8.502 5.387a0.75 0.75 0 0 0 -1.004 -1.115L5.761 5.836c-0.737 0.663 -1.347 1.212 -1.767 1.71c-0.44 0.525 -0.754 1.088 -0.754 1.784c0 0.695 0.313 1.258 0.754 1.782c0.42 0.499 1.03 1.049 1.767 1.711l1.737 1.564a0.75 0.75 0 1 0 1.004 -1.115l-1.697 -1.527c-0.788 -0.709 -1.319 -1.19 -1.663 -1.598c-0.33 -0.393 -0.402 -0.622 -0.402 -0.817c0 -0.196 0.072 -0.425 0.402 -0.818c0.344 -0.409 0.875 -0.889 1.663 -1.598zm5.678 -1.112a0.75 0.75 0 0 1 0.532 0.918l-3.987 15a0.75 0.75 0 1 1 -1.45 -0.386l3.987 -15a0.75 0.75 0 0 1 0.918 -0.532m1.263 6.223a0.75 0.75 0 0 1 1.059 -0.055l1.737 1.563c0.737 0.663 1.347 1.213 1.767 1.711c0.44 0.524 0.754 1.088 0.754 1.783s-0.313 1.259 -0.754 1.783c-0.42 0.498 -1.03 1.048 -1.767 1.71l-1.737 1.565a0.75 0.75 0 1 1 -1.004 -1.116l1.697 -1.526c0.788 -0.71 1.319 -1.19 1.663 -1.599c0.33 -0.392 0.402 -0.622 0.402 -0.817s-0.072 -0.425 -0.402 -0.817c-0.344 -0.41 -0.875 -0.89 -1.663 -1.599l-1.697 -1.527a0.75 0.75 0 0 1 -0.055 -1.059" android:fillColor="?iconAccentTintColor" />
</vector>