//
// Process next BrowseToSolution
//
void SharedUtil::ProcessPendingBrowseToSolution ( void )
{
    SString strType, strMessageBoxMessage;
    int bAskQuestion;

    // Get args from the registry
    CArgMap argMap;
    argMap.SetFromString ( GetApplicationSetting ( "pending-browse-to-solution" ) );
    argMap.Get ( "type", strType );
    argMap.Get ( "message", strMessageBoxMessage );
    argMap.Get ( "bAskQuestion", bAskQuestion );

    // Check if anything to do
    if ( strType.empty () )
        return;

    ClearPendingBrowseToSolution ();

    // Show message box if required
    if ( !strMessageBoxMessage.empty () )
        MessageBox ( 0, strMessageBoxMessage, "Error", MB_OK|MB_ICONEXCLAMATION );

    // Ask question if required, and then launch URL
    if ( !bAskQuestion || IDYES == MessageBox( 0, "Do you want to see some on-line help about this problem ?", "MTA: San Andreas", MB_ICONQUESTION|MB_YESNO ) )
    {
        SString strQueryURL = GetApplicationSetting ( "trouble-url" );
        if ( strQueryURL == "" )
            strQueryURL = TROUBLE_URL1;
        strQueryURL = strQueryURL.Replace ( "%VERSION%", GetApplicationSetting ( "mta-version-ext" ) );
        strQueryURL = strQueryURL.Replace ( "%ID%", GetApplicationSetting ( "serial" ) );
        strQueryURL = strQueryURL.Replace ( "%TROUBLE%", strType );
        ShellExecuteNonBlocking ( "open", strQueryURL.c_str () );
    }
}
///////////////////////////////////////////////////////////////
//
// CDatabaseConnectionMySql::CDatabaseConnectionMySql
//
//
//
///////////////////////////////////////////////////////////////
CDatabaseConnectionMySql::CDatabaseConnectionMySql ( CDatabaseType* pManager, const SString& strHost, const SString& strUsername, const SString& strPassword, const SString& strOptions )
    : m_iRefCount ( 1 )
    , m_pManager ( pManager )
{
    // Parse options string
    CArgMap optionsMap ( "=", ";" );
    optionsMap.SetFromString ( strOptions );
    optionsMap.Get ( "autoreconnect", m_bAutomaticReconnect, 1 );
    optionsMap.Get ( "batch", m_bAutomaticTransactionsEnabled, 1 );

    SString strHostname;
    SString strDatabaseName;
    int iPort = 0;
    SString strUnixSocket;
    ulong ulClientFlags = 0;

    // Parse host string
    CArgMap argMap ( "=", ";" );
    argMap.SetFromString ( strHost );
    argMap.Get ( "dbname", strDatabaseName, "" );
    argMap.Get ( "host", strHostname, "localhost" );
    argMap.Get ( "port", iPort, 0 );
    argMap.Get ( "unix_socket", strUnixSocket, "" );

    m_handle = mysql_init ( NULL );
    if ( m_handle )
    {
        my_bool reconnect = m_bAutomaticReconnect;
        mysql_options ( m_handle, MYSQL_OPT_RECONNECT, &reconnect );

        if ( mysql_real_connect ( m_handle, strHostname, strUsername, strPassword, strDatabaseName, iPort, strUnixSocket, ulClientFlags ) )
            m_bOpened = true;
        else
        {
            SetLastError ( mysql_errno( m_handle ), mysql_error ( m_handle ) );
        }
    }
}
//////////////////////////////////////////////////////////
//
// CInstallManager::_InstallNewsItems
//
//
//
//////////////////////////////////////////////////////////
SString CInstallManager::_InstallNewsItems ( void )
{
    // Get install news queue
    CArgMap queue;
    queue.SetFromString ( GetApplicationSetting ( "news-install" ) );
    SetApplicationSetting ( "news-install", "" );

    std::vector < SString > keyList;
    queue.GetKeys ( keyList );
    for ( uint i = 0 ; i < keyList.size () ; i++ )
    {
        // Install each file
        SString strDate = keyList[i];
        SString strFileLocation = queue.Get ( strDate );

        // Save cwd
        SString strSavedDir = GetSystemCurrentDirectory ();

        // Calc and make target dir
        SString strTargetDir = PathJoin ( GetMTADataPath (), "news", strDate );
        MkDir ( strTargetDir );

        // Extract into target dir
        SetCurrentDirectory ( strTargetDir );

        // Try to extract the files
        if ( !ExtractFiles ( strFileLocation ) )
        {
            // If extract failed and update file is an exe, try to run it
            if ( ExtractExtension ( strFileLocation ).CompareI ( "exe" ) )
                ShellExecuteBlocking ( "open", strFileLocation, "-s" );
        }

        // Restore cwd
        SetCurrentDirectory ( strSavedDir );

        // Check result
        if ( FileExists ( PathJoin ( strTargetDir, "files.xml" ) ) )
        {
            SetApplicationSettingInt ( "news-updated", 1 );
            AddReportLog ( 2051, SString ( "InstallNewsItems ok for '%s'", *strDate ) );
        }
        else
        {
            AddReportLog ( 4048, SString ( "InstallNewsItems failed with '%s' '%s' '%s'", *strDate, *strFileLocation, *strTargetDir ) );
        }
    }
    return "ok";
}
Exemple #4
0
//
// Extract and map data from a shoutcast meta string
//
void CBassAudio::ParseShoutcastMeta ( const SString& strMeta )
{
    // Get title
    int startPos = strMeta.find ( "=" );
    SString strStreamTitle = strMeta.SubStr ( startPos + 2, strMeta.find ( ";" ) - startPos - 3 );

    if ( !strStreamTitle.empty () )
        m_strStreamTitle = strStreamTitle;

    // Get url
    startPos = strMeta.find ( "=" , startPos + 1 );
    SString strStreamUrl = strMeta.SubStr ( startPos + 2, strMeta.find ( ";", startPos ) - startPos - 3 );

    // Extract info from url
    CArgMap shoutcastInfo;
    shoutcastInfo.SetEscapeCharacter ( '%' );
    shoutcastInfo.SetFromString ( strStreamUrl );

    // Convert from shoutcast identifiers to map of tags
    static const char* convList[] = {
                        // Mapable
                        "%ARTI", "artist",
                        "%TITL", "title",
                        "%ALBM", "album",

                        // Mapable, but possibly don't exist
                        "%GNRE", "genre",
                        "%YEAR", "year",
                        "%CMNT", "comment",
                        "%TRCK", "track",
                        "%COMP", "composer",
                        "%COPY", "copyright",
                        "%SUBT", "subtitle",
                        "%AART", "albumartist",

                        // Not mapabale
                        "%DURATION", "duration",
                        "%SONGTYPE", "songtype",
                        "%OVERLAY", "overlay",
                        "%BUYCD", "buycd",
                        "%WEBSITE", "website",
                        "%PICTURE", "picture",
                   };

    std::vector < SString > shoutcastKeyList;
    shoutcastInfo.GetKeys ( shoutcastKeyList );

    // For each shoutcast pair
    for ( std::vector < SString >::iterator iter = shoutcastKeyList.begin () ; iter != shoutcastKeyList.end () ; ++iter )
    {
        const SString& strKey = *iter;
        SString strValue = shoutcastInfo.Get ( strKey );

        // Find %TAG match
        for ( uint i = 0 ; i < NUMELMS( convList ) - 1 ; i += 2 )
        {
            if ( strKey == convList[ i + 1 ] )
            {
                MapSet ( m_ConvertedTagMap, convList[ i ], strValue );
                break;
            }
        }
    }
}