From fdd8a3411e2900ce8737e999bec6b29533219b44 Mon Sep 17 00:00:00 2001 From: xorloser Date: Sat, 12 Sep 2020 22:25:54 +1000 Subject: [PATCH] Import file had a max 4MB header size limit before it would fail. This removes that limit and lets it keep reading in more data until it succeeds or reaches the end of the file. This allows for import filetypes where channel info isnt in the first 4MB, such as when it is in a footer or inside a zip file. --- pv/devices/inputfile.cpp | 52 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/pv/devices/inputfile.cpp b/pv/devices/inputfile.cpp index 9cc99f4e..c79ebde2 100644 --- a/pv/devices/inputfile.cpp +++ b/pv/devices/inputfile.cpp @@ -131,19 +131,27 @@ void InputFile::open() vector buffer(BufferSize); - f->read(buffer.data(), BufferSize); - const streamsize size = f->gcount(); + do { + if (!f->eof()) { + f->read(buffer.data(), BufferSize); + const streamsize size = f->gcount(); - if (size == 0) - throw QString("Failed to read file"); + if (size == 0) + throw QString("Failed to read file"); - input_->send(buffer.data(), size); + input_->send(buffer.data(), size); + } - try { - device_ = input_->device(); - } catch (sigrok::Error& e) { - throw e; - } + try { + // If this succeeds then enough of the file was read in to create the device. + device_ = input_->device(); + } catch (sigrok::Error& e) { + // Failed so may need more of file in order to successfully create the device. + // If already read in all of the file, then throw error. + if (f->eof()) + throw e; + } + } while(!device_); session_->add_device(device_); } @@ -169,19 +177,23 @@ void InputFile::run() input_->reset(); } - vector buffer(BufferSize); + // May already be at eof due to processing inside open(). + // If this is the case we don't want to do any more send() calls. + if (!f->eof()) { + vector buffer(BufferSize); - interrupt_ = false; - while (!interrupt_ && !f->eof()) { - f->read(buffer.data(), BufferSize); - const streamsize size = f->gcount(); - if (size == 0) - break; + interrupt_ = false; + while (!interrupt_ && !f->eof()) { + f->read(buffer.data(), BufferSize); + const streamsize size = f->gcount(); + if (size == 0) + break; - input_->send(buffer.data(), size); + input_->send(buffer.data(), size); - if (size != BufferSize) - break; + if (size != BufferSize) + break; + } } input_->end();