added try except in most function to help debugging error

This commit is contained in:
raphael60650 2021-06-15 17:03:31 +02:00
parent 1b7bb6ec1f
commit e4fa9ba95c
9 changed files with 315 additions and 280 deletions

View file

@ -3,6 +3,7 @@ from PIL import Image, ImageFont, ImageDraw
from tkinter import messagebox, filedialog, ttk from tkinter import messagebox, filedialog, ttk
from threading import Thread from threading import Thread
import subprocess import subprocess
import traceback
import requests import requests
import zipfile import zipfile
import shutil import shutil
@ -26,6 +27,7 @@ class ClassApp():
from source.restart import restart from source.restart import restart
from source.patch_img_desc import patch_img_desc from source.patch_img_desc import patch_img_desc
from source.patch_ct_icon import patch_ct_icon from source.patch_ct_icon import patch_ct_icon
from source.log_error import log_error
App = ClassApp() App = ClassApp()

View file

@ -6,13 +6,17 @@ import sys
import os import os
VERSION_FILE_URL = "https://raw.githubusercontent.com/Faraphel/MKWF-Install/master/version" VERSION_FILE_URL = "https://raw.githubusercontent.com/Faraphel/MKWF-Install/master/version"
def check_update(self): def check_update(self):
try: try:
gitversion = requests.get(VERSION_FILE_URL, allow_redirects=True).json() gitversion = requests.get(VERSION_FILE_URL, allow_redirects=True).json()
with open("version", "rb") as f: with open("./version", "rb") as f:
locversion = json.load(f) locversion = json.load(f)
if float(gitversion["version"]) > float(locversion["version"]): if ((float(gitversion["version"]) > float(locversion["version"])) or
(float(gitversion["version"]) == float(locversion["version"])) and
float(gitversion["subversion"]) > float(locversion["subversion"])):
if messagebox.askyesno(self.translate("Mise à jour disponible !"), self.translate("Une mise à jour est disponible, souhaitez-vous l'installer ?") + if messagebox.askyesno(self.translate("Mise à jour disponible !"), self.translate("Une mise à jour est disponible, souhaitez-vous l'installer ?") +
f"\n\nVersion : {locversion['version']}.{locversion['subversion']} -> {gitversion['version']}.{gitversion['subversion']}\n"+\ f"\n\nVersion : {locversion['version']}.{locversion['subversion']} -> {gitversion['version']}.{gitversion['subversion']}\n"+\
f"Changelog :\n{gitversion['changelog']}"): f"Changelog :\n{gitversion['changelog']}"):
@ -34,5 +38,5 @@ def check_update(self):
os.startfile(os.path.realpath("./Updater/Updater.exe")) os.startfile(os.path.realpath("./Updater/Updater.exe"))
sys.exit() sys.exit()
except Exception as e: except:
print(e) self.log_error()

View file

