diff --git a/source/Game.py b/source/Game.py index f8cb707..8f0cba9 100644 --- a/source/Game.py +++ b/source/Game.py @@ -1,5 +1,7 @@ from tkinter import messagebox from PIL import Image +import requests +import zipfile import shutil import glob import json @@ -419,6 +421,32 @@ class Game: new_4_3.paste(img_lang_4_3, (0, 0), img_lang_4_3) new_4_3.save(dest_dir + f"/strapA_608x456{get_filename(get_nodir(file_lang))}.png") + def patch_all_tracks(self): + all_tracks_zip_url = (ZIPBALL_DEV_BRANCH if self.gui.is_dev_version + else ZIPBALL_MASTER_BRANCH) + "file/Track-WU8" + + dl = requests.get(all_tracks_zip_url, allow_redirects=True, stream=True) + dl_size = int(dl.headers["Content-Length"]) + + if dl.status_code == 200: # if page is found + with open("./file/Track-WU8.zip", "wb") as TrackWU8_zip: + for i, chunk in enumerate(dl.iter_content(chunk_size=CHUNK_SIZE)): + TrackWU8_zip.write(chunk) + TrackWU8_zip.flush() + + self.gui.progress( + statut=self.gui.translate( + "Downloading all tracks", + f"{i * CHUNK_SIZE}/{dl_size} ({int(i * CHUNK_SIZE/dl_size * 100)}%)"), + indeter=True) + + with zipfile.ZipFile("./file/Track-WU8.zip") as TrackWU8_zip: + TrackWU8_zip.extractall("./file/Track-WU8/") + + for track in self.ctconfig.all_tracks: + if os.path.exists(track.file_wu8) and not track.check_szs_sha1(): track.convert_wu8_to_szs() + else: pass # error + def patch_tracks(self) -> int: """ Download track's wu8 file and convert them to szs diff --git a/source/Track.py b/source/Track.py index eaea26b..2b8628e 100644 --- a/source/Track.py +++ b/source/Track.py @@ -3,8 +3,6 @@ import requests from .definition import * from .wszst import * -CHUNK_SIZE = 524288 - class CantDownloadTrack(Exception): def __init__(self, track, http_error: [str, int]): diff --git a/source/definition.py b/source/definition.py index 3c25bf3..06e02ba 100644 --- a/source/definition.py +++ b/source/definition.py @@ -6,8 +6,12 @@ import os GITHUB_REPOSITORY = "Faraphel/MKWF-Install" GITHUB_MASTER_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/master/" GITHUB_DEV_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/dev/" +ZIPBALL_MASTER_BRANCH = f"https://github.com/{GITHUB_REPOSITORY}/zipball/master/" +ZIPBALL_DEV_BRANCH = f"https://github.com/{GITHUB_REPOSITORY}/zipball/dev/" VERSION_FILE_URL = GITHUB_MASTER_BRANCH + "version" +CHUNK_SIZE: int = 524288 # chunk size used to download file + get_filename = lambda file: ".".join(file.split(".")[:-1]) get_nodir = lambda file: file.replace("\\", "/").split("/")[-1] get_dir = lambda file: "/".join(file.replace("\\", "/").split("/")[:-1])