[cli] Accurately track verified file size

This commit is contained in:
derrod 2022-01-04 12:11:46 +01:00
parent ecb04324d5
commit bec119bc03
2 changed files with 9 additions and 8 deletions

View file

@ -1111,6 +1111,7 @@ class LegendaryCLI:
for fm in file_list)
num = processed = last_processed = 0
speed = 0.0
percentage = 0.0
failed = []
missing = []
@ -1118,8 +1119,8 @@ class LegendaryCLI:
logger.info(f'Verifying "{igame.title}" version "{manifest.meta.build_version}"')
repair_file = []
for result, path, result_hash in validate_files(igame.install_path, file_list):
processed += manifest.file_manifest_list.get_file_by_path(path).file_size
for result, path, result_hash, bytes_read in validate_files(igame.install_path, file_list):
processed += bytes_read
percentage = (processed / total_size) * 100.0
num += 1
@ -1145,7 +1146,7 @@ class LegendaryCLI:
logger.error(f'Other failure (see log), treating file as missing: "{path}"')
missing.append(path)
stdout.write(f'Verification progress: {num}/{total} ({num * 100 / total:.01f}%) [{speed:.1f} MiB/s]\t\n')
stdout.write(f'Verification progress: {num}/{total} ({percentage:.01f}%) [{speed:.1f} MiB/s]\t\n')
# always write repair file, even if all match
if repair_file:

View file

@ -86,7 +86,7 @@ def validate_files(base_path: str, filelist: List[tuple], hash_type='sha1',
:param filelist: list of tuples in format (path, hash [hex])
:param hash_type: (optional) type of hash, default is sha1
:param large_file_threshold: (optional) threshold for large files, default is 512 MiB
:return: yields tuples in format (VerifyResult, path, hash [hex])
:return: yields tuples in format (VerifyResult, path, hash [hex], bytes read)
"""
if not filelist:
@ -100,7 +100,7 @@ def validate_files(base_path: str, filelist: List[tuple], hash_type='sha1',
# logger.debug(f'Checking "{file_path}"...')
if not os.path.exists(full_path):
yield VerifyResult.FILE_MISSING, file_path, ''
yield VerifyResult.FILE_MISSING, file_path, '', 0
continue
show_progress = False
@ -139,12 +139,12 @@ def validate_files(base_path: str, filelist: List[tuple], hash_type='sha1',
result_hash = real_file_hash.hexdigest()
if file_hash != result_hash:
yield VerifyResult.HASH_MISMATCH, file_path, result_hash
yield VerifyResult.HASH_MISMATCH, file_path, result_hash, f.tell()
else:
yield VerifyResult.HASH_MATCH, file_path, result_hash
yield VerifyResult.HASH_MATCH, file_path, result_hash, f.tell()
except Exception as e:
logger.fatal(f'Could not verify "{file_path}"; opening failed with: {e!r}')
yield VerifyResult.OTHER_ERROR, file_path, ''
yield VerifyResult.OTHER_ERROR, file_path, '', 0
def clean_filename(filename):