Skip to content

Commit

Permalink
Reformat & Support bundled heimdall
Browse files Browse the repository at this point in the history
  • Loading branch information
justaCasualCoder committed Dec 19, 2023
1 parent a39119e commit 6c42c1b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions guiunstable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import subprocess
import os
import re
import requests # Needed for Downloading TWRP
from bs4 import BeautifulSoup # Needed for Downloading TWRP
import requests # Needed for Downloading TWRP
from bs4 import BeautifulSoup # Needed for Downloading TWRP
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
Expand Down Expand Up @@ -94,6 +94,7 @@ def flash_window(self, checked):
self.w = FlashWindow()
self.w.start_process(partition, image)
self.w.show()

def TWRP_window(self, checked):
if self.i is None:
self.i = TWRPWindow()
Expand All @@ -118,6 +119,8 @@ def aboutdialog(self):
dlg.setWindowTitle("About")
dlg.setText(text)
dlg.exec()


class FlashWindow(QWidget):
"""
This "window" is a QWidget. If it has no parent, it
Expand Down Expand Up @@ -149,7 +152,13 @@ def start_process(self, partition, image):
self.p.readyReadStandardError.connect(self.handle_stderr)
self.p.stateChanged.connect(self.handle_state)
self.p.finished.connect(self.process_finished) # Clean up once complete.
command = ["heimdall", "flash", f"--{partition}", image]
heimdallbin = os.path.abspath(os.path.join(cwd, "heimdall"))
if os.path.exists(heimdallbin):
print("Using Bundled Heimdall")
heimdallbin = "./heimdall"
else:
heimdallbin = "/bin/heimdall"
command = [f"{heimdallbin}", "flash", f"--{partition}", image]
self.p.start(command[0], command[1:])

def handle_stdout(self):
Expand Down Expand Up @@ -216,12 +225,14 @@ def __init__(self):
layout.addWidget(self.progress)
layout.addWidget(self.text)
self.setLayout(layout)


class TWRPWindow(QWidget):
def download_flash(self):
# Huge thanks to the orginal creator - JBBgameich
# https://github.com/JBBgameich/halium-install
dlpagerequest = requests.get("https://dl.twrp.me/" + self.entry.text())
dlpage = BeautifulSoup(dlpagerequest.content, 'html.parser')
dlpage = BeautifulSoup(dlpagerequest.content, "html.parser")
try:
dllinks = dlpage.table.find_all("a")
except:
Expand All @@ -232,7 +243,7 @@ def download_flash(self):
print("I: Downloading " + dlurl)
referer_header = {"Referer": dlurl + ".html"}
response = requests.get(dlurl, headers=referer_header, stream=True)
total_size = int(response.headers.get('content-length', 0))
total_size = int(response.headers.get("content-length", 0))
current_size = 0
with open(imgname, "wb") as f:
for chunk in response.iter_content():
Expand All @@ -241,12 +252,13 @@ def download_flash(self):
current_size += len(chunk)
percent = current_size / total_size * 100
self.progressb.setValue(percent)
print(percent , end="\r")
print(percent, end="\r")
self.close()

self.w = FlashWindow()
self.w.start_process("RECOVERY", imgname)
self.w.show()

def __init__(self):
super().__init__()
self.p = None
Expand All @@ -263,6 +275,7 @@ def __init__(self):
layoutv.addWidget(self.progressb)
self.setLayout(layoutv)


if __name__ == "__main__":
# Create the Qt Application
app = QApplication(sys.argv)
Expand Down

0 comments on commit 6c42c1b

Please sign in to comment.