@ -2,73 +2,77 @@ import json
def create_lecode_config(self): def create_lecode_config(self):
def get_star_text(track): try:
if "warning" in track: warning = "!" * track["warning"] def get_star_text(track):
else: warning = "" if "warning" in track: warning = "!" * track["warning"]
else: warning = ""
if "score" in track: if "score" in track:
if track["score"] > 0: if track["score"] > 0:
return "" * track["score"] + "" * (3 - track["score"]) + warning + " " return "" * track["score"] + "" * (3 - track["score"]) + warning + " "
return "" return ""
def get_ctfile_text(track, race=False): def get_ctfile_text(track, race=False):
track_name = track["name"].replace("_", "") track_name = track["name"].replace("_", "")
if "prefix" in track: prefix = f"{track['prefix']} " if "prefix" in track: prefix = f"{track['prefix']} "
else: prefix = "" else: prefix = ""
if "suffix" in track: suffix = f" ({track['suffix']})" if "suffix" in track: suffix = f" ({track['suffix']})"
else: suffix = "" else: suffix = ""
if race: if race:
return f' T {track["music"]}; ' + \ return f' T {track["music"]}; ' + \
f'{track["special"]}; ' + \ f'{track["special"]}; ' + \
f'{"0x01" if track["new"] else "0x00"}; ' + \ f'{"0x01" if track["new"] else "0x00"}; ' + \
f'"-"; ' + \ f'"-"; ' + \
f'"{get_star_text(track)}{prefix}{track_name}{suffix}\\n{track["author"]}"; ' + \ f'"{get_star_text(track)}{prefix}{track_name}{suffix}\\n{track["author"]}"; ' + \
f'"-"\n' f'"-"\n'
else: else:
return f' T {track["music"]}; ' + \ return f' T {track["music"]}; ' + \
f'{track["special"]}; ' + \ f'{track["special"]}; ' + \
f'{"0x01" if track["new"] else "0x00"}; ' + \ f'{"0x01" if track["new"] else "0x00"}; ' + \
f'"{prefix}{track["name"]}{suffix}"; ' + \ f'"{prefix}{track["name"]}{suffix}"; ' + \
f'"{get_star_text(track)}{prefix}{track_name}{suffix}"; ' + \ f'"{get_star_text(track)}{prefix}{track_name}{suffix}"; ' + \
f'"-"\n' f'"-"\n'
with open("./ct_config.json", encoding="utf-8") as f: with open("./ct_config.json", encoding="utf-8") as f:
ctconfig = json.load(f) ctconfig = json.load(f)
with open("./file/CTFILE.txt", "w", encoding="utf-8") as ctfile, \ with open("./file/CTFILE.txt", "w", encoding="utf-8") as ctfile, \
open("./file/RCTFILE.txt", "w", encoding="utf-8") as rctfile: open("./file/RCTFILE.txt", "w", encoding="utf-8") as rctfile:
header = "#CT-CODE\n" +\ header = "#CT-CODE\n" +\
"[RACING-TRACK-LIST]\n" +\ "[RACING-TRACK-LIST]\n" +\
"%LE-FLAGS=1\n" +\ "%LE-FLAGS=1\n" +\
"%WIIMM-CUP=1\n" +\ "%WIIMM-CUP=1\n" +\
"N N$SWAP | N$F_WII\n\n" "N N$SWAP | N$F_WII\n\n"
ctfile.write(header) ctfile.write(header)
rctfile.write(header) rctfile.write(header)
for cup in ctconfig["cup"]: # defined cup section for cup in ctconfig["cup"]: # defined cup section
_cup_config = ctconfig["cup"][cup] _cup_config = ctconfig["cup"][cup]
if int(cup) >= 9: # Course qui ne sont ni les originales, ni les courses aléatoires. if int(cup) >= 9: # Course qui ne sont ni les originales, ni les courses aléatoires.
cup = f'\nC "{_cup_config["name"]}"\n' cup = f'\nC "{_cup_config["name"]}"\n'
ctfile.write(cup) ctfile.write(cup)
rctfile.write(cup) rctfile.write(cup)
for course in _cup_config["courses"]: for course in _cup_config["courses"]:
_course_config = _cup_config["courses"][course] _course_config = _cup_config["courses"][course]
ctfile.write(get_ctfile_text(_course_config, race=False)) ctfile.write(get_ctfile_text(_course_config, race=False))
rctfile.write(get_ctfile_text(_course_config, race=True)) rctfile.write(get_ctfile_text(_course_config, race=True))
for i, _course_config in enumerate(ctconfig["tracks_list"]): # undefined cup section for i, _course_config in enumerate(ctconfig["tracks_list"]): # undefined cup section
if i % 4 == 0: if i % 4 == 0:
cup = f'\nC "TL{i//4}"\n' cup = f'\nC "TL{i//4}"\n'
ctfile.write(cup) ctfile.write(cup)
rctfile.write(cup) rctfile.write(cup)
ctfile.write(get_ctfile_text(_course_config, race=False)) ctfile.write(get_ctfile_text(_course_config, race=False))
rctfile.write(get_ctfile_text(_course_config, race=True)) rctfile.write(get_ctfile_text(_course_config, race=True))
for _ in range(1, 4-(i%4)): # Complete cup if track are missing for _ in range(1, 4-(i%4)): # Complete cup if track are missing
ctfile.write(f' T T44; T44; 0x00; "_"; ""; "-"\n') ctfile.write(f' T T44; T44; 0x00; "_"; ""; "-"\n')
rctfile.write(f' T T44; T44; 0x00; "_"; ""; "-"\n') rctfile.write(f' T T44; T44; 0x00; "_"; ""; "-"\n')
except:
self.log_error()

View file

