void ResourceLoader::loadFromModel( Path path2model, const Directory dir )
{
  VariantMap archives = config::load( path2model );
  for( auto& entry : archives )
  {
    Path absArchivePath( entry.second.toString() );

    if( !absArchivePath.exist() )
    {
      Path rpath = entry.second.toString();
      absArchivePath = dir/rpath;
    }
    Logger::warning( "ResourceLoader: try mount archive " + absArchivePath.toString() );

    Directory absDir = absArchivePath.directory();
    absArchivePath = absDir.find( absArchivePath.baseName(), Path::ignoreCase );       

    ArchivePtr archive = FileSystem::instance().mountArchive( absArchivePath );

    if( archive.isValid() )
    {
      emit _d->onStartLoadingSignal( entry.first );

      NFile archiveInfo = archive->createAndOpenFile( archiveDescFile );
      loadAtlases( archiveInfo, true );

      //FileSystem::instance().unmountArchive( archive );
    }
    else
    {
      Logger::warning( "ResourceLoader: cannot load archive " + absArchivePath.toString() );
    }
  }
}
void ResourceLoader::loadFiles(Path path)
{
  ArchivePtr archive = FileSystem::instance().mountArchive( path );
  if( archive.isValid() )
  {
    loadFiles( archive );
    FileSystem::instance().unmountArchive( archive );
  }
}
Exemple #3
0
void ViewManager::restoreViews(ArchivePtr archive, const std::string& key, ViewManager::ViewStateInfo& out_viewStateInfo)
{
    MessageView* mv = MessageView::instance();

    typedef map<ViewInfo*, vector<View*> > ViewsMap;
    ViewsMap remainingViewsMap;
        
    Listing* viewList = archive->findListing(key);
    
    if(viewList->isValid() && !viewList->empty()){

        vector<ViewState>* viewsToRestoreState = new vector<ViewState>();        
        out_viewStateInfo.data = viewsToRestoreState;
        int id;
        string moduleName;
        string className;
        string instanceName;
        
        for(int i=0; i < viewList->size(); ++i){
            Archive* viewArchive = dynamic_cast<Archive*>(viewList->at(i)->toMapping());
            if(viewArchive){
                bool isHeaderValid =
                    viewArchive->read("id", id) &&
                    viewArchive->read("plugin", moduleName) &&
                    viewArchive->read("class", className);
            
                if(isHeaderValid){
                    View* view = 0;
                    if(!viewArchive->read("name", instanceName)){
                        view = getOrCreateView(moduleName, className);
                    } else {
                        // get one of the view instances having the instance name, or create a new instance.
                        // Different instances are assigned even if there are instances with the same name in the archive
                        ViewInfo* info = findViewInfo(moduleName, className);
                        if(info){
                            vector<View*>* remainingViews;
                            ViewsMap::iterator p = remainingViewsMap.find(info);
                            if(p != remainingViewsMap.end()){
                                remainingViews = &p->second;
                            } else {
                                remainingViews = &remainingViewsMap[info];
                                InstanceInfoList& instances = info->instances;
                                remainingViews->reserve(instances.size());
                                InstanceInfoList::iterator q = instances.begin();
                                if(info->hasDefaultInstance() && q != instances.end()){
                                    ++q;
                                }
                                while(q != instances.end()){
                                    remainingViews->push_back((*q++)->view);
                                }
                            }
                            for(vector<View*>::iterator q = remainingViews->begin(); q != remainingViews->end(); ++q){
                                if((*q)->name() == instanceName){
                                    view = *q;
                                    remainingViews->erase(q);
                                    break;
                                }
                            }
                            if(!view){
                                if(!info->isSingleton() || info->instances.empty()){
                                    view = info->createView(instanceName, true);
                                } else {
                                    mv->putln(MessageView::ERROR,
                                              boost::format(_("A singleton view \"%1%\" of the %2% type cannot be created because its singleton instance has already been created."))
                                              % instanceName % info->className());
                                }
                            }
                        }
                    }
                    if(view){
                        archive->registerViewId(view, id);
                        
                        ArchivePtr state = viewArchive->findSubArchive("state");
                        if(state->isValid()){
                            state->inheritSharedInfoFrom(*archive);
                            viewsToRestoreState->push_back(ViewState(view, state));
                        }

                        if(viewArchive->get("mounted", false)){
                            mainWindow->viewArea()->addView(view);
                        }
                    }
                }
            }
        }
    }
}