src/PepperGrains/Addons.cpp
// Parse a package and add to the loading list
Parse a package and add to the loading list
Parse a package and add to the loading list
void preloadAddon(std::string strPackageDir) {
        boost::filesystem::path packageDir(strPackageDir);
        if(!boost::filesystem::exists(packageDir)) {
            Logger::log(Logger::WARN) << "Addon directory does not exist: " << packageDir << std::endl;
            return;
        }
        Json::Value jPackage;
        {
            std::ifstream reader((packageDir / "data.package").string().c_str());
            reader >> jPackage;
            reader.close();
        }
        Addon* addon = new Addon();
        Json::Value& jInfo = jPackage["info"];
        if(!jInfo.isNull()) {
            Json::Value& jName = jInfo["name"];
            Json::Value& jDesc = jInfo["description"];
            Json::Value& jAuthor = jInfo["author"];
            Json::Value& jLicense = jInfo["license"];
            if(!jName.isNull()) {
                addon->mName = jName.asString();
            }
            if(!jDesc.isNull()) {
                addon->mDesc = jDesc.asString();
            }
            if(!jAuthor.isNull()) {
                addon->mAuthor = jAuthor.asString();
            }
            if(!jLicense.isNull()) {
                addon->mLicense = jLicense.asString();
            }
        }
        Json::Value& jEnviron = jPackage["environment"];
        if(!jEnviron.isNull()) {
            Json::Value& jAddress = jEnviron["address"];
            Json::Value& jShare = jEnviron["share"];
            Json::Value& jRequire = jEnviron["requre"];
            Json::Value& jAfter = jEnviron["after"];
            if(!jAddress.isNull()) {
                addon->mAddress = jAddress.asString();
            }
            if(!jShare.isNull() && jShare.isArray()) {
                for(Json::Value::iterator iter = jShare.begin(); iter != jShare.end(); ++ iter) {
                    addon->mShare.push_back(iter->asString());
                    std::sort(addon->mShare.begin(), addon->mShare.end());
                }
            }
            if(!jRequire.isNull() && jRequire.isArray()) {
                for(Json::Value::iterator iter = jRequire.begin(); iter != jRequire.end(); ++ iter) {
                    addon->mRequire.push_back(iter->asString());
                    std::sort(addon->mRequire.begin(), addon->mRequire.end());
                }
            }
            if(!jAfter.isNull() && jAfter.isArray()) {
                for(Json::Value::iterator iter = jAfter.begin(); iter != jAfter.end(); ++ iter) {
                    addon->mAfter.push_back(iter->asString());
                    std::sort(addon->mAfter.begin(), addon->mAfter.end());
                }
            }
        }
        Json::Value& jBootstrap = jPackage["bootstrap"];
        if(!jBootstrap.isNull() && jBootstrap.isArray()) {
            for(Json::Value::iterator iter = jBootstrap.begin(); iter != jBootstrap.end(); ++ iter) {
                addon->mBootstap.push_back(iter->asString());
            }
        }
        const Json::Value& jResources = jPackage["resources"];
        Resources::populateResourceMap(addon->mResources, jResources, packageDir);
        mPreloadAddons.push_back(addon);
    }
void preloadAddon ( std :: string strPackageDir ) { boost :: filesystem :: path packageDir ( strPackageDir ) ; if ( ! boost :: filesystem :: exists ( packageDir ) ) { Logger :: log ( Logger :: WARN ) << " " << packageDir << std :: endl ; return ; } Json :: Value jPackage ; { std :: ifstream reader ( ( packageDir / " " ) . string ( ) . c_str ( ) ) ; reader >> jPackage ; reader . close ( ) ; } Addon * addon = new Addon ( ) ; Json :: Value & jInfo = jPackage [ " " ] ; if ( ! jInfo . isNull ( ) ) { Json :: Value & jName = jInfo [ " " ] ; Json :: Value & jDesc = jInfo [ " " ] ; Json :: Value & jAuthor = jInfo [ " " ] ; Json :: Value & jLicense = jInfo [ " " ] ; if ( ! jName . isNull ( ) ) { addon -> mName = jName . asString ( ) ; } if ( ! jDesc . isNull ( ) ) { addon -> mDesc = jDesc . asString ( ) ; } if ( ! jAuthor . isNull ( ) ) { addon -> mAuthor = jAuthor . asString ( ) ; } if ( ! jLicense . isNull ( ) ) { addon -> mLicense = jLicense . asString ( ) ; } } Json :: Value & jEnviron = jPackage [ " " ] ; if ( ! jEnviron . isNull ( ) ) { Json :: Value & jAddress = jEnviron [ " " ] ; Json :: Value & jShare = jEnviron [ " " ] ; Json :: Value & jRequire = jEnviron [ " " ] ; Json :: Value & jAfter = jEnviron [ " " ] ; if ( ! jAddress . isNull ( ) ) { addon -> mAddress = jAddress . asString ( ) ; } if ( ! jShare . isNull ( ) && jShare . isArray ( ) ) { for ( Json :: Value :: iterator iter = jShare . begin ( ) ; iter != jShare . end ( ) ; ++ iter ) { addon -> mShare . push_back ( iter -> asString ( ) ) ; std :: sort ( addon -> mShare . begin ( ) , addon -> mShare . end ( ) ) ; } } if ( ! jRequire . isNull ( ) && jRequire . isArray ( ) ) { for ( Json :: Value :: iterator iter = jRequire . begin ( ) ; iter != jRequire . end ( ) ; ++ iter ) { addon -> mRequire . push_back ( iter -> asString ( ) ) ; std :: sort ( addon -> mRequire . begin ( ) , addon -> mRequire . end ( ) ) ; } } if ( ! jAfter . isNull ( ) && jAfter . isArray ( ) ) { for ( Json :: Value :: iterator iter = jAfter . begin ( ) ; iter != jAfter . end ( ) ; ++ iter ) { addon -> mAfter . push_back ( iter -> asString ( ) ) ; std :: sort ( addon -> mAfter . begin ( ) , addon -> mAfter . end ( ) ) ; } } } Json :: Value & jBootstrap = jPackage [ " " ] ; if ( ! jBootstrap . isNull ( ) && jBootstrap . isArray ( ) ) { for ( Json :: Value :: iterator iter = jBootstrap . begin ( ) ; iter != jBootstrap . end ( ) ; ++ iter ) { addon -> mBootstap . push_back ( iter -> asString ( ) ) ; } } const Json :: Value & jResources = jPackage [ " " ] ; Resources :: populateResourceMap ( addon -> mResources , jResources , packageDir ) ; mPreloadAddons . push_back ( addon ) ; }
Parse a package and add to the loading list
Parse a package and add to the loading list