コード例 #1
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::CheckLuaFileForIssues
//
//
//
///////////////////////////////////////////////////////////////
void CResourceChecker::CheckLuaFileForIssues ( const string& strPath, const string& strFileName, const string& strResourceName, bool bClientScript )
{
    // Load the original file into a string
    SString strFileContents;

    // Open the file
    FileLoad ( strPath, strFileContents );
    if ( strFileContents.length () == 0 )
        return;

    // Update decrypt version requirements, and do no more checking if encrypted
    if ( CheckLuaDecryptRequirements( strFileContents, strFileName, strResourceName, bClientScript ) )
        return;

    // Check if a compiled script
    bool bCompiledScript = IsLuaCompiledScript( strFileContents.c_str(), strFileContents.length() );

    // Process
    if ( strFileContents.length () > 1000000 )
        CLogger::LogPrintf ( "Please wait...\n" );

    // Ouput warnings...
    if ( m_bUpgradeScripts == false )
    {
        CheckLuaSourceForIssues ( strFileContents, strFileName, strResourceName, bClientScript, bCompiledScript, ECheckerMode::WARNINGS );
    }
    else
    // ..or do an upgrade (if not compiled)
    if ( m_bUpgradeScripts == true && !bCompiledScript )
    {
        string strNewFileContents;
        CheckLuaSourceForIssues ( strFileContents, strFileName, strResourceName, bClientScript, bCompiledScript, ECheckerMode::UPGRADE, &strNewFileContents );

        // Has contents changed?
        if ( strNewFileContents.length () > 0 && strNewFileContents != strFileContents )
        {
            // Rename original to lua.old
            if( !RenameBackupFile( strPath, ".old" ) )
                return;

            // Save new content
            if ( FILE* pFile = fopen ( strPath.c_str (), "wb" ) )
            {
                fwrite ( strNewFileContents.c_str (), 1, strNewFileContents.length (), pFile );
                fclose ( pFile );
                CLogger::LogPrintf ( "Upgrading %s:%s ...........done\n", strResourceName.c_str (), strFileName.c_str () );

                m_upgradedFullPathList.push_back( strPath );
            }
        }
    }
}
コード例 #2
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::CheckMetaFileForIssues
//
//
//
///////////////////////////////////////////////////////////////
void CResourceChecker::CheckMetaFileForIssues ( const string& strPath, const string& strFileName, const string& strResourceName )
{
    // Load the meta file
    CXMLFile* metaFile = g_pServerInterface->GetXML ()->CreateXML ( strPath.c_str() );
    if ( !metaFile )
        return;

    CXMLNode* pRootNode = metaFile->Parse () ? metaFile->GetRootNode () : NULL;
    if ( !pRootNode )
    {
        delete metaFile;
        return;
    }

    // Ouput warnings...
    if ( m_bUpgradeScripts == false )
    {
        CheckMetaSourceForIssues ( pRootNode, strFileName, strResourceName, ECheckerMode::WARNINGS );
    }
    else
    // ..or do an upgrade
    if ( m_bUpgradeScripts == true )
    {
        bool bHasChanged = false;
        CheckMetaSourceForIssues ( pRootNode, strFileName, strResourceName, ECheckerMode::UPGRADE, &bHasChanged );

        // Has contents changed?
        if ( bHasChanged )
        {
            // Rename original to xml.old
            if( !RenameBackupFile( strPath, ".old" ) )
                return;

            // Save new content
            metaFile->Write ();
            CLogger::LogPrintf ( "Upgrading %s:%s ...........done\n", strResourceName.c_str (), strFileName.c_str () );

            m_upgradedFullPathList.push_back( strPath );
        }
    }

    delete metaFile;
}
コード例 #3
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::CheckResourceForIssues
//
// Check each file and do the appropriate action
//
///////////////////////////////////////////////////////////////
void CResourceChecker::CheckResourceForIssues( CResource* pResource, const string& strResourceZip )
{
    m_strMinClientReqFromMetaXml = pResource->GetMinClientReqFromMetaXml();
    m_strMinServerReqFromMetaXml = pResource->GetMinServerReqFromMetaXml();
    m_strReqClientVersion = "";
    m_strReqServerVersion = "";
    m_strReqClientReason = "";
    m_strReqServerReason = "";

    m_ulDeprecatedWarningCount = 0;
    m_upgradedFullPathList.clear ();

    // Check each file in the resource
    list < CResourceFile* > ::iterator iterf = pResource->IterBegin ();
    for ( ; iterf != pResource->IterEnd (); iterf++ )
    {
        CResourceFile* pResourceFile = *iterf;
        // Skip this one if validate=false in the meta.xml
        if ( stricmp( pResourceFile->GetMetaFileAttribute ( "validate" ).c_str (), "false" ) )
        {
            string strPath;
            if ( pResource->GetFilePath ( pResourceFile->GetName(), strPath ) )
            {
                CResourceFile::eResourceType type = pResourceFile->GetType ();

                bool bScript;
                bool bClient;
                if ( type == CResourceFile::RESOURCE_FILE_TYPE_SCRIPT )
                {
                    bScript = true;
                    bClient = false;
                }
                else
                if ( type == CResourceFile::RESOURCE_FILE_TYPE_CLIENT_SCRIPT )
                {
                    bScript = true;
                    bClient = true;
                }
                else
                if ( type == CResourceFile::RESOURCE_FILE_TYPE_CLIENT_FILE )
                {
                    bScript = false;
                    bClient = true;
                }
                else
                    continue;

                CheckFileForIssues ( strPath, pResourceFile->GetName(), pResource->GetName (), bScript, bClient, false );
            }
        }
    }

    // Also check meta.xml
    {
        SString strFilename = "meta.xml";
        string strPath;
        if ( pResource->GetFilePath ( strFilename, strPath ) )
        {
            CheckFileForIssues ( strPath, strFilename, pResource->GetName (), false, false, true );
        }
    }

    // Output deprecated warning if required
    if ( m_ulDeprecatedWarningCount )
    {
        CLogger::LogPrintf ( "Some files in '%s' use deprecated functions.\n", pResource->GetName ().c_str () );
        CLogger::LogPrintf ( "Use the 'upgrade' command to perform a basic upgrade of resources.\n" );
    }

    // Handle upgrading a zip file if required
    if ( m_upgradedFullPathList.size () )
    {
        if ( pResource->IsResourceZip () )
        {
            string strOrigZip = strResourceZip;
            string strTempZip = strResourceZip.substr ( 0, strResourceZip.length () - 4 ) + "_tmp.zip";

            string strCacheDir = pResource->GetResourceCacheDirectoryPath ();

            vector < string > pathInArchiveList;

            for ( unsigned long i = 0 ; i < m_upgradedFullPathList.size () ; i++ )
            {
                string strFullPath = m_upgradedFullPathList[i];
                string strPathInArchive = strFullPath.substr ( strCacheDir.length () );
                pathInArchiveList.push_back ( strPathInArchive );
            }

            File::Delete( strTempZip.c_str () );

            if ( !ReplaceFilesInZIP( strOrigZip, strTempZip, pathInArchiveList, m_upgradedFullPathList ) )
            {
                CLogger::LogPrintf ( "Failed to upgrade (ReplaceFilesInZIP) '%s'\n", strOrigZip.c_str () );
            }
            else
            {
                if ( !RenameBackupFile( strOrigZip, ".old" ) )
                {
                    CLogger::LogPrintf ( "Failed to upgrade (RenameBackupFile) '%s'\n", strOrigZip.c_str () );
                }
                else
                {
                    if ( File::Rename( strTempZip.c_str (), strOrigZip.c_str () ) )
                    {
                        CLogger::LogPrintf ( "Failed to upgrade (rename) '%s'\n", strOrigZip.c_str () );
                    }
                }
            }

            File::Delete( strTempZip.c_str () );
        }
    }

    // Check LC_COLLATE is correct
    if ( strcoll( "a", "B" ) < 0 )
    {
        CLogger::LogPrintf ( "ERROR: LC_COLLATE is not set correctly\n" );
    }
}