started implementation of a better function to download and patch tracks

This commit is contained in:
raphael60650 2021-07-31 09:21:29 +02:00
parent 95dae163d9
commit 3c291bb66f
3 changed files with 32 additions and 2 deletions

View file

@ -1,5 +1,7 @@
from tkinter import messagebox from tkinter import messagebox
from PIL import Image from PIL import Image
import requests
import zipfile
import shutil import shutil
import glob import glob
import json 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.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") 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: def patch_tracks(self) -> int:
""" """
Download track's wu8 file and convert them to szs Download track's wu8 file and convert them to szs

View file

@ -3,8 +3,6 @@ import requests
from .definition import * from .definition import *
from .wszst import * from .wszst import *
CHUNK_SIZE = 524288
class CantDownloadTrack(Exception): class CantDownloadTrack(Exception):
def __init__(self, track, http_error: [str, int]): def __init__(self, track, http_error: [str, int]):

View file

@ -6,8 +6,12 @@ import os
GITHUB_REPOSITORY = "Faraphel/MKWF-Install" GITHUB_REPOSITORY = "Faraphel/MKWF-Install"
GITHUB_MASTER_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/master/" GITHUB_MASTER_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/master/"
GITHUB_DEV_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/dev/" 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" 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_filename = lambda file: ".".join(file.split(".")[:-1])
get_nodir = lambda file: file.replace("\\", "/").split("/")[-1] get_nodir = lambda file: file.replace("\\", "/").split("/")[-1]
get_dir = lambda file: "/".join(file.replace("\\", "/").split("/")[:-1]) get_dir = lambda file: "/".join(file.replace("\\", "/").split("/")[:-1])