parent
f0c51530c4
commit
2477ed1a06
@ -457,25 +457,20 @@ class Installer:
|
||||
|
||||
async def download_full_game(self, pre_download=False):
|
||||
game = await self._get_game(pre_download)
|
||||
if not game.latest.path == "":
|
||||
archive_name = game.latest.path.split("/")[-1]
|
||||
if calculate_md5(self.temp_path.joinpath(archive_name)) != game.latest.md5:
|
||||
raise RuntimeError("mismatch md5 for downloaded game archive")
|
||||
return
|
||||
# Segment download
|
||||
base_archive = None
|
||||
for i, segment in enumerate(game.latest.segments):
|
||||
# base_archive = None
|
||||
for _, segment in enumerate(game.latest.segments):
|
||||
archive_name = segment["path"].split("/")[-1]
|
||||
if i == 0:
|
||||
base_archive = archive_name = Path(archive_name).stem # Remove .001
|
||||
if self.temp_path.joinpath(archive_name + ".downloaded").exists():
|
||||
if self.temp_path.joinpath(archive_name + ".downloaded").exists() and self.temp_path.joinpath(archive_name).exists():
|
||||
continue
|
||||
await self._download_file(segment["path"], archive_name)
|
||||
if i != 0:
|
||||
with open(self.temp_path.joinpath(base_archive), 'ab') as f:
|
||||
with open(self.temp_path.joinpath(archive_name), 'rb') as f2:
|
||||
f.write(f2.read())
|
||||
self.temp_path.joinpath(archive_name).unlink()
|
||||
if calculate_md5(self.temp_path.joinpath(archive_name)) != segment["md5"]:
|
||||
raise RuntimeError(f"mismatch md5 for downloaded game archive: {archive_name}")
|
||||
# if i != 0:
|
||||
# with open(self.temp_path.joinpath(base_archive), 'ab') as f:
|
||||
# with open(self.temp_path.joinpath(archive_name), 'rb') as f2:
|
||||
# shutil.copyfileobj(f2, f)
|
||||
# self.temp_path.joinpath(archive_name).unlink()
|
||||
self.temp_path.joinpath(archive_name + ".downloaded").touch()
|
||||
|
||||
|
||||
@ -489,13 +484,21 @@ class Installer:
|
||||
async def uninstall_game(self):
|
||||
await asyncio.to_thread(shutil.rmtree, self._gamedir, ignore_errors=True)
|
||||
|
||||
async def _extract_game_file(self, archive: str | Path | Path):
|
||||
async def _extract_game_file(self, archive: str | Path):
|
||||
if isinstance(archive, str | Path):
|
||||
archive = Path(archive).resolve()
|
||||
if not archive.exists():
|
||||
raise FileNotFoundError(f"'{archive}' not found")
|
||||
with zipfile.ZipFile(archive, 'r') as f:
|
||||
await asyncio.to_thread(f.extractall, path=self._gamedir)
|
||||
game_dir_str = str(self._gamedir)
|
||||
if not game_dir_str.endswith("/"):
|
||||
game_dir_str += "/"
|
||||
print(f'-o"{game_dir_str}"')
|
||||
proc = await asyncio.create_subprocess_shell(f'7z x {str(archive)} -o"{game_dir_str}"')
|
||||
await proc.wait()
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError("Extracting failed")
|
||||
# with zipfile.ZipFile(archive, 'r') as f:
|
||||
# await asyncio.to_thread(f.extractall, path=self._gamedir)
|
||||
|
||||
async def apply_voiceover(self, voiceover_archive: str | Path):
|
||||
# Since Voiceover packages are unclear about diff package or full package
|
||||
|
Loading…
Reference in New Issue
Block a user