mirror of
https://github.com/Radiquum/anixart-patcher.git
synced 2025-09-06 11:13:51 +05:00
refactor: tqdm -> rich.progress
This commit is contained in:
parent
43b1406b4a
commit
7b5ba163bd
10 changed files with 260 additions and 141 deletions
|
@ -1,73 +1,88 @@
|
|||
"""Change app color theme"""
|
||||
|
||||
# patch settings
|
||||
# priority, default: -99 (run before last)
|
||||
priority = -99
|
||||
|
||||
import os
|
||||
# imports
|
||||
## bundled
|
||||
from typing import TypedDict
|
||||
from beaupy import select
|
||||
from tqdm import tqdm
|
||||
|
||||
## installed
|
||||
from lxml import etree
|
||||
|
||||
## custom
|
||||
from config import config, log, console
|
||||
|
||||
|
||||
class PatchConfig_ChangeColorThemeValue(TypedDict):
|
||||
attributes: list[dict[str, str]]
|
||||
text: list[dict[str, str]]
|
||||
files: list[dict[str, str]]
|
||||
|
||||
|
||||
class PatchConfig_ChangeColorTheme(TypedDict):
|
||||
src: str
|
||||
themes: str
|
||||
themes: list[str]
|
||||
key: PatchConfig_ChangeColorThemeValue
|
||||
|
||||
def apply(config: PatchConfig_ChangeColorTheme) -> bool:
|
||||
print("select color theme to apply")
|
||||
|
||||
theme = select(config["themes"], cursor="->", cursor_style="cyan")
|
||||
theme_attr = config[theme]['attributes']
|
||||
theme_text = config[theme]['text']
|
||||
theme_files = config[theme]['files']
|
||||
def apply(patch_config: PatchConfig_ChangeColorTheme) -> bool:
|
||||
|
||||
with tqdm(
|
||||
total=len(theme_attr),
|
||||
unit="attr",
|
||||
unit_divisor=1,
|
||||
desc="color attributes"
|
||||
) as bar:
|
||||
for attr in theme_attr:
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(f"{config['src']}/{attr['file_path']}", parser)
|
||||
root = tree.getroot()
|
||||
root.find(attr['tag_path']).set(attr['attr_name'], attr['attr_value']['to'])
|
||||
tree.write(
|
||||
f"{config['src']}/{attr['file_path']}",
|
||||
pretty_print=True,
|
||||
xml_declaration=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
bar.update()
|
||||
|
||||
with tqdm(
|
||||
total=len(theme_text),
|
||||
unit="attr",
|
||||
unit_divisor=1,
|
||||
desc="color values"
|
||||
) as bar:
|
||||
for text in theme_text:
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(f"{config['src']}/{text['file_path']}", parser)
|
||||
root = tree.getroot()
|
||||
root.find(text['tag_path']).text = text['text']['to']
|
||||
tree.write(
|
||||
f"{config['src']}/{text['file_path']}",
|
||||
pretty_print=True,
|
||||
xml_declaration=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
bar.update()
|
||||
console.print("select color theme to apply (press [bold]enter[/bold] to confirm)")
|
||||
theme = select(patch_config["themes"], cursor="->", cursor_style="cyan")
|
||||
if not theme:
|
||||
console.print(f"theme: default")
|
||||
return False
|
||||
console.print(f"theme: {theme}")
|
||||
|
||||
theme_attr = patch_config[theme]["attributes"]
|
||||
theme_text = patch_config[theme]["text"]
|
||||
theme_files = patch_config[theme]["files"]
|
||||
|
||||
for item in theme_attr:
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(
|
||||
f"{config['folders']['decompiled']}/{item['file_path']}", parser
|
||||
)
|
||||
root = tree.getroot()
|
||||
root.find(item["tag_path"]).set(item["attr_name"], item["attr_value"]["to"])
|
||||
tree.write(
|
||||
f"{config['folders']['decompiled']}/{item['file_path']}",
|
||||
pretty_print=True,
|
||||
xml_declaration=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
log.debug(
|
||||
f"[CHANGE_COLOR_THEME/ATTRIBUTES] set attribute `{item['attr_name']}` from `{item['attr_value']['from']}` to `{item['attr_value']['to']}`"
|
||||
)
|
||||
|
||||
for item in theme_text:
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(
|
||||
f"{config['folders']['decompiled']}/{item['file_path']}", parser
|
||||
)
|
||||
root = tree.getroot()
|
||||
root.find(item["tag_path"]).text = item["text"]["to"]
|
||||
tree.write(
|
||||
f"{config['folders']['decompiled']}/{item['file_path']}",
|
||||
pretty_print=True,
|
||||
xml_declaration=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
log.debug(
|
||||
f"[CHANGE_COLOR_THEME/VALUES] set text from `{item['text']['from']}` to `{item['text']['to']}`"
|
||||
)
|
||||
|
||||
if len(theme_files) > 0:
|
||||
with tqdm(
|
||||
total=len(theme_files),
|
||||
unit="files",
|
||||
unit_divisor=1,
|
||||
desc="color files"
|
||||
) as bar:
|
||||
for file in theme_files:
|
||||
with open(f"{config['src']}/{file['file_path']}", "w", encoding="utf-8") as f:
|
||||
f.write("\n".join(file['file_content']))
|
||||
bar.update()
|
||||
|
||||
return True
|
||||
for item in theme_files:
|
||||
with open(
|
||||
f"{config['folders']['decompiled']}/{item['file_path']}",
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
) as f:
|
||||
f.write("\n".join(item["file_content"]))
|
||||
log.debug(f"[CHANGE_COLOR_THEME/FILES] replaced file {item['file_path']}")
|
||||
|
||||
log.debug(f"[CHANGE_COLOR_THEME] color theme `{theme}` has been applied")
|
||||
return True
|
||||
|
|
|
@ -1,36 +1,51 @@
|
|||
"""Change package name"""
|
||||
|
||||
# patch settings
|
||||
# priority, default: -100 (run last)
|
||||
priority = -100
|
||||
|
||||
# imports
|
||||
## bundled
|
||||
import os
|
||||
from typing import TypedDict
|
||||
|
||||
## custom
|
||||
from config import config, log
|
||||
|
||||
|
||||
class PatchConfig_ChangePackageName(TypedDict):
|
||||
src: str
|
||||
new_package_name: str
|
||||
|
||||
|
||||
def rename_dir(src, dst):
|
||||
os.makedirs(dst, exist_ok=True)
|
||||
os.rename(src, dst)
|
||||
|
||||
def apply(config: dict) -> bool:
|
||||
assert config["new_package_name"] is not None, "new_package_name is not configured"
|
||||
|
||||
for root, dirs, files in os.walk(f"{config['src']}"):
|
||||
def apply(patch_config: PatchConfig_ChangePackageName) -> bool:
|
||||
assert (
|
||||
patch_config["new_package_name"] is not None
|
||||
), "new_package_name is not configured"
|
||||
|
||||
for root, dirs, files in os.walk(f"{config['folders']['decompiled']}"):
|
||||
if len(files) < 0:
|
||||
continue
|
||||
|
||||
dir_name = root.removeprefix(f"{config['folders']['decompiled']}/")
|
||||
|
||||
for filename in files:
|
||||
file_path = os.path.join(root, filename)
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
file_contents = file.read()
|
||||
|
||||
new_contents = file_contents.replace(
|
||||
"com.swiftsoft.anixartd", config["new_package_name"]
|
||||
"com.swiftsoft.anixartd", patch_config["new_package_name"]
|
||||
)
|
||||
new_contents = new_contents.replace(
|
||||
"com/swiftsoft/anixartd",
|
||||
config["new_package_name"].replace(".", "/"),
|
||||
patch_config["new_package_name"].replace(".", "/"),
|
||||
)
|
||||
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
|
@ -38,22 +53,31 @@ def apply(config: dict) -> bool:
|
|||
except:
|
||||
pass
|
||||
|
||||
if os.path.exists(f"{config['src']}/smali/com/swiftsoft/anixartd"):
|
||||
if os.path.exists(
|
||||
f"{config['folders']['decompiled']}/smali/com/swiftsoft/anixartd"
|
||||
):
|
||||
rename_dir(
|
||||
f"{config['src']}/smali/com/swiftsoft/anixartd",
|
||||
f"{config['folders']['decompiled']}/smali/com/swiftsoft/anixartd",
|
||||
os.path.join(
|
||||
f"{config['src']}", "smali", config["new_package_name"].replace(".", "/")
|
||||
f"{config['folders']['decompiled']}",
|
||||
"smali",
|
||||
patch_config["new_package_name"].replace(".", "/"),
|
||||
),
|
||||
)
|
||||
|
||||
if os.path.exists(f"{config['src']}/smali_classes2/com/swiftsoft/anixartd"):
|
||||
if os.path.exists(
|
||||
f"{config['folders']['decompiled']}/smali_classes2/com/swiftsoft/anixartd"
|
||||
):
|
||||
rename_dir(
|
||||
f"{config['src']}/smali_classes2/com/swiftsoft/anixartd",
|
||||
f"{config['folders']['decompiled']}/smali_classes2/com/swiftsoft/anixartd",
|
||||
os.path.join(
|
||||
f"{config['src']}",
|
||||
f"{config['folders']['decompiled']}",
|
||||
"smali_classes2",
|
||||
config["new_package_name"].replace(".", "/"),
|
||||
patch_config["new_package_name"].replace(".", "/"),
|
||||
),
|
||||
)
|
||||
|
||||
return True
|
||||
log.debug(
|
||||
f"[CHANGE_PACKAGE_NAME] package name has been changed to {patch_config['new_package_name']}"
|
||||
)
|
||||
return True
|
||||
|
|
|
@ -1,25 +1,45 @@
|
|||
"""Remove unnecessary resources"""
|
||||
|
||||
# patch settings
|
||||
# priority, default: 0
|
||||
priority = 0
|
||||
from tqdm import tqdm
|
||||
|
||||
# imports
|
||||
## bundled
|
||||
import os
|
||||
import shutil
|
||||
from typing import TypedDict
|
||||
|
||||
## installed
|
||||
from rich.progress import track
|
||||
|
||||
## custom
|
||||
from config import config, log, console
|
||||
|
||||
|
||||
# Patch
|
||||
|
||||
class PatchConfig_Compress(TypedDict):
|
||||
src: str
|
||||
keep_dirs: list[str]
|
||||
|
||||
def apply(config: PatchConfig_Compress) -> bool:
|
||||
for item in os.listdir(f"{config['src']}/unknown/"):
|
||||
item_path = os.path.join(f"{config['src']}/unknown/", item)
|
||||
def apply(patch_config: PatchConfig_Compress) -> bool:
|
||||
path = f"{config['folders']['decompiled']}/unknown"
|
||||
items = os.listdir(path)
|
||||
|
||||
for item in track(
|
||||
items,
|
||||
console=console,
|
||||
description="[COMPRESS]",
|
||||
total=len(items),
|
||||
):
|
||||
item_path = f"{path}/{item}"
|
||||
if os.path.isfile(item_path):
|
||||
os.remove(item_path)
|
||||
tqdm.write(f"removed file: {item_path}")
|
||||
log.debug(f"[COMPRESS] removed file: {item_path}")
|
||||
elif os.path.isdir(item_path):
|
||||
if item not in config["keep_dirs"]:
|
||||
if item not in patch_config["keep_dirs"]:
|
||||
shutil.rmtree(item_path)
|
||||
tqdm.write(f"removed directory: {item_path}")
|
||||
log.debug(f"[COMPRESS] removed directory: {item_path}")
|
||||
|
||||
log.debug(f"[COMPRESS] resources have been removed")
|
||||
return True
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
"""Disable ad banners"""
|
||||
|
||||
# patch settings
|
||||
# priority, default: 0
|
||||
priority = 0
|
||||
from typing import TypedDict
|
||||
|
||||
# imports
|
||||
## custom
|
||||
from config import config, log
|
||||
from scripts.smali_parser import (
|
||||
find_smali_method_end,
|
||||
find_smali_method_start,
|
||||
|
@ -11,10 +15,7 @@ from scripts.smali_parser import (
|
|||
)
|
||||
|
||||
|
||||
class PatchConfig_DisableAdBanner(TypedDict):
|
||||
src: str
|
||||
|
||||
|
||||
# Patch
|
||||
replace = """ .locals 0
|
||||
|
||||
const/4 p0, 0x1
|
||||
|
@ -23,9 +24,10 @@ replace = """ .locals 0
|
|||
"""
|
||||
|
||||
|
||||
def apply(config: PatchConfig_DisableAdBanner) -> bool:
|
||||
path = f"{config['src']}/smali_classes2/com/swiftsoft/anixartd/Prefs.smali"
|
||||
def apply(__no_config__) -> bool:
|
||||
path = f"{config['folders']['decompiled']}/smali_classes2/com/swiftsoft/anixartd/Prefs.smali"
|
||||
lines = get_smali_lines(path)
|
||||
|
||||
for index, line in enumerate(lines):
|
||||
if line.find("IS_SPONSOR") >= 0:
|
||||
method_start = find_smali_method_start(lines, index)
|
||||
|
@ -33,7 +35,8 @@ def apply(config: PatchConfig_DisableAdBanner) -> bool:
|
|||
new_content = replace_smali_method_body(
|
||||
lines, method_start, method_end, replace
|
||||
)
|
||||
|
||||
with open(path, "w", encoding="utf-8") as file:
|
||||
file.writelines(new_content)
|
||||
|
||||
log.debug(f"[DISABLE_AD] file {path} has been modified")
|
||||
return True
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
"""Remove beta banner"""
|
||||
|
||||
# patch settings
|
||||
# priority, default: 0
|
||||
priority = 0
|
||||
|
||||
# imports
|
||||
## bundled
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
|
||||
## installed
|
||||
from lxml import etree
|
||||
|
||||
from typing import TypedDict
|
||||
## custom
|
||||
from config import config, log
|
||||
|
||||
|
||||
class PatchConfig_DisableBetaBanner(TypedDict):
|
||||
src: str
|
||||
|
||||
|
||||
def apply(config: PatchConfig_DisableBetaBanner) -> bool:
|
||||
xml_ns = {
|
||||
"android": "http://schemas.android.com/apk/res/android",
|
||||
"app": "http://schemas.android.com/apk/res-auto",
|
||||
}
|
||||
def apply(__no_config__) -> bool:
|
||||
beta_banner_xml = f"{config['folders']['decompiled']}/res/layout/item_beta.xml"
|
||||
attributes = [
|
||||
"paddingTop",
|
||||
"paddingBottom",
|
||||
|
@ -27,19 +27,23 @@ def apply(config: PatchConfig_DisableBetaBanner) -> bool:
|
|||
"layout_marginTop",
|
||||
"layout_marginBottom",
|
||||
"layout_marginStart",
|
||||
"layout_marginEnd"
|
||||
"layout_marginEnd",
|
||||
]
|
||||
|
||||
beta_banner_xml = f"{config['src']}/res/layout/item_beta.xml"
|
||||
if os.path.exists(beta_banner_xml):
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(beta_banner_xml, parser)
|
||||
root = tree.getroot()
|
||||
|
||||
|
||||
for attr in attributes:
|
||||
tqdm.write(f"set {attr} = 0.0dip")
|
||||
root.set(f"{{{xml_ns['android']}}}{attr}", "0.0dip")
|
||||
log.debug(
|
||||
f"[DISABLE_BETA_BANNER] set attribute `{attr}` from `{root.get(attr)}` to `0.0dip`"
|
||||
)
|
||||
root.set(f"{{{config['xml_ns']['android']}}}{attr}", "0.0dip")
|
||||
|
||||
tree.write(beta_banner_xml, pretty_print=True, xml_declaration=True, encoding="utf-8")
|
||||
tree.write(
|
||||
beta_banner_xml, pretty_print=True, xml_declaration=True, encoding="utf-8"
|
||||
)
|
||||
|
||||
log.debug(f"[DISABLE_BETA_BANNER] file {beta_banner_xml} has been modified")
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue