bool ArticleDownloader::Write(char* szLine, int iLen) { if (!m_pOutFile && !PrepareFile(szLine)) { return false; } if (g_pOptions->GetDecode()) { bool bOK = false; if (m_eFormat == Decoder::efYenc) { bOK = m_YDecoder.Write(szLine, iLen, m_pOutFile); } else if (m_eFormat == Decoder::efUx) { bOK = m_UDecoder.Write(szLine, iLen, m_pOutFile); } else { warn("Decoding %s failed: unsupported encoding", m_szInfoName); return false; } if (!bOK) { debug("Failed line: %s", szLine); warn("Decoding %s failed", m_szInfoName); } return bOK; } else { return fwrite(szLine, 1, iLen, m_pOutFile) > 0; } }
void SendTransaction::Go() { socket_ = new QUdpSocket; connect(this->thread(), SIGNAL(finished()), socket_, SLOT(deleteLater())); socket_->bind(); timeout_ = timeout_for_permission_; if (!RequestId()) { return; } PrepareFile(); timeout_ = timeout_for_sending_; if (!SendFile()) { emit TransmissionFailed(State::Error::SEND_DATA_FAILED); return; } if (!FinishSending()) { emit TransmissionFailed(State::Error::FINISH_FAILED); return; } emit TransmissionFinished(); }
/*********************************************************************************** ** Fully update an existing message in the store (overwrites existing message) ** ** MboxMonthly::UpdateMessage ** @param message Message to update ** @param mbx_data Existing mbx_data from the store if there was any, 0 otherwise. ** Might be changed by this function to have new mbx_data. ** @return OpStatus::OK if save was successful, error codes otherwise ***********************************************************************************/ OP_STATUS MboxMonthly::UpdateMessage(StoreMessage& message, INT64& mbx_data) { // Construct file - will be closed on destruction OpFile file; // Get sent time of message time_t date; RETURN_IF_ERROR(message.GetDateHeaderValue(Header::DATE, date)); // Prepare file for writing RETURN_IF_ERROR(PrepareFile(file, message.GetId(), message.GetAccountId(), date, FALSE, mbx_data != 0)); // Go to correct position (if there already was mbx_data), which is past the from header - else write the from header if (mbx_data != 0) RETURN_IF_ERROR(file.SetFilePos(mbx_data)); else RETURN_IF_ERROR(WriteFromLine(message, file)); // Set the mbx_data past the from header, start of the raw message OpFileLength length; RETURN_IF_ERROR(file.GetFilePos(length)); mbx_data = length; // Write message to file RETURN_IF_ERROR(WriteRawMessage(message, file)); // Close file, making sure it's written to disk return file.SafeClose(); }
ULONG CLogFile::BeginBatch() { if (m_threshold == 0) return 0; if (m_lBatch == -1) return 0; if (!PrepareFile()) return 0; return ++m_lBatch; }
size_t CLogFile::TraceLog(const void* pData, size_t size) { if (m_threshold == 0) return 0; if (!PrepareFile() && m_hFile == INVALID_HANDLE_VALUE) return FALSE; DWORD writesize = 0; if (!::WriteFile(m_hFile, pData, size, &writesize, NULL)) return 0; return writesize; }
/*********************************************************************************** ** Update the status of an existing message in the store ** ** MboxMonthly::UpdateMessageStatus ** @param message Message to update ** @param mbx_data Existing mbx_data from the store if there was any, 0 otherwise. ** Might be changed by this function to have new mbx_data. ** @return OpStatus::OK if save was successful, error codes otherwise ***********************************************************************************/ OP_STATUS MboxMonthly::UpdateMessageStatus(StoreMessage& message, INT64& mbx_data) { OpFile file; OpString8 buf; time_t sent_date; // Get sent time of message RETURN_IF_ERROR(message.GetDateHeaderValue(Header::DATE, sent_date)); // Prepare file for reading and writing RETURN_IF_ERROR(PrepareFile(file, message.GetId(), message.GetAccountId(), sent_date, FALSE, mbx_data)); // Write X-Opera-Status line return WriteStatusLine(message, file); }
** ID and sent date ** @return OpStatus::OK if message was found and retrieved, ** OpStatus::ERR_FILE_NOT_FOUND if not found, error codes otherwise ***********************************************************************************/ OP_STATUS MboxMonthly::GetMessage(INT64 mbx_data, StoreMessage& message, BOOL override) { OpFile file; // Get time of message time_t date; RETURN_IF_ERROR(message.GetDateHeaderValue(Header::DATE, date)); // Prepare file for reading RETURN_IF_ERROR(PrepareFile(file, message.GetId(), message.GetAccountId(), date, TRUE, mbx_data)); // Read message from file return ReadRawMessage(message, file, override); } /*********************************************************************************** ** Remove a message from the store ** ** MboxMonthly::RemoveMessage ** @param mbx_data mbx_data that was saved with the message ** @param id Message to remove ** @param account_id Account of this message ** @param sent_date Time when message was sent ** @param draft Whether this was a draft