Skip to content

Commit

Permalink
- Improved error handling.
Browse files Browse the repository at this point in the history
- `Flash Boot` regression fix.
- Delete temporary files created by PixelFlasher in case apps key on them.
- Check Magisk created backup instead of relying on the return code, which is erroneously returning 1.
- Suppress not applicable warnings/errors when flashing non-Pixel devices.
- When in Recovery or sideload mode, reduce the properties queried, as they are unavailable.
  • Loading branch information
badabing2005 committed Jan 22, 2025
1 parent 21b3b96 commit a78f1cf
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 257 deletions.
277 changes: 139 additions & 138 deletions advanced_settings.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build-on-mac.spec
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ exe = EXE(pyz,
icon='images/icon-dark-256.icns')
app = BUNDLE(exe,
name='PixelFlasher.app',
version='7.9.0.3',
version='7.9.1.0',
icon='./images/icon-dark-256.icns',
bundle_identifier='com.badabing.pixelflasher')
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# <https://www.gnu.org/licenses/>.

rm -rf build dist
VERSION=7.9.0.3
VERSION=7.9.1.0
NAME="PixelFlasher"
DIST_NAME="PixelFlasher"

Expand Down
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

APPNAME = 'PixelFlasher'
CONFIG_FILE_NAME = 'PixelFlasher.json'
VERSION = '7.9.0.3'
VERSION = '7.9.1.0'
SDKVERSION = '33.0.3'
MAIN_WIDTH = 1400
MAIN_HEIGHT = 1040
Expand Down
41 changes: 24 additions & 17 deletions modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ def process_file(self, file_type):
print(f"Detected Non Pixel firmware, with: {found_boot_img} {found_init_boot_img}")
# Check if the firmware file starts with image-* and warn the user or abort
firmware_file_name = os.path.basename(file_to_process)
# empty mkdir - Nothing will be extracted here, needed for Non-Pixel factory firmware
os.makedirs(package_dir_full, exist_ok=True)
if firmware_file_name.startswith('image-'):
title = "Possibly extracted firmware."
message = f"WARNING: It looks like you have extracted the firmware file.\nand selected the image zip from it.\n\n"
Expand Down Expand Up @@ -2027,7 +2029,7 @@ def patch_magisk_script(patch_method):
data += " echo $PATCH_FILENAME > /data/local/tmp/pf_patch.log\n"
data += " if [[ -n \"$PATCHING_MAGISK_VERSION\" ]]; then echo $PATCHING_MAGISK_VERSION >> /data/local/tmp/pf_patch.log; fi\n"
data += "else\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += "fi\n\n"
if delete_temp_files:
data += "echo \"Cleaning up ...\"\n"
Expand Down Expand Up @@ -2160,7 +2162,7 @@ def patch_kernelsu_script(kernelsu_version):
data += " echo $PATCH_FILENAME > /data/local/tmp/pf_patch.log\n"
data += " if [[ -n \"$KERNELSU_VERSION\" ]]; then echo $KERNELSU_VERSION >> /data/local/tmp/pf_patch.log; fi\n"
data += "else\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += "fi\n\n"
if delete_temp_files:
data += "echo \"Cleaning up ...\"\n"
Expand Down Expand Up @@ -2328,7 +2330,7 @@ def patch_kernelsu_lkm_script():
data += " echo \"$PATCHING_KSU_VERSION\" >> /data/local/tmp/pf_patch.log\n"
data += " fi\n"
data += " else\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += " fi\n"
data += "fi\n\n"
delete_temp_files = False
Expand Down Expand Up @@ -2554,7 +2556,7 @@ def patch_apatch_script(patch_method="app", kernel_patch_version=""):
data += " echo $PATCH_FILENAME > /data/local/tmp/pf_patch.log\n"
data += " if [[ -n \"$PATCHING_APATCH_VERSION\" ]]; then echo $PATCHING_APATCH_VERSION >> /data/local/tmp/pf_patch.log; fi\n"
data += "else\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += " echo \"ERROR: Patching failed!\"\n"
data += "fi\n\n"
if delete_temp_files:
data += "echo \"Cleaning up ...\"\n"
Expand Down Expand Up @@ -3498,11 +3500,16 @@ def magisk_not_found():
puml("#lightgreen:Magisk Backup: Success;\n")
else:
print(f"Magisk has NOT made a backup of the source {boot_file_name}")
print("Triggering Magisk to create a backup ...")
# Trigger Magisk to make a backup
res = device.run_magisk_migration(boot_sha1_long)
# if return is -2, then copy boot.img to stock_boot.img
if res == -2:
do_manual_backup = True
if method == 1:
print("Triggering Magisk to create a backup ...")
# Trigger Magisk to make a backup
res = device.run_magisk_migration(boot_sha1_long)
if res != -2:
do_manual_backup = False
else:
print("Magisk did not make a backup, will do a manual backup.")
if do_manual_backup:
# copy stock_boot from Downloads folder it already exists, and do it as su if rooted
stock_boot_path = '/data/adb/magisk/stock_boot.img'
print(f"Copying {boot_img} to {stock_boot_path} ...")
Expand All @@ -3511,7 +3518,7 @@ def magisk_not_found():
print("Aborting Backup ...\n")
else:
# rerun the migration.
print("Triggering Magisk migration again to create a backup ...")
print("Triggering Magisk migration to create a backup ...")
res = device.run_magisk_migration(boot_sha1_long)
print(f"\nChecking to see if Magisk made a backup of the source {boot_file_name}")
magisk_backups = device.magisk_backups
Expand Down Expand Up @@ -3871,7 +3878,7 @@ def live_flash_boot_phone(self, option): # sourcery skip: de-morgan
if self.config.fastboot_verbose:
fastboot_options += '--verbose '
fastboot_options += 'flash '
theCmd = f"\"{get_fastboot()}\" -s {device.id} {fastboot_options} boot \"{boot_img_path}\""
theCmd = f"\"{get_fastboot()}\" -s {device.id} {fastboot_options} {partition} \"{boot_img_path}\""
debug(theCmd)
res = run_shell(theCmd)
if res and isinstance(res, subprocess.CompletedProcess):
Expand Down Expand Up @@ -4195,7 +4202,7 @@ def flash_phone(self):
# cp = get_system_codepage()
cp = "65001"
if cp:
first_line_win = f"chcp {cp}\n@ECHO OFF\n"
first_line_win = f"\nchcp {cp}\n@ECHO OFF\n"
else:
first_line_win = f"@ECHO OFF\n"
first_line_linux = "#!/bin/sh\n"
Expand Down Expand Up @@ -4257,8 +4264,8 @@ def flash_phone(self):
action = "boot"
msg = "\nLive Boot to: "
if device.hardware in KNOWN_INIT_BOOT_DEVICES:
print(f"\n{datetime.now():%Y-%m-%d %H:%M:%S} ERROR: Live booting Pixel 7 or newer are not supported yet.")
puml("#orange:Live booting Pixel 7 or newer are not supported yet;\n}\n")
print(f"\n{datetime.now():%Y-%m-%d %H:%M:%S} ERROR: Live booting Pixel 7 or newer are not supported.")
puml("#orange:Live booting Pixel 7 or newer are not supported;\n}\n")
self.toast("Flash action", "⚠️ Live booting Pixel 7 or newer devices is not supported.")
# return -1
else:
Expand Down Expand Up @@ -4450,7 +4457,7 @@ def flash_phone(self):
# Process flash_all files
flash_all_win32 = process_flash_all_file(os.path.join(package_dir_full, "flash-all.bat"))
if (flash_all_win32 == 'ERROR'):
print("Aborting ...\n")
print("Make sure you have a supported firmware file.\nAborting ...\n")
puml("#red:Error processing flash_all.bat file;\n}\n")
return -1
flash_all_linux = process_flash_all_file(os.path.join(package_dir_full, "flash-all.sh"))
Expand All @@ -4474,7 +4481,7 @@ def flash_phone(self):
debug(f"\nsh file\n{s2}\n")

