mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-04 03:38:26 +02:00
simplified download code in Game.py
This commit is contained in:
parent
43e46008c7
commit
5461c17217
1 changed files with 26 additions and 44 deletions
|
@ -4,6 +4,7 @@ import shutil
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from .Track import CantDownloadTrack
|
||||||
from .CT_Config import CT_Config
|
from .CT_Config import CT_Config
|
||||||
from .definition import *
|
from .definition import *
|
||||||
from .wszst import *
|
from .wszst import *
|
||||||
|
@ -57,9 +58,9 @@ class NoGui:
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
def progress(*args, **kwargs): print(args, kwargs)
|
def progress(self, *args, **kwargs): print(args, kwargs)
|
||||||
def translate(*args, **kwargs): return ""
|
def translate(self, *args, **kwargs): return ""
|
||||||
def log_error(*args, **kwargs): print(args, kwargs)
|
def log_error(self, *args, **kwargs): print(args, kwargs)
|
||||||
|
|
||||||
is_dev_version = False
|
is_dev_version = False
|
||||||
button_install_mod = NoButton()
|
button_install_mod = NoButton()
|
||||||
|
@ -427,7 +428,7 @@ class Game:
|
||||||
thread_list = {}
|
thread_list = {}
|
||||||
error_count, error_max = 0, 3
|
error_count, error_max = 0, 3
|
||||||
|
|
||||||
def add_process(track) -> int:
|
def add_process(track) -> None:
|
||||||
"""
|
"""
|
||||||
a "single thread" to download, check sha1 and convert a track
|
a "single thread" to download, check sha1 and convert a track
|
||||||
:param track: the track that will be patched
|
:param track: the track that will be patched
|
||||||
|
@ -441,47 +442,28 @@ class Game:
|
||||||
os.remove(_track)
|
os.remove(_track)
|
||||||
|
|
||||||
if not self.gui.boolvar_disable_download.get():
|
if not self.gui.boolvar_disable_download.get():
|
||||||
while True:
|
if not os.path.exists(track.file_wu8):
|
||||||
download_returncode = 0
|
try: track.download_wu8(GITHUB_DEV_BRANCH if self.gui.is_dev_version else GITHUB_MASTER_BRANCH)
|
||||||
if not os.path.exists(track.file_wu8):
|
except CantDownloadTrack:
|
||||||
download_returncode = track.download_wu8(
|
error_count += 1
|
||||||
GITHUB_DEV_BRANCH if self.gui.is_dev_version else GITHUB_MASTER_BRANCH)
|
if error_count > error_max: # Too much track wasn't correctly converted
|
||||||
if download_returncode == -1: # can't download
|
messagebox.showerror(
|
||||||
error_count += 1
|
self.gui.translate("Error"),
|
||||||
if error_count > error_max: # Too much track wasn't correctly converted
|
self.gui.translate("Too much tracks had a download issue."))
|
||||||
messagebox.showerror(
|
raise TooMuchDownloadFailed()
|
||||||
self.gui.translate("Error"),
|
else:
|
||||||
self.gui.translate("Too much tracks had a download issue."))
|
messagebox.showwarning(self.gui.translate("Warning"),
|
||||||
raise TooMuchDownloadFailed()
|
self.gui.translate("Can't download this track !",
|
||||||
else:
|
f" ({error_count} / {error_max})"))
|
||||||
messagebox.showwarning(self.gui.translate("Warning"),
|
|
||||||
self.gui.translate("Can't download this track !",
|
|
||||||
f" ({error_count} / {error_max})"))
|
|
||||||
|
|
||||||
if track.sha1:
|
if not track.check_szs_sha1(): # if sha1 of track's szs is incorrect or track's szs does not exist
|
||||||
if not self.gui.boolvar_dont_check_track_sha1.get():
|
if os.path.exists(track.file_wu8): track.convert_wu8_to_szs()
|
||||||
if track.check_sha1() != 0: # if track sha1 is not the one excepted
|
else:
|
||||||
error_count += 1
|
messagebox.showerror(self.gui.translate("Error"),
|
||||||
if error_count > error_max: # Too much track wasn't correctly converted
|
self.gui.translate("Can't convert track.\nEnable track download and retry."))
|
||||||
messagebox.showerror(
|
raise CantConvertTrack()
|
||||||
self.gui.translate("Error"),
|
elif self.gui.boolvar_del_track_after_conv.get():
|
||||||
self.gui.translate("Too much tracks had an issue during sha1 check."))
|
os.remove(track.file_wu8)
|
||||||
raise TooMuchSha1CheckFailed()
|
|
||||||
continue
|
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
if not os.path.exists(track.file_szs) or download_returncode == 3:
|
|
||||||
# returncode 3 is track has been updated
|
|
||||||
if os.path.exists(track.file_wu8):
|
|
||||||
track.convert_wu8_to_szs()
|
|
||||||
else:
|
|
||||||
messagebox.showerror(self.gui.translate("Error"),
|
|
||||||
self.gui.translate("Can't convert track.\nEnable track download and retry."))
|
|
||||||
raise CantConvertTrack()
|
|
||||||
elif self.gui.boolvar_del_track_after_conv.get():
|
|
||||||
os.remove(track.file_wu8)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def clean_process() -> int:
|
def clean_process() -> int:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue