diff --git a/pyproject.toml b/pyproject.toml index 2f2760b..368a2e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "verifydump" -version = "1.0.0" +version = "1.0.1" description = "A tool for verifying compressed (.chd/.rvz) disc dumps against a Datfile" license = "MIT" authors = ["j68k"] diff --git a/verifydump/__init__.py b/verifydump/__init__.py index 3dc1f76..5c4105c 100644 --- a/verifydump/__init__.py +++ b/verifydump/__init__.py @@ -1 +1 @@ -__version__ = "0.1.0" +__version__ = "1.0.1" diff --git a/verifydump/convert.py b/verifydump/convert.py index 5befbe8..ebbb8c2 100644 --- a/verifydump/convert.py +++ b/verifydump/convert.py @@ -1,3 +1,4 @@ +import glob import logging import os import pathlib @@ -53,21 +54,23 @@ def normalize_redump_bincue_dump(cue_file_path: pathlib.Path): dump_path = cue_file_path.parent dump_name = cue_file_path.stem - has_multiple_tracks = len(list(dump_path.glob(f"{dump_name} (Track *).bin"))) > 1 - if not has_multiple_tracks: - original_bin_name = f"{dump_name} (Track 1).bin" + tracks = list(dump_path.glob(glob.escape(dump_name) + "*.bin")) + has_single_track = len(tracks) == 1 + if has_single_track: + original_bin_name = pathlib.Path(tracks[0]).name single_track_bin_name = f"{dump_name}.bin" - logging.debug(f'Renaming "{original_bin_name}" to "{single_track_bin_name}" because there is only one .bin file in the dump') + if original_bin_name != single_track_bin_name: + logging.debug(f'Renaming "{original_bin_name}" to "{single_track_bin_name}" because there is only one .bin file in the dump') - os.rename( - pathlib.Path(dump_path, original_bin_name), - pathlib.Path(dump_path, single_track_bin_name), - ) + os.rename( + pathlib.Path(dump_path, original_bin_name), + pathlib.Path(dump_path, single_track_bin_name), + ) - cue_file_path.write_text(cue_file_path.read_text().replace(f'FILE "{original_bin_name}"', f'FILE "{single_track_bin_name}"'), newline="\r\n") + cue_file_path.write_text(cue_file_path.read_text().replace(f'FILE "{original_bin_name}"', f'FILE "{single_track_bin_name}"'), newline="\r\n") - is_cue_iso_compatible = not has_multiple_tracks and re.match(r'^\s*FILE\s+"' + re.escape(f"{dump_name}.bin") + r'"\s*BINARY\s+TRACK 01 MODE1/2048\s+INDEX 01 00:00:00\s*$', cue_file_path.read_text()) + is_cue_iso_compatible = has_single_track and re.match(r'^\s*FILE\s+"' + re.escape(f"{dump_name}.bin") + r'"\s*BINARY\s+TRACK 01 MODE1/2048\s+INDEX 01 00:00:00\s*$', cue_file_path.read_text()) if is_cue_iso_compatible: logging.debug(f'"{cue_file_path.name}" is .iso compatible so converting dump to .iso and discarding .cue') @@ -90,7 +93,7 @@ def convert_chd_to_bin_gdi(chd_file_path: pathlib.Path, output_folder_path: path def normalize_redump_bin_gdi_dump(cue_file_path: pathlib.Path): game_name = cue_file_path.stem - bin_and_raw_file_paths = list(cue_file_path.parent.glob(f"{game_name}*.bin")) + list(cue_file_path.parent.glob(f"{game_name}*.raw")) + bin_and_raw_file_paths = list(cue_file_path.parent.glob(glob.escape(game_name) + "*.bin")) + list(cue_file_path.parent.glob(glob.escape(game_name) + "*.raw")) redump_bin_filename_format = get_redump_bin_filename_format(game_name, len(bin_and_raw_file_paths)) track_number_parser = re.compile(f"^{re.escape(game_name)}(?P[0-9]+)\\.(?:bin|raw)$") diff --git a/verifydump/verify.py b/verifydump/verify.py index 16a2a2a..87a59af 100644 --- a/verifydump/verify.py +++ b/verifydump/verify.py @@ -110,8 +110,8 @@ def verify_redump_dump_folder(dump_folder: pathlib.Path, dat: Dat, extra_cue_sou rom_with_matching_sha1_and_name = next((rom for rom in roms_with_matching_sha1 if rom.name == dump_file_path.name), None) if not rom_with_matching_sha1_and_name: - list_of_rom_names_that_match_sha1 = " or ".join([f'"{rom.name}"' for rom in roms_with_matching_sha1]) - raise VerificationException(f'Dump file "{dump_file_path.name}" found in Dat, but it should be named {list_of_rom_names_that_match_sha1}') + list_of_rom_names_that_match_sha1 = "\n\t".join(sorted([f'"{rom.name}"' for rom in roms_with_matching_sha1])) + raise VerificationException(f'Dump file "{dump_file_path.name}" found in Dat, but it should be named one of the following:\n\t{list_of_rom_names_that_match_sha1}') if rom_with_matching_sha1_and_name.size != dump_file_path.stat().st_size: print(f"{rom_with_matching_sha1_and_name.size} {dump_file_path.stat().st_size}") @@ -243,8 +243,10 @@ def verify_dump_if_format_is_supported(dump_path: pathlib.Path, error_if_unsuppo elif error_if_unsupported: raise VerificationException(f'{pathlib.Path(sys.argv[0]).stem} doesn\'t know how to handle "{suffix_lower}" dumps') except VerificationException as e: + logging.error(str(e)) errors.append(e) except ConversionException as e: + logging.error(str(e)) errors.append(e) for dump_file_or_folder_path in dump_file_or_folder_paths: