fix(common/update): zipfile -> py7zr
So py7zr does have some differences from zipfile
This commit is contained in:
@ -43,14 +43,19 @@ def apply_update_archive(
|
|||||||
files.remove(file)
|
files.remove(file)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
# Think for me a better name for this variable
|
||||||
|
txtfiles = archive.read(["deletefiles.txt", "hdifffiles.txt"])
|
||||||
try:
|
try:
|
||||||
# miHoYo loves CRLF
|
# miHoYo loves CRLF
|
||||||
deletefiles = archive.read("deletefiles.txt").decode().split("\r\n")
|
deletebytes = txtfiles["deletefiles.txt"].read()
|
||||||
|
if deletebytes is bytes:
|
||||||
|
deletebytes = deletebytes.decode()
|
||||||
|
deletefiles = deletebytes.split("\r\n")
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for file_str in deletefiles:
|
for file_str in deletefiles:
|
||||||
file = game.path.joinpath(file)
|
file = game.path.joinpath(file_str)
|
||||||
if file == game.path:
|
if file == game.path:
|
||||||
# Don't delete the game folder
|
# Don't delete the game folder
|
||||||
continue
|
continue
|
||||||
@ -63,7 +68,10 @@ def apply_update_archive(
|
|||||||
# hdiffpatch implementation
|
# hdiffpatch implementation
|
||||||
# Read hdifffiles.txt to get the files to patch
|
# Read hdifffiles.txt to get the files to patch
|
||||||
hdifffiles = []
|
hdifffiles = []
|
||||||
for x in archive.read("hdifffiles.txt").decode().split("\r\n"):
|
hdiffbytes = txtfiles["hdifffiles.txt"].read()
|
||||||
|
if hdiffbytes is bytes:
|
||||||
|
hdiffbytes = hdiffbytes.decode()
|
||||||
|
for x in hdiffbytes.split("\r\n"):
|
||||||
try:
|
try:
|
||||||
hdifffiles.append(json.loads(x.strip())["remoteName"])
|
hdifffiles.append(json.loads(x.strip())["remoteName"])
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
@ -75,7 +83,8 @@ def apply_update_archive(
|
|||||||
# Delete old patch file if exists
|
# Delete old patch file if exists
|
||||||
patchpath.unlink(missing_ok=True)
|
patchpath.unlink(missing_ok=True)
|
||||||
# Extract patch file
|
# Extract patch file
|
||||||
archive.extract(patch_file, game.temppath)
|
# Spaghetti code :(, fuck my eyes.
|
||||||
|
archive.extract(game.temppath, [patch_file])
|
||||||
file = file.rename(file.with_suffix(file.suffix + ".bak"))
|
file = file.rename(file.with_suffix(file.suffix + ".bak"))
|
||||||
try:
|
try:
|
||||||
_hdiff.patch_file(file, file.with_suffix(""), patchpath)
|
_hdiff.patch_file(file, file.with_suffix(""), patchpath)
|
||||||
@ -97,10 +106,10 @@ def apply_update_archive(
|
|||||||
# Remove old file, since we don't need it anymore.
|
# Remove old file, since we don't need it anymore.
|
||||||
file.unlink()
|
file.unlink()
|
||||||
|
|
||||||
def extract_or_repair(file):
|
def extract_or_repair(file: str):
|
||||||
# Extract file
|
# Extract file
|
||||||
try:
|
try:
|
||||||
archive.extract(file, game.path)
|
archive.extract(game.path, [file])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Repair file
|
# Repair file
|
||||||
if not auto_repair:
|
if not auto_repair:
|
||||||
@ -126,10 +135,12 @@ def apply_update_archive(
|
|||||||
patch_executor.shutdown(wait=True)
|
patch_executor.shutdown(wait=True)
|
||||||
|
|
||||||
# Extract files from archive after we have filtered out the patch files
|
# Extract files from archive after we have filtered out the patch files
|
||||||
# Using ThreadPoolExecutor instead of archive.extractall() because
|
# Using ProcessPoolExecutor instead of archive.extractall() because
|
||||||
# archive.extractall() can crash with large archives, and it doesn't
|
# archive.extractall() can crash with large archives, and it doesn't
|
||||||
# handle broken files.
|
# handle broken files.
|
||||||
extract_executor = concurrent.futures.ThreadPoolExecutor()
|
# ProcessPoolExecutor is faster than ThreadPoolExecutor, and it shouldn't
|
||||||
|
# cause any problems here.
|
||||||
|
extract_executor = concurrent.futures.ProcessPoolExecutor()
|
||||||
for file in files:
|
for file in files:
|
||||||
extract_executor.submit(extract_or_repair, file)
|
extract_executor.submit(extract_or_repair, file)
|
||||||
extract_executor.shutdown(wait=True)
|
extract_executor.shutdown(wait=True)
|
||||||
@ -213,7 +224,7 @@ def repair_game(
|
|||||||
# We only need to read 4 bytes to see if the file is readable or not
|
# We only need to read 4 bytes to see if the file is readable or not
|
||||||
f.read(4)
|
f.read(4)
|
||||||
except Exception:
|
except Exception:
|
||||||
print(f"File {file=} is corrupted.")
|
print(f"File '{file}' is corrupted.")
|
||||||
target_files.append(file)
|
target_files.append(file)
|
||||||
# value not used for now
|
# value not used for now
|
||||||
for key, _ in pkg_version.items():
|
for key, _ in pkg_version.items():
|
||||||
|
|||||||
@ -23,8 +23,8 @@ class PatchType(Enum):
|
|||||||
Jadeite: The new patch which patch the game in memory by DLL injection.
|
Jadeite: The new patch which patch the game in memory by DLL injection.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Astra: int = 0
|
Astra = 0
|
||||||
Jadeite: int = 1
|
Jadeite = 1
|
||||||
|
|
||||||
|
|
||||||
class Patcher(PatcherABC):
|
class Patcher(PatcherABC):
|
||||||
|
|||||||
Reference in New Issue
Block a user