@ -11,104 +11,109 @@ from .definition import *
def install_mod(self): def install_mod(self):
def func(): def func():
with open("./fs.json") as f: try:
fs = json.load(f) with open("./fs.json") as f:
fs = json.load(f)
# This part is used to estimate the max_step # This part is used to estimate the max_step
extracted_file = [] extracted_file = []
max_step, step = 1, 0 max_step, step = 1, 0
def count_rf(path): def count_rf(path):
nonlocal max_step nonlocal max_step
max_step += 1 max_step += 1
extension = get_extension(path) extension = get_extension(path)
if extension == "szs": if extension == "szs":
if not (os.path.realpath(path) in extracted_file): if not (os.path.realpath(path) in extracted_file):
extracted_file.append(os.path.realpath(path)) extracted_file.append(os.path.realpath(path))
max_step += 1 max_step += 1
for fp in fs: for fp in fs:
for f in glob.glob(self.path_mkwf + "/files/" + fp, recursive=True): for f in glob.glob(self.path_mkwf + "/files/" + fp, recursive=True):
if type(fs[fp]) == str: if type(fs[fp]) == str:
count_rf(path=f) count_rf(path=f)
elif type(fs[fp]) == dict: elif type(fs[fp]) == dict:
for nf in fs[fp]: for nf in fs[fp]:
if type(fs[fp][nf]) == str: if type(fs[fp][nf]) == str:
count_rf(path=f) count_rf(path=f)
elif type(fs[fp][nf]) == list: elif type(fs[fp][nf]) == list:
for ffp in fs[fp][nf]: count_rf(path=f) for ffp in fs[fp][nf]: count_rf(path=f)
### ###
extracted_file = [] extracted_file = []
max_step += 4 # PATCH main.dol et PATCH lecode.bin, conversion, changement d'ID max_step += 4 # PATCH main.dol et PATCH lecode.bin, conversion, changement d'ID
self.Progress(show=True, indeter=False, statut=self.translate("Installation du mod"), max=max_step, step=0) self.Progress(show=True, indeter=False, statut=self.translate("Installation du mod"), max=max_step, step=0)
def replace_file(path, file, subpath="/"): def replace_file(path, file, subpath="/"):
self.Progress(statut=self.translate("Modification de")+f"\n{get_nodir(path)}", add=1) self.Progress(statut=self.translate("Modification de")+f"\n{get_nodir(path)}", add=1)
extension = get_extension(path) extension = get_extension(path)
if extension == "szs": if extension == "szs":
if not (os.path.realpath(path) in extracted_file): if not (os.path.realpath(path) in extracted_file):
subprocess.call(["./tools/szs/wszst", "EXTRACT", path, "-d", path + ".d", "--overwrite"] subprocess.call(["./tools/szs/wszst", "EXTRACT", path, "-d", path + ".d", "--overwrite"]
, creationflags=CREATE_NO_WINDOW) , creationflags=CREATE_NO_WINDOW)
extracted_file.append(os.path.realpath(path)) extracted_file.append(os.path.realpath(path))
szs_extract_path = path + ".d" szs_extract_path = path + ".d"
if os.path.exists(szs_extract_path + subpath): if os.path.exists(szs_extract_path + subpath):
if subpath[-1] == "/": if subpath[-1] == "/":
filecopy(f"./file/{file}", szs_extract_path + subpath + file) filecopy(f"./file/{file}", szs_extract_path + subpath + file)
else: else:
filecopy(f"./file/{file}", szs_extract_path + subpath) filecopy(f"./file/{file}", szs_extract_path + subpath)
elif path[-1] == "/": elif path[-1] == "/":
filecopy(f"./file/{file}", path + file) filecopy(f"./file/{file}", path + file)
else: else:
filecopy(f"./file/{file}", path) filecopy(f"./file/{file}", path)
for fp in fs: for fp in fs:
for f in glob.glob(self.path_mkwf + "/files/" + fp, recursive=True): for f in glob.glob(self.path_mkwf + "/files/" + fp, recursive=True):
if type(fs[fp]) == str: if type(fs[fp]) == str:
replace_file(path=f, file=fs[fp]) replace_file(path=f, file=fs[fp])
elif type(fs[fp]) == dict: elif type(fs[fp]) == dict:
for nf in fs[fp]: for nf in fs[fp]:
if type(fs[fp][nf]) == str: if type(fs[fp][nf]) == str:
replace_file(path=f, subpath=nf, file=fs[fp][nf]) replace_file(path=f, subpath=nf, file=fs[fp][nf])
elif type(fs[fp][nf]) == list: elif type(fs[fp][nf]) == list:
for ffp in fs[fp][nf]: replace_file(path=f, subpath=nf, file=ffp) for ffp in fs[fp][nf]: replace_file(path=f, subpath=nf, file=ffp)
for file in extracted_file: for file in extracted_file:
self.Progress(statut=self.translate("Recompilation de")+f"\n{get_nodir(file)}", add=1) self.Progress(statut=self.translate("Recompilation de")+f"\n{get_nodir(file)}", add=1)
subprocess.call(["./tools/szs/wszst", "CREATE", file + ".d", "-d", file, subprocess.call(["./tools/szs/wszst", "CREATE", file + ".d", "-d", file,
"--overwrite"], creationflags=CREATE_NO_WINDOW) "--overwrite"], creationflags=CREATE_NO_WINDOW)
if os.path.exists(file + ".d"): shutil.rmtree(file + ".d") if os.path.exists(file + ".d"): shutil.rmtree(file + ".d")
self.Progress(statut=self.translate("Patch main.dol"), add=1) self.Progress(statut=self.translate("Patch main.dol"), add=1)
subprocess.call(["./tools/szs/wstrt", "patch", self.path_mkwf + "/sys/main.dol", "--clean-dol", subprocess.call(["./tools/szs/wstrt", "patch", self.path_mkwf + "/sys/main.dol", "--clean-dol",
"--add-lecode"], creationflags=CREATE_NO_WINDOW) "--add-lecode"], creationflags=CREATE_NO_WINDOW)
self.Progress(statut=self.translate("Patch lecode-PAL.bin"), add=1) self.Progress(statut=self.translate("Patch lecode-PAL.bin"), add=1)
subprocess.call( subprocess.call(
["./tools/szs/wlect", "patch", "./file/lecode-PAL.bin", "-od", self.path_mkwf + "/files/rel/lecode-PAL.bin", ["./tools/szs/wlect", "patch", "./file/lecode-PAL.bin", "-od", self.path_mkwf +
"--track-dir", self.path_mkwf + "/files/Race/Course/", "--copy-tracks", "./file/Track/", "/files/rel/lecode-PAL.bin", "--track-dir", self.path_mkwf + "/files/Race/Course/", "--copy-tracks",
"--move-tracks", self.path_mkwf + "/files/Race/Course/", "--le-define", "./file/Track/", "--move-tracks", self.path_mkwf + "/files/Race/Course/", "--le-define",
"./file/CTFILE.txt", "--lpar", "./file/lpar-default.txt", "--overwrite"], creationflags=CREATE_NO_WINDOW) "./file/CTFILE.txt", "--lpar", "./file/lpar-default.txt", "--overwrite"]
, creationflags=CREATE_NO_WINDOW)
outputformat = self.listbox_outputformat.get() outputformat = self.listbox_outputformat.get()
self.Progress(statut=self.translate("Conversion en")+f" {outputformat}", add=1) self.Progress(statut=self.translate("Conversion en")+f" {outputformat}", add=1)
if outputformat in ["ISO", "WBFS", "CISO"]: if outputformat in ["ISO", "WBFS", "CISO"]:
self.path_mkwf_format = os.path.realpath(self.path_mkwf + "/../MKWFaraphel." + outputformat.lower()) self.path_mkwf_format = os.path.realpath(self.path_mkwf + "/../MKWFaraphel." + outputformat.lower())
subprocess.call(["./tools/wit/wit", "COPY", self.path_mkwf, "--DEST", subprocess.call(["./tools/wit/wit", "COPY", self.path_mkwf, "--DEST",
self.path_mkwf_format, f"--{outputformat.lower()}", "--overwrite"] self.path_mkwf_format, f"--{outputformat.lower()}", "--overwrite"]
, creationflags=CREATE_NO_WINDOW) , creationflags=CREATE_NO_WINDOW)
shutil.rmtree(self.path_mkwf) shutil.rmtree(self.path_mkwf)
self.Progress(statut=self.translate("Changement de l'ID du jeu"), add=1) self.Progress(statut=self.translate("Changement de l'ID du jeu"), add=1)
subprocess.call(["./tools/wit/wit", "EDIT", self.path_mkwf_format, "--id", "RMCP60"] subprocess.call(["./tools/wit/wit", "EDIT", self.path_mkwf_format, "--id", "RMCP60"]
, creationflags=CREATE_NO_WINDOW) , creationflags=CREATE_NO_WINDOW)
self.Progress(show=False) self.Progress(show=False)
messagebox.showinfo(self.translate("Fin"), self.translate("L'installation est terminé !")) messagebox.showinfo(self.translate("Fin"), self.translate("L'installation est terminé !"))
except:
self.log_error()
t = Thread(target=func) t = Thread(target=func)
t.setDaemon(True) t.setDaemon(True)

