From 9894acf2f81c52e90987bae6a984a4043b230b2d Mon Sep 17 00:00:00 2001 From: Jaen Date: Wed, 13 Sep 2023 19:51:07 +0300 Subject: [PATCH] fix: Reader proceeds to next volume when current one runs out of bytes --- lib/file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/file.c b/lib/file.c index c385b9f..47f096f 100644 --- a/lib/file.c +++ b/lib/file.c @@ -536,8 +536,17 @@ static bool unshield_reader_read(UnshieldReader* reader, void* buffer, size_t si #endif if (bytes_to_read == 0) { - unshield_error("bytes_to_read can't be zero"); - goto exit; + if ((reader->file_descriptor->flags & FILE_SPLIT) && + reader->volume_bytes_left == 0) + { + unshield_warning("Split file, proceeding to next volume"); + goto next_volume; + } + else + { + unshield_error("bytes_to_read can't be zero"); + goto exit; + } } if (bytes_to_read != fread(p, 1, bytes_to_read, reader->volume_file)) @@ -565,11 +574,11 @@ static bool unshield_reader_read(UnshieldReader* reader, void* buffer, size_t si /* Open next volume */ - +next_volume: if (!unshield_reader_open_volume(reader, reader->volume + 1)) { unshield_error("Failed to open volume %i to read %i more bytes", - reader->volume + 1, bytes_to_read); + reader->volume + 1, bytes_left); goto exit; } } @@ -815,7 +824,6 @@ bool unshield_file_save (Unshield* unshield, int index, const char* filename)/*{ { unshield_error("Failed to read %i bytes of file %i (%s) from input cabinet file %i", sizeof(bytes_to_read_bytes), index, unshield_file_name(unshield, index), file_descriptor->volume); - goto exit; } bytes_to_read = READ_UINT16(bytes_to_read_bytes);