authorblues / bizhawk-shuffler-2

A script to randomly shuffle between games played in Bizhawk, with plugins to enhance the experience
MIT License
58 stars 21 forks source link

.cue file handling should not be case sensitive on Windows #43

Closed kalimag closed 3 months ago

kalimag commented 2 years ago

The way get_games_list removes data files referenced in cue/ccd/xml files is case sensitive, so if a .cue file contains the string FILE "FOO.BIN" BINARY but the associated file is named foo.bin, it will not be removed from the games list, and cause issues when the script tries to load it as a ROM.

BizHawk will open such cue files without issue (at least on Windows), so the source of the problem will not be obvious to the user, and I've seen a couple of disc images with inconsistent casing like that "in the wild".

https://github.com/authorblues/bizhawk-shuffler-2/blob/7545ddd025e66537fd3b6f1549c7665657f9a7c2/shuffler.lua#L182-L184

https://github.com/authorblues/bizhawk-shuffler-2/blob/7545ddd025e66537fd3b6f1549c7665657f9a7c2/shuffler.lua#L103-L113

table_subtract uses table lookups, and string keys are case-sensitive. The easiest solution may be to add an alternative table_subtract implementation which uses :lower() on the table keys in the temporary table (with an OS check?).

kalimag commented 2 years ago

Also, the double quotes around the file name in .cue files are optional if the file name does not contain whitespace, while the script assumes they're always there. I haven't found any examples of unquoted file names in .cue files myself, but it's a theoretical source of error.

authorblues commented 2 years ago

I have no issues with table_subtract just being made case-insensitive, based on the way it's being used, but that would break some weird edge cases on Linux (which currently isn't supported anyways, so a pointless issue).

kalimag commented 1 year ago

BizHawk actually uses a much more complicated file lookup that mostly ignores file extensions and is case insensitive even on Linux.

https://github.com/TASEmulators/BizHawk/blob/ea7683a9964a583d7b8bd2e467e905df296e535e/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CueFileResolver.cs#L74

kalimag commented 3 months ago

This is mostly resolved now in 75b71d4, acc35cc and dfbb142ea9ad817708714ce4d149f8c05ae2efb4 (#58).

BizHawk is very flexible about cue files, and can for example fall back to a foo.mp3 if it can't find a foo.bin audio track listed in the .cue, so it's still possible that the shuffler chokes on weird compressed discs that BizHawk can successfully load.