forked from anixart-mod/patcher
Обновление структуры проекта, использование pydantic для конфигураций, улучшение отчёта о патчах
This commit is contained in:
+16
-11
@@ -12,7 +12,15 @@ priority = -1
|
||||
# imports
|
||||
import os
|
||||
from lxml import etree
|
||||
from tqdm import tqdm
|
||||
from typing import Dict, Any
|
||||
from pydantic import Field
|
||||
|
||||
from utils.config import PatchConfig
|
||||
|
||||
#Config
|
||||
class Config(PatchConfig):
|
||||
package_name: str = Field("com.wowlikon.anixart", description="Название пакета")
|
||||
|
||||
# Patch
|
||||
def rename_dir(src, dst):
|
||||
@@ -20,7 +28,7 @@ def rename_dir(src, dst):
|
||||
os.rename(src, dst)
|
||||
|
||||
|
||||
def apply(config: dict) -> bool:
|
||||
def apply(config: Config, base: Dict[str, Any]) -> bool:
|
||||
for root, dirs, files in os.walk("./decompiled"):
|
||||
for filename in files:
|
||||
file_path = os.path.join(root, filename)
|
||||
@@ -31,11 +39,11 @@ def apply(config: dict) -> bool:
|
||||
file_contents = file.read()
|
||||
|
||||
new_contents = file_contents.replace(
|
||||
"com.swiftsoft.anixartd", config["new_package_name"]
|
||||
"com.swiftsoft.anixartd", config.package_name
|
||||
)
|
||||
new_contents = new_contents.replace(
|
||||
"com/swiftsoft/anixartd",
|
||||
config["new_package_name"].replace(".", "/"),
|
||||
config.package_name.replace(".", "/"),
|
||||
)
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write(new_contents)
|
||||
@@ -46,7 +54,7 @@ def apply(config: dict) -> bool:
|
||||
rename_dir(
|
||||
"./decompiled/smali/com/swiftsoft/anixartd",
|
||||
os.path.join(
|
||||
"./decompiled", "smali", config["new_package_name"].replace(".", "/")
|
||||
"./decompiled", "smali", config.package_name.replace(".", "/")
|
||||
),
|
||||
)
|
||||
if os.path.exists("./decompiled/smali_classes2/com/swiftsoft/anixartd"):
|
||||
@@ -55,7 +63,7 @@ def apply(config: dict) -> bool:
|
||||
os.path.join(
|
||||
"./decompiled",
|
||||
"smali_classes2",
|
||||
config["new_package_name"].replace(".", "/"),
|
||||
config.package_name.replace(".", "/"),
|
||||
),
|
||||
)
|
||||
if os.path.exists("./decompiled/smali_classes4/com/swiftsoft"):
|
||||
@@ -64,7 +72,7 @@ def apply(config: dict) -> bool:
|
||||
os.path.join(
|
||||
"./decompiled",
|
||||
"smali_classes4",
|
||||
"/".join(config["new_package_name"].split(".")[:-1]),
|
||||
"/".join(config.package_name.split(".")[:-1]),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -88,7 +96,7 @@ def apply(config: dict) -> bool:
|
||||
|
||||
new_contents = file_contents.replace(
|
||||
"com/swiftsoft",
|
||||
"/".join(config["new_package_name"].split(".")[:-1]),
|
||||
"/".join(config.package_name.split(".")[:-1]),
|
||||
)
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write(new_contents)
|
||||
@@ -101,11 +109,8 @@ def apply(config: dict) -> bool:
|
||||
root = tree.getroot()
|
||||
|
||||
last_linear = root.xpath("//LinearLayout/LinearLayout[4]")[0]
|
||||
last_linear.set(f"{{{config['xml_ns']['android']}}}visibility", "gone")
|
||||
last_linear.set(f"{{{base['xml_ns']['android']}}}visibility", "gone")
|
||||
|
||||
tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# smali_classes2/com/wowlikon/anixart/utils/DeviceInfoUtil.smali: const-string v3, "\u0411\u0430\u0433-\u0440\u0435\u043f\u043e\u0440\u0442 9.0 BETA 5 (25062213)"
|
||||
|
||||
Reference in New Issue
Block a user