Patch .bin filename to .yml
This commit is contained in:
@@ -158,3 +158,18 @@ bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data)
|
||||
writeYamlToByteArray(node, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string patchFilenameToYaml(const std::string& str)
|
||||
{
|
||||
constexpr const char MODELS_EXT[] = ".bin";
|
||||
constexpr const char YAML_EXT[] = ".yml";
|
||||
constexpr unsigned bin_len = sizeof(MODELS_EXT) - 1;
|
||||
|
||||
// patch file extension
|
||||
auto const dot_pos = str.find_last_of('.');
|
||||
if ((dot_pos != std::string::npos) && (str.substr(dot_pos) == MODELS_EXT)) {
|
||||
std::string tmp = str;
|
||||
return tmp.replace(dot_pos, bin_len, YAML_EXT);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -50,3 +50,5 @@ bool writeModelsListToYaml(const std::vector<CategoryData>& categories,
|
||||
|
||||
bool writeModelToYaml(const ModelData& model, QByteArray& data);
|
||||
bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data);
|
||||
|
||||
std::string patchFilenameToYaml(const std::string& str);
|
||||
|
||||
@@ -88,7 +88,7 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
|
||||
node["calib"] = calib;
|
||||
|
||||
node["currModel"] = rhs.currModelIndex;
|
||||
node["currModelFilename"] = rhs.currModelFilename;
|
||||
node["currModelFilename"] = patchFilenameToYaml(rhs.currModelFilename);
|
||||
node["contrast"] = rhs.contrast;
|
||||
node["vBatWarn"] = rhs.vBatWarn;
|
||||
node["txVoltageCalibration"] = rhs.txVoltageCalibration;
|
||||
|
||||
@@ -316,9 +316,11 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
||||
|
||||
QString modelFilename;
|
||||
if (hasCategories) {
|
||||
modelFilename = QString("MODELS/%1").arg(model.filename);
|
||||
modelFiles.push_back({std::string(model.filename),
|
||||
std::string(model.name), model.category});
|
||||
std::string ymlFilename = patchFilenameToYaml(model.filename);
|
||||
modelFilename =
|
||||
QString("MODELS/%1").arg(QString::fromStdString(ymlFilename));
|
||||
modelFiles.push_back(
|
||||
{ymlFilename, std::string(model.name), model.category});
|
||||
} else {
|
||||
modelFilename = QString("MODELS/model%1.yml")
|
||||
.arg(model.modelIndex, 2, 10, QLatin1Char('0'));
|
||||
|
||||
Reference in New Issue
Block a user