Skip to content

Commit

Permalink
WIP: Auto-Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphwetzel authored and ralphwetzel committed May 2, 2020
1 parent bf3ef25 commit 738c8ff
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions theonionpack/top/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def check_update(self, mode: Optional[str] = None) -> bool:

if mode == 'auto':
self.update_status = 4 # Update found, trying to run auto-update
if self.get_latest_pack():
if self.launch_latest_theonionpack():
sleep(2)
self.do_quit()
else:
Expand Down Expand Up @@ -344,27 +344,36 @@ def version(self):

return None

def get_latest_pack(self):
def launch_latest_theonionpack(self):

url = self.get_updater_url()

if url is not None:
if url is None:
return False

file = tempfile.NamedTemporaryFile(suffix='.exe', delete=False)

r = requests.get(url, stream=True)
for chunk in r.iter_content(chunk_size=512):
if chunk: # filter out keep-alive new chunks
file.write(chunk)

file.close()

params = [file.name]

file = tempfile.NamedTemporaryFile(suffix='.exe', delete=False)
# Be sure to run the installer in our working directory!
# This is especially demanded as we are going to uninstall previous versions!
params.append(f'/DIR="{os.getcwd()}"')

r = requests.get(url, stream=True)
for chunk in r.iter_content(chunk_size=512):
if chunk: # filter out keep-alive new chunks
file.write(chunk)
params.append('/RunUninstall')

file.close()
params.append('/SILENT')
# params.append('/VERYSILENT')
params.append('/LOG')
params.append('/SUPPRESSMSGBOXES')

params = [file.name]
params.append('/SILENT')
# params.append('/VERYSILENT')
params.append('/LOG')
params.append('/SUPPRESSMSGBOXES')
params.append('/TASKS="startup,obfs4proxy"')
with contextlib.suppress(Exception):
subprocess.Popen(params, close_fds=True, creationflags=subprocess.DETACHED_PROCESS + subprocess.CREATE_NEW_PROCESS_GROUP)
return True

Expand Down

0 comments on commit 738c8ff

Please sign in to comment.