Skip to content

Commit

Permalink
Make it save TWRP image to a temp file
Browse files Browse the repository at this point in the history
  • Loading branch information
justaCasualCoder committed Jan 4, 2024
1 parent 225a6b8 commit 85730d6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions guiunstable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import re
import json
import atexit
import tempfile
import urllib.request # Needed for Downloading TWRP
import requests # Needed for Downloading TWRP
from bs4 import BeautifulSoup # Needed for Downloading TWRP
Expand Down Expand Up @@ -35,6 +37,7 @@ class Form(QMainWindow):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.setWindowTitle("SamsungFlashGUI")
atexit.register(self.on_exit)
self.w = None
self.i = None
# Create widgets
Expand Down Expand Up @@ -85,7 +88,10 @@ def __init__(self, parent=None):
layout.addWidget(self.flash)
self.chooseimage.clicked.connect(self.Image)
self.flash.clicked.connect(self.flash_window)

def on_exit(self):
if local_filename is not None:
print("Deleting Temp File...")
os.remove(local_filename)
def Image(self):
global filename
file_dialog = QFileDialog()
Expand Down Expand Up @@ -334,7 +340,8 @@ def download_flash(self):
sys.exit(1)
url = "https://dl.twrp.me" + dllinks[1]["href"].replace(".html", "")
print("I: Downloading " + url)
local_filename = url.split("/")[-1]
global local_filename
local_filename = tempfile.NamedTemporaryFile(suffix=".img", delete=False).name
referer_url = url + ".html"

headers = {"Referer": referer_url}
Expand Down

0 comments on commit 85730d6

Please sign in to comment.