Example #1
0
int
P4ClientApi::FormatSpec( const char * type, int table )
{
	if ( !specMgr.HaveSpecDef( type ) )
	{
		StrBuf m;
		m = "No spec definition for ";
		m.Append( type );
		m.Append( " objects." );
		return Except( "P4#format_spec", m.Text() );
	}

	// Got a specdef so now we can attempt to convert.
	StrBuf	buf;
	Error	e;

	specMgr.SpecToString( type, table, buf, &e );
	if( !e.Test() ) {
		lua_pushstring( L, buf.Text() );
		return 1;
	}

	StrBuf m;
	m = "Error converting hash to a string.";
	if( e.Test() ) e.Fmt( m, EF_PLAIN );
	return Except( "P4#format_spec", m.Text() );
}
Example #2
0
bool Provider::Connect()
{
    if ( m_IsConnected )
    {
        // This extra 'info' command is unfortunate but necessary
        //  .Dropped() can only be trusted immediately after .Run(), so do a lightweight run here to update .Dropped()'s state

        class NullClient : public ClientUser
        {
        public:
            virtual void OutputInfo( char level, const char* data ) {}
            virtual void OutputError( const char* data )            {}
        } nullClient;

        m_Client.SetBreak( this );
        m_Client.Run( "info", &nullClient );
    }

    if ( m_Client.Dropped() )
    {
        Error e;
        m_Client.Final( &e );
        m_IsConnected = false;

#ifdef PERFORCE_DEBUG_CONNECT
        if ( e.Test() )
        {
            StrBuf buf;
            e.Fmt( &buf, EF_PLAIN );
            Log::Warning( "%s\n", buf.Text() );
        }
#endif
    }

    if ( !m_IsConnected )
    {
        Error e;
        m_Client.SetProtocol( "tag", "" );
        m_Client.Init( &e );
        m_Client.SetBreak( this );

#ifdef PERFORCE_DEBUG_CONNECT
        if ( e.Test() )
        {
            StrBuf buf;
            e.Fmt( &buf, EF_PLAIN );
            Log::Warning( "%s\n", buf.Text() );
        }
#endif

        char buf[ 64 ];
        sprintf_s( buf, sizeof(buf), "Perforce.dll" );
        buf[ sizeof(buf) - 1 ] = 0; 

        m_Client.SetProg( buf );

        bool converted = Helium::ConvertString( m_Client.GetUser().Text(), m_UserName );
        HELIUM_ASSERT( converted );

        converted = Helium::ConvertString( m_Client.GetClient().Text(), m_ClientName );
        HELIUM_ASSERT( converted );

        m_IsConnected = e.Test() == 0;
    }

    return m_IsConnected;
}