mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 01:45:28 +00:00
[cli] Accurately track verified file size
This commit is contained in:
parent
ecb04324d5
commit
bec119bc03
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue