Ejemplo n.º 1
0
int loadLabels (const char *fileName, long nbObjects, int *labels) {
    FILE *inLabels = openInFile(fileName);
    long nbO, nbC;
    fscanf(inLabels, "%li %li", &nbO, &nbC);
    if (nbO != nbObjects)
      errorAndQuit("\nNumber of objects in label file (%li) does not match expected number of objects (%li).\n\n", nbO, nbObjects);
    int minClass = INT_MAX;
    int maxClass = INT_MIN;
    for (int i=0; i<nbObjects; i++) {
      if (!fscanf(inLabels, "%i", labels+i))
	errorAndQuit("\nUnexpected en of input while reading init label file '%s'.\n\n", fileName);
      if (labels[i] < minClass) minClass = labels[i];
      if (labels[i] > maxClass) maxClass = labels[i];
    }
    long nbClasses = maxClass - minClass + 1;
    if (nbClasses != nbC)
      errorAndQuit("\nObserved number of classes (%i), not equal to declared number of classes (%li)\nin labels file '%s'.\n\n", nbClasses, nbC, fileName);
    // Normalize to have labels in [0, nbClasses-1]
    for (int i=0; i<nbObjects; i++)
      labels[i] -= minClass;
    fclose(inLabels);
    return (int)nbClasses;
}
Ejemplo n.º 2
0
int exec_cia(const char* path, const char** args){
	struct stat sBuff;
	bool fileExists;
	bool inited;

	if(path == NULL || path[0] == '\0'){
		errno = EINVAL;
		return -1;
	}

	fileExists = stat(path, &sBuff) == 0;
	if(!fileExists){
		errno = ENOENT;
		return -1;
	}
	else if(S_ISDIR(sBuff.st_mode)){
		errno = EINVAL;;
		return -1;
	}

	inited = R_SUCCEEDED(amInit()) && R_SUCCEEDED(fsInit());
	if(inited){
		Result res;
		AM_TitleEntry ciaInfo;
		FS_Archive ciaArchive;
		Handle ciaFile;
		int ciaInstalled;
		ciaParam param;
		int argsLength;

		//open cia file
		res = FSUSER_OpenArchive(&ciaArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
		if(R_FAILED(res))
			errorAndQuit("Cant open SD FS archive.");

		res = FSUSER_OpenFile(&ciaFile, ciaArchive, fsMakePath(PATH_ASCII, path + 5/*skip "sdmc:"*/), FS_OPEN_READ, 0);
		if(R_FAILED(res))
			errorAndQuit("Cant open CIA file.");

		res = AM_GetCiaFileInfo(MEDIATYPE_SD, &ciaInfo, ciaFile);
		if(R_FAILED(res))
			errorAndQuit("Cant get CIA file info.");

		ciaInstalled = isCiaInstalled(ciaInfo.titleID, ciaInfo.version);
		if(ciaInstalled == -1){
			//error
			errorAndQuit("Could not read title id list.");
		}
		else if(ciaInstalled == 0){
			//not installed
			int error = installCia(ciaFile);
			if(error == -1)
				errorAndQuit("Cant install CIA.");
		}

		FSFILE_Close(ciaFile);
		FSUSER_CloseArchive(ciaArchive);

		param.argc = 0;
		argsLength = 0;
		char* argLocation = param.args;
		while(args[param.argc] != NULL){
			strcpy(argLocation, args[param.argc]);
			argLocation += strlen(args[param.argc]) + 1;
			argsLength += strlen(args[param.argc]) + 1;
			param.argc++;
		}

		res = APT_PrepareToDoApplicationJump(0, ciaInfo.titleID, 0x1);
		if(R_FAILED(res))
			errorAndQuit("CIA cant run, cant prepare.");

		res = APT_DoApplicationJump(&param, sizeof(param.argc) + argsLength, argvHmac);
		if(R_FAILED(res))
			errorAndQuit("CIA cant run, cant jump.");

		//wait for application jump, for some reason its not instant
		while(1);
	}

	//should never be reached
	amExit();
	fsExit();
	errno = ENOTSUP;
	return -1;
}
Ejemplo n.º 3
0
FILE *openOutFile (const char *outFileName) {  
  FILE *fin = fopen(outFileName, "wb");
  if (!fin)  errorAndQuit ("\nCould not open file '%s' for writing.\n\n", outFileName);
  return fin;
}
Ejemplo n.º 4
0
FILE *openInFile (const char *inFileName) {  
  FILE *fin = fopen(inFileName, "rb");
  if (!fin)  errorAndQuit ("\nCould not open file '%s' for reading.\n\n", inFileName);
  return fin;
}