void ChatLog::FillLastLineArray()
{
    int fd ( open(GetCurrentLogfilePath().mb_str(), O_RDONLY) );
    if ( fd < 0 )
    {
        wxLogError(_T("%s: failed to open log file."), __PRETTY_FUNCTION__);
        return;
    }
    size_t num_lines ( sett().GetAutoloadedChatlogLinesCount() );

    m_last_lines.Clear();
    m_last_lines.Alloc(num_lines);

    const wxChar* wc_EOL ( wxTextBuffer::GetEOL() );
    size_t eol_num_chars ( wxStrlen(wc_EOL) );
#ifndef WIN32
    char* eol ( static_cast<char*>( alloca(eol_num_chars) ) );
#else
    char* eol ( new char[eol_num_chars] );
#endif
    wxConvUTF8.WC2MB(eol, wc_EOL, eol_num_chars);

    size_t lines_added ( find_tail_sequences(fd, eol, eol_num_chars, num_lines, m_last_lines) );
    wxLogMessage(_T("ChatLog::FillLastLineArray: Loaded %lu lines from %s."), lines_added, GetCurrentLogfilePath().c_str());
    close(fd);

#ifdef WIN32
    delete[] eol;
#endif
}
Exemple #2
0
void ChatLog::FillLastLineArray()
{
	m_last_lines.Clear();

	if (!m_logfile.IsOpened()) {
		wxLogError(_T("%s: failed to open log file."), __PRETTY_FUNCTION__);
		return;
	}

	if (m_logfile.Length() <= 0) {
		return;
	}

#ifdef TEST
	const size_t num_lines = 6;
#else
	const size_t num_lines = sett().GetAutoloadedChatlogLinesCount();
#endif

	m_last_lines.Alloc(num_lines);

	const wxChar* wc_EOL(wxTextBuffer::GetEOL());
	const size_t eol_num_chars(wxStrlen(wc_EOL));
#ifndef WIN32
	char* eol(static_cast<char*>(alloca(eol_num_chars)));
#else
	char* eol(new char[eol_num_chars]);
#endif
	wxConvUTF8.WC2MB(eol, wc_EOL, eol_num_chars);

	const size_t lines_added = find_tail_sequences(m_logfile, eol, eol_num_chars, num_lines, m_last_lines);
	wxLogMessage(_T("ChatLog::FillLastLineArray: Loaded %lu lines from %s."), lines_added, GetCurrentLogfilePath().c_str());

#ifdef WIN32
	delete[] eol;
#endif
	m_logfile.SeekEnd();
}