forked from distok/cutthecord
Add xml-port support.
This commit is contained in:
parent
55e2e94b63
commit
1a7ad17c87
4 changed files with 154 additions and 102 deletions
|
@ -14,14 +14,20 @@ FORCE = False
|
|||
DEFAULT_PATCHES = ["necessary", "branding", "customversion"]
|
||||
OPTIONAL_PATCHES = ["necessary", "blobs"]
|
||||
|
||||
def xmlpatch(patch_file, workdir, patch_name=""):
|
||||
if not os.path.exists(patch_file):
|
||||
# Allow missing patches
|
||||
return
|
||||
|
||||
print(f"Applying {patch_file}")
|
||||
|
||||
subprocess.run(f"java -cp /opt/ctc/tools/xml-patch.jar com.github.dnault.xmlpatch.BatchPatcher --patch {patch_file} --srcdir {workdir}",
|
||||
shell=True, check=True, cwd=workdir)
|
||||
|
||||
def patch(patch_file, workdir, patch_name=""):
|
||||
if not os.path.exists(patch_file):
|
||||
# Allow missing optional patches
|
||||
if patch_name in OPTIONAL_PATCHES:
|
||||
return
|
||||
|
||||
raise FileNotFoundError(f"No patches with name \"{patch_file}\" :(")
|
||||
# Allow missing patches
|
||||
return
|
||||
|
||||
print(f"Applying {patch_file}")
|
||||
|
||||
|
@ -78,42 +84,34 @@ shutil.copytree(BASE_APK_PATH, WORK_APK_PATH)
|
|||
|
||||
# Go through patches and apply every single one of them
|
||||
for patch_name in PATCHES:
|
||||
pre_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, f"{VERSION}-pre.sh")
|
||||
pre_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, f"{VERSION}-pre.sh")
|
||||
if os.path.exists(pre_script):
|
||||
subprocess.run(f"bash {pre_script}",
|
||||
shell=True,
|
||||
cwd=WORK_APK_PATH)
|
||||
subprocess.run(f"bash {pre_script}", shell=True, cwd=WORK_APK_PATH)
|
||||
pre_script = os.path.join(REPO_FOLDER, "resources/xmlpatches", patch_name, f"{VERSION}-pre.sh")
|
||||
if os.path.exists(pre_script):
|
||||
subprocess.run(f"bash {pre_script}", shell=True, cwd=WORK_APK_PATH)
|
||||
|
||||
# Apply custom emoji patches
|
||||
if patch_name in ["mutant", "blobs"]:
|
||||
print(f"Applying {patch_name} emoji patch")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "emojireplace.py")
|
||||
subprocess.run(f"{PYTHON_BIN} {patch_script}",
|
||||
shell=True,
|
||||
cwd=WORK_APK_PATH)
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "emojireplace.py")
|
||||
subprocess.run(f"{PYTHON_BIN} {patch_script}", shell=True, cwd=WORK_APK_PATH)
|
||||
|
||||
# Apply custom emoji patches
|
||||
elif patch_name == "customtheme":
|
||||
print(f"Applying splash patch")
|
||||
splash = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "asset_loading.png")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "fixsplash.sh")
|
||||
splash = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "asset_loading.png")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "fixsplash.sh")
|
||||
|
||||
subprocess.run(f"bash {patch_script} {splash}",
|
||||
shell=True,
|
||||
cwd=WORK_APK_PATH)
|
||||
subprocess.run(f"bash {patch_script} {splash}", shell=True, cwd=WORK_APK_PATH)
|
||||
|
||||
patch_file = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, f"{VERSION}.patch")
|
||||
patch_file = os.path.join(REPO_FOLDER, "resources/patches", patch_name, f"{VERSION}.patch")
|
||||
xml_patch_file = os.path.join(REPO_FOLDER, "resources/xmlpatches", patch_name, f"{VERSION}.xml")
|
||||
|
||||
# Apply custom version patches
|
||||
if patch_name == "customversion":
|
||||
print(f"Applying custom version")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "addpatch.py")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "addpatch.py")
|
||||
|
||||
subprocess.run(f"{PYTHON_BIN} {patch_script} {patch_file} "
|
||||
f"{' '.join(PATCHES)}",
|
||||
|
@ -126,44 +124,31 @@ for patch_name in PATCHES:
|
|||
print(f"Applying branding icon patch")
|
||||
if BRANCH in ICONS:
|
||||
shutil.copyfile(ICONS[BRANCH],
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"mipmap-xxxhdpi", "logo_debug.png"))
|
||||
os.path.join(WORK_APK_PATH, "res", "mipmap-xxxhdpi", "logo_debug.png"))
|
||||
elif "default" in ICONS:
|
||||
shutil.copyfile(ICONS["default"],
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"mipmap-xxxhdpi", "logo_debug.png"))
|
||||
os.path.join(WORK_APK_PATH, "res", "mipmap-xxxhdpi", "logo_debug.png"))
|
||||
|
||||
if BRANCH in DYN_ICONS:
|
||||
shutil.copyfile(DYN_ICONS[BRANCH]["bg"],
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"mipmap-xxxhdpi",
|
||||
"ic_launcher_background.png"))
|
||||
os.path.join(WORK_APK_PATH, "res", "mipmap-xxxhdpi", "ic_launcher_background.png"))
|
||||
shutil.copyfile(DYN_ICONS[BRANCH]["fg"],
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"mipmap-xxxhdpi",
|
||||
"ic_launcher_foreground.png"))
|
||||
os.path.join(WORK_APK_PATH, "res", "mipmap-xxxhdpi", "ic_launcher_foreground.png"))
|
||||
elif "default" in ICONS:
|
||||
shutil.copyfile(DYN_ICONS["default"]["bg"],
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"mipmap-xxxhdpi",
|
||||
"ic_launcher_background.png"))
|
||||
os.path.join(WORK_APK_PATH, "res", "mipmap-xxxhdpi", "ic_launcher_background.png"))
|
||||
shutil.copyfile(DYN_ICONS["default"]["fg"],
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"mipmap-xxxhdpi",
|
||||
"ic_launcher_foreground.png"))
|
||||
os.path.join(WORK_APK_PATH, "res", "mipmap-xxxhdpi", "ic_launcher_foreground.png"))
|
||||
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "customicon.sh")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "customicon.sh")
|
||||
|
||||
subprocess.run(f"bash {patch_script}", shell=True, cwd=WORK_APK_PATH)
|
||||
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "customdynamicicon.sh")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "customdynamicicon.sh")
|
||||
|
||||
subprocess.run(f"bash {patch_script}", shell=True, cwd=WORK_APK_PATH)
|
||||
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "addpatch.py")
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "addpatch.py")
|
||||
|
||||
# Hell code
|
||||
app_name = APP_NAMES.get(BRANCH, APP_NAMES.get("default", "CutTheCord"))
|
||||
|
@ -176,13 +161,9 @@ for patch_name in PATCHES:
|
|||
patch(patch_file.replace(".patch", "-custom.patch"), WORK_APK_PATH)
|
||||
elif patch_name in ["bettertm", "bettertmlight"]:
|
||||
print(f"Applying bettertm emoji patch")
|
||||
patch_dir = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name)
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, "bettertm.sh")
|
||||
subprocess.run(f"bash {patch_script} {patch_dir}",
|
||||
shell=True,
|
||||
cwd=WORK_APK_PATH)
|
||||
patch_dir = os.path.join(REPO_FOLDER, "resources/patches", patch_name)
|
||||
patch_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, "bettertm.sh")
|
||||
subprocess.run(f"bash {patch_script} {patch_dir}", shell=True, cwd=WORK_APK_PATH)
|
||||
# Apply custom ringtone
|
||||
elif patch_name == "customring":
|
||||
print(f"Applying custom ringtone")
|
||||
|
@ -191,9 +172,7 @@ for patch_name in PATCHES:
|
|||
else:
|
||||
CUSTOM_RINGTONE = RINGTONES["default"]
|
||||
|
||||
shutil.copyfile(CUSTOM_RINGTONE,
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"raw", "call_ringing.mp3"))
|
||||
shutil.copyfile(CUSTOM_RINGTONE, os.path.join(WORK_APK_PATH, "res", "raw", "call_ringing.mp3"))
|
||||
# Apply custom fonts
|
||||
elif patch_name == "customfont":
|
||||
print(f"Applying custom font")
|
||||
|
@ -203,19 +182,18 @@ for patch_name in PATCHES:
|
|||
fonts = FONTS["default"]
|
||||
|
||||
for font in fonts:
|
||||
shutil.copyfile(fonts[font],
|
||||
os.path.join(WORK_APK_PATH, "res",
|
||||
"font", font))
|
||||
shutil.copyfile(fonts[font], os.path.join(WORK_APK_PATH, "res", "font", font))
|
||||
# Apply any other patches
|
||||
else:
|
||||
patch(patch_file, WORK_APK_PATH, patch_name)
|
||||
xmlpatch(xml_patch_file, WORK_APK_PATH, patch_name)
|
||||
|
||||
post_script = os.path.join(REPO_FOLDER, "resources/patches",
|
||||
patch_name, f"{VERSION}-post.sh")
|
||||
post_script = os.path.join(REPO_FOLDER, "resources/patches", patch_name, f"{VERSION}-post.sh")
|
||||
if os.path.exists(post_script):
|
||||
subprocess.run(f"bash {post_script}",
|
||||
shell=True,
|
||||
cwd=WORK_APK_PATH)
|
||||
subprocess.run(f"bash {post_script}", shell=True, cwd=WORK_APK_PATH)
|
||||
post_script = os.path.join(REPO_FOLDER, "resources/xmlpatches", patch_name, f"{VERSION}-post.sh")
|
||||
if os.path.exists(post_script):
|
||||
subprocess.run(f"bash {post_script}", shell=True, cwd=WORK_APK_PATH)
|
||||
|
||||
# Pack the APK
|
||||
subprocess.run(f"{APKTOOL_BIN} b discord",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue