Ejemplo n.º 1
0
void autoRestore(menu m)
{
    //This still needs user input.
    for(unsigned i = 0; i < m.getSize(); i++)
    {
        FS_Archive saveArch;
        if(m.optSelected(i) && openSaveArch(&saveArch, sdTitle[i], false))
            restoreData(sdTitle[i], saveArch, MODE_SAVE);
        FSUSER_CloseArchive(&saveArch);

        FS_Archive extArch;
        if(m.optSelected(i) && openExtdata(&extArch, sdTitle[i], false))
            restoreData(sdTitle[i], extArch, MODE_EXTDATA);
        FSUSER_CloseArchive(&extArch);
    }
}
Ejemplo n.º 2
0
bool LoginScene::init()
{
    Node* ccsNode=CSLoader::createNode("uiccs/LoginLayer.csb");
    Size winSize=Director::getInstance()->getWinSize();
    ccsNode->setPosition(winSize.width/2,winSize.height/2);
    addChild(ccsNode);
    
    _nameTextField=(ui::TextField*)ccsNode->getChildByName("_nameTextField");
    _psTextField=(ui::TextField*)ccsNode->getChildByName("_psTextField");
    _ipTextField=(ui::TextField*)ccsNode->getChildByName("_ipTextField");
    
    std::function<void(const char*,const char*,ui::TextField*)> restoreData;
    restoreData=[](const char* key,const char* defaultValue,ui::TextField* textField){
        std::string userName=UserDefault::getInstance()->getStringForKey(key);
        if (userName.length()==0)
        {
            UserDefault::getInstance()->setStringForKey(key,defaultValue);
            textField->setString(defaultValue);
        }
        else
        {
            textField->setString(userName);
        }
    };

    restoreData("userName","",_nameTextField);
    restoreData("password","",_psTextField);
//    restoreData("ip","0.0.0.0",_ipTextField);

    ui::Button* _loginButton=(ui::Button*)ccsNode->getChildByName("_loginButton");
    _loginButton->setPressedActionEnabled(true);
    _loginButton->addTouchEventListener([=](Ref* sender,ui::Widget::TouchEventType eventType){
        if(eventType==ui::Widget::TouchEventType::ENDED)
        {
            this->loginGame();
        }
    });
    
	return true;
}
Ejemplo n.º 3
0
uint32 Sword2Engine::restoreGame(uint16 slotNo) {
	uint32 bufferSize = findBufferSize();
	byte *saveBufferMem = (byte *)malloc(bufferSize);

	uint32 errorCode = restoreData(slotNo, saveBufferMem, bufferSize);

	// If it was read in successfully, then restore the game from the
	// buffer & free the buffer. Note that restoreFromBuffer() frees the
	// buffer in order to clear it from memory before loading in the new
	// screen and runlist, so we only need to free it in case of failure.

	if (errorCode == SR_OK)
		errorCode = restoreFromBuffer(saveBufferMem, bufferSize);
	else
		free(saveBufferMem);

	if (errorCode != SR_OK) {
		uint32 textId;

		switch (errorCode) {
		case SR_ERR_FILEOPEN:
			textId = TEXT_RESTORE_CANT_OPEN;
			break;
		case SR_ERR_INCOMPATIBLE:
			textId = TEXT_RESTORE_INCOMPATIBLE;
			break;
		default:
			textId = TEXT_RESTORE_FAILED;
			break;
		}

		_screen->displayMsg(fetchTextLine(_resman->openResource(textId / SIZE), textId & 0xffff) + 2, 0);
	} else {
		// Prime system with a game cycle

		// Reset the graphic 'BuildUnit' list before a new logic list
		// (see fnRegisterFrame)
		_screen->resetRenderLists();

		// Reset the mouse hot-spot list. See fnRegisterMouse()
		// and fnRegisterFrame()
		_mouse->resetMouseList();

		if (_logic->processSession())
			error("restore 1st cycle failed??");
	}

	// Force the game engine to pick a cursor. This appears to be needed
	// when using the -x command-line option to restore a game.
	_mouse->setMouseTouching(1);
	return errorCode;
}
Ejemplo n.º 4
0
void sharedBackupMenu(const titleData dat, FS_Archive arch)
{
    menu backupMenu(136, 80, false);
    backupMenu.addItem("Export Data");
    backupMenu.addItem("Import Data");
    backupMenu.addItem("Back");

    std::u32string info = tou32(dat.nameSafe) + U" : Shared Extdata";

    bool loop = true;
    while(loop)
    {
        hidScanInput();

        u32 up = hidKeysUp();

        backupMenu.handleInput(up);

        if(up & KEY_A)
        {
            switch(backupMenu.getSelected())
            {
                case _exp:
                    createTitleDir(dat, MODE_SHARED);
                    backupData(dat, arch, MODE_SHARED, false);
                    break;
                case _imp:
                    restoreData(dat, arch, MODE_SHARED);
                    break;
                case _back:
                    loop = false;
                    break;
            }
        }
        else if(up & KEY_B)
            break;

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
            drawTopBar(info);
            backupMenu.draw();
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }
}
Ejemplo n.º 5
0
/*恢复
	lb_libary_path:linux系统的动态链接库路径(android 4.0以上机器使用pm需要指定这个路径)
*/
int restoreApkAndData(const char* lb_libary_path, const char* apkPath, const char* busyboxPath, const char* dataPath, const char* internalDataPath, int forwardLocked){
	char buffer[1024];
	int result = 0;

	//恢复apk
	if(restoreApk(lb_libary_path, apkPath, forwardLocked)){
		//安装apk失败
		return result;
	}

	//恢复数据
	if(restoreData(busyboxPath, dataPath, internalDataPath)){
		//恢复数据失败
		return result;
	}
	return result;
}
Ejemplo n.º 6
0
int restore_app_main(int argc, char** argv){
	int forward_locked = 0, specified_ld_library_path = 0, restore_apk=0, restore_data = 0, arg_error = 0;
	char buffer[1024];
	char* dataPath = NULL;
	char* internalFilePath = NULL;
	char* ld_library_path = NULL;
	char* busygoxPath = NULL;
	char* apkPath = NULL;
	int c;


	struct option longopts[] = {
		{"data", 1, 0, 'd'},
		{"innerpath", 1, 0, 'i'},
		{"librarypath", 1, 0, 'D'},
		{"apk", 1, 0, 'a'},
		{"lock", 0, 0, 'l'},
		{ 0, 0, 0, 0}
	};

	opterr = 0;
	while ((c = getopt_long (argc, argv, "d:i:D:a:l", longopts, NULL)) != EOF){
		switch(c){
		case 'd':
			restore_data = 1;
			dataPath = optarg;
			DLOG_MSG(DEBUG_FALG_RESTORE, dataPath);
			break;
		case 'i':
			internalFilePath = optarg;
			break;
		case 'D':
			specified_ld_library_path = 1;
			ld_library_path = optarg;
			DLOG_MSG(DEBUG_FALG_RESTORE, ld_library_path);
			break;
		case 'a':
			restore_apk = 1;
			apkPath = optarg;
			break;
		case 'l':
			forward_locked = 1;
			break;
		case ':':
			arg_error = 1;
			break;
		case '?':
			arg_error = 1;
			break;
		case -1:
			break;
		default:
			break;
		}
	}//end of while

	if(argc - optind != 1){
		arg_error = 1;
	}else{
		busygoxPath = argv[optind];
		DLOG_MSG(DEBUG_FALG_RESTORE, busygoxPath);
	}

	if(restore_data == 1 && (dataPath == NULL || internalFilePath == NULL)){
		arg_error = 1;
	}
	if(specified_ld_library_path == 1 && ld_library_path == NULL){
		arg_error = 1;
	}
	if(restore_apk && apkPath == NULL){
		arg_error = 1;
	}

	if(arg_error == 1){
		fprintf(stderr, "%s\n%s, %s\n", ERROR_ARGUMENT_INVALID, RESTORE_FAILURE, GO_FAILURE);
		return 1;
	}

// 	if(restore_apk && restore_data){
// 		if(restoreApkAndData(ld_library_path, apkPath, busygoxPath, dataPath, internalFilePath, forward_locked)){
// 			DLOG_MSG(DEBUG_FALG_RESTORE, "restore apk and data failed");
// 			return 1;
// 		}
// 		fprintf(stdout, "%s, %s\n", RESTORE_SUCCESS, GO_SUCCESS);
// 		return 0;
// 	}

	if(restore_apk){
		if(restoreApk(ld_library_path, apkPath, forward_locked)){
			DLOG_MSG(DEBUG_FALG_RESTORE, "restore apk failed");
			fprintf(stdout, "%s, %s\n", RESTORE_FAILURE, GO_FAILURE);
			return 1;
		}
	}

	if(restore_data){
		if(restoreData(busygoxPath, dataPath, internalFilePath)){
			DLOG_MSG(DEBUG_FALG_RESTORE, "restore data failed");
			fprintf(stdout, "%s, %s\n", RESTORE_FAILURE, GO_FAILURE);
			return 1;
		}
	}
	fprintf(stdout, "%s, %s\n", RESTORE_SUCCESS, GO_SUCCESS);
	return 0;
}
Ejemplo n.º 7
0
void main(int argc, char *argv[])
{
  float minX,maxX,minE,maxE,dx,eenergy,superP;
  int i,j,rnk,numParticle,numX,numE,time,indexI,indexJ,index;
  int cnt,min,max,remain,tmp,numData;
  float **n,*nE,*x,*E,*energy,*xx,*px,*py,*pz,*send,*sendE;
  FILE *in,*out;
  char fileName[100];
  void restoreData();

  MPI_Init(&argc,&argv);

  int myrank, nTasks;    
  MPI_Status status;
  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
  MPI_Comm_size(MPI_COMM_WORLD, &nTasks);
  int cntOffSet[nTasks];
  for(i=0; i<nTasks; i++)
    cntOffSet[i]=0;

  if(argc < 8)   { 
    printf("energy3D_HDF numParticle minX maxX numX minE maxE time superP(3.14e4)\n");
    exit(0);  
  }

  numParticle=atoi(argv[1]);
  minX=atof(argv[2]);
  maxX=atof(argv[3]);
  numX=atoi(argv[4]);
  minE=atof(argv[5]);
  maxE=atof(argv[6]);
  time=atoi(argv[7]);
  superP=atof(argv[8]);
  

  dx=(maxX-minX)/((float) numX);
  numE=(int)((maxE-minE)/1e6);
  x=(float *)malloc(numX*sizeof(float ));
  E=(float *)malloc(numE*sizeof(float ));
  nE=(float *)malloc(numE*sizeof(float ));
  n=(float **)malloc(numX*sizeof(float *));
  for(i=0; i<numX; i++)
    n[i]=(float *)malloc(numE*sizeof(float ));
  for(i=0; i<numX; i++)
    for(j=0; j<numE; j++)
      n[i][j]=0.0;
  for(i=0; i<numE; i++)
    nE[i]=0.0;

  cnt=numParticle/nTasks;
  remain=numParticle%nTasks;
  min=max=0;
  for(i=0; i<nTasks; i++)
  {
    if(i<remain) tmp=cnt+1;
    else	 tmp=cnt;
    min=max;
    max=min+tmp;
    if(i==myrank)
    {
      cntOffSet[i]=min;
      numData=tmp;
    }
  }
  xx=(float *)malloc(numData*sizeof(float ));
  px=(float *)malloc(numData*sizeof(float ));
  py=(float *)malloc(numData*sizeof(float ));
  pz=(float *)malloc(numData*sizeof(float ));
  energy=(float *)malloc(numData*sizeof(float ));
  send=(float *)malloc(numX*numE*sizeof(float ));
  sendE=(float *)malloc(numE*sizeof(float ));

  sprintf(fileName,"0Particle%d.h5",time);
  restoreData(xx,fileName,"/x",numParticle,numData,cntOffSet);
  restoreData(px,fileName,"/px",numParticle,numData,cntOffSet);
  restoreData(py,fileName,"/py",numParticle,numData,cntOffSet);
  restoreData(pz,fileName,"/pz",numParticle,numData,cntOffSet);

  //Saving denE file
  for(i=0; i<numData; i++)
  {
    indexI=(int)((xx[i]-minX)/dx);
    eenergy=(sqrt(1.0+px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i])-1.0)*0.511*1e6;
    indexJ=(int)((eenergy-minE)/1e6);
    if(indexI>=0 && indexI<numX && indexJ>=0 && indexJ<numE)
      n[indexI][indexJ]+=1.0;
  }
  index=0;
  for(i=0; i<numX; i++)
    for(j=0; j<numE; j++)
    {
      send[index]=n[i][j];
      index++;
    }
  
  for(rnk=1; rnk<nTasks; rnk++)
  {
    if(myrank==rnk)
      MPI_Send(send,numE*numX,MPI_FLOAT,0,myrank,MPI_COMM_WORLD);
    else if(myrank==0)
    {
      MPI_Recv(send,numE*numX,MPI_FLOAT,rnk,rnk,MPI_COMM_WORLD,&status);
      index=0;
      for(i=0; i<numX; i++)
        for(j=0; j<numE; j++)
        {
          n[i][j]+=send[index];
          index++;
        }
    }
    else	;
    printf("rank%d is done\n",rnk);
  }

  for(i=0; i<numX; i++)
    x[i]=i*dx+minX;
  for(i=0; i<numE; i++)
    E[i]=i*1e6+minE;

  if(myrank==0)
  {
    sprintf(fileName,"denE%d",time);
    out=fopen(fileName,"w");
    for(i=0; i<numX; i++)
    {
      for(j=0; j<numE; j++)
        fprintf(out,"%g %g %g\n",x[i],E[j],n[i][j]*superP*1.6e-19*1e12);
      fprintf(out,"\n");
    }
    fclose(out);
    printf("%s is made.\n",fileName);
  }  
  else	;

  //Saving energy file
  for(i=0; i<numData; i++)
  {
    indexI=(int)((xx[i]-minX)/dx);
    eenergy=(sqrt(1.0+px[i]*px[i]+py[i]*py[i]+pz[i]*pz[i])-1.0)*0.511*1e6;
    indexJ=(int)((eenergy-minE)/1e6);
    if(indexJ>=0 && indexJ<numE)
      nE[indexJ]+=1.0;
  }
  index=0;
  for(j=0; j<numE; j++)
  {
    sendE[index]=nE[j];
    index++;
  }
  
  for(rnk=1; rnk<nTasks; rnk++)
  {
    if(myrank==rnk)
      MPI_Send(sendE,numE,MPI_FLOAT,0,myrank,MPI_COMM_WORLD);
    else if(myrank==0)
    {
      MPI_Recv(sendE,numE,MPI_FLOAT,rnk,rnk,MPI_COMM_WORLD,&status);
      index=0;
      for(j=0; j<numE; j++)
      {
        nE[j]+=sendE[index];
        index++;
      }
    }
    else	;
    printf("rank%d is done\n",rnk);
  }

  for(i=0; i<numE; i++)
    E[i]=i*1e6+minE;

  if(myrank==0)
  {
    sprintf(fileName,"energy%d",time);
    out=fopen(fileName,"w");
    for(j=0; j<numE; j++)
      fprintf(out,"%g %g\n",E[j],nE[j]*superP*1.6e-19*1e12);
    fclose(out);
    printf("%s is made.\n",fileName);
  }  
  else	;

  free(x);
  free(E);
  free(xx);
  free(px);
  free(py);
  free(pz);
  free(energy);
  free(send);
  free(sendE);
  for(i=0; i<numX; i++)
    free(n[i]);
  free(n);
  free(nE);

  MPI_Finalize();
}