4
source/log_error.py Normal file
View file

@ -0,0 +1,4 @@
import traceback
def log_error(self, exception):
with open("error.log", "a") as f: f.write(f"---\n{traceback.format_exc()}\n")

View file

@ -85,62 +85,66 @@ trackname_color = {
} }
def patch_bmg(self, gamefile): # gamefile est le fichier .szs trouvé dans le /files/Scene/UI/ du jeu def patch_bmg(self, gamefile): # gamefile est le fichier .szs trouvé dans le /files/Scene/UI/ du jeu
bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier try:
self.Progress(statut=self.translate("Patch des textes " + bmglang), add=1) bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier
self.Progress(statut=self.translate("Patch des textes " + bmglang), add=1)
subprocess.call(["./tools/szs/wszst", "EXTRACT", gamefile, "-d", gamefile + ".d", "--overwrite"] subprocess.call(["./tools/szs/wszst", "EXTRACT", gamefile, "-d", gamefile + ".d", "--overwrite"]
, creationflags=CREATE_NO_WINDOW) , creationflags=CREATE_NO_WINDOW)
# Common.bmg # Common.bmg
bmgtracks = subprocess.check_output(["./tools/szs/wbmgt", "CAT", gamefile + ".d/message/Common.bmg"], bmgtracks = subprocess.check_output(["./tools/szs/wbmgt", "CAT", gamefile + ".d/message/Common.bmg"],
creationflags=CREATE_NO_WINDOW) creationflags=CREATE_NO_WINDOW)
bmgtracks = bmgtracks.decode() bmgtracks = bmgtracks.decode()
trackheader = "#--- standard track names" trackheader = "#--- standard track names"
trackend = "2328" trackend = "2328"
bmgtracks = bmgtracks[bmgtracks.find(trackheader) + len(trackheader):bmgtracks.find(trackend)] bmgtracks = bmgtracks[bmgtracks.find(trackheader) + len(trackheader):bmgtracks.find(trackend)]
with open("./file/ExtraCommon.txt", "w") as f: with open("./file/ExtraCommon.txt", "w") as f:
f.write("#BMG\n\n" f.write("#BMG\n\n"
f" 703e\t= {self.translate('Aléatoire: Toutes les pistes', lang=bmglang)}\n" f" 703e\t= {self.translate('Aléatoire: Toutes les pistes', lang=bmglang)}\n"
f" 703f\t= {self.translate('Aléatoire: Pistes Originales', lang=bmglang)}\n" f" 703f\t= {self.translate('Aléatoire: Pistes Originales', lang=bmglang)}\n"
f" 7040\t= {self.translate('Aléatoire: Custom Tracks', lang=bmglang)}\n" f" 7040\t= {self.translate('Aléatoire: Custom Tracks', lang=bmglang)}\n"
f" 7041\t= {self.translate('Aléatoire: Pistes Nouvelles', lang=bmglang)}\n") f" 7041\t= {self.translate('Aléatoire: Pistes Nouvelles', lang=bmglang)}\n")
for bmgtrack in bmgtracks.split("\n"): for bmgtrack in bmgtracks.split("\n"):
if "=" in bmgtrack: if "=" in bmgtrack:
prefix = "" prefix = ""
if "T" in bmgtrack[:bmgtrack.find("=")]: if "T" in bmgtrack[:bmgtrack.find("=")]:
sTid = bmgtrack.find("T") sTid = bmgtrack.find("T")
Tid = bmgtrack[sTid:sTid + 3] Tid = bmgtrack[sTid:sTid + 3]
if Tid[1] in "1234": prefix = "Wii " # Si la course est original à la wii if Tid[1] in "1234": prefix = "Wii " # Si la course est original à la wii
Tid = hex(bmgID_track_move[Tid])[2:] Tid = hex(bmgID_track_move[Tid])[2:]
else: # Arena else: # Arena
sTid = bmgtrack.find("U") + 1 sTid = bmgtrack.find("U") + 1
Tid = bmgtrack[sTid:sTid + 2] Tid = bmgtrack[sTid:sTid + 2]
Tid = hex((int(Tid[0]) - 1) * 5 + (int(Tid[1]) - 1) + 0x7020)[2:] Tid = hex((int(Tid[0]) - 1) * 5 + (int(Tid[1]) - 1) + 0x7020)[2:]
Tname = bmgtrack[bmgtrack.find("= ") + 2:] Tname = bmgtrack[bmgtrack.find("= ") + 2:]
f.write(f" {Tid}\t= {prefix}{Tname}\n") f.write(f" {Tid}\t= {prefix}{Tname}\n")
bmgtext = subprocess.check_output(["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/CTFILE.txt", bmgtext = subprocess.check_output(["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/CTFILE.txt",
"--patch-bmg", "OVERWRITE=" + gamefile + ".d/message/Common.bmg", "--patch-bmg", "OVERWRITE=" + gamefile + ".d/message/Common.bmg",
"--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"], "--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"],
creationflags=CREATE_NO_WINDOW).decode() creationflags=CREATE_NO_WINDOW).decode()
rbmgtext = subprocess.check_output(["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/RCTFILE.txt", rbmgtext = subprocess.check_output(["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/RCTFILE.txt",
"--patch-bmg", "OVERWRITE=" + gamefile + ".d/message/Common.bmg", "--patch-bmg", "OVERWRITE=" + gamefile + ".d/message/Common.bmg",
"--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"], "--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"],
creationflags=CREATE_NO_WINDOW).decode() creationflags=CREATE_NO_WINDOW).decode()
shutil.rmtree(gamefile + ".d") shutil.rmtree(gamefile + ".d")
os.remove("./file/ExtraCommon.txt") os.remove("./file/ExtraCommon.txt")
def finalise(common_file, bmgtext): def finalise(common_file, bmgtext):
for console in trackname_color: bmgtext = bmgtext.replace(console, trackname_color[console]) for console in trackname_color: bmgtext = bmgtext.replace(console, trackname_color[console])
with open(common_file, "w", encoding="utf-8") as f: f.write(bmgtext) with open(common_file, "w", encoding="utf-8") as f: f.write(bmgtext)
subprocess.call(["./tools/szs/wbmgt", "ENCODE", common_file, "--overwrite"], creationflags=CREATE_NO_WINDOW) subprocess.call(["./tools/szs/wbmgt", "ENCODE", common_file, "--overwrite"], creationflags=CREATE_NO_WINDOW)
os.remove(common_file) os.remove(common_file)
finalise(f"./file/Common_{bmglang}.txt", bmgtext) finalise(f"./file/Common_{bmglang}.txt", bmgtext)
finalise(f"./file/Common_R{bmglang}.txt", rbmgtext) finalise(f"./file/Common_R{bmglang}.txt", rbmgtext)
except:
self.log_error()

