Fix -di command line option for template images causing 'Problem reading from disc image.' #107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The -di option (disc image template) fails with the error "Problem reading from disc image" when attempting to use an existing disc image as a template for a new disc image,
The commits of this PR add a failing test to reproduce the issue, improve the diagnostics to shed light on the problem, and implement a fix.
Cause: In
discimage.cpp, the constructor reads the 512-byte catalogue into memory, advancing the file pointer to position 0x200. The subsequent sector-copying loop then attempts to read sectors from the current file position instead of seeking back to the start of the file. This causes reads to fail when the loop tries to read past the end of the file.The fix writes the catalogue directly from the in-memory buffer (to which it was already read) and only reads the remaining data sectors from the input file. This:
m_aCatalogas the single source of truth for the catalogueI took a few liberties with improving the capabilities of the error reporting, but I felt that,
was a sufficiently worthwhile improvement over,
so as to be worthwhile. Similar improvements to error reporting elsewhere are now a bit easier too.