-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuser_host_main.py
157 lines (137 loc) · 6.14 KB
/
user_host_main.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
151
152
153
154
155
156
157
user_host_main_version = '2.5.2'
from threading import Thread
from random import choice
from requests import get
from time import sleep, time
from os import makedirs, path, system as system_caller
import webbrowser
import sys
def download_with_progress(link, string, timeout=20):
s_time = time()
response = get(link, stream=True, timeout=timeout)
total_length = response.headers.get('content-length')
if total_length is None: # no content length header
return response.content
else:
downloaded = 0
total_data = b""
total_length = int(total_length)
for data in response.iter_content(chunk_size=4096 * 32):
downloaded += len(data)
total_data += data
sys.stdout.write("\r " + string.replace("REPLACE_PROGRESS", f"[{int(time()-s_time)} secs] [{int(100 * downloaded / total_length)}%] ({downloaded}/{total_length})"))
sys.stdout.flush()
return total_data
def fetch_global_addresses():
while True:
try:
response = get("https://raw.githubusercontent.com/BhaskarPanja93/AllLinks.github.io/master/README.md", timeout=15)
response.close()
link_dict = eval(response.text)
global_host_page = choice(link_dict['viewbot_global_host_page_list'])
global_host_address = choice(link_dict['viewbot_tcp_connection_list']).split(":")
global_host_address[-1] = int(global_host_address[-1])
global_host_address = tuple(global_host_address)
break
except Exception as e:
print(f"Unable to connect to GitHub : {repr(e)}")
sleep(0.1)
return global_host_address, global_host_page
system_caller('cls')
## Check self version
while True:
global_host_address, global_host_page = fetch_global_addresses()
try:
print("\n\nChecking user host main version...")
response = get(f"{global_host_page}/current_user_host_main_version", timeout=15)
response.close()
current_version = response.text
if len(current_version) > 10 or current_version.count(".") != 2:
raise ZeroDivisionError
if current_version == user_host_main_version:
break
else:
current_version_split = current_version.split('.')
version_split = user_host_main_version.split('.')
if version_split[0] == current_version_split[0]:
if version_split[1] != current_version_split[1]:
print(f"An recommended update is available. v{current_version}. Please download from github for important patches.\n https://github.com/BhaskarPanja93/View-Bot-Client/releases")
sleep(5)
webbrowser.open("https://github.com/BhaskarPanja93/View-Bot-Client/releases", new=2)
else:
print(f"An optional update is available. v{current_version}")
sleep(3)
webbrowser.open("https://github.com/BhaskarPanja93/View-Bot-Client/releases", new=2)
break
else:
print(f"User Host Main is too old to run. Please update to v{current_version} to continue!!\n https://github.com/BhaskarPanja93/View-Bot-Client/releases")
webbrowser.open("https://github.com/BhaskarPanja93/View-Bot-Client/releases", new=2)
input()
exit()
except Exception as e:
print(f"Retrying... : {repr(e)}")
system_caller('cls')
print("Version fetched...")
### Check local drive to use
print('\n\nChecking directories...')
local_drive_name = 'C'
if not path.exists(f"{local_drive_name}://"):
for _ascii in range(67, 90 + 1):
local_drive_name = chr(_ascii)
if path.exists(f"{local_drive_name}://"):
break
else:
local_drive_name = ''
print('No available local drive, please create a github issue!!')
sleep(2)
webbrowser.open("https://github.com/BhaskarPanja93/View-Bot-Client/issues/new", new=2)
input()
exit()
live_location = f"{local_drive_name}://viewbot_files"
updates_location = f"{local_drive_name}://viewbot_files/updates"
### If first run, make necessary directories
if not path.exists(live_location) or not path.exists(updates_location):
makedirs(live_location, exist_ok=True)
makedirs(updates_location, exist_ok=True)
with open(f'{live_location}/DO NOT MODIFY!!.txt', 'w') as file:
file.write("Do not modify any file in this directory. It can cause conflicts and/or security bugs")
system_caller('cls')
print("Directories found...")
### check user_host version
try:
with open(f'{live_location}/version', 'r') as version_info_file:
version = float(version_info_file.read())
except:
open(f'{live_location}/version', 'w').write('0')
version = 0.0
while True:
try:
system_caller("cls")
print('\n\nChecking user_host version...')
print('This can take a while...')
file_code = 'stable_user_host'
global_host_address, global_host_page = fetch_global_addresses()
response = download_with_progress(f"{global_host_page}/other_files?file_code={file_code}&version={version}", "Downloading: REPLACE_PROGRESS", timeout=40)
if response[0] == 123 and response[-1] == 125:
system_caller('cls')
print("\n\nData received.")
response = eval(response)
if response['file_code'] == file_code:
if response['version'] != version:
print("Writing new file")
with open(f'{live_location}/user_host.exe', 'wb') as file:
file.write(response['data'])
with open(f'{live_location}/version', 'w') as file:
file.write(str(response['version']))
else:
system_caller('cls')
print("\n\nNo new Updates")
break
else:
raise ZeroDivisionError
else:
raise ZeroDivisionError
except Exception as e:
print(f"Retrying... : {repr(e)}")
sleep(1)
Thread(target=system_caller, args=(f'{live_location}/user_host.exe',)).start()