-
Notifications
You must be signed in to change notification settings - Fork 3
/
init_troppical.py
68 lines (57 loc) · 2.06 KB
/
init_troppical.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
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
import sys
import os
import requests
import tempfile
import subprocess
from zipfile import ZipFile
from PyQt6.QtWidgets import QApplication, QMessageBox
import shutil
def download_and_launch():
url = 'https://nightly.link/kleidis/Troppical/workflows/build/master/troppical-windows.zip'
response = requests.get(url, stream=True)
if response.status_code == 200:
# Create a temporary file for the ZIP
with tempfile.NamedTemporaryFile(delete=False, suffix='.zip') as temp_zip:
for chunk in response.iter_content(chunk_size=8192):
temp_zip.write(chunk)
# Extract the ZIP file
with ZipFile(temp_zip.name, 'r') as zip_ref:
temp_dir = tempfile.mkdtemp()
zip_ref.extractall(temp_dir)
exe_path = None
for root, dirs, files in os.walk(temp_dir):
for file in files:
if file.lower().endswith('.exe'):
exe_path = os.path.join(root, file)
break
if exe_path:
break
if not exe_path:
QMessageBox.critical(None, "Execution Error", "Executable file not found in the archive.")
return False
# Display launching message
msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Icon.Information)
msg_box.setText("Troppical is initializing...")
msg_box.show()
QApplication.processEvents()
# Launch the downloaded executable
process = subprocess.Popen([exe_path], close_fds=True)
msg_box.close()
process.wait()
# Clean up the temporary files and directory
os.unlink(temp_zip.name)
shutil.rmtree(temp_dir)
return True
else:
QMessageBox.critical(None, "Download Error", "Failed to download the update.")
return False
def main():
app = QApplication(sys.argv)
success = download_and_launch()
if success:
QMessageBox.information(None, "Bye!", "Thanks for using Troppical.")
app.quit()
if __name__ == '__main__':
main()
sys.exit(0)