Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion verifydump/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "1.0.1"
25 changes: 14 additions & 11 deletions verifydump/convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import logging
import os
import pathlib
Expand Down Expand Up @@ -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')

Expand All @@ -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<track_number>[0-9]+)\\.(?:bin|raw)$")
Expand Down
6 changes: 4 additions & 2 deletions verifydump/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down