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,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue