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