Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
285 lines (237 loc) · 10.5 KB
/
Copy pathmain.py
File metadata and controls
285 lines (237 loc) · 10.5 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
import sys
sys.path.append(r'utils')
from constants import *
from tkinter import *
from tkinter import ttk, filedialog, messagebox
import os
import binascii
import shutil
# Variables
DB = []
DBCs = []
PCB6Folder = ""
maxFolder = -1
def decToHex(number):
return hex(number)[2:].upper().rjust(2, "0")
def copytree(source, destination, symlinks = False, ignore = None):
for item in os.listdir(source):
s = os.path.join(source, item)
d = os.path.join(destination, item)
if os.path.isdir(s):
shutil.copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)
def fnOnClickSelectFolder():
PCB6FolderShow = filedialog.askdirectory(initialdir = "/", title = "Selecciona la carpeta de instalación del PC Basket 6.0:")
PCB6Folder = PCB6FolderShow.replace("/", "\\")
txtFolder.configure(state = "normal")
txtFolder.delete(first = 0, last = 500)
txtFolder.insert(0, PCB6FolderShow)
txtFolder.configure(state = "readonly")
# Load data
try:
# Global variables
global MANAGER_EXE
global EQ_PKF
global COUNTRIES_ALL
global COUNTRIES_PLAYERS
global maxFolder
global DB
# Load files and test sizes
MANAGER_EXE = PCB6Folder + "\\" + MANAGER_EXE
EQ_PKF = PCB6Folder + "\\" + EQ_PKF
COUNTRIES_ALL = PCB6Folder + "\\" + COUNTRIES_ALL
COUNTRIES_PLAYERS = PCB6Folder + "\\" + COUNTRIES_PLAYERS
managerSize = os.stat(MANAGER_EXE).st_size
eqPKFSize = os.stat(EQ_PKF).st_size
lblImgLoading.place(x = 368, y = 271)
lblLoading.place(x = (800 - 128) / 2, y = 346)
lblImgLoading.update()
lblLoading.update()
if managerSize == 2619392:
if eqPKFSize == 1632501:
# Right Sizes
# Find last folder in patches
for origin, dirs, files in os.walk("patches"):
for folder in dirs:
if folder.isnumeric():
if int(folder) > maxFolder:
maxFolder = int(folder)
# Create new folders in patches
if maxFolder == -1:
newFolder = "000"
else:
newFolder = str(maxFolder + 1).rjust(3, "0")
os.mkdir("patches\\" + newFolder)
os.mkdir("patches\\" + newFolder + "\\DBDAT")
os.mkdir("patches\\" + newFolder + "\\DBDAT\\BANDERAS")
os.mkdir("patches\\" + newFolder + "\\DBDAT\\BANDERAS\\MINI")
# Copy Mini Flags
copytree(PCB6Folder + "\\DBDAT\\BANDERAS\\MINI", "patches\\" + newFolder + "\\DBDAT\\BANDERAS\\MINI")
# Get Countries
countriesPlayers = open(COUNTRIES_PLAYERS, "rb")
countryName = ""
currentByte = 0
numCharsName = 0
nextCountry = 18
firstByte = nextCountry + 2
inCountry = False
country = {}
for byte in countriesPlayers.read():
if currentByte == nextCountry:
# Country found
inCountry = True
numCharsName = byte
lastByte = nextCountry + byte + 1
pointerByte = lastByte + 1
else:
if inCountry and currentByte >= firstByte:
if currentByte <= lastByte:
countryName += HEX_STRING[decToHex(byte)]
if currentByte == lastByte:
country['name'] = countryName
else:
if currentByte == pointerByte:
country['pointer'] = byte
inCountry = False
nextCountry = lastByte + 5
firstByte = nextCountry + 2
countryName = ""
DB.append(country)
country = {}
currentByte += 1
DB = sorted(DB, key = lambda user: user['name'])
for index, country in enumerate(DB):
root.listbox.insert((index + 1), country['name'])
lblCountries.place(x = 10, y = 50)
lblCountries.update()
root.listbox.place(x = 10, y = 58 + lblCountries.winfo_height(), height = 500)
root.listbox.update()
scrollbar.place(x = 10 + root.listbox.winfo_width(), y = 58 + lblCountries.winfo_height(), height = 500)
root.listbox.configure(yscrollcommand = scrollbar.set)
# Mini Flag
imgFlag = BitmapImage(data = "patches/" + newFolder + "/DBDAT/BANDERAS/MINI/BAN0037.BMP")
lblImgFlag = Label(root, image = imgFlag, bg = "#F0F0F0")
lblImgFlag.place(x = 10, y = 500)
'''
eqPKF = open(EQ_PKF, "rb")
foundFirst = False
foundSecond = False
foundTeam = False
currentTeam = ""
for byte in eqPKF.read():
if foundTeam:
currentTeam += decToHex(byte)
if decToHex(byte) == "43":
foundFirst = True
else:
if decToHex(byte) == "6F" and foundFirst:
foundSecond = True
else:
if decToHex(byte) == "70" and foundSecond:
# Found team
if foundTeam:
currentTeam = currentTeam[:-6]
DBCs.insert(len(DBCs), currentTeam)
foundTeam = True
foundFirst = False
foundSecond = False
currentTeam = "436F70"
else:
# Team not found
foundFirst = False
foundSecond = False
eqPKF.close()
# Find last folder in patches
for root, dirs, files in os.walk("patches"):
for folder in dirs:
if folder.isnumeric():
if int(folder) > maxFolder:
maxFolder = int(folder)
# Create new folder in patches
if maxFolder == -1:
newFolder = "000"
else:
newFolder = str(maxFolder + 1).rjust(3, "0")
os.mkdir("patches\\" + newFolder)
# Save the DBCs of the teams
for index, DBC in enumerate(DBCs):
numCharsShortName = int(DBC[84:86], 16)
currentChar = 88
numChars = 0
shortName = ""
while numChars < numCharsShortName:
shortName += HEX_STRING[DBC[currentChar:(currentChar + 2)]]
numChars += 1
currentChar += 2
#print(shortName)
newDBC = open("patches\\" + newFolder + "\\EQBA" + str(POINTERS[index]).rjust(4, "0") + ".DBC", "wb")
newDBC.write(binascii.unhexlify(DBC))
newDBC.close()
'''
# Hide Loading image and text
lblImgLoading.place_forget()
lblLoading.place_forget()
else:
# Wrong Teams PKF size
messagebox.showerror("PKF incorrecto", "ERROR: El tamaño del PKF de equipos es incorrecto.")
else:
# Wrong EXE size
messagebox.showerror("MANAGER.EXE incorrecto", "ERROR: El tamaño del MANAGER.EXE es incorrecto.")
except FileNotFoundError as e:
print(e)
messagebox.showerror("Directorio incorrecto", "ERROR: No se han encontrado los archivos adecuados en el directorio seleccionado. Seleccione otro directorio, por favor.")
def fnClose():
root.destroy() # Destroy window
# Tkinter window
root = Tk()
root.title(APP_TITLE)
bit = root.iconbitmap("editor.ico")
# Fonts
fntTahoma10 = ("Tahoma", 10)
fntTahomaBold10 = ("Tahoma", 10, "bold")
# Menu
menubar = Menu(root)
filemenu = Menu(menubar, tearoff = 0)
# Menu options
filemenu.add_command(label = "Salir", command = fnClose)
#filemenu.add_separator()
# Add menu to bar
menubar.add_cascade(label = "Archivo", menu = filemenu)
# Add menu to window
root.config(menu = menubar)
# Folder selector
lblSelectFolder = Label(root, text = "Selecciona la carpeta donde tienes instalado el PC Basket 6.0:", font = fntTahoma10)
lblSelectFolder.place(x = 5, y = 7)
lblSelectFolder.update()
# Folder textbox
txtFolder = Entry(root, font = fntTahoma10, relief = SOLID, borderwidth = 1, width = 40)
txtFolder.configure(state = "readonly")
txtFolder.place(x = 10 + lblSelectFolder.winfo_width(), y = 7)
# Folder selection Button
btnSelectFolder = Button(root, text = "Examinar...", font = fntTahoma10, command = fnOnClickSelectFolder, relief = SOLID, borderwidth = 1, width = 15)
btnSelectFolder.place(x = 800 - 113 - 10, y = 5)
btnSelectFolder.update()
# Separator
separator1 = ttk.Separator(root, orient = HORIZONTAL)
separator1.place(x = 0, y = 12 + btnSelectFolder.winfo_height(), relwidth = 1.0)
# Loading image
imgLoading = PhotoImage(file = "img/loading.png")
lblImgLoading = Label(root, image = imgLoading, bg = "#F0F0F0")
# Loading Label
lblLoading = Label(root, text = "Cargando los datos...", font = fntTahoma10)
lblLoading.update()
# Countries label
lblCountries = Label(root, text = "Países:", font = fntTahomaBold10)
# Countries listbox
root.listbox = Listbox(root, exportselection = 0, highlightcolor = "#808080", selectbackground = "#FF4000", selectmode = SINGLE, activestyle = NONE, font = fntTahoma10)
# Scrollbar for countries Listbox
scrollbar = ttk.Scrollbar(root, orient = VERTICAL, command = root.listbox.yview)
# Show window
posLeft = int((root.winfo_screenwidth() - 800) / 2 )
posTop = int((root.winfo_screenheight() - 660) / 2 )
geoParam = "800x600+" + str(posLeft) + "+" + str(posTop)
root.geometry(geoParam)
root.protocol("WM_DELETE_WINDOW", fnClose)
#root.configure(background = "#000040")
root.mainloop()