Use decimal session IDs for chunk YAML file names, add original file path to YAML.

This commit is contained in:
sawinglogz 2019-06-07 21:12:55 -04:00
parent 2ace7d3a6d
commit c93932664c

View File

@ -150,10 +150,8 @@ static QString byteList(QByteArray data, int limit=-1)
return s; return s;
} }
void ChunkToYaml(QFile & file, PRS1DataChunk* chunk, bool ok) void ChunkToYaml(QTextStream & out, PRS1DataChunk* chunk, bool ok)
{ {
QTextStream out(&file);
// chunk header // chunk header
out << "chunk:" << endl; out << "chunk:" << endl;
out << " at: " << hex << chunk->m_filepos << endl; out << " at: " << hex << chunk->m_filepos << endl;
@ -224,7 +222,7 @@ void ChunkToYaml(QFile & file, PRS1DataChunk* chunk, bool ok)
} }
} }
} }
if (dump_data) { if (dump_data || !ok) {
out << " data: " << byteList(chunk->m_data, 100) << endl; out << " data: " << byteList(chunk->m_data, 100) << endl;
} }
@ -276,7 +274,7 @@ void parseAndEmitChunkYaml(const QString & path)
} }
QString ext_s = fi.fileName().section(".", -1); QString ext_s = fi.fileName().section(".", -1);
ext_s.toInt(&ok); int ext = ext_s.toInt(&ok);
if (!ok) { if (!ok) {
// not a numerical extension // not a numerical extension
qWarning() << inpath << "unexpected filename"; qWarning() << inpath << "unexpected filename";
@ -284,7 +282,7 @@ void parseAndEmitChunkYaml(const QString & path)
} }
QString session_s = fi.fileName().section(".", 0, -2); QString session_s = fi.fileName().section(".", 0, -2);
session_s.toInt(&ok, sessionid_base); int sessionid = session_s.toInt(&ok, sessionid_base);
if (!ok) { if (!ok) {
// not a numerical session ID // not a numerical session ID
qWarning() << inpath << "unexpected filename"; qWarning() << inpath << "unexpected filename";
@ -292,12 +290,19 @@ void parseAndEmitChunkYaml(const QString & path)
} }
// Create the YAML file. // Create the YAML file.
QString outpath = prs1OutputPath(path, m->serial(), fi.fileName(), "-chunks.yml"); QString suffix = QString(".%1-chunks.yml").arg(ext, 3, 10, QChar('0'));
QString outpath = prs1OutputPath(path, m->serial(), sessionid, suffix);
QFile file(outpath); QFile file(outpath);
if (!file.open(QFile::WriteOnly | QFile::Truncate)) { if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
qDebug() << outpath; qDebug() << outpath;
Q_ASSERT(false); Q_ASSERT(false);
} }
QTextStream out(&file);
// keep only P1234568/Pn/00000000.001
QStringList pathlist = QDir::toNativeSeparators(inpath).split(QDir::separator(), QString::SkipEmptyParts);
QString relative = pathlist.mid(pathlist.size()-3).join(QDir::separator());
out << "file: " << relative << endl;
// Parse the chunks in the file. // Parse the chunks in the file.
QList<PRS1DataChunk *> chunks = s_loader->ParseFile(inpath); QList<PRS1DataChunk *> chunks = s_loader->ParseFile(inpath);
@ -314,7 +319,7 @@ void parseAndEmitChunkYaml(const QString & path)
} }
// Emit the YAML. // Emit the YAML.
ChunkToYaml(file, chunk, ok); ChunkToYaml(out, chunk, ok);
delete chunk; delete chunk;
} }