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
}
bool ChatLog::OpenLogFile()
{
    wxLogMessage( _T( "OpenLogFile( ) server = %s, room = %s" ), m_server.c_str(), m_room.c_str() ) ;
    wxString logFilePath ( GetCurrentLogfilePath() );

    if ( LogEnabled() && CreateCurrentLogFolder() ) {
        m_logfile.Open( logFilePath, wxFile::write_append );

        if ( !m_logfile.IsOpened() ) {
            wxLogWarning( _T( "Can't open log file %s" ), logFilePath.c_str() ) ;
            customMessageBox( SL_MAIN_ICON,
                              _( "Can't open log file \"" ) + logFilePath + _("\".\nBe sure that there isn't a write protection.\n" ),
                              _( "Log Warning" ) ) ;
            m_active = false;
        }
        else {
            FillLastLineArray();

            wxDateTime now = wxDateTime::Now();
            wxString text = _T( "### Session Start at [" ) + now.Format( _T( "%Y-%m-%d %H:%M" ) ) + _T( "]" ) + wxTextBuffer::GetEOL();
            return WriteLine( text );
        }
    }
    return false;
}
Beispiel #3
0
bool ChatLog::OpenLogFile()
{
	wxLogMessage(_T( "OpenLogFile( ) %s" ), m_logname.c_str());
	wxString logFilePath(GetCurrentLogfilePath());

	if (!LogEnabled()) {
		return true;
	}

	if (!CreateCurrentLogFolder()) {
		return false;
	}

	if (!wxFile::Exists(logFilePath)) {
		m_logfile.Create(logFilePath);
	} else {
		m_logfile.Open(logFilePath, wxFile::read_write);
	}

	if (!m_logfile.IsOpened()) {
		wxLogWarning(_T( "Can't open log file %s" ), logFilePath.c_str());
		m_active = false;
		return false;
	}

	FillLastLineArray();
	m_active = true;

	return AddMessage(wxDateTime::Now().Format(_("### Session Start at [%Y-%m-%d %H:%M]")));
}
Beispiel #4
0
bool ChatLog::CreateCurrentLogFolder()
{
	const wxString path = wxFileName(GetCurrentLogfilePath()).GetPath();
	if (!wxFileName::Mkdir(path, 0755, wxPATH_MKDIR_FULL)) {
		wxLogWarning(_T( "can't create logging folder: %s" ), path.c_str());
		m_active = false;
		return false;
	}
	return true;
}
bool ChatLog::CreateCurrentLogFolder()
{
    wxString path ( wxFileName(GetCurrentLogfilePath()).GetPath() );
    if ( !tryCreateDirectory( path ) ) {
        wxLogWarning( _T( "can't create logging folder: %s" ), path.c_str() );
        customMessageBox( SL_MAIN_ICON,
                          _( "Couldn't create folder. \nBe sure that there isn't a write protection.\n" ) + path
                          + _( "Log function is disabled until restart SpringLobby." ), _( "Log Warning" ) );
        m_active = false;
        return false;
    }
    return true;
}
void ChatLog::OpenInEditor()
{
    ui().OpenFileInEditor( GetCurrentLogfilePath());
}
Beispiel #7
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();
}