View file

@ -5,37 +5,41 @@ import os
def patch_ct_icon(self): def patch_ct_icon(self):
with open("./ct_config.json", encoding="utf8") as f: config = json.load(f) try:
with open("./ct_config.json", encoding="utf8") as f: config = json.load(f)
cup_number = len(config["cup"]) + math.ceil(len(config["tracks_list"]) / 4) cup_number = len(config["cup"]) + math.ceil(len(config["tracks_list"]) / 4)
ct_icon = Image.new("RGBA", (128, 128 * (cup_number + 2))) ct_icon = Image.new("RGBA", (128, 128 * (cup_number + 2)))
files = ["left", "right"] files = ["left", "right"]
files.extend(config["cup"].keys()) files.extend(config["cup"].keys())
files.extend(["_"] * ((len(config["tracks_list"]) // 4) + 1)) files.extend(["_"] * ((len(config["tracks_list"]) // 4) + 1))
for i, id in enumerate(files): for i, id in enumerate(files):
if os.path.exists(f"./file/cup_icon/{id}.png"): if os.path.exists(f"./file/cup_icon/{id}.png"):
cup_icon = Image.open(f"./file/cup_icon/{id}.png").resize((128, 128)) cup_icon = Image.open(f"./file/cup_icon/{id}.png").resize((128, 128))
else: else:
cup_icon = Image.new("RGBA", (128, 128)) cup_icon = Image.new("RGBA", (128, 128))
draw = ImageDraw.Draw(cup_icon) draw = ImageDraw.Draw(cup_icon)
font = ImageFont.truetype("./file/SuperMario256.ttf", 90) font = ImageFont.truetype("./file/SuperMario256.ttf", 90)
draw.text((4 - 2, 4 - 2), "CT", (0, 0, 0), font=font) draw.text((4 - 2, 4 - 2), "CT", (0, 0, 0), font=font)
draw.text((4 + 2, 4 - 2), "CT", (0, 0, 0), font=font) draw.text((4 + 2, 4 - 2), "CT", (0, 0, 0), font=font)
draw.text((4 - 2, 4 + 2), "CT", (0, 0, 0), font=font) draw.text((4 - 2, 4 + 2), "CT", (0, 0, 0), font=font)
draw.text((4 + 2, 4 + 2), "CT", (0, 0, 0), font=font) draw.text((4 + 2, 4 + 2), "CT", (0, 0, 0), font=font)
draw.text((4, 4), "CT", (255, 165, 0), font=font) draw.text((4, 4), "CT", (255, 165, 0), font=font)
font = ImageFont.truetype("./file/SuperMario256.ttf", 60) font = ImageFont.truetype("./file/SuperMario256.ttf", 60)
draw.text((5 - 2, 80 - 2), "%03i" % (i-10), (0, 0, 0), font=font) # i-10 car on ne compte pas les 8 coupes draw.text((5 - 2, 80 - 2), "%03i" % (i-10), (0, 0, 0), font=font) # i-10 car on ne compte pas les 8 coupes
draw.text((5 + 2, 80 - 2), "%03i" % (i-10), (0, 0, 0), font=font) # de base (0-7), la coupe aléatoire, et draw.text((5 + 2, 80 - 2), "%03i" % (i-10), (0, 0, 0), font=font) # de base (0-7), la coupe aléatoire, et
draw.text((5 - 2, 80 + 2), "%03i" % (i-10), (0, 0, 0), font=font) # les icones droite et gauche. draw.text((5 - 2, 80 + 2), "%03i" % (i-10), (0, 0, 0), font=font) # les icones droite et gauche.
draw.text((5 + 2, 80 + 2), "%03i" % (i-10), (0, 0, 0), font=font) draw.text((5 + 2, 80 + 2), "%03i" % (i-10), (0, 0, 0), font=font)
draw.text((5, 80), "%03i" % (i-10), (255, 165, 0), font=font) draw.text((5, 80), "%03i" % (i-10), (255, 165, 0), font=font)
ct_icon.paste(cup_icon, (0, i * 128)) ct_icon.paste(cup_icon, (0, i * 128))
ct_icon.save("./file/ct_icons.tpl.png") ct_icon.save("./file/ct_icons.tpl.png")
except:
self.log_error()

View file

@ -9,65 +9,69 @@ from .definition import *
def patch_file(self): def patch_file(self):
def func(): def func():
if os.path.exists("./file/Track-WU8/"): try:
total_track = len(os.listdir("./file/Track-WU8/")) if os.path.exists("./file/Track-WU8/"):
else: total_track = len(os.listdir("./file/Track-WU8/"))
total_track = 0 else:
with open("./convert_file.json") as f: total_track = 0
fc = json.load(f) with open("./convert_file.json") as f:
max_step = len(fc["img"]) + total_track + 3 + len("EGFIS") fc = json.load(f)
self.Progress(show=True, indeter=False, statut=self.translate("Conversion des fichiers"), max=max_step, step=0) max_step = len(fc["img"]) + total_track + 3 + len("EGFIS")
self.Progress(show=True, indeter=False, statut=self.translate("Conversion des fichiers"), max=max_step, step=0)
self.Progress(statut=self.translate("Configuration de LE-CODE"), add=1) self.Progress(statut=self.translate("Configuration de LE-CODE"), add=1)
self.create_lecode_config() self.create_lecode_config()
self.Progress(statut=self.translate("Création de ct_icon.png"), add=1) self.Progress(statut=self.translate("Création de ct_icon.png"), add=1)
self.patch_ct_icon() self.patch_ct_icon()
self.Progress(statut=self.translate("Création des images descriptives"), add=1) self.Progress(statut=self.translate("Création des images descriptives"), add=1)
self.patch_img_desc() self.patch_img_desc()
for i, file in enumerate(fc["img"]): for i, file in enumerate(fc["img"]):
self.Progress(statut=self.translate("Conversion des images")+f"\n({i + 1}/{len(fc['img'])}) {file}", add=1) self.Progress(statut=self.translate("Conversion des images")+f"\n({i + 1}/{len(fc['img'])}) {file}", add=1)
subprocess.call(["./tools/szs/wimgt", "ENCODE", "./file/" + file, "-x", fc["img"][file], "--overwrite"] subprocess.call(["./tools/szs/wimgt", "ENCODE", "./file/" + file, "-x", fc["img"][file], "--overwrite"]
, creationflags=CREATE_NO_WINDOW) , creationflags=CREATE_NO_WINDOW)
for file in glob.glob(self.path_mkwf+"/files/Scene/UI/MenuSingle_?.szs"): for file in glob.glob(self.path_mkwf+"/files/Scene/UI/MenuSingle_?.szs"):
self.patch_bmg(file) self.patch_bmg(file)
if not (os.path.exists("./file/auto-add/")): if not (os.path.exists("./file/auto-add/")):
subprocess.call(["./tools/szs/wszst", "AUTOADD", self.path_mkwf + "/files/Race/Course/", "--DEST", subprocess.call(["./tools/szs/wszst", "AUTOADD", self.path_mkwf + "/files/Race/Course/", "--DEST",
"./file/auto-add/"], creationflags=CREATE_NO_WINDOW) "./file/auto-add/"], creationflags=CREATE_NO_WINDOW)
max_process = 8 max_process = 8
process_list = {} process_list = {}
for i, file in enumerate(os.listdir("./file/Track-WU8/")): for i, file in enumerate(os.listdir("./file/Track-WU8/")):
while True: while True:
if len(process_list) < max_process: if len(process_list) < max_process:
process_list[file] = None process_list[file] = None
self.Progress(statut=self.translate("Conversion des courses")+f"\n({i + 1}/{total_track})\n" + self.Progress(statut=self.translate("Conversion des courses")+f"\n({i + 1}/{total_track})\n" +
"\n".join(process_list.keys()), add=1) "\n".join(process_list.keys()), add=1)
if not (os.path.exists("./file/Track/" + get_filename(file) + ".szs")): if not (os.path.exists("./file/Track/" + get_filename(file) + ".szs")):
process_list[file] = subprocess.Popen([ process_list[file] = subprocess.Popen([
"./tools/szs/wszst", "NORMALIZE", "./file/Track-WU8/" + file, "--DEST", "./tools/szs/wszst", "NORMALIZE", "./file/Track-WU8/" + file, "--DEST",
"./file/Track/%N.szs", "--szs", "--overwrite", "--autoadd-path", "./file/Track/%N.szs", "--szs", "--overwrite", "--autoadd-path",
"./file/auto-add/"], creationflags=CREATE_NO_WINDOW) "./file/auto-add/"], creationflags=CREATE_NO_WINDOW)
break break
else: else:
for process in process_list: for process in process_list:
if process_list[process] is not None: if process_list[process] is not None:
if not (process_list[process].poll() is None): if not (process_list[process].poll() is None):
process_list.pop(process)
break
else:
process_list.pop(process) process_list.pop(process)
break break
else:
process_list.pop(process)
break
self.Progress(show=False) self.Progress(show=False)
self.button_install_mod.grid(row=2, column=1, sticky="NEWS") self.button_install_mod.grid(row=2, column=1, sticky="NEWS")
self.listbox_outputformat.grid(row=2, column=2, sticky="NEWS") self.listbox_outputformat.grid(row=2, column=2, sticky="NEWS")
except:
self.log_error()
t = Thread(target=func) t = Thread(target=func)
t.setDaemon(True) t.setDaemon(True)

View file

@ -5,21 +5,25 @@ from .definition import *
def patch_img_desc(self): def patch_img_desc(self):
il = Image.open("./file/img_desc/illustration.png") try:
il_16_9 = il.resize((832, 456)) il = Image.open("./file/img_desc/illustration.png")
il_4_3 = il.resize((608, 456)) il_16_9 = il.resize((832, 456))
il_4_3 = il.resize((608, 456))
for file_lang in glob.glob("./file/img_desc/??.png"): for file_lang in glob.glob("./file/img_desc/??.png"):
img_lang = Image.open(file_lang) img_lang = Image.open(file_lang)
img_lang_16_9 = img_lang.resize((832, 456)) img_lang_16_9 = img_lang.resize((832, 456))
img_lang_4_3 = img_lang.resize((608, 456)) img_lang_4_3 = img_lang.resize((608, 456))
new_16_9 = Image.new("RGBA", (832, 456), (0, 0, 0, 255)) new_16_9 = Image.new("RGBA", (832, 456), (0, 0, 0, 255))
new_16_9.paste(il_16_9, (0, 0), il_16_9) new_16_9.paste(il_16_9, (0, 0), il_16_9)
new_16_9.paste(img_lang_16_9, (0, 0), img_lang_16_9) new_16_9.paste(img_lang_16_9, (0, 0), img_lang_16_9)
new_16_9.save(f"./file/strapA_16_9_832x456{get_filename(get_nodir(file_lang))}.png") new_16_9.save(f"./file/strapA_16_9_832x456{get_filename(get_nodir(file_lang))}.png")
new_4_3 = Image.new("RGBA", (608, 456), (0, 0, 0, 255)) new_4_3 = Image.new("RGBA", (608, 456), (0, 0, 0, 255))
new_4_3.paste(il_4_3, (0, 0), il_4_3) new_4_3.paste(il_4_3, (0, 0), il_4_3)
new_4_3.paste(img_lang_4_3, (0, 0), img_lang_4_3) new_4_3.paste(img_lang_4_3, (0, 0), img_lang_4_3)
new_4_3.save(f"./file/strapA_608x456{get_filename(get_nodir(file_lang))}.png") new_4_3.save(f"./file/strapA_608x456{get_filename(get_nodir(file_lang))}.png")
except:
self.log_error()