feat(cpn): model notes and checklist files packaged with model files (#6578)
This commit is contained in:
@@ -90,12 +90,17 @@ bool EtxFormat::write(const RadioData & radioData)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool EtxFormat::loadFile(QByteArray & filedata, const QString & filename)
|
||||
bool EtxFormat::loadFile(QByteArray & filedata, const QString & filename, bool optional)
|
||||
{
|
||||
size_t size;
|
||||
void * data = mz_zip_reader_extract_file_to_heap(&zip_archive, qPrintable(filename), &size, 0);
|
||||
if (!data) {
|
||||
return false;
|
||||
if (optional) {
|
||||
//qDebug() << "File not found:" << filename;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << QString("Extracted file %1, size=%2").arg(filename).arg(size);
|
||||
|
||||
@@ -40,7 +40,7 @@ class EtxFormat : public LabelsStorageFormat
|
||||
virtual bool write(const RadioData & radioData);
|
||||
|
||||
protected:
|
||||
virtual bool loadFile(QByteArray & fileData, const QString & fileName);
|
||||
virtual bool loadFile(QByteArray & fileData, const QString & fileName, bool optional = false);
|
||||
virtual bool writeFile(const QByteArray & fileData, const QString & fileName);
|
||||
virtual bool getFileList(std::list<std::string>& filelist);
|
||||
virtual bool deleteFile(const QString & fileName) { return false; }
|
||||
|
||||
@@ -160,6 +160,9 @@ bool LabelsStorageFormat::load(RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loadChecklist(model))
|
||||
return false;
|
||||
|
||||
model.modelIndex = modelIdx;
|
||||
strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1);
|
||||
|
||||
@@ -235,6 +238,9 @@ bool LabelsStorageFormat::write(const RadioData & radioData)
|
||||
writeModelToYaml(model, modelData);
|
||||
if (!writeFile(modelData, modelFilename))
|
||||
return false;
|
||||
|
||||
if (!writeChecklist(model))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasLabels) {
|
||||
@@ -245,3 +251,32 @@ bool LabelsStorageFormat::write(const RadioData & radioData)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LabelsStorageFormat::loadChecklist(ModelData & model)
|
||||
{
|
||||
const QString fname("MODELS/" + model.getChecklistFilename());
|
||||
//qDebug() << "Searching for checklist file:" << fname;
|
||||
|
||||
if (!loadFile(model.checklistData, fname, true)) {
|
||||
setError(tr("Cannot load ") + fname);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LabelsStorageFormat::writeChecklist(const ModelData & model)
|
||||
{
|
||||
const QString fname("MODELS/" + model.getChecklistFilename());
|
||||
|
||||
// not every model has a checklist
|
||||
if (!model.checklistData.isEmpty()) {
|
||||
//qDebug() << "Writing checklist file:" << fname;
|
||||
if (!writeFile(model.checklistData, fname)) {
|
||||
setError(tr("Cannot write ") + fname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,10 +45,13 @@ class LabelsStorageFormat : public StorageFormat
|
||||
virtual bool write(const RadioData & radioData);
|
||||
|
||||
protected:
|
||||
virtual bool loadFile(QByteArray & fileData, const QString & fileName) = 0;
|
||||
virtual bool loadFile(QByteArray & fileData, const QString & fileName, bool optional = false) = 0;
|
||||
virtual bool writeFile(const QByteArray & fileData, const QString & fileName) = 0;
|
||||
virtual bool getFileList(std::list<std::string>& filelist) = 0;
|
||||
virtual bool deleteFile(const QString & fileName) = 0;
|
||||
|
||||
StorageType probeFormat();
|
||||
|
||||
bool loadChecklist(ModelData &model);
|
||||
bool writeChecklist(const ModelData & model);
|
||||
};
|
||||
|
||||
@@ -31,10 +31,19 @@ bool SdcardFormat::write(const RadioData & radioData)
|
||||
return LabelsStorageFormat::write(radioData);
|
||||
}
|
||||
|
||||
bool SdcardFormat::loadFile(QByteArray & filedata, const QString & filename)
|
||||
bool SdcardFormat::loadFile(QByteArray & filedata, const QString & filename, bool optional)
|
||||
{
|
||||
QString path = this->filename + "/" + filename;
|
||||
QFile file(path);
|
||||
if (!file.exists()) {
|
||||
if (optional) {
|
||||
//qDebug() << "File not found:" << filename;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
setError(tr("Error opening file %1:\n%2.").arg(path).arg(file.errorString()));
|
||||
return false;
|
||||
|
||||
@@ -39,7 +39,7 @@ class SdcardFormat : public LabelsStorageFormat
|
||||
virtual bool write(const RadioData & radioData);
|
||||
|
||||
protected:
|
||||
virtual bool loadFile(QByteArray & fileData, const QString & fileName);
|
||||
virtual bool loadFile(QByteArray & fileData, const QString & fileName, bool optional = false);
|
||||
virtual bool writeFile(const QByteArray & fileData, const QString & fileName);
|
||||
virtual bool getFileList(std::list<std::string>& filelist);
|
||||
virtual bool deleteFile(const QString & fileName);
|
||||
|
||||
Reference in New Issue
Block a user