* @brief Creates a new MDF4 file with hierarchical structure */
| 396 | * @brief Creates a new MDF4 file with hierarchical structure |
| 397 | */ |
| 398 | void MDF4::ExportWorker::createFile(const DataModel::Frame& frame) |
| 399 | { |
| 400 | if (isResourceOpen()) |
| 401 | closeResources(); |
| 402 | |
| 403 | const auto& token = Licensing::CommercialToken::current(); |
| 404 | if (!token.isValid() || !SS_LICENSE_GUARD() |
| 405 | || token.featureTier() < Licensing::FeatureTier::Trial) |
| 406 | return; |
| 407 | |
| 408 | const auto dateTime = QDateTime::currentDateTime(); |
| 409 | const auto fileName = |
| 410 | dateTime.toString(QStringLiteral("yyyy-MM-dd_HH-mm-ss")) + QStringLiteral(".mf4"); |
| 411 | const QString frameName = sanitizeFrameTitle(frame.title); |
| 412 | |
| 413 | QDir dir(Misc::WorkspaceManager::instance().path("MDF4")); |
| 414 | if (!dir.exists(frameName)) |
| 415 | dir.mkpath(frameName); |
| 416 | |
| 417 | dir.cd(frameName); |
| 418 | m_filePath = dir.filePath(fileName); |
| 419 | |
| 420 | try { |
| 421 | if (!initWriterAndHeader(frameName, dateTime)) |
| 422 | return; |
| 423 | |
| 424 | auto* dataGroup = m_writer->CreateDataGroup(); |
| 425 | if (!dataGroup) |
| 426 | return; |
| 427 | |
| 428 | dataGroup->Description("Serial Studio Data"); |
| 429 | buildChannelGroups(dataGroup, frame); |
| 430 | |
| 431 | m_writer->InitMeasurement(); |
| 432 | m_writer->StartMeasurement(dateTime.toMSecsSinceEpoch() * 1000000); |
| 433 | |
| 434 | m_fileOpen = true; |
| 435 | Q_EMIT resourceOpenChanged(); |
| 436 | } catch (const std::exception& e) { |
| 437 | qWarning() << "[MDF4] Failed to create file:" << e.what(); |
| 438 | m_fileOpen = false; |
| 439 | m_writer.reset(); |
| 440 | } catch (...) { |
| 441 | qWarning() << "[MDF4] Failed to create file: unknown exception"; |
| 442 | m_fileOpen = false; |
| 443 | m_writer.reset(); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | #endif |
| 448 |
nothing calls this directly
no test coverage detected