-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.py
43 lines (30 loc) · 989 Bytes
/
updater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import shutil
import subprocess
import sys
import time
import psutil
exe_name = "OnionSavesBackup-win64.exe"
def is_process_running(exe_name):
for proc in psutil.process_iter(["name"]):
if proc.info["name"] == exe_name:
return True
return False
def replace_and_restart(temp_exe):
# Wait for the main application to exit
while is_process_running(exe_name):
time.sleep(0.5)
# Ensure the new file is renamed to the proper executable name
new_exe_path = os.path.join(os.path.dirname(temp_exe), exe_name)
# Replace the old executable with the new one
os.remove(exe_name)
shutil.move(temp_exe, new_exe_path)
# Restart the application
subprocess.Popen([new_exe_path], cwd=os.path.dirname(new_exe_path))
sys.exit(0)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: updater.exe <temp_exe>")
sys.exit(1)
temp_exe = sys.argv[1]
replace_and_restart(temp_exe)