-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdater.py
More file actions
139 lines (119 loc) · 4.33 KB
/
updater.py
File metadata and controls
139 lines (119 loc) · 4.33 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os
import shutil
import subprocess
import urllib.request
import zipfile
import platform
import psutil
import sys
def safe_remove_file(path):
try:
if os.path.isfile(path):
os.remove(path)
except Exception as e:
print(f"Warning: could not remove file {path}: {e}")
def safe_remove_folder(path):
try:
if os.path.isdir(path):
shutil.rmtree(path)
except Exception as e:
print(f"Warning: could not remove folder {path}: {e}")
def kill_ttcom():
found_procs = []
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
try:
name = proc.info['name'] or ''
cmdline = ' '.join(proc.info['cmdline']) if proc.info['cmdline'] else ''
if 'ttcom.exe' in name.lower() or 'ttcom.py' in cmdline.lower():
found_procs.append((proc, name or cmdline))
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
if not found_procs:
return
print("\nWARNING: The following TTCom processes will be terminated:")
for _, pname in found_procs:
print(f" - {pname}")
confirm = input("Do you want to continue? (y/N): ").strip().lower()
if confirm != 'y':
print("Aborting script.")
sys.exit(0)
for proc, pname in found_procs:
try:
proc.kill()
print(f"[+] Killed: {pname}")
except (psutil.NoSuchProcess, psutil.AccessDenied):
print(f"[-] Could not kill: {pname}")
# ------------------ Updater Logic ------------------
def main():
print("Welcome to TTCom Updater, please select an option.")
while True:
choice = input(
"1. Update to the latest version of TTCom\n"
"2. Update to the latest version of TTCom compiled for Windows\n"
"3. Update to the latest beta revision of TTCom\n"
"4. Update to the latest beta revision of TTCom compiled for Windows\n"
"Press any other key to exit.\n"
"Your choice: "
).strip()
if choice in ["1", "2", "3", "4"]:
kill_ttcom()
if choice == "1":
update_ttcom()
break
elif choice == "2":
update_ttcom(windows=True)
break
elif choice == "3":
update_ttcom(beta=True)
break
elif choice == "4":
update_ttcom(beta=True, windows=True)
break
else:
print("Exiting program.")
exit()
def update_ttcom(beta=False, windows=False):
print("Updating, please wait.")
remove_pre_extraction_files(windows)
if beta:
download_url = "https://www.dlee.org/teamtalk/ttcom/beta/ttcom.zip"
if windows:
download_url = "https://www.dlee.org/teamtalk/ttcom/beta/ttcom_win.zip"
else:
download_url = "https://www.dlee.org/teamtalk/ttcom/ttcom.zip"
if windows:
download_url = "https://www.dlee.org/teamtalk/ttcom/ttcom_win.zip"
if windows:
remove_internal_folder()
download_file(download_url, windows)
extract_file("ttcom.zip" if not windows else "ttcom_win.zip")
cleanup_post_extraction_files(windows)
def remove_pre_extraction_files(windows=False):
if not windows:
files_to_delete = [
"banreq.py", "bitflags.py", "conf.py", "geolocator.py", "LICENSE.txt",
"parmline.py", "trigger_cc.py", "triggers.py", "tt_attrdict.py",
"ttapi.py", "ttcom.exe", "ttcom.htm", "ttcom.py", "TTComCmd.py",
"ttflags.py", "upgrade_conf.py"
]
for file in files_to_delete:
safe_remove_file(file)
safe_remove_folder("mplib")
else:
safe_remove_file("ttcom.exe")
def download_file(url, windows=False):
print("Downloading, please wait.")
local_filename = url.split('/')[-1]
urllib.request.urlretrieve(url, local_filename)
def remove_internal_folder():
safe_remove_folder("_internal")
def extract_file(file_name):
print(f"Extracting {file_name}, please wait.")
with zipfile.ZipFile(file_name, 'r') as zip_ref:
zip_ref.extractall()
def cleanup_post_extraction_files(windows=False):
print("Deleting unnecessary files, please wait.")
safe_remove_file("ttcom.zip" if not windows else "ttcom_win.zip")
safe_remove_file("ttcom.conf.sample")
if __name__ == "__main__":
main()