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 threading import Thread
import subprocess
import traceback
import requests
import zipfile
import shutil
@ -26,6 +27,7 @@ class ClassApp():
from source.restart import restart
from source.patch_img_desc import patch_img_desc
from source.patch_ct_icon import patch_ct_icon
from source.log_error import log_error
App = ClassApp()

View file

@ -6,13 +6,17 @@ import sys
import os
VERSION_FILE_URL = "https://raw.githubusercontent.com/Faraphel/MKWF-Install/master/version"
def check_update(self):
try:
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)
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 ?") +
f"\n\nVersion : {locversion['version']}.{locversion['subversion']} -> {gitversion['version']}.{gitversion['subversion']}\n"+\
f"Changelog :\n{gitversion['changelog']}"):
@ -34,5 +38,5 @@ def check_update(self):
os.startfile(os.path.realpath("./Updater/Updater.exe"))
sys.exit()
except Exception as e:
print(e)
except:
self.log_error()

View file

@ -2,6 +2,7 @@ import json
def create_lecode_config(self):
try:
def get_star_text(track):
if "warning" in track: warning = "!" * track["warning"]
else: warning = ""
@ -72,3 +73,6 @@ def create_lecode_config(self):
for _ in range(1, 4-(i%4)): # Complete cup if track are missing
ctfile.write(f' T T44; T44; 0x00; "_"; ""; "-"\n')
rctfile.write(f' T T44; T44; 0x00; "_"; ""; "-"\n')
except:
self.log_error()

View file

@ -11,6 +11,7 @@ from .definition import *
def install_mod(self):
def func():
try:
with open("./fs.json") as f:
fs = json.load(f)
@ -88,10 +89,11 @@ def install_mod(self):
self.Progress(statut=self.translate("Patch lecode-PAL.bin"), add=1)
subprocess.call(
["./tools/szs/wlect", "patch", "./file/lecode-PAL.bin", "-od", self.path_mkwf + "/files/rel/lecode-PAL.bin",
"--track-dir", self.path_mkwf + "/files/Race/Course/", "--copy-tracks", "./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)
["./tools/szs/wlect", "patch", "./file/lecode-PAL.bin", "-od", self.path_mkwf +
"/files/rel/lecode-PAL.bin", "--track-dir", self.path_mkwf + "/files/Race/Course/", "--copy-tracks",
"./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)
outputformat = self.listbox_outputformat.get()
self.Progress(statut=self.translate("Conversion en")+f" {outputformat}", add=1)
@ -110,6 +112,9 @@ def install_mod(self):
self.Progress(show=False)
messagebox.showinfo(self.translate("Fin"), self.translate("L'installation est terminé !"))
except:
self.log_error()
t = Thread(target=func)
t.setDaemon(True)
t.start()

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,6 +85,7 @@ trackname_color = {
}
def patch_bmg(self, gamefile): # gamefile est le fichier .szs trouvé dans le /files/Scene/UI/ du jeu
try:
bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier
self.Progress(statut=self.translate("Patch des textes " + bmglang), add=1)
@ -144,3 +145,6 @@ def patch_bmg(self, gamefile): # gamefile est le fichier .szs trouvé dans le /
finalise(f"./file/Common_{bmglang}.txt", bmgtext)
finalise(f"./file/Common_R{bmglang}.txt", rbmgtext)
except:
self.log_error()

View file

@ -5,6 +5,7 @@ import os
def patch_ct_icon(self):
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)
@ -39,3 +40,6 @@ def patch_ct_icon(self):
ct_icon.paste(cup_icon, (0, i * 128))
ct_icon.save("./file/ct_icons.tpl.png")
except:
self.log_error()

View file

@ -9,6 +9,7 @@ from .definition import *
def patch_file(self):
def func():
try:
if os.path.exists("./file/Track-WU8/"):
total_track = len(os.listdir("./file/Track-WU8/"))
else:
@ -69,6 +70,9 @@ def patch_file(self):
self.button_install_mod.grid(row=2, column=1, sticky="NEWS")
self.listbox_outputformat.grid(row=2, column=2, sticky="NEWS")
except:
self.log_error()
t = Thread(target=func)
t.setDaemon(True)
t.start()

View file

@ -5,6 +5,7 @@ from .definition import *
def patch_img_desc(self):
try:
il = Image.open("./file/img_desc/illustration.png")
il_16_9 = il.resize((832, 456))
il_4_3 = il.resize((608, 456))
@ -23,3 +24,6 @@ def patch_img_desc(self):
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.save(f"./file/strapA_608x456{get_filename(get_nodir(file_lang))}.png")
except:
self.log_error()