-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmainWindow.py
More file actions
351 lines (308 loc) · 13.4 KB
/
mainWindow.py
File metadata and controls
351 lines (308 loc) · 13.4 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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
from PySide6 import QtWidgets, QtCore, QtGui
import webbrowser, api, browseWindow, settingsWindow, configFileWindow, cmdWindow, exportAllWindow, licensesWindow, aboutWindow
from uip import ui_mainWindow
import windowGetter, win32gui, win32con, _thread, time, os, path_saver
class PathOpenMethod(object):
FAST = 0
LEGACY = 1
class MainWindow(ui_mainWindow.Ui_MainWindow, QtWidgets.QMainWindow):
def __init__(self):
self.port = None
self.hasFile = False
self.version = None
self.version_option = None
self.export_all_window = None
super().__init__()
self.setupUi(self)
if os.path.exists("./icon.ico"):
icon = QtGui.QIcon("./icon.ico")
self.setWindowIcon(icon)
self.setupLinks()
self.setupActions()
api.StatusMachine.onApiCallFinished = self.onApiCallFinished
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.check_btn_stat)
self.timer.start(500)
def check_btn_stat(self):
if self.hasFile:
self.pushButton.setEnabled(True)
self.actionExport_All_Files.setEnabled(True)
self.pushButton.setStyleSheet(
"QPushButton{background-color:#198754;color:white;}QPushButton:hover{background-color:#157347}"
)
self.pushButton.setText("View Loaded Files")
else:
self.pushButton.setEnabled(False)
self.actionExport_All_Files.setEnabled(False)
self.pushButton.setStyleSheet(str())
self.pushButton.setText("No Files Loaded")
if self.version:
if not self.version_option:
self.version_option = QtGui.QAction(list(self.version.keys())[0])
self.version_option.triggered.connect(self.open_version)
self.menu_Export.addAction(self.version_option)
else:
if self.version_option:
self.menu_Export.removeAction(self.version_option)
self.version_option = None
def open_version(self):
webbrowser.open(list(self.version.values())[0])
def onApiCallFinished(self, res: api.requests.Response):
print("返回码:", res.status_code)
if res.status_code == 302 or res.status_code == 200:
self.hasFile = api.check_is_file(self.port)
print("hasFile:", self.hasFile)
self.version = api.check_version(self.port)
print("Unity version:", self.version)
def export_all(self):
pass
def set_port(self, port):
self.port = port
def setupActions(self):
self.actionOpen_File.triggered.connect(self.open_file)
self.actionOpen_Folder.triggered.connect(self.open_folder)
self.actionReset.triggered.connect(self.reset)
self.actionSettings.triggered.connect(self.to_settings)
self.actionSettings_2.triggered.connect(self.to_settings)
self.actionConfiguration_Files.triggered.connect(self.to_config_files)
self.actionCommands.triggered.connect(self.to_cmds)
self.actionExport_All_Files.triggered.connect(self.to_export_all)
self.actionPrivacy.triggered.connect(self.privacy_dialog)
self.actionLicenses.triggered.connect(self.to_licenses)
self.actionOpenAPI_JSON.triggered.connect(
lambda: webbrowser.open(f"http://localhost:{self.port}/openapi.json")
)
self.actionSwagger_Documentation.triggered.connect(
lambda: webbrowser.open(f"http://localhost:{self.port}/swagger/")
)
self.actionOriginal_UI.triggered.connect(
lambda: webbrowser.open(f"http://localhost:{self.port}/")
)
self.actionAbout_Qt.triggered.connect(
lambda: QtWidgets.QMessageBox.aboutQt(self)
)
self.action_About.triggered.connect(self.about)
self.pushButton.clicked.connect(self.view_files)
def about(self):
self.about_window = aboutWindow.AboutWindow(self)
self.about_window.show()
def to_licenses(self):
self.lic_window = licensesWindow.LicencesWindow(self)
self.lic_window.show()
def privacy_dialog(self):
QtWidgets.QMessageBox.information(
self, "Privacy", "This application doesn't access the Internet."
)
def to_cmds(self):
if self.hasFile:
self.to_export_all()
else:
self.cmds_window = cmdWindow.CmdWindow(self)
self.cmds_window.setModal(True)
self.cmds_window.show()
def to_export_all(self):
self.export_all_window = exportAllWindow.ExportAllWindow(self)
self.export_all_window.setModal(True)
self.export_all_window.show()
def to_config_files(self):
self._prompt_window = QtWidgets.QLabel("请稍后... Please wait...")
self._prompt_window.setWindowTitle("加载中... Loading...")
self._prompt_window.show()
self.setEnabled(False)
self.configs = None
self.configs_got = False
_thread.start_new_thread(self._get_config, tuple())
while not self.configs_got:
self.update()
QtWidgets.QApplication.processEvents()
self._prompt_window.close()
self.setEnabled(True)
self.config_dialog = configFileWindow.ConfigFileWindow(self)
self.config_dialog.setModal(True)
self.config_dialog.show()
self.config_dialog.setData(self.configs)
def _get_config(self):
self.configs = api.get_configs(self.port)
print(self.configs)
self.configs_got = True
def to_settings(self):
if self.hasFile:
QtWidgets.QMessageBox.information(
self,
"Configuration Options",
"Settings can only be changed before loading files.",
)
else:
self.open_settings()
def open_settings(self):
self._prompt_window = QtWidgets.QLabel("请稍后... Please wait...")
self._prompt_window.setWindowTitle("加载中... Loading...")
self._prompt_window.show()
self.setEnabled(False)
self.settings = None
self.settings_names = None
self.settings_got = False
_thread.start_new_thread(self._get_settings, tuple())
while not self.settings_got:
self.update()
QtWidgets.QApplication.processEvents()
self._prompt_window.close()
self.setEnabled(True)
self.settings_window = settingsWindow.SettingsWindow(self)
self.settings_window.setModal(True)
flags = self.settings_window.windowFlags()
flags |= QtCore.Qt.WindowType.WindowMaximizeButtonHint
self.settings_window.setWindowFlags(flags)
self.settings_window.show()
self.settings_window.setData(self.settings)
self.settings_window.setFormNames(self.settings_names)
def _get_settings(self):
ret = api.get_settings(self.port)
self.settings = ret[0]
self.settings_names = ret[1]
self.settings_got = True
print(self.settings)
def view_files(self, *d):
self._prompt_window = QtWidgets.QLabel("请稍后... Please wait...")
self._prompt_window.setWindowTitle("加载中... Loading...")
self._prompt_window.show()
self.setEnabled(False)
self.data = None
self.finished = False
_thread.start_new_thread(self._view_files, tuple())
while not self.finished:
self.update()
QtWidgets.QApplication.processEvents()
self._prompt_window.close()
self.setEnabled(True)
self.browseFileDialog = browseWindow.BrowseWindow(self)
self.browseFileDialog.setModal(True)
self.browseFileDialog.show()
self.browseFileDialog.setType(browseWindow.BrowseWindow.Types.BUNDLE)
self.browseFileDialog.setData(self.data)
def _view_files(self, *d):
self.data = api.get_loaded_files(self.port)
self.finished = True
def reset(self, *d):
api.reset(self.port)
self._prompt_window = QtWidgets.QLabel("请稍后... Please wait...")
self._prompt_window.setWindowTitle("加载中... Loading...")
self._prompt_window.show()
self.setEnabled(False)
timer = QtCore.QElapsedTimer()
timer.start()
while timer.elapsed() <= 1000:
QtWidgets.QApplication.processEvents()
self.update()
self._prompt_window.close()
self.setEnabled(True)
def open_file(self, *d, method=PathOpenMethod.FAST):
if method == PathOpenMethod.LEGACY:
api.open_file(self.port)
self._prompt_window = QtWidgets.QLabel("请稍后... Please wait...")
self._prompt_window.setWindowTitle("加载中... Loading...")
self._prompt_window.show()
self.setEnabled(False)
self.need_close_win = False
_thread.start_new_thread(self._wait_window, tuple())
while not self.need_close_win:
QtWidgets.QApplication.processEvents()
self.update()
time.sleep(1)
self._prompt_window.close()
elif method == PathOpenMethod.FAST:
path = QtWidgets.QFileDialog.getOpenFileName(
self, "Select File...", dir=path_saver.get_last_path()
)[0]
if not path:
return # 取消了
path_saver.save_last_path(path_saver.get_file_dir(path))
api.load_file_or_folder_from_path(path, port=self.port)
def open_folder(self, *d, method=PathOpenMethod.FAST):
if method == PathOpenMethod.LEGACY:
api.open_folder(self.port)
self._prompt_window = QtWidgets.QLabel("请稍后... Please wait...")
self._prompt_window.setWindowTitle("加载中... Loading...")
self._prompt_window.show()
self.setEnabled(False)
self.need_close_win = False
_thread.start_new_thread(self._wait_window, tuple())
while not self.need_close_win:
QtWidgets.QApplication.processEvents()
self.update()
time.sleep(1)
self._prompt_window.close()
elif method == PathOpenMethod.FAST:
path = QtWidgets.QFileDialog.getExistingDirectory(
self, "Select Directory...", dir=path_saver.get_last_path()
)
if not path:
return # 取消了
path_saver.save_last_path(path)
api.load_file_or_folder_from_path(path, port=self.port)
def _wait_window(self):
while True:
pid = (
windowGetter.find_process_by_name("AssetRipper.GUI.Free.exe")
if not windowGetter.StatusMachine.known_pid
else windowGetter.StatusMachine.known_pid
)
windows = windowGetter.get_window_info(pid)
if len(windows) < 1:
continue
hwnd = windows[0]["hwnd"]
if win32gui.IsIconic(hwnd):
win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
win32gui.SetForegroundWindow(hwnd)
print("foreground set")
self.setEnabled(True)
self.need_close_win = True
break
def setupLinks(self):
dic = {
self.linkBtn1: "https://patreon.com/ds5678",
self.linkBtn2: "https://paypal.me/ds5678",
self.linkBtn3: "https://github.com/sponsors/ds5678",
self.linkBtn4: "ar://dialog1",
self.linkBtn5: "ar://lics",
}
for button, url in dic.items():
if url.startswith("http"):
# 使用默认参数创建局部变量
button.clicked.connect(
lambda checked=False, link=url: webbrowser.open(link)
)
def finishExportingEvent(self):
if self.export_all_window:
if self.export_all_window.exporting_window:
self.export_all_window.exporting_window.setValue(
None, None, "Finished Exporting"
)
def handleExportingOutPut(self, current: str, total: str, name: str):
if self.export_all_window:
if self.export_all_window.exporting_window:
try:
self.export_all_window.exporting_window.setValue(
int(current.strip()), int(total.strip()), name
)
except TypeError:
pass
def handleDecompilingMessage(self, name: str):
if self.export_all_window:
if self.export_all_window.exporting_window:
self.export_all_window.exporting_window.setValue(
None, None, f"Decompiling: {name}"
)
def handleSavingMessage(self, content: str):
if self.export_all_window:
if self.export_all_window.exporting_window:
self.export_all_window.exporting_window.setValue(
None, None, f"Saving: {content}"
)
def setProcessPid(self, pid: int):
windowGetter.StatusMachine.known_pid = pid
if __name__ == "__main__":
qa = QtWidgets.QApplication(list())
mw = MainWindow()
mw.show()
qa.exec()