if cp:
data_win = f"chcp {cp}\n"
data_win = f"\nchcp {cp}\n"
else:
data_win = ''
if self.config.flash_mode == 'dryRun':
Expand Down Expand Up @@ -4789,7 +4796,7 @@ def apply_patch_if_needed():
# flash the patch
flash = "flash"

if (boot.is_init_boot or (device.hardware is not None and device.hardware in KNOWN_INIT_BOOT_DEVICES)) and boot.patch_method not in ['kernelsu', 'apatch', 'apatch_manual']:
if boot.is_init_boot:
print("Flashing patched init_boot ...")
theCmd = f"\"{get_fastboot()}\" -s {device_id} {fastboot_options} {flash} init_boot \"{boot.boot_path}\"\n"
is_init_boot = True
Expand Down
21 changes: 14 additions & 7 deletions package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,20 @@ def EnableDisableButton(self, state):
# OnClose
# -----------------------------------------------
def OnClose(self, e):
print(f"{datetime.now():%Y-%m-%d %H:%M:%S} User Pressed Close.")
labels = get_labels()
if (labels):
with open(get_labels_file_path(), "w", encoding='ISO-8859-1', errors="replace") as f:
# Write the dictionary to the file in JSON format
json.dump(labels, f, indent=4)
self.EndModal(wx.ID_CANCEL)
try:
print(f"{datetime.now():%Y-%m-%d %H:%M:%S} User Pressed Close.")
labels = get_labels()
if (labels):
with open(get_labels_file_path(), "w", encoding='ISO-8859-1', errors="replace") as f:
# Write the dictionary to the file in JSON format
json.dump(labels, f, indent=4)
# Delete aapt2 from the device
res = self.device.delete("/data/local/tmp/aapt2", self.device.rooted)
except Exception:
traceback.print_exc()
print(f"{datetime.now():%Y-%m-%d %H:%M:%S} ERROR: Failed to properly close the window.")
finally:
self.EndModal(wx.ID_CANCEL)

# -----------------------------------------------
# OnDisable
Expand Down
Loading

0 comments on commit a78f1cf

Please sign in to comment.