WIP game patcher
Now worthless can patch the game using xdelta3-python
This commit is contained in:
@ -84,12 +84,16 @@ class Installer:
|
||||
self.temp_path.mkdir(parents=True, exist_ok=True)
|
||||
config_file = self._gamedir.joinpath("config.ini")
|
||||
self._config_file = config_file.resolve()
|
||||
self._download_chunk = 8192
|
||||
self._version = None
|
||||
self._overseas = overseas
|
||||
self._launcher = Launcher(self._gamedir, overseas=self._overseas)
|
||||
self._version = self.get_game_version()
|
||||
|
||||
async def _download_file(self, file_url: str, file_name: str, file_len: int = None):
|
||||
def set_download_chunk(self, chunk: int):
|
||||
self._download_chunk = chunk
|
||||
|
||||
async def _download_file(self, file_url: str, file_name: str, file_len: int = None, overwrite=False):
|
||||
"""
|
||||
Download file name to temporary directory,
|
||||
:param file_url:
|
||||
@ -98,9 +102,10 @@ class Installer:
|
||||
"""
|
||||
params = {}
|
||||
file_path = AsyncPath(self.temp_path).joinpath(file_name)
|
||||
if overwrite:
|
||||
await file_path.unlink(missing_ok=True)
|
||||
if file_path.exists():
|
||||
async with file_path.open("rb") as f:
|
||||
cur_len = len(await f.read())
|
||||
cur_len = len(await file_path.read_bytes())
|
||||
params |= {
|
||||
"Range": f"bytes={cur_len}-{file_len if file_len else ''}"
|
||||
}
|
||||
@ -110,7 +115,7 @@ class Installer:
|
||||
rsp = await session.get(file_url, params=params, timeout=None)
|
||||
rsp.raise_for_status()
|
||||
while True:
|
||||
chunk = await rsp.content.read(8192)
|
||||
chunk = await rsp.content.read(self._download_chunk)
|
||||
if not chunk:
|
||||
break
|
||||
async with file_path.open("ab") as f:
|
||||
@ -207,7 +212,9 @@ class Installer:
|
||||
# Update game version on local variable.
|
||||
self._version = self.get_game_version()
|
||||
|
||||
async def download_full_game(self):
|
||||
async def download_full_game(self, overwrite: bool = False):
|
||||
if self._version and not overwrite:
|
||||
raise ValueError("Game already exists")
|
||||
archive = await self._launcher.get_resource_info()
|
||||
if archive is None:
|
||||
raise RuntimeError("Failed to fetch game resource info.")
|
||||
|
||||
Reference in New Issue
Block a user