diff --git a/buildtool/build.py b/buildtool/build.py
index ccd08b4..4ee3a17 100644
--- a/buildtool/build.py
+++ b/buildtool/build.py
@@ -1,5 +1,7 @@
# from task.extract import extract
+from task.patch_smali import patch_smali
from task.patch_resources import patch_resources
+from task.merge_resources import merge_resources
if __name__ == '__main__':
- _ = patch_resources()
\ No newline at end of file
+ _ = merge_resources()
\ No newline at end of file
diff --git a/buildtool/polly/patcher.py b/buildtool/polly/patcher.py
index d7003aa..85b2833 100644
--- a/buildtool/polly/patcher.py
+++ b/buildtool/polly/patcher.py
@@ -56,7 +56,10 @@ def process_patch_file(patch_file: str, check_date: bool = True):
continue
i2["pos"] += len(insertion["content"])
-
+
+ # Make parent dirs
+ target_dest.parent.mkdir(parents=True, exist_ok=True)
+
# Write the changed output
with open(target_dest, 'w') as f:
f.write(src)
@@ -64,8 +67,6 @@ def process_patch_file(patch_file: str, check_date: bool = True):
def process_all_patches(dir: Path | str, check_date: bool = True):
dir = Path(dir)
- for (cd, _, files) in dir.walk():
- for f in files:
- if f.endswith(".patch"):
- print("Processing patch {}".format((cd / f).relative_to(dir)))
- process_patch_file(str(cd / f), check_date=check_date)
\ No newline at end of file
+ for patch_file in dir.rglob("*.patch"):
+ print("Processing patch {}".format(patch_file.relative_to(dir)))
+ process_patch_file(str(patch_file), check_date=check_date)
\ No newline at end of file
diff --git a/buildtool/task/merge_resources.py b/buildtool/task/merge_resources.py
new file mode 100644
index 0000000..a049d6c
--- /dev/null
+++ b/buildtool/task/merge_resources.py
@@ -0,0 +1,27 @@
+from .util import *
+from . import fileutil
+
+import shutil
+
+# Task dependencies
+from .patch_resources import patch_resources
+from .patch_smali import patch_smali
+
+# Merges resources from all the previous steps
+
+def merge_resources():
+ _ = patch_resources()
+ _ = patch_smali()
+
+ first_time = False
+
+ # Copy original resources only the first time
+ if not MERGED_RSC_DIR.exists():
+ print("Merging original resources...")
+ shutil.copytree(EXTRACTED_DIR, MERGED_RSC_DIR, ignore=shutil.ignore_patterns("smali*"))
+ first_time = True
+
+ print("Merging patched resources...")
+ _ = fileutil.merge_into(PATCHED_RSC_DIR, MERGED_RSC_DIR, check_date=not first_time)
+ print("Merging patched smali...")
+ _ = fileutil.merge_into(PATCHED_SMALI_DIR, MERGED_RSC_DIR, check_date=not first_time)
diff --git a/buildtool/task/patch_resources.py b/buildtool/task/patch_resources.py
index 9b59ff3..baa740a 100644
--- a/buildtool/task/patch_resources.py
+++ b/buildtool/task/patch_resources.py
@@ -1,8 +1,6 @@
from .util import *
from . import fileutil
-import shutil
-
from polly.patcher import process_all_patches
# Task dependencies
@@ -11,19 +9,13 @@ from .extract import extract
def patch_resources():
_ = extract()
- first_time = False
+ # Previously, we populated patched_resources with original resources too, now that is covered in the merge_resources step
- # Copy original resources only the first time
- if not PATCHED_RSC_DIR.exists():
- print("Copying original resources...")
- shutil.copytree(EXTRACTED_DIR, PATCHED_RSC_DIR, ignore=shutil.ignore_patterns("smali*"))
- first_time = True
-
- s = fileutil.merge_into(SRC_RESOURCES_DIR, PATCHED_RSC_DIR, check_date=not first_time)
+ s = fileutil.merge_into(SRC_RESOURCES_DIR, PATCHED_RSC_DIR)
if s:
print("Copied custom resources from src/resources")
else:
print("Skipped copying resources from src/resources")
# Patch other resources
- process_all_patches(SRC_PATCHES_DIR, check_date=not first_time)
\ No newline at end of file
+ process_all_patches(SRC_RESOURCE_PATCHES_DIR)
\ No newline at end of file
diff --git a/buildtool/task/patch_smali.py b/buildtool/task/patch_smali.py
new file mode 100644
index 0000000..1bdea96
--- /dev/null
+++ b/buildtool/task/patch_smali.py
@@ -0,0 +1,30 @@
+from .util import *
+from . import fileutil
+
+import shutil
+
+from polly.patcher import process_all_patches
+
+# Task dependencies
+from .extract import extract
+
+def patch_smali():
+ _ = extract()
+
+ first_time = False
+
+ # Copy original resources only the first time
+ if not PATCHED_SMALI_DIR.exists():
+ print("Copying original smali...")
+ for smali_dir in EXTRACTED_DIR.glob("smali*"):
+ shutil.copytree(smali_dir, PATCHED_SMALI_DIR / smali_dir.relative_to(EXTRACTED_DIR))
+ first_time = True
+
+ s = fileutil.merge_into(SRC_SMALI_DIR, PATCHED_SMALI_DIR, check_date=not first_time)
+ if s:
+ print("Copied custom code from src/smali")
+ else:
+ print("Skipped copying code from src/smali")
+
+ # Patch other resources
+ process_all_patches(SRC_SMALI_PATCHES_DIR, check_date=not first_time)
\ No newline at end of file
diff --git a/buildtool/task/util.py b/buildtool/task/util.py
index cae3d2e..870d8d7 100644
--- a/buildtool/task/util.py
+++ b/buildtool/task/util.py
@@ -5,7 +5,11 @@ SOURCE_APK_DIR = Path("source-apk")
BUILD_DIR = Path("build")
EXTRACTED_DIR = BUILD_DIR / "extracted"
PATCHED_RSC_DIR = BUILD_DIR / "patched_resources"
+PATCHED_SMALI_DIR = BUILD_DIR / "patched_smali"
+MERGED_RSC_DIR = BUILD_DIR / "merged_resources"
SRC_DIR = Path("src")
SRC_RESOURCES_DIR = SRC_DIR / "resources"
-SRC_PATCHES_DIR = SRC_DIR / "patches"
\ No newline at end of file
+SRC_SMALI_DIR = SRC_DIR / "smali"
+SRC_RESOURCE_PATCHES_DIR = SRC_DIR / "patches" / "resource"
+SRC_SMALI_PATCHES_DIR = SRC_DIR / "patches" / "smali"
\ No newline at end of file
diff --git a/src/patches/public.patch b/src/patches/resource/public.patch
similarity index 90%
rename from src/patches/public.patch
rename to src/patches/resource/public.patch
index 730ed5c..abea7eb 100644
--- a/src/patches/public.patch
+++ b/src/patches/resource/public.patch
@@ -1,5 +1,7 @@
file 'res/values/public.xml'
+# IDs and resources used by various ykit elements
+
insert ln17595 << @end
diff --git a/src/patches/yellow.patch b/src/patches/resource/yellow.patch
similarity index 87%
rename from src/patches/yellow.patch
rename to src/patches/resource/yellow.patch
index 219a62e..f42adc9 100644
--- a/src/patches/yellow.patch
+++ b/src/patches/resource/yellow.patch
@@ -1,5 +1,7 @@
file 'res/layout/color_options_toolbar.xml'
+# Adds yellow into the list of colors in the toolbar
+
insert ln8 << @end
diff --git a/src/patches/ykit_settings.patch b/src/patches/resource/ykit_settings.patch
similarity index 80%
rename from src/patches/ykit_settings.patch
rename to src/patches/resource/ykit_settings.patch
index 4f78655..2a13ec8 100644
--- a/src/patches/ykit_settings.patch
+++ b/src/patches/resource/ykit_settings.patch
@@ -1,5 +1,7 @@
file 'res/layout/fragment_blog_settings.xml'
+# Adds the YKit Settings entry to the account settings menu
+
insert ln10 << @end
diff --git a/src/smali/smali_classes6/dev/maelstrom/ykit/settings/YkitSettingsActivity.smali b/src/smali/smali_classes6/dev/maelstrom/ykit/settings/YkitSettingsActivity.smali
index 73b2174..3ef9f0c 100644
--- a/src/smali/smali_classes6/dev/maelstrom/ykit/settings/YkitSettingsActivity.smali
+++ b/src/smali/smali_classes6/dev/maelstrom/ykit/settings/YkitSettingsActivity.smali
@@ -7,7 +7,7 @@
.method static constructor ()V
.locals 0
- invoke-static {}, Ldev/maelstrom/ykit/java/Test;->test()V
+ # invoke-static {}, Ldev/maelstrom/ykit/java/Test;->test()V
return-void
.end method
diff --git a/tools/apksigner.jar b/tools/apksigner.jar
new file mode 100644
index 0000000..f4adcff
Binary files /dev/null and b/tools/apksigner.jar differ