if track is not found in file/Track-WU8/, the installer will try to download it from the github

This commit is contained in:
raphael60650 2021-06-16 23:42:16 +02:00
parent 169ead9a8d
commit 725bb1bf4d

View file

@ -18,7 +18,16 @@ def patch_file(self):
total_track = 0 total_track = 0
with open("./convert_file.json") as f: with open("./convert_file.json") as f:
fc = json.load(f) fc = json.load(f)
max_step = len(fc["img"]) + total_track + 3 + len("EGFIS")
tracks = []
with open("./ct_config.json", encoding="utf-8") as f:
ctconfig = json.load(f)
for cup in ctconfig["cup"].values():
if not (cup["locked"]): tracks.extend(cup["courses"].values())
tracks.extend(ctconfig["tracks_list"])
total_track = len(tracks)
max_step = len(fc["img"]) + (total_track * 2) + 3 + len("EGFIS")
self.Progress(show=True, indeter=False, statut=self.translate("Conversion des fichiers"), max=max_step, step=0) 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)
@ -51,21 +60,42 @@ def patch_file(self):
process_list = {} process_list = {}
error_count, error_max = 0, 3 error_count, error_max = 0, 3
for i, file in enumerate(os.listdir("./file/Track-WU8/")): for i, track in enumerate(tracks):
track_file = track["name"]
if "prefix" in track: track_file = track["prefix"] + " " + track_file
if "suffix" in track: track_file = track_file + " (" + track["suffix"] + ")"
track_wu8_file = f"./file/Track-WU8/{track_file}.wu8"
track_szs_file = f"./file/Track/{track_file}.szs"
while True: while True:
if len(process_list) < max_process: if len(process_list) < max_process:
process_list[file] = None process_list[track_szs_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([get_nodir(file) for file in process_list.keys()]), add=1)
if not(os.path.exists(track_wu8_file)):
dl_code = self.get_github_file(track_wu8_file)
if dl_code == -1:
error_count += 1
if error_count > error_max: # Too much track wasn't correctly converted
messagebox.showerror(
self.translate("Erreur"),
self.translate("Trop de course ont eu une erreur du téléchargement."))
return
else:
messagebox.showwarning(self.translate("Attention"),
self.translate(
"Impossible de télécharger cette course ! (") +
str(error_count) + "/" + str(error_max) + ")")
track_szs_file = f"./file/Track/{get_filename(file)}.szs"
if os.path.exists(track_szs_file): if os.path.exists(track_szs_file):
if os.path.getsize(track_szs_file) < 1000: # File under this size are corrupted if os.path.getsize(track_szs_file) < 1000: # File under this size are corrupted
os.remove(track_szs_file) os.remove(track_szs_file)
if not(os.path.exists(track_szs_file)): if not(os.path.exists(track_szs_file)):
process_list[file] = subprocess.Popen([ print(f"convert {track_szs_file}")
"./tools/szs/wszst", "NORMALIZE", "./file/Track-WU8/" + file, "--DEST", process_list[track_szs_file] = subprocess.Popen([
"./tools/szs/wszst", "NORMALIZE", track_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, stderr=subprocess.PIPE) "./file/auto-add/"], creationflags=CREATE_NO_WINDOW, stderr=subprocess.PIPE)
break break
@ -78,7 +108,7 @@ def patch_file(self):
stderr = process_list[process].stderr.read() stderr = process_list[process].stderr.read()
if b"wszst: ERROR" in stderr: # Error occured if b"wszst: ERROR" in stderr: # Error occured
process_list.pop(process) process_list.pop(process)
os.remove(f"./file/Track/{get_filename(process)}.szs") os.remove(process)
error_count += 1 error_count += 1
if error_count > error_max: # Too much track wasn't correctly converted if error_count > error_max: # Too much track wasn't correctly converted
messagebox.showerror( messagebox.showerror(