mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-07 11:40:42 +00:00
Split PRS1DataChunk::ReadHeader into ReadHeader/ReadData.
This commit is contained in:
parent
451963de25
commit
e07c4ce63c
@ -3449,8 +3449,37 @@ PRS1DataChunk* PRS1DataChunk::ParseNext(QFile & f)
|
|||||||
PRS1DataChunk* chunk = new PRS1DataChunk(f);
|
PRS1DataChunk* chunk = new PRS1DataChunk(f);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
// Parse the header and calculate its checksum.
|
||||||
bool ok = chunk->ReadHeader(f);
|
bool ok = chunk->ReadHeader(f);
|
||||||
if (!ok) break;
|
if (!ok) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the calculated checksum matches the stored checksum.
|
||||||
|
if (chunk->calcChecksum != chunk->storedChecksum) {
|
||||||
|
qWarning() << chunk->m_path << "header checksum calc" << chunk->calcChecksum << "!= stored" << chunk->storedChecksum;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log mismatched waveform session IDs
|
||||||
|
if (chunk->ext >= 5) {
|
||||||
|
QFileInfo fi(f);
|
||||||
|
bool numeric;
|
||||||
|
int sessionid_base = (chunk->fileVersion == 2 ? 10 : 16);
|
||||||
|
QString session_s = fi.fileName().section(".", 0, -2);
|
||||||
|
quint32 sid = session_s.toInt(&numeric, sessionid_base);
|
||||||
|
if (!numeric || sid != chunk->sessionid) {
|
||||||
|
qDebug() << chunk->m_path << chunk->sessionid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the block's data and calculate the block CRC.
|
||||||
|
ok = chunk->ReadData(f);
|
||||||
|
if (!ok) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: move block CRC comparison here
|
||||||
|
|
||||||
// Only return the chunk if it has passed all tests above.
|
// Only return the chunk if it has passed all tests above.
|
||||||
out_chunk = chunk;
|
out_chunk = chunk;
|
||||||
@ -3533,15 +3562,6 @@ bool PRS1DataChunk::ReadHeader(QFile & f)
|
|||||||
this->m_headerblock = headerB2;
|
this->m_headerblock = headerB2;
|
||||||
|
|
||||||
} else { // Waveform Chunk
|
} else { // Waveform Chunk
|
||||||
QFileInfo fi(f);
|
|
||||||
bool ok;
|
|
||||||
int sessionid_base = (this->fileVersion == 2 ? 10 : 16);
|
|
||||||
QString session_s = fi.fileName().section(".", 0, -2);
|
|
||||||
quint32 sid = session_s.toInt(&ok, sessionid_base);
|
|
||||||
if (!ok || sid != this->sessionid) {
|
|
||||||
qDebug() << this->m_path << this->sessionid; // log mismatched waveforum session IDs
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray extra = f.read(5);
|
QByteArray extra = f.read(5);
|
||||||
if (extra.size() != 5) {
|
if (extra.size() != 5) {
|
||||||
qWarning() << this->m_path << "read error in waveform header";
|
qWarning() << this->m_path << "read error in waveform header";
|
||||||
@ -3607,12 +3627,17 @@ bool PRS1DataChunk::ReadHeader(QFile & f)
|
|||||||
// Append the stored checksum to the raw data *after* calculating the checksum on the preceding data.
|
// Append the stored checksum to the raw data *after* calculating the checksum on the preceding data.
|
||||||
this->m_header.append(checksum);
|
this->m_header.append(checksum);
|
||||||
|
|
||||||
// Make sure the calculated checksum matches the stored checksum.
|
ok = true;
|
||||||
if (this->calcChecksum != this->storedChecksum) { // Header checksum mismatch?
|
} while (false);
|
||||||
qWarning() << this->m_path << "header checksum calc" << this->calcChecksum << "!= stored" << this->storedChecksum;
|
|
||||||
break;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PRS1DataChunk::ReadData(QFile & f)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
do {
|
||||||
// Read data block
|
// Read data block
|
||||||
int data_size = this->blockSize - this->m_header.size();
|
int data_size = this->blockSize - this->m_header.size();
|
||||||
this->m_data = f.read(data_size);
|
this->m_data = f.read(data_size);
|
||||||
|
@ -73,6 +73,8 @@ public:
|
|||||||
|
|
||||||
duration = 0;
|
duration = 0;
|
||||||
|
|
||||||
|
m_filepos = -1;
|
||||||
|
m_index = -1;
|
||||||
}
|
}
|
||||||
PRS1DataChunk(class QFile & f);
|
PRS1DataChunk(class QFile & f);
|
||||||
~PRS1DataChunk() {
|
~PRS1DataChunk() {
|
||||||
@ -110,6 +112,9 @@ public:
|
|||||||
|
|
||||||
//! \brief Read and parse the next chunk header from a PRS1 file
|
//! \brief Read and parse the next chunk header from a PRS1 file
|
||||||
bool ReadHeader(class QFile & f);
|
bool ReadHeader(class QFile & f);
|
||||||
|
|
||||||
|
//! \brief Read the chunk's data from a PRS1 file and calculate its CRC, must be called after ReadHeader
|
||||||
|
bool ReadData(class QFile & f);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PRS1Loader;
|
class PRS1Loader;
|
||||||
|
Loading…
Reference in New Issue
Block a user