コード例 #1
0
//////////////////////////////////////////////////////////
//
// 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";
}
コード例 #2
0
ファイル: CBassAudio.cpp プロジェクト: Bargas/mtasa-blue
//
// 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;
            }
        }
    }
}