* @brief Starts a ZMODEM file transfer. */
| 74 | * @brief Starts a ZMODEM file transfer. |
| 75 | */ |
| 76 | void IO::Protocols::ZMODEM::startTransfer(const QString& filePath) |
| 77 | { |
| 78 | Q_ASSERT(!filePath.isEmpty()); |
| 79 | Q_ASSERT(m_maxRetries > 0); |
| 80 | |
| 81 | if (isActive()) |
| 82 | cancelTransfer(); |
| 83 | |
| 84 | m_file.setFileName(filePath); |
| 85 | if (!m_file.open(QIODevice::ReadOnly)) { |
| 86 | Q_EMIT finished(false, tr("Cannot open file: %1").arg(m_file.errorString())); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | m_filePath = filePath; |
| 91 | m_fileSize = m_file.size(); |
| 92 | m_bytesSent = 0; |
| 93 | m_fileOffset = 0; |
| 94 | m_retryCount = 0; |
| 95 | m_parseState = ParseState::Idle; |
| 96 | m_headerBuf.clear(); |
| 97 | m_zdleEscape = false; |
| 98 | |
| 99 | static constexpr qint64 kZmodemMaxFileSize = static_cast<qint64>(0xFFFFFFFFULL); |
| 100 | if (m_fileSize > kZmodemMaxFileSize) [[unlikely]] { |
| 101 | m_file.close(); |
| 102 | Q_EMIT finished(false, |
| 103 | tr("File is too large for ZMODEM (%1 bytes, limit 4 GiB).").arg(m_fileSize)); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | Q_EMIT progressChanged(0, m_fileSize); |
| 108 | |
| 109 | sendZRQINIT(); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @brief Cancels the current transfer. |
no test coverage detected