Exemple #1
0
 void serialize(ArchivePtr& par)
 {
    par->update(m_b);
    par->update(m_d);
    par->update(m_i);
    par->update(m_str);
 }
Exemple #2
0
	void TestParser(const String& dir, const String& suff, const String& pattern) {
		suffix = suff;
		ArchivePtr arch = FileSystem::Instance().OpenArchive("EngineData");
		if (arch) {
			arch->Scan(this, dir + "/" + pattern);
		}
	}
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 #5
0
void ViewArea::storeAllViewAreaLayouts(ArchivePtr archive)
{
    ListingPtr layouts = new Listing();
    for(size_t i=0; i < viewAreas.size(); ++i){
        ArchivePtr layout = new Archive();
        layout->inheritSharedInfoFrom(*archive);
        viewAreas[i]->storeLayout(layout);
        layouts->append(layout);
    }
    if(!layouts->empty()){
        archive->insert("viewAreas", layouts);
    }
}
bool ItemTreeArchiver::restore(ArchivePtr archive, ItemPtr parentItem)
{
    bool result = false;

    archive->setCurrentParentItem(0);

    try {
        result = restoreItemIter(archive.get(), parentItem);
    } catch (const YamlNode::Exception& ex) {
        messageView->put(ex.message());
    }

    archive->setCurrentParentItem(0);

    return result;
}
void initialize(ClimateType climate)
{
    VariantMap climateArchives = config::load( SETTINGS_RC_PATH( climateModel ) );

    std::string optName;
    if( climate == central ) {
        optName = CAESARIA_STR_A(central);
    }
    else if( climate == northen )  {
        optName = "north";
    }
    else if( climate == desert ) {
        optName = "south";
    }

    StringArray archives = climateArchives.get( optName ).toStringArray();

    for( auto& str : archives )
    {
        Path archivePath = str;
        Directory dir = archivePath.directory();

        archivePath = dir.find( archivePath.baseName(), Path::ignoreCase );

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

        if( archive.isNull() )
        {
            Logger::warning( "ClimateManager: can't load file " + archivePath.toString() );
            continue;
        }

        ResourceLoader rc;
        NFile atlasInfo = archive->createAndOpenFile( "info" );
        if( atlasInfo.isOpen() )
        {
            rc.loadAtlases( atlasInfo, false );
        }
        else
        {
            rc.loadFiles( archive );
        }
    }
}
bool SensorVisualizerItem::store(Archive& archive)
{
    ListingPtr subItems = new Listing();

    for(size_t i=0; i < impl->subItems.size(); i++){
        Item* item = impl->subItems[i];
        string pluginName, className;
        ItemManager::getClassIdentifier(item, pluginName, className);

        ArchivePtr subArchive = new Archive();
        subArchive->write("class", className);
        subArchive->write("name", item->name());
        item->store(*subArchive);

        subItems->append(subArchive);
    }

    archive.insert("subItems", subItems);

    return true;
}
void ResourceLoader::loadFiles(ArchivePtr archive)
{
  const vfs::Entries::Items& files = archive->entries()->items();
  gfx::PictureBank& pb = gfx::PictureBank::instance();

  std::string basename;
  basename.reserve( 256 );
  for( auto& entry : files )
  {
    NFile file = archive->createAndOpenFile( entry.name );
    if( file.isOpen() )
    {
      gfx::Picture pic = PictureLoader::instance().load( file );
      if( pic.isValid() )
      {
        basename = entry.name.baseName().toString();
        pb.setPicture( basename, pic );
      }
    }
  }
}
void ArchiveListWidget::deleteItem()
{
    ArchiveListWidgetItem *archiveItem =
        qobject_cast<ArchiveListWidgetItem *>(sender());
    if(archiveItem)
    {
        ArchivePtr archive = archiveItem->archive();

        QMessageBox::StandardButton confirm =
            QMessageBox::question(this, tr("Confirm delete"),
                                  tr("Are you sure you want to delete"
                                     " archive %1 (this cannot be undone)?")
                                      .arg(archive->name()));
        if(confirm == QMessageBox::Yes)
        {
            QList<ArchivePtr> archiveList;
            archiveList.append(archive);
            emit deleteArchives(archiveList);
        }
    }
}
Exemple #11
0
bool ViewManager::storeViewStates(ArchivePtr archive, const std::string& key)
{
    // assign view ids first
    int id = 0;
    ModuleNameToClassNameToViewInfoMap::iterator p;
    for(p = moduleNameToClassNameToViewInfoMap.begin(); p != moduleNameToClassNameToViewInfoMap.end(); ++p){
        ClassNameToViewInfoMap& viewInfoMap = *p->second;
        for(ClassNameToViewInfoMap::iterator q = viewInfoMap.begin(); q != viewInfoMap.end(); ++q){
            ViewInfoPtr& viewInfo = q->second;
            InstanceInfoList& instances = viewInfo->instances;
            for(InstanceInfoList::iterator p = instances.begin(); p != instances.end(); ++p){            
                archive->registerViewId((*p)->view, id++);
            }
        }
    }
    
    ListingPtr viewList = new Listing();

    for(p = moduleNameToClassNameToViewInfoMap.begin(); p != moduleNameToClassNameToViewInfoMap.end(); ++p){
        const std::string& moduleName = p->first;
        ClassNameToViewInfoMap& viewInfoMap = *p->second;
        for(ClassNameToViewInfoMap::iterator q = viewInfoMap.begin(); q != viewInfoMap.end(); ++q){
            ViewInfoPtr& viewInfo = q->second;
            InstanceInfoList& instances = viewInfo->instances;
            for(InstanceInfoList::iterator p = instances.begin(); p != instances.end(); ++p){            
                View* view = (*p)->view;
                ArchivePtr viewArchive = storeView(*archive, moduleName, *viewInfo, view);
                if(viewArchive){
                    viewList->append(viewArchive);
                }
            }
        }
    }

    if(!viewList->empty()){
        archive->insert(key, viewList);
        return true;
    }
    return false;
}
Exemple #12
0
int main(void)
{
	// Get hold of the Manager class
	ManagerPtr manager = getManager();

	// Use the manager to look up a particular archive format
	ArchiveTypePtr archiveType = manager->getArchiveTypeByCode("grp-duke3d");

	// Open an archive file on disk
	stream::file_sptr file(new stream::file());
	file->open("duke3d.grp");

	// We cheat here - we should check and load any supplementary files, but
	// for the sake of keeping this example simple we know this format doesn't
	// need any supps.
	camoto::SuppData supps;

	// Use the archive format handler to read in the file we opened as an archive
	ArchivePtr arch = archiveType->open(file, supps);

	// Get a list of all the files in the archive
	const Archive::VC_ENTRYPTR& contents = arch->getFileList();

	// Print the size of the list (the number of files in the archive)
	std::cout << "Found " << contents.size() << " files.\n";

	// Run through the list of files and show the filename
	for (Archive::VC_ENTRYPTR::const_iterator i = contents.begin(); i != contents.end(); i++) {
		const Archive::EntryPtr subfile = *i;
		std::cout << subfile->strName << "\n";
	}
	std::cout << "Done." << std::endl;

	// No cleanup required because all the Ptr variables are shared pointers,
	// which get destroyed automatically when they go out of scope (and nobody
	// else is using them!)

	return 0;
}
void ArchiveListWidget::selectArchive(ArchivePtr archive)
{
    if(!archive)
    {
        DEBUG << "Null ArchivePtr passed.";
        return;
    }

    for(int i = 0; i < count(); ++i)
    {
        ArchiveListWidgetItem *archiveItem =
            static_cast<ArchiveListWidgetItem *>(item(i));
        if(archiveItem
           && (archiveItem->archive()->objectKey() == archive->objectKey()))
        {
            clearSelection();
            setCurrentItem(archiveItem);
            scrollToItem(currentItem(), QAbstractItemView::EnsureVisible);
            break;
        }
    }
}
void ArchiveListWidget::addArchive(ArchivePtr archive)
{
    if(!archive)
    {
        DEBUG << "Null ArchivePtr passed.";
        return;
    }

    // Find insertion position based on sorted timestamps.
    int pos = 0;
    for(; pos < count(); ++pos)
    {
        ArchiveListWidgetItem *archiveItem =
            static_cast<ArchiveListWidgetItem *>(item(pos));
        if(archiveItem
           && (archive->timestamp() > archiveItem->archive()->timestamp()))
        {
            break;
        }
    }
    insertArchive(archive, pos);
}
void ArchiveListWidget::insertArchive(ArchivePtr archive, int pos)
{
    if(!archive)
    {
        DEBUG << "Null ArchivePtr passed.";
        return;
    }

    ArchiveListWidgetItem *item = new ArchiveListWidgetItem(archive);
    connect(item, &ArchiveListWidgetItem::requestDelete, this,
            &ArchiveListWidget::deleteItem);
    connect(item, &ArchiveListWidgetItem::requestInspect, this,
            &ArchiveListWidget::inspectItem);
    connect(item, &ArchiveListWidgetItem::requestRestore, this,
            &ArchiveListWidget::restoreItem);
    connect(item, &ArchiveListWidgetItem::requestGoToJob, this,
            &ArchiveListWidget::goToJob);
    connect(item, &ArchiveListWidgetItem::removeItem, this,
            &ArchiveListWidget::removeItem);
    insertItem(pos, item);
    setItemWidget(item, item->widget());
    item->setHidden(!archive->name().contains(_filter));
    emit countChanged(count(), visibleItemsCount());
}
ArchivePtr ItemTreeArchiver::storeIter(ArchivePtr& parentArchive, Item* item)
{
    string pluginName;
    string className;

    if(!ItemManager::getClassIdentifier(item, pluginName, className)) {
        messageView->putln(format(_("\"%1%\" cannot be stored. Its type is not registered.")) % item->name());
        return 0;
    }

    ArchivePtr archive = new Archive();
    archive->inheritSharedInfoFrom(parentArchive);

    messageView->putln(format(_("Storing %1% \"%2%\"")) % className % item->name());
    messageView->flush();

    ArchivePtr dataArchive = new Archive();
    dataArchive->inheritSharedInfoFrom(parentArchive);

    if(!item->store(*dataArchive)) {
        messageView->putln(format(_("\"%1%\" cannot be stored.")) % item->name());
        return 0;
    }

    archive->registerItemId(item, itemIdCounter);
    archive->write("id", itemIdCounter);
    itemIdCounter++;

    archive->write("name", item->name(), YAML_DOUBLE_QUOTED);
    archive->write("plugin", pluginName);
    archive->write("class", className);

    if(!dataArchive->empty()) {
        archive->insert("data", dataArchive);
    }

    YamlSequencePtr children = new YamlSequence();

    for(Item* childItem = item->childItem(); childItem; childItem = childItem->nextItem()) {
        if(childItem->isSubItem()) {
            continue;
        }
        ArchivePtr childArchive = storeIter(archive, childItem);
        if(childArchive) {
            children->append(childArchive);
        }
    }

    if(!children->empty()) {
        archive->insert("children", children);
    }

    return archive;
}
Exemple #17
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);
                        }
                    }
                }
            }
        }
    }
}
static bool ArchiveCompare (ArchivePtr a, ArchivePtr b) { return (a->timestamp() > b->timestamp()); }
Exemple #19
0
void ViewArea::restoreAllViewAreaLayouts(ArchivePtr archive)
{
    ViewAreaImpl* mainViewAreaImpl = MainWindow::instance()->viewArea()->impl;
    
    if(archive){
        Listing& layouts = *archive->findListing("viewAreas");
        if(!layouts.isValid()){
            // for the compatibility with the older (1.4 or earlier) versions
            Archive* layoutOfViews = archive->findSubArchive("layoutOfViews");
            if(layoutOfViews->isValid()){
                layoutOfViews->inheritSharedInfoFrom(*archive);
                mainViewAreaImpl->restoreLayout(layoutOfViews);
            }
        } else {
            QDesktopWidget* desktop = QApplication::desktop();
            const int numScreens = desktop->screenCount();
            
            for(int i=0; i < layouts.size(); ++i){
                Mapping& layout = *layouts[i].toMapping();
                Archive* contents = dynamic_cast<Archive*>(layout.get("contents").toMapping());
                if(contents){
                    contents->inheritSharedInfoFrom(*archive);
                    const string type = layout.get("type").toString();

                    if(type == "embedded"){
                        mainViewAreaImpl->restoreLayout(contents);
                        mainViewAreaImpl->self->setViewTabsVisible(layout.get("tabs", mainViewAreaImpl->viewTabsVisible));

                    } else if(type == "independent"){
                        ViewArea* viewWindow = new ViewArea();
                        viewWindow->impl->viewTabsVisible = layout.get("tabs", true);

                        viewWindow->impl->restoreLayout(contents);

                        if(viewWindow->impl->numViews == 0){
                            delete viewWindow;
                        } else {
                            const Listing& geo = *layout.findListing("geometry");
                            if(geo.isValid() && geo.size() == 4){
                                // -1 means the primary screen
                                int screen = -1;
                                if(layout.read("screen", screen)){
                                    if(screen >= numScreens){
                                        screen = -1;
                                    }
                                }
                                const QRect s = desktop->screenGeometry(screen);
                                const QRect r(geo[0].toInt(), geo[1].toInt(), geo[2].toInt(), geo[3].toInt());
                                viewWindow->setGeometry(r.translated(s.x(), s.y()));
                            }
                            if(layout.get("fullScreen", false)){
                                layout.read("maximized", viewWindow->impl->isMaximizedBeforeFullScreen);
                                viewWindow->showFullScreen();
                            } else {
                                if(layout.get("maximized"), false){
                                    viewWindow->showMaximized();
                                } else {
                                    viewWindow->show();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if(isBeforeDoingInitialLayout){
        mainViewAreaImpl->resetLayout();
    }
}
Exemple #20
0
void ViewArea::restoreLayout(ArchivePtr archive)
{
    impl->restoreLayout(archive.get());
}
static bool cmp_timestamp(const ArchivePtr &a, const ArchivePtr &b)
{
    return (a->timestamp() > b->timestamp());
}