From bec119bc03a2c1c2975fdb67b5ccb11b8bfee377 Mon Sep 17 00:00:00 2001 From: derrod Date: Tue, 4 Jan 2022 12:11:46 +0100 Subject: [PATCH] [cli] Accurately track verified file size --- legendary/cli.py | 7 ++++--- legendary/utils/lfs.py | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/legendary/cli.py b/legendary/cli.py index ae20291..3f94cb5 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -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: diff --git a/legendary/utils/lfs.py b/legendary/utils/lfs.py index 37f640f..cae16b7 100644 --- a/legendary/utils/lfs.py +++ b/legendary/utils/lfs.py @@ -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):