-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher_updater.py
150 lines (124 loc) · 4.92 KB
/
launcher_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
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
140
141
142
143
144
145
146
147
148
149
150
import requests
import configparser
from tqdm import tqdm
import time
import os
import tempfile
import zipfile
from halo import Halo
import platform
import subprocess
import psutil
def clear_screen():
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
def welcome_screen():
print("======VL UPDATER======")
def get_current_destination():
return os.getcwd()
def download_file(url, filename):
try:
print('INFO - Starting downloading launcher...')
response = requests.get(url, stream=True)
response.raise_for_status()
temp_dir = tempfile.mkdtemp()
destination = os.path.join(temp_dir, filename)
total_size = int(response.headers.get('content-length', 0))
block_size = 1024 # 1 KB blocks
with open(destination, 'wb') as file, tqdm(total=total_size, unit='B', unit_scale=True, unit_divisor=1024) as progress_bar:
for data in response.iter_content(block_size):
file.write(data)
progress_bar.update(len(data))
print("INFO - Download complete!")
return destination
except requests.exceptions.RequestException as e:
print('ERROR - ', e)
def extract_zip(zip_file, destination):
try:
if zip_file is None:
print("ERROR - No zip file provided for extraction.")
return
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
total_size = sum(file.file_size for file in zip_ref.infolist())
extracted_size = 0
progress_bar = tqdm(total=total_size, unit="B", unit_scale=True)
for file in zip_ref.infolist():
zip_ref.extract(file, destination)
extracted_size += file.file_size
progress_bar.update(file.file_size)
progress_bar.close()
print('INFO - Extraction completed!')
except zipfile.BadZipFile as e:
print("ERROR - ", e)
def fetch_local_version():
config = configparser.ConfigParser()
config.read('config.ini')
local_version = config.get('LAUNCHER', 'version')
return local_version
def fetch_version_info():
spinner = Halo(text='Fetching version info', spinner='dots')
spinner.start()
time.sleep(2)
url = "https://drive.google.com/uc?export=download&id=1J6wLmEkOQCQq6jzjksPgAnd51X2HL8B5"
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
version_number = response.text.strip()
spinner.succeed("INFO - Version fetched successfully!")
return version_number
except requests.exceptions.RequestException as e:
spinner.fail(f"ERROR - Failed to fetch version: {e}")
return None
def compare_versions(local_version, online_version):
return local_version != online_version
def download_launcher():
#launcher_url = "https://dl.dropboxusercontent.com/scl/fi/5jrnlg5yzdgtzzbtfidpf/launcher.zip?rlkey=lxndou25mr1ylsrgfejwnxhxs&dl=0"
#mini10lolix
launcher_url = "https://dl.dropboxusercontent.com/scl/fi/ikkj4j0ku84fkg9ydoi6i/launcher.zip?rlkey=2mucktvvwnryb2bnd7yuzh7te&dl=0"
destination = download_file(launcher_url, 'launcher.zip')
return destination
def update_local_config(new_version):
config = configparser.ConfigParser()
config.read('config.ini')
config['LAUNCHER']['version'] = new_version
with open('config.ini', 'w') as config_file:
config.write(config_file)
def terminate_process():
process_name = "launcher_gui.exe"
for proc in psutil.process_iter():
if proc.name() == process_name:
proc.terminate()
print(f"INFO - Process {process_name} terminated successfully.")
return True
print(f"Process {process_name} not found.")
return False
def main():
clear_screen()
welcome_screen()
terminate_process()
try:
config = configparser.ConfigParser()
config.read('config.ini')
online_version = fetch_version_info()
local_version = fetch_local_version()
if online_version is None:
print('ERROR - Failed to fetch online version information.')
return
if compare_versions(local_version, online_version):
print(f"INFO - New {online_version} version for launcher available. Downloading...")
zip_file = download_launcher()
extract_zip(zip_file, os.getcwd())
update_local_config(online_version)
print("INFO - Launcher updated successfully to version", online_version)
current_pid = os.getpid()
subprocess.Popen(["launcher_gui.exe", str(current_pid)], cwd=os.getcwd())
else:
print('INFO - Launcher is up to date!')
current_pid = os.getpid()
subprocess.Popen(["launcher_gui.exe", str(current_pid)], cwd=os.getcwd())
except Exception as e:
print(e)
if __name__ == "__main__":
main()