-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.pyw
More file actions
377 lines (293 loc) · 12.9 KB
/
main.pyw
File metadata and controls
377 lines (293 loc) · 12.9 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
import json
import os, wx, subprocess
import GlobalVariables
from pathlib import Path
class FileDropInput(wx.FileDropTarget):
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):
if len(filenames) != 1:
return True
GlobalVariables.input_path = str(Path(filenames[0]))
GlobalVariables.file_input_textbox.SetValue(GlobalVariables.input_path)
return True
class FileDropOutput(wx.FileDropTarget):
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):
if len(filenames) != 1:
return True
GlobalVariables.output_path = str(Path(filenames[0]))
GlobalVariables.file_output_textbox.SetValue(GlobalVariables.output_path)
return True
#
# For PAKing
#
def PAK():
if not can_PAK():
return
unrealpak_path = Path("UnrealPaker\\Engine\\Binaries\\Win64\\UnrealPak.exe")
base_file_name = GlobalVariables.input_path.split("\\")[-1].split(".")[0]
file_list = Path("UnrealPaker\\Engine\\Binaries\\Win64\\filelist.txt")
# Create filelist
subprocess.Popen(
f'@echo "{Path(GlobalVariables.output_path)}\\{base_file_name}\*.*" "../../../{GlobalVariables.game_name}/" > "{file_list}"',
shell=True)
cmd = f'"{unrealpak_path}" "{Path(GlobalVariables.output_path)}\\{base_file_name}.pak" -create="{os.path.abspath(file_list)}" -compress'
# Create pak file
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
split_lines = output.read().decode().split("\n")
for line in split_lines:
if "Warning" in line:
add_console_message(line + "\n", '#FFA500')
elif "Error" in line:
add_console_message(line + "\n", wx.RED)
elif "executed" in line:
add_console_message(line + "\n", wx.GREEN)
else:
add_console_message(line + "\n")
#
# For UNPAKing
#
def UNPAK():
if not can_UNPAK():
return
unrealpak_path = Path("UnrealPaker\\Engine\\Binaries\\Win64\\UnrealPak.exe")
base_file_name = GlobalVariables.input_path.split("\\")[-1].split(".")[0]
cmd = f' "{unrealpak_path}" "{GlobalVariables.input_path}" -extract "{GlobalVariables.output_path}\\{base_file_name}"'
# UNPAK file
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
split_lines = output.read().decode().split("\n")
for line in split_lines:
if "Warning" in line:
add_console_message(line + "\n", '#FFA500')
elif "Error" in line:
add_console_message(line + "\n", wx.RED)
elif "executed" in line:
add_console_message(line + "\n", wx.GREEN)
else:
add_console_message(line + "\n")
#
# Add a console message.
#
def add_console_message(text, color=wx.WHITE, spacers=False):
GlobalVariables.console_textbox.SetDefaultStyle(wx.TextAttr(color))
if spacers:
GlobalVariables.console_textbox.AppendText("\n")
GlobalVariables.console_textbox.AppendText(text)
if spacers:
GlobalVariables.console_textbox.AppendText("\n")
#
# Check if can PAK
#
def can_PAK():
if len(GlobalVariables.file_input_textbox.GetValue()) == 0:
add_console_message("Input is empty.\n", wx.RED)
return False
if len(GlobalVariables.file_output_textbox.GetValue()) == 0:
add_console_message("Output is empty.\n", wx.RED)
return False
if "." in GlobalVariables.file_output_textbox.GetValue():
add_console_message("Output contains a file, not folder.\n", wx.RED)
return False
if "." in GlobalVariables.file_input_textbox.GetValue():
add_console_message("Input contains a file, not folder.\n", wx.RED)
return False
return True
#
# Check if can UNPAK
#
def can_UNPAK():
if len(GlobalVariables.file_input_textbox.GetValue()) == 0:
add_console_message("Input is empty.\n", wx.RED)
return False
if len(GlobalVariables.file_output_textbox.GetValue()) == 0:
add_console_message("Output is empty.\n", wx.RED)
return False
if "." in GlobalVariables.file_output_textbox.GetValue():
add_console_message("Output contains a file, not folder.\n", wx.RED)
return False
if "." not in GlobalVariables.file_input_textbox.GetValue():
add_console_message("Input contains a folder, not file.\n", wx.RED)
return False
return True
class QuantumPAK(wx.Frame):
def __init__(self, *args, **kw):
super(QuantumPAK, self).__init__(size=(400, 500), *args, **kw)
self.SetTitle('QuantumPAK')
self.Centre()
self.init_gui()
def init_gui(self):
# Init Panel
panel = wx.Panel(self)
panel.SetBackgroundColour('#333')
# Set Font
font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
# Set Font Size
font.SetPointSize(9)
# Set Overall BoxSizer Layout
outer_box = wx.BoxSizer(wx.VERTICAL)
###########
## NAMES ##
###########
name_horz = wx.BoxSizer(wx.HORIZONTAL)
pak_text = wx.StaticText(panel, label='Input')
pak_text.SetFont(font)
pak_text.SetForegroundColour("#FFF")
unpak_text = wx.StaticText(panel, label='Output')
unpak_text.SetFont(font)
unpak_text.SetForegroundColour("#FFF")
name_horz.Add(pak_text, proportion=1)
name_horz.Add(unpak_text, proportion=1)
outer_box.Add(name_horz, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
###########################
## Input Output Text Box ##
###########################
text_ctrl_horz = wx.BoxSizer(wx.HORIZONTAL)
# Input Text Box
GlobalVariables.file_input_textbox = wx.TextCtrl(panel)
GlobalVariables.file_input_textbox.SetValue(GlobalVariables.input_path)
GlobalVariables.file_input_textbox.SetDropTarget(FileDropInput(panel))
GlobalVariables.file_input_textbox.SetForegroundColour("#FFF")
GlobalVariables.file_input_textbox.SetBackgroundColour("#333")
# Output Text Box
GlobalVariables.file_output_textbox = wx.TextCtrl(panel)
GlobalVariables.file_output_textbox.SetValue(GlobalVariables.output_path)
GlobalVariables.file_output_textbox.SetDropTarget(FileDropInput(panel))
GlobalVariables.file_output_textbox.SetForegroundColour("#FFF")
GlobalVariables.file_output_textbox.SetBackgroundColour("#333")
text_ctrl_horz.Add(GlobalVariables.file_input_textbox, proportion=1)
text_ctrl_horz.Add(GlobalVariables.file_output_textbox, proportion=1)
outer_box.Add(text_ctrl_horz, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
#######################
## SELECTION BUTTONS ##
#######################
select_button_horz = wx.BoxSizer(wx.HORIZONTAL)
# File Selection Button
file_input_selection = wx.Button(panel, -1, "Select File")
file_input_selection.Bind(wx.EVT_BUTTON, self.OpenInputSelector)
file_input_selection.SetDropTarget(FileDropInput(panel))
file_input_selection.SetForegroundColour("#FFF")
file_input_selection.SetBackgroundColour("#333")
# Folder Selection Button
file_input_selection_f = wx.Button(panel, -1, "Select Folder")
file_input_selection_f.Bind(wx.EVT_BUTTON, self.OpenInputSelectorFolder)
file_input_selection_f.SetDropTarget(FileDropInput(panel))
file_input_selection_f.SetForegroundColour("#FFF")
file_input_selection_f.SetBackgroundColour("#333")
# File Selection Button
file_output_selection = wx.Button(panel, -1, "Select Folder")
file_output_selection.Bind(wx.EVT_BUTTON, self.OpenOutputSelector)
file_output_selection.SetDropTarget(FileDropOutput(panel))
file_output_selection.SetForegroundColour("#FFF")
file_output_selection.SetBackgroundColour("#333")
select_button_horz.Add(file_input_selection, proportion=1)
select_button_horz.Add(file_input_selection_f, proportion=1)
select_button_horz.Add(file_output_selection, proportion=2)
outer_box.Add(select_button_horz, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
#################
## DRAG AREAS ###
#################
drag_areas_horz = wx.BoxSizer(wx.HORIZONTAL)
# Input Drag and Drop
input_drag_box = wx.StaticBox(panel, label="Drag n' Drop")
input_drag_box.SetDropTarget(FileDropInput(panel))
input_drag_box.SetBackgroundColour("#333")
input_drag_box.SetForegroundColour("#FFF")
# Output Drag and Drop
output_drag_box = wx.StaticBox(panel, label="Drag n' Drop")
output_drag_box.SetDropTarget(FileDropOutput(panel))
output_drag_box.SetBackgroundColour("#333")
output_drag_box.SetForegroundColour("#FFF")
drag_areas_horz.Add(input_drag_box, proportion=1, flag=wx.EXPAND)
drag_areas_horz.Add(output_drag_box, proportion=1, flag=wx.EXPAND)
outer_box.Add(drag_areas_horz, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
#######################
## PAK UNPAK Buttons ##
#######################
pak_horz = wx.BoxSizer(wx.HORIZONTAL)
# PAK Button
pakButton = wx.Button(panel, label='PAK', size=(100, 50))
pakButton.Bind(wx.EVT_BUTTON, self.PAKEvent)
pakButton.SetForegroundColour("#FFF")
pakButton.SetBackgroundColour("#333")
# UNPAK Button
unpakButton = wx.Button(panel, label='UNPACK', size=(100, 50))
unpakButton.Bind(wx.EVT_BUTTON, self.UNPAKEvent)
unpakButton.SetForegroundColour("#FFF")
unpakButton.SetBackgroundColour("#333")
pak_horz.Add(pakButton, proportion=1)
pak_horz.Add(unpakButton, proportion=1)
outer_box.Add(pak_horz, flag=wx.EXPAND | wx.RIGHT | wx.LEFT | wx.BOTTOM, border=7)
#############
## Console ##
#############
console_horz = wx.BoxSizer(wx.HORIZONTAL)
console_text = wx.StaticText(panel, label='Console')
console_text.SetFont(font)
console_text.SetForegroundColour("#FFF")
console_horz.Add(console_text)
outer_box.Add(console_horz, flag=wx.LEFT | wx.TOP, border=10)
console2_horz = wx.BoxSizer(wx.HORIZONTAL)
GlobalVariables.console_textbox = wx.TextCtrl(panel, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH)
GlobalVariables.console_textbox.SetBackgroundColour("#333")
console2_horz.Add(GlobalVariables.console_textbox, proportion=1, flag=wx.EXPAND)
outer_box.Add(console2_horz, proportion=1, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=10)
# Add outer box to panel.
panel.SetSizer(outer_box)
#
# On PAK Button Press
#
def PAKEvent(self, event):
PAK()
def UNPAKEvent(self, event):
UNPAK()
#
# On --put Button Press
#
def OpenOutputSelector(self, event):
dialog = wx.DirDialog(None, "Choose a directory/file:",
style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dialog.ShowModal() == wx.ID_OK:
GlobalVariables.output_path = dialog.GetPath()
GlobalVariables.file_output_textbox.SetValue(GlobalVariables.output_path)
dialog.Destroy()
def OpenInputSelector(self, event):
dialog = wx.FileDialog(None, "Choose a directory/file:",
style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON, wildcard="PAK files (*.pak)|*.pak")
if dialog.ShowModal() == wx.ID_OK:
GlobalVariables.input_path = dialog.GetPath()
GlobalVariables.file_input_textbox.SetValue(GlobalVariables.input_path)
dialog.Destroy()
def OpenInputSelectorFolder(self, event):
dialog = wx.DirDialog(None, "Choose a directory/file:",
style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dialog.ShowModal() == wx.ID_OK:
GlobalVariables.input_path = dialog.GetPath()
GlobalVariables.file_input_textbox.SetValue(GlobalVariables.input_path)
dialog.Destroy()
#
# Main Function.
#
def main():
# Read or Create Config
if os.path.isfile("Settings.ini"):
json_data = json.load(open("Settings.ini", "r"))
GlobalVariables.game_name = json_data["game_name"]
GlobalVariables.input_path = json_data["input_path"]
GlobalVariables.output_path = json_data["output_path"]
else:
json_data = {}
json_data["game_name"] = "ReadyOrNot"
json_data["input_path"] = ""
json_data["output_path"] = ""
json.dump(json_data, open("Settings.ini", "w"))
# Create Visual
app = wx.App()
ex = QuantumPAK(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()