-
Notifications
You must be signed in to change notification settings - Fork 11
/
helper.py
285 lines (224 loc) · 10.4 KB
/
helper.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
import os
import vpk
import shutil
import webbrowser
import tkinter
import urllib.error
from urllib.request import urlopen
import requests
import yaml
workshop_installed = False
# # ---------------------------------------------------------------------------- #
# # Connect Remote #
# # ---------------------------------------------------------------------------- #
response = requests.get('https://raw.githubusercontent.com/robbyz512/dota2-minify-remote/remote-data/data.yaml')
if response.status_code == 200:
data = yaml.safe_load(response.text)
latest_version_url = data.get('latest_version')
discord_url = data.get('discord')
donations_url = data.get('donations')
help_url = data.get('help')
new_version = data.get('minify_2')
update_url = data.get('releases')
else:
latest_version_url = None
discord_url = None
donations_url = None
help_url = None
new_version = None
update_url = None
# ---------------------------------------------------------------------------- #
# Warnings #
# ---------------------------------------------------------------------------- #
# Output can be passed here to display as warnings at the end of patching.
warnings = []
def handleWarnings(logs_dir):
global warnings
if len(warnings) != 0:
with open(os.path.join(logs_dir, 'warnings.txt'), 'w') as file:
for line in warnings:
file.write(line + "\n")
if len(warnings) == 1:
print(f"{len(warnings)} error occured. Check logs\\warnings.txt for details.")
elif len(warnings) >= 2:
print(f"{len(warnings)} errors occured. Check logs\\warnings.txt for details.")
# ---------------------------------------------------------------------------- #
# GUI #
# ---------------------------------------------------------------------------- #
# when you add new arguments to bind function tkinter seems to expect event as the last argument.
def modLabelColorConfig(widget, color, event):
widget.configure(foreground=color)
def modInfo(widget, name, mod_path, event):
with open(os.path.join(mod_path, 'notes.txt'), 'r') as file:
data = file.read() # Read the entire file as a single string
infoWindow = tkinter.Toplevel()
infoWindow.title(name)
infoWindow.iconbitmap('bin/images/info.ico')
infoWindow.resizable(False, False)
window_width = infoWindow.winfo_width()
window_height = infoWindow.winfo_height()
screen_width = infoWindow.winfo_screenwidth()
screen_height = infoWindow.winfo_screenheight()
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
infoWindow.geometry(f"+{x}+{y}")
text_widget = tkinter.Text(infoWindow, bg='#1C1F2B', fg='#fff', wrap=tkinter.WORD)
text_widget.grid(row=0, column=0, padx=5, pady=5, sticky='nsew')
text_widget.insert("1.0", data)
text_widget.config(state="disabled")
close_button = tkinter.Button(infoWindow, text="Close", command=infoWindow.destroy, font=("Poplar Std", 10), height=1, width=10)
close_button.grid(row=1, column=0, pady=5)
def cryptoInfo():
BTC = "bc1qeykc7qfhkp0h0e8a3nry3dwh2tnyryg8r3pgwv"
ETH = "0x1A751823E32AdbB5c119D0908DabF2095290f97b"
Solana = "71s57cHbgqV8Xyi5y8R5U7yxJEP2L4EcoNMvacEAErUL"
Monero = "43kr1X9AxJ3iTCNRfTSRzAaWJgMgCpoMz63JeUnDDC7yQ2WvuHuHdtAQV7bnBSEY44Hv9C4kLarKtH7tPiN48pZeVm3d1nN"
infoWindow = tkinter.Toplevel()
infoWindow.title("Donate Crypto")
infoWindow.iconbitmap('bin/images/info.ico')
infoWindow.resizable(False, False)
# Center the window
window_width = infoWindow.winfo_width()
window_height = infoWindow.winfo_height()
screen_width = infoWindow.winfo_screenwidth()
screen_height = infoWindow.winfo_screenheight()
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
infoWindow.geometry(f"+{x}+{y}")
# Create text widget
text_widget = tkinter.Text(infoWindow, bg='#1C1F2B', fg='#fff', wrap=tkinter.WORD)
text_widget.grid(row=0, column=0, padx=5, pady=5, sticky='nsew')
# Define color tags
text_widget.tag_configure("btc", foreground="#F7931A") # Bitcoin orange
text_widget.tag_configure("eth", foreground="#89CFF0") # Ethereum blue
text_widget.tag_configure("sol", foreground="#9945FF") # Solana purple
text_widget.tag_configure("xmr", foreground="#FF6600") # Monero orange
# Insert text with color tags
text_widget.insert("1.0", "Bitcoin (BTC): ", "btc")
text_widget.insert("2.0", BTC + "\n\n", "btc")
text_widget.insert("3.0", "Ethereum (ETH): ", "eth")
text_widget.insert("4.0", ETH + "\n\n", "eth")
text_widget.insert("5.0", "Solana (SOL): ", "sol")
text_widget.insert("6.0", Solana + "\n\n", "sol")
text_widget.insert("7.0", "Monero (XMR): ", "xmr")
text_widget.insert("8.0", Monero, "xmr")
# Disable editing
text_widget.config(state="disabled")
# Close button
close_button = tkinter.Button(infoWindow, text="Close", command=infoWindow.destroy, font=("Poplar Std", 10), height=1, width=10)
close_button.grid(row=1, column=0, pady=5)
def disableWorkshopMods(mods_dir, mods_folders, checkboxes):
for folder in mods_folders:
mod_path = os.path.join(mods_dir, folder)
styling_txt = os.path.join(mod_path, 'styling.txt')
for box in checkboxes:
if checkboxes[box] == folder:
if os.stat(styling_txt).st_size != 0:
box.configure(state='disable')
def toggleFrameOn(frame_checkbox, frame_buttons, mods_dir, mods_folders, checkboxes):
for widget in frame_checkbox.winfo_children():
widget.configure(state='normal')
for widget in frame_buttons.winfo_children():
if widget.cget('text') == 'Patch':
widget.configure(state='normal')
if widget.cget('text') == 'Uninstall':
widget.configure(state='normal')
if workshop_installed == False:
disableWorkshopMods(mods_dir, mods_folders, checkboxes)
def toggleFrameOff(frame_checkbox, frame_buttons):
for widget in frame_checkbox.winfo_children():
widget.configure(state='disable')
for widget in frame_buttons.winfo_children():
if widget.cget('text') == 'Patch':
widget.configure(state='disable')
if widget.cget('text') == 'Uninstall':
widget.configure(state='disable')
def getAppHeight(mods_folders):
height = 400
num_of_mods = len(mods_folders)
i = 10
while (i < num_of_mods):
i += 1
height += 30
return height
# ---------------------------------------------------------------------------- #
def cleanFolders(build_dir, logs_dir, content_dir, game_dir, minify_dir, dota_minify_maps):
shutil.rmtree(build_dir, ignore_errors=True)
for root, dirs, files in os.walk(logs_dir):
for filename in files:
open(os.path.join(root, filename), 'w').close()
for root, dirs, files in os.walk(content_dir):
for filename in files:
os.remove(os.path.join(root, filename))
for root, dirs, files in os.walk(game_dir):
for filename in files:
os.remove(os.path.join(root, filename))
for root, dirs, files in os.walk(dota_minify_maps):
for filename in files:
os.remove(os.path.join(root, filename))
os.makedirs(os.path.join(minify_dir, 'build'))
def urlDispatcher(url):
if url == None:
print("Could not connect to Github")
else:
webbrowser.open(url)
def getBlankFileExtensions(blank_files_dir):
extensions = []
for file in os.listdir(blank_files_dir): extensions.append(os.path.splitext(file)[1])
return extensions
def vpkExtractor(path, pak01_dir, build_dir):
pak1 = vpk.open(pak01_dir)
fullPath = os.path.join(build_dir, path)
if not os.path.exists(fullPath): # extract files from VPK only once
print(" extracting: " + path)
path = path.replace(os.sep,'/')
pakfile = pak1.get_file(path)
pakfile.save(os.path.join(fullPath))
def urlValidator(url):
content = []
url = url.replace('@@', '')
try:
for line in urlopen(url):
try:
line = line.decode('utf-8').split()
line = ''.join(line)
except UnicodeDecodeError as exception:
warnings.append("[{}]".format(type(exception).__name__) + " Cannot decode -> " + str(line) + " Make sure your URL is using a 'utf-8' charset")
content.append(line)
except urllib.error.HTTPError as exception:
warnings.append("[{}]".format(type(exception).__name__) + f" Could not connect to -> " + url)
except ValueError as exception:
warnings.append("[{}]".format(type(exception).__name__) + f" Invalid URL -> " + url)
except urllib.error.URLError as exception:
warnings.append("[{}]".format(type(exception).__name__) + f" Invalid URL -> " + url)
return content
def processBlacklistDir(index, line, folder, pak01_dir):
data = []
line = line.replace('>>', '')
line = line.replace(os.sep,'/')
pak1 = vpk.open(pak01_dir)
for filepath in pak1:
if filepath.startswith(line):
data.append(filepath)
if not data:
warnings.append(f"[Directory Not Found] Could not find '{line}' in pak01_dir.vpk -> mods\\{folder}\\blacklist.txt [line: {index+1}]")
return data
def processBlackList(index, line, folder, blank_file_extensions, pak01_dir):
data = []
if line.startswith("@@"):
content = urlValidator(line)
for line in content:
if line.startswith("#"):
continue
if line.startswith(">>"):
for path in processBlacklistDir(index, line, folder, pak01_dir):
data.append(path)
continue
try:
if line.endswith(tuple(blank_file_extensions)):
data.append(line)
else:
warnings.append(f"[Invalid Extension] '{line}' in 'mods\\{folder}\\blacklist.txt' [line: {index+1}] does not end in one of the valid extensions -> {blank_file_extensions}")
except TypeError as exception:
warnings.append("[{}]".format(type(exception).__name__) + " Invalid data type in line -> " + str(line))
return data