forked from Log0-git/gdl-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
325 lines (273 loc) · 10.7 KB
/
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import os
import sys
import json
import shutil
import winreg
from requests import get
from threading import Thread
from PyQt5 import QtWidgets, QtCore
from files.installer import Ui_MainWindow
base_url = 'https://pixelsuft.github.io/gdl-installer-files/'
base_folder = ''
REG_PATH = 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\GDLoc'
os.chdir(os.path.dirname(__file__))
forward_events = []
back_events = []
def clear_temp():
for i in os.listdir(os.environ['TEMP']):
path = os.path.join(os.environ['TEMP'], i)
if not os.path.isdir(path):
continue
if not i.startswith('_MEI'):
continue
try:
shutil.rmtree(path)
except Exception as e:
print(f'Not fully cleared: {e}')
def unbind_buttons():
global forward_events, back_events
for i in forward_events:
ui.goForwardButton.clicked.disconnect(i)
for i in back_events:
ui.goBackButton.clicked.disconnect(i)
forward_events, back_events = [], []
def bind_forward(func):
forward_events.append(func)
ui.goForwardButton.clicked.connect(func)
def bind_back(func):
back_events.append(func)
ui.goBackButton.clicked.connect(func)
log_to_do = None
progress_to_do = None
to_setup = 0
def log(text_to_log):
global log_to_do
log_to_do = text_to_log.split('\n')
while log_to_do:
pass
# ui.logEdit.addItem(i)
def progress(percent):
global progress_to_do
progress_to_do = percent
while progress_to_do:
pass
# ui.barEdit.setValue(percent)
def get_url(url_path):
return base_url + url_path
def fast_write(filename, content):
if type(content) == bytes:
temp_file = open(filename, 'wb')
temp_file.write(content)
temp_file.close()
elif type(content) == str:
temp_file = open(filename, 'w')
temp_file.write(content)
temp_file.close()
def testo():
global progress_to_do, log_to_do, to_setup
if to_setup == 2:
return
elif to_setup == 1:
to_setup = 2
setup_buttons(4)
if log_to_do:
need_scroll = ui.logEdit.verticalScrollBar().maximum() == ui.logEdit.verticalScrollBar().value()
for i in log_to_do:
ui.logEdit.addItem(i)
if need_scroll:
ui.logEdit.scrollToBottom()
log_to_do = None
if progress_to_do:
ui.barEdit.setValue(progress_to_do)
progress_to_do = None
def install_gdl(install_type):
global to_setup
backup = {}
log(f'Базовый url: {base_url}')
log(f'Базовая папка: {base_folder}')
progress(1)
log(f'Скачиваем файл локализации...')
progress(3)
fast_write(os.path.join(base_folder, 'ru_ru.json'), get(get_url('gdl_res/ru_ru.json')).content)
progress(5)
if install_type == 'default':
'''log('Делаем бэкап файла расширений...')
ext_path = os.path.join(base_folder, 'libExtensions.dll')
backup[ext_path] = ext_path + '.backup'
log('Скачиваем модифицированный файл расширений...')
fast_write(ext_path, get(get_url('gdl_res/libExtensions.dll')).content)
fast_write(os.path.join(base_folder, 'GDDLLLoader.dll'), get(get_url('gdl_res/GDDLLLoader.dll')).content)'''
ext_path = os.path.join(base_folder, 'xinput9_1_0.dll')
if not file_exists(ext_path):
log('Скачиваем фейковый XInput...')
fast_write(ext_path, get(get_url('gdl_res/xinput9_1_0.dll')).content)
progress(7)
log('Скачиваем dll...')
dll_dir = os.path.join(base_folder, 'adaf-dll' if install_type == 'default' else install_type)
if not os.path.isdir(dll_dir):
os.makedirs(dll_dir)
progress(8)
dll_path = os.path.join(dll_dir, 'GDLocalisation.dll')
progress(9)
fast_write(dll_path, get(get_url('gdl_res/GDLocalisation.dll')).content)
progress(10)
log('Скачиваем дезинсталлятор...')
progress(11)
uninstall_path = os.path.join(
base_folder, 'gdl_unins000.exe'
).replace("/", "\\")
progress(12)
fast_write(uninstall_path, get(get_url('gdl_res/gdl_unins000_32bit.exe')).content)
progress(15)
log('Получаем список файлов...')
progress(16)
files_list = get(get_url('gdl_res/res_files.txt')).content.decode().split('\n')
progress(20)
list_len = len(files_list)
one_progress = 70 / list_len if list_len > 0 else 70
for i in range(list_len):
log(f'Сохраняем файл {files_list[i]}...')
file_url = get_url('gd_res/' + files_list[i])
file_path = os.path.join(base_folder, 'Resources', files_list[i])
if not files_list[i].strip():
continue
try:
file_content = get(file_url).content
except Exception as e:
log(f'Ошибка скачивания файла: {e}')
continue
if file_exists(file_path) and not file_exists(file_path + '.backup'):
log(f'Делаем бэкап файла...')
os.rename(file_path, file_path + '.backup')
backup[file_path] = file_path + '.backup'
fast_write(file_path, file_content)
progress(20 + int(one_progress * i))
log('Регистрируем как приложение...')
icon_path = os.path.join(base_folder, 'Resources', 'gdl_icon.ico').replace("/", "\\")
shutil.copy('files/gdl_icon.ico', icon_path)
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
try:
winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, REG_PATH)
except WindowsError:
pass
key = winreg.OpenKey(reg, REG_PATH, 0, winreg.KEY_WRITE)
winreg.SetValueEx(key, 'DisplayIcon', 0, winreg.REG_SZ, icon_path)
winreg.SetValueEx(key, 'DisplayName', 0, winreg.REG_SZ, 'Geometry Dash Localisation')
winreg.SetValueEx(key, 'DisplayVersion', 0, winreg.REG_SZ, '1.0.0')
winreg.SetValueEx(key, 'UninstallString', 0, winreg.REG_SZ, f'"{uninstall_path}"')
winreg.SetValueEx(key, 'Publisher', 0, winreg.REG_SZ, 'The GDL Community')
winreg.SetValueEx(key, 'NoModify', 0, winreg.REG_DWORD, 1)
winreg.SetValueEx(key, 'NoRepair', 0, winreg.REG_DWORD, 1)
log('Сохраняем файлы бэкапа в файл...')
fast_write(os.path.join(base_folder, 'gdl_unins000.txt'), json.dumps(backup))
progress(100)
to_setup = 1
def file_exists(file_path):
return os.access(file_path, os.F_OK)
def setup_buttons(tab_id):
if tab_id == 0:
ui.tabs.setCurrentIndex(0)
ui.goBackButton.setEnabled(False)
ui.goForwardButton.setEnabled(True)
unbind_buttons()
bind_forward(lambda: setup_buttons(1))
elif tab_id == 1:
ui.tabs.setCurrentIndex(1)
ui.folderpathEdit.setText('')
ui.goBackButton.setEnabled(True)
ui.goForwardButton.setEnabled(False)
ui.goForwardButton.setText('Далее')
unbind_buttons()
bind_back(lambda: setup_buttons(0))
bind_forward(lambda: setup_buttons(2))
elif tab_id == 2:
ui.tabs.setCurrentIndex(2)
ui.goBackButton.setEnabled(True)
ui.goForwardButton.setEnabled(True)
ui.goForwardButton.setText('Установить')
unbind_buttons()
bind_back(lambda: setup_buttons(1))
bind_forward(lambda: setup_buttons(3))
elif tab_id == 3:
ui.tabs.setCurrentIndex(3)
ui.goBackButton.setEnabled(False)
ui.goForwardButton.setEnabled(False)
ui.cancelButton.setEnabled(False)
unbind_buttons()
install_type = 'default'
if ui.loaderType.isChecked():
install_type = 'adaf-dll'
elif ui.modType.isChecked():
install_type = 'mods'
elif ui.hackType.isChecked():
install_type = 'extensions'
elif ui.gdhmType.isChecked():
install_type = os.path.join('.GDHM', 'dll')
# install_gdl(install_type)
MainWindow.tomer=QtCore.QTimer()
MainWindow.tomer.timeout.connect(testo)
MainWindow.tomer.start(10)
Thread(target=lambda: install_gdl(install_type)).start()
elif tab_id == 4:
ui.tabs.setCurrentIndex(4)
ui.goBackButton.setEnabled(False)
ui.goForwardButton.setEnabled(True)
ui.goForwardButton.setText('Готово')
unbind_buttons()
bind_forward(lambda: sys.exit(on_exit(0)))
def bind_events():
def on_cancel_pressed():
box = QtWidgets.QMessageBox(MainWindow)
box.setIcon(box.Question)
box.setWindowTitle('Выход из установки')
box.setText('Вы уверены, что хотите выйти?')
box.addButton('Да', box.ActionRole).clicked.connect(lambda: sys.exit(on_exit(0)))
box.addButton('Нет', box.ActionRole).clicked.connect(box.hide)
box.show()
ui.cancelButton.clicked.connect(on_cancel_pressed)
def check_path():
global base_folder
path = ui.folderpathEdit.text()
curl_path = os.path.join(path, 'libcurl.dll')
extensions_path = os.path.join(path, 'libExtensions.dll')
if file_exists(curl_path) and file_exists(extensions_path):
dll_loader_path = os.path.join(path, 'adaf-dll')
mod_loader_path = os.path.join(path, 'mods')
mega_hack_path = os.path.join(path, 'extensions')
gdhm_path = os.path.join(path, '.GDHM')
if os.path.isdir(dll_loader_path):
ui.loaderType.setCheckable(True)
if os.path.isdir(mod_loader_path):
ui.modType.setCheckable(True)
if os.path.isdir(mega_hack_path):
ui.hackType.setCheckable(True)
if os.path.isdir(gdhm_path):
ui.gdhmType.setCheckable(True)
ui.goForwardButton.setEnabled(True)
base_folder = path
else:
ui.goForwardButton.setEnabled(False)
def select_folder_pressed():
path = QtWidgets.QFileDialog.getExistingDirectory(
MainWindow, 'Выбор папки с игрой', os.getcwd()
)
ui.folderpathEdit.setText(path)
check_path()
ui.folderpathButton.clicked.connect(select_folder_pressed)
ui.folderpathEdit.textChanged.connect(check_path)
def on_init():
ui.tabs.tabBar().setEnabled(False)
bind_events()
setup_buttons(0)
def on_exit(exit_code: int = 0):
if not exit_code == 0:
print('App crashed with code ' + str(exit_code) + '.')
clear_temp()
return exit_code
app = QtWidgets.QApplication([__file__])
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
on_init()
sys.exit(on_exit(app.exec_()))