MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / fileSave

Method fileSave

app/src/API/Handlers/ProjectHandler.cpp:1616–1647  ·  view source on GitHub ↗

* @brief Save project */

Source from the content-addressed store, hash-verified

1614 * @brief Save project
1615 */
1616API::CommandResponse API::Handlers::ProjectHandler::fileSave(const QString& id,
1617 const QJsonObject& params)
1618{
1619 const QString explicit_path = params.value(QStringLiteral("filePath")).toString();
1620
1621 DataModel::ProjectModel::instance().setSuppressMessageBoxes(true);
1622 bool success = false;
1623 if (!explicit_path.isEmpty()) {
1624 if (!API::isPathAllowed(explicit_path)) {
1625 DataModel::ProjectModel::instance().setSuppressMessageBoxes(false);
1626 return CommandResponse::makeError(
1627 id, ErrorCode::InvalidParam, QStringLiteral("filePath is not allowed"));
1628 }
1629
1630 success = DataModel::ProjectModel::instance().apiSaveJsonFile(explicit_path);
1631 } else {
1632 const bool ask_path = params.value(QStringLiteral("askPath")).toBool(false);
1633 success = DataModel::ProjectModel::instance().saveJsonFile(ask_path);
1634 }
1635
1636 DataModel::ProjectModel::instance().setSuppressMessageBoxes(false);
1637
1638 if (!success) {
1639 return CommandResponse::makeError(
1640 id, ErrorCode::OperationFailed, QStringLiteral("Failed to save project"));
1641 }
1642
1643 QJsonObject result;
1644 result[QStringLiteral("saved")] = true;
1645 result[QStringLiteral("filePath")] = DataModel::ProjectModel::instance().jsonFilePath();
1646 return CommandResponse::makeSuccess(id, result);
1647}
1648
1649//--------------------------------------------------------------------------------------------------
1650// Getters

Callers

nothing calls this directly

Calls 5

isEmptyMethod · 0.80
apiSaveJsonFileMethod · 0.80
saveJsonFileMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected