示例#1
0
bool Unpack(const char* fn,const char* path=NULL)
{
  ResourceLibrary lib;
  MakeRobotResourceLibrary(lib);
  ResourcePtr r = lib.LoadItem(fn);
  if(!r) return false;
  if(unpackTypes.find(r->Type()) == unpackTypes.end()) {
    printf("Type %s is not a compound type\n",r->Type());
    return false;
  }
  cout<<"Resource of type "<<r->Type()<<endl;
  vector<string> s = unpackTypes[r->Type()];
  if(0==strcmp(r->Type(),"MultiPath")) {
    //conditional unpack -- if untimed, unpack sections as Configs.  If timed,
    //unpack sections as LinearPaths
    MultiPathResource* mp = dynamic_cast<MultiPathResource*>(&(*r));
    if(mp->path.HasTiming()) 
      s.erase(find(s.begin(),s.end(),"Configs"));
    else
      s.erase(find(s.begin(),s.end(),"LinearPath"));
  }
  for(size_t i=0;i<s.size();i++) {
    vector<ResourcePtr> res = ExtractResources(r,s[i].c_str());
    //change "name." to "name/"
    for(size_t j=0;j<res.size();j++) {
      int n = res[j]->name.find('.');
      if(n == string::npos)
	res[j]->fileName = r->name+"/"+lib.DefaultFileName(res[j]);
      else {
	res[j]->fileName = lib.DefaultFileName(res[j]);
	res[j]->fileName.replace(n,1,"/");
      }
      if(path != NULL) {
	res[j]->fileName = string(path)+"/"+res[j]->fileName;
      }
      else {
	char path[1024];
	GetFilePath(fn,path);
	res[j]->fileName = string(path) + res[j]->fileName;
      }
      cout<<"Extracted item "<<res[j]->name<<", saving to "<<res[j]->fileName<<endl;
      if(!res[j]->Save()) {
	printf("Could not save %s to %s\n",res[j]->name.c_str(),res[j]->fileName.c_str());
	return false;
      }
    }
  }
  return true;
}
示例#2
0
ResourceNodePtr ResourceGUIBackend::Add(ResourcePtr r)
{
  if(resources == NULL) return NULL;
  ResourceNode* parent = (resources->selected != NULL ? resources->selected->parent : NULL);
  if(r->name.empty()) {
      stringstream ss;
      if(parent == NULL){
	ss<<r->Type()<<"["<<resources->topLevel.size()<<"]";
      }
      else{
	ss<<r->Type()<<"["<<parent->children.size()<<"]";
      }
      r->name = ss.str();
  }
  last_added = resources->Add(r,parent);
  //SendCommand("new_resource", r->Type()+string(" ")+r->name);
  SendCommand("new_resource", last_added->Identifier());
  return last_added;
}