Testing smali patching + fixed bug where old patches just dont get applied. Now this is done per file instead of per patch
This commit is contained in:
parent
ae7b361482
commit
88993f3694
|
@ -19,7 +19,7 @@ def evaluate_position(content: str, location: Location):
|
|||
|
||||
for i, line in enumerate(content.split('\n')):
|
||||
if location.line == i + 1:
|
||||
if location.column > len(line):
|
||||
if location.column-1 > len(line):
|
||||
raise RuntimeError("Column number out of range")
|
||||
|
||||
return chars_read + location.column - 1
|
||||
|
@ -32,7 +32,8 @@ def evaluate_position(content: str, location: Location):
|
|||
class ProcessedInsertion:
|
||||
position: int
|
||||
content: str
|
||||
patch_file_name: str
|
||||
patch_file_name: str # TODO: Refactor this out of ProcessedInsertion
|
||||
is_old: bool
|
||||
|
||||
type ProcessedAction = ProcessedInsertion
|
||||
|
||||
|
@ -43,7 +44,7 @@ def update_positions_of_patches(actions: list[ProcessedAction], at: int, by: int
|
|||
|
||||
action.position += by
|
||||
|
||||
def process_all_patches(dir: Path | str, check_date: bool = True):
|
||||
def process_all_patches(dir: Path | str, dest: Path | str, check_date: bool = True):
|
||||
dir = Path(dir)
|
||||
|
||||
patches: dict[Path, list[ProcessedAction]] = {}
|
||||
|
@ -54,30 +55,38 @@ def process_all_patches(dir: Path | str, check_date: bool = True):
|
|||
for patch in parse_patch_file(str(patch_file)):
|
||||
patches[patch.target] = patches.get(patch.target, [])
|
||||
src_file = EXTRACTED_DIR / patch.target
|
||||
dest_file = PATCHED_RSC_DIR / patch.target
|
||||
dest_file = dest / patch.target
|
||||
|
||||
for action in patch.actions:
|
||||
|
||||
# Skip patch if it is older than the target file
|
||||
if dest_file.exists() and src_file.stat().st_mtime <= dest_file.stat().st_mtime:
|
||||
print(f"Skipped {pfrn}::{patch.target}")
|
||||
continue
|
||||
|
||||
with open(src_file, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
is_old = dest_file.exists() and patch_file.stat().st_mtime <= dest_file.stat().st_mtime
|
||||
|
||||
# We also consider the true position of each insertion, too
|
||||
if isinstance(action, InsertionAction):
|
||||
processed_action = ProcessedInsertion(position=evaluate_position(content, action.location), content=action.content, patch_file_name=str(pfrn))
|
||||
processed_action = ProcessedInsertion(position=evaluate_position(content, action.location),
|
||||
content=action.content,
|
||||
patch_file_name=str(pfrn),
|
||||
is_old=is_old)
|
||||
else:
|
||||
raise RuntimeError("I don't know how to deal with those kinds of patches")
|
||||
|
||||
patches[patch.target].append(processed_action)
|
||||
|
||||
# Skip all patches for which the destination file is newer than all the patches themselves
|
||||
for file in list(patches.keys()):
|
||||
for action in patches[file]:
|
||||
if not action.is_old:
|
||||
break
|
||||
else:
|
||||
print(f"Skipped {file}")
|
||||
del patches[file]
|
||||
|
||||
# Now we actually do all the patching
|
||||
for target_file, actions in patches.items():
|
||||
src_file = EXTRACTED_DIR / target_file
|
||||
dest_file = PATCHED_RSC_DIR / target_file
|
||||
dest_file = dest / target_file
|
||||
|
||||
with open(src_file, 'r') as f:
|
||||
content = f.read()
|
||||
|
|
|
@ -18,4 +18,4 @@ def patch_resources():
|
|||
print("Skipped copying resources from src/resources")
|
||||
|
||||
# Patch other resources
|
||||
process_all_patches(SRC_RESOURCE_PATCHES_DIR)
|
||||
process_all_patches(SRC_RESOURCE_PATCHES_DIR, dest=PATCHED_RSC_DIR)
|
|
@ -30,4 +30,4 @@ def patch_smali():
|
|||
print("Skipped copying code from src/smali")
|
||||
|
||||
# Patch other resources
|
||||
process_all_patches(SRC_SMALI_PATCHES_DIR, check_date=not first_time)
|
||||
process_all_patches(SRC_SMALI_PATCHES_DIR, dest=PATCHED_SMALI_DIR, check_date=not first_time)
|
21
src/patches/smali/ykit_settings_btn.patch
Normal file
21
src/patches/smali/ykit_settings_btn.patch
Normal file
|
@ -0,0 +1,21 @@
|
|||
file 'smali_classes2/com/tumblr/ui/fragment/BlogSettingsFragment.smali'
|
||||
|
||||
insert ln2980 << @end
|
||||
|
||||
# YKit Settings button
|
||||
const p2, 0x7f0bf001
|
||||
|
||||
invoke-virtual {p1, p2}, Landroid/view/View;->findViewById(I)Landroid/view/View;
|
||||
|
||||
move-result-object p2
|
||||
|
||||
check-cast p2, Lcom/tumblr/ui/widget/TMBlogSettingsTextRow;
|
||||
|
||||
new-instance p3, Ldev/maelstrom/ykit/settings/YkitSettingsClickListener;
|
||||
|
||||
invoke-direct {p3, p0}, Ldev/maelstrom/ykit/settings/YkitSettingsClickListener;-><init>(Lcom/tumblr/ui/fragment/BlogSettingsFragment;)V
|
||||
|
||||
invoke-virtual {p2, p3}, Landroid/view/View;->setOnClickListener(Landroid/view/View$OnClickListener;)V
|
||||
# /YKit Settings Button
|
||||
|
||||
@end
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue