Esempio n. 1
0
SeekableReadStream *ZipFile::getFile(uint32 index, bool tryNoCopy) const {
	const IFile &file = getIFile(index);

	uint16 compMethod;
	uint32 compSize;
	uint32 realSize;

	getFileProperties(*_zip, file, compMethod, compSize, realSize);

	if (tryNoCopy && (compMethod == 0))
		return new SeekableSubReadStream(_zip.get(), _zip->pos(), _zip->pos() + compSize);

	return decompressFile(*_zip, compMethod, compSize, realSize);
}
Esempio n. 2
0
/**
 * This is a simple main tester to check if the connection to HPSS could be
 * established. Everything is hardcoded (authentication type, keytab location,
 * username and filename), however is a very simple example completely
 * functional that helps to do a bigger script.
 *
 * @author Andres Gomez
 */
int main(int argc, char **argv) {
	int rc = -1;

	// Parameters for the initialization.
	const char * authType = "unix";
	const char * keytab = KEYTAB;
	const char * user = KEYTAB_USER;

	// File to query.
	const char * filename = FILENAME;

	int position;
	int higherStorageLevel;
	char tape[12];
	unsigned long long size;

	printf("> Starting Broker tester\n");

	// Initializes the api.
	rc = initContext(authType, keytab, user);
	printf("Code from initContext: %d\n", rc);
	if (rc == 0) {
		// Gets the file properties.
		rc = getFileProperties(filename, &position, &higherStorageLevel, tape,
				&size);
		printf("Code from getFileProps: %d\n", rc);
		if (rc == 0) {
			printf("File properties %s, %d, %d, %s, %lld\n", filename, position,
					higherStorageLevel, tape, size);

			if (higherStorageLevel > 0) {
				printf("File ready to stage\n");
				// Stages the file.
				rc = stage(filename, &size);
			} else {
				printf("File already in disk (higher storage level)\n");
			}
		} else {
			printf("Error getting properties\n");
		}
	} else {
		printf("Error in init\n");
	}
	endContext();
	printf("< Ending Broker tester\n");

	return rc;
}
Esempio n. 3
0
const ADGameDescription *AdvancedMetaEngine::detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback, ADFilePropertiesMap *filesProps) const {
	const ADFileBasedFallback *ptr;
	const char* const* filenames;

	int maxNumMatchedFiles = 0;
	const ADGameDescription *matchedDesc = 0;

	for (ptr = fileBasedFallback; ptr->desc; ++ptr) {
		const ADGameDescription *agdesc = ptr->desc;
		int numMatchedFiles = 0;
		bool fileMissing = false;

		for (filenames = ptr->filenames; *filenames; ++filenames) {
			debug(3, "++ %s", *filenames);
			if (!allFiles.contains(*filenames)) {
				fileMissing = true;
				break;
			}

			numMatchedFiles++;
		}

		if (!fileMissing) {
			debug(4, "Matched: %s", agdesc->gameId);

			if (numMatchedFiles > maxNumMatchedFiles) {
				matchedDesc = agdesc;
				maxNumMatchedFiles = numMatchedFiles;

				debug(4, "and overridden");

				if (filesProps) {
					for (filenames = ptr->filenames; *filenames; ++filenames) {
						ADFileProperties tmp;

						if (getFileProperties(fslist.begin()->getParent(), allFiles, *agdesc, *filenames, tmp))
							(*filesProps)[*filenames] = tmp;
					}
				}

			}
		}
	}

	return matchedDesc;
}
Esempio n. 4
0
ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const {
	ADFilePropertiesMap filesProps;

	const ADGameFileDescription *fileDesc;
	const ADGameDescription *g;
	const byte *descPtr;

	debug(3, "Starting detection in dir '%s'", parent.getPath().c_str());

	// Check which files are included in some ADGameDescription *and* are present.
	// Compute MD5s and file sizes for these files.
	for (descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameId != 0; descPtr += _descItemSize) {
		g = (const ADGameDescription *)descPtr;

		for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
			Common::String fname = fileDesc->fileName;
			ADFileProperties tmp;

			if (filesProps.contains(fname))
				continue;

			if (getFileProperties(parent, allFiles, *g, fname, tmp)) {
				debug(3, "> '%s': '%s'", fname.c_str(), tmp.md5.c_str());
				filesProps[fname] = tmp;
			}
		}
	}

	ADGameDescList matched;
	ADGameIdList matchedGameIds;
	int maxFilesMatched = 0;
	bool gotAnyMatchesWithAllFiles = false;

	// MD5 based matching
	uint i;
	for (i = 0, descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameId != 0; descPtr += _descItemSize, ++i) {
		g = (const ADGameDescription *)descPtr;
		bool fileMissing = false;

		// Do not even bother to look at entries which do not have matching
		// language and platform (if specified).
		if ((language != Common::UNK_LANG && g->language != Common::UNK_LANG && g->language != language
			 && !(language == Common::EN_ANY && (g->flags & ADGF_ADDENGLISH))) ||
			(platform != Common::kPlatformUnknown && g->platform != Common::kPlatformUnknown && g->platform != platform)) {
			continue;
		}

		if ((_flags & kADFlagUseExtraAsHint) && !extra.empty() && g->extra != extra)
			continue;

		bool allFilesPresent = true;
		int curFilesMatched = 0;
		bool hashOrSizeMismatch = false;

		// Try to match all files for this game
		for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
			Common::String tstr = fileDesc->fileName;

			if (!filesProps.contains(tstr)) {
				fileMissing = true;
				allFilesPresent = false;
				break;
			}

			if (hashOrSizeMismatch)
				continue;

			if (fileDesc->md5 != NULL && fileDesc->md5 != filesProps[tstr].md5) {
				debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fileDesc->md5, filesProps[tstr].md5.c_str());
				fileMissing = true;
				hashOrSizeMismatch = true;
				continue;
			}

			if (fileDesc->fileSize != -1 && fileDesc->fileSize != filesProps[tstr].size) {
				debug(3, "Size Mismatch. Skipping");
				fileMissing = true;
				hashOrSizeMismatch = true;
				continue;
			}

			debug(3, "Matched file: %s", tstr.c_str());
			curFilesMatched++;
		}

		// We found at least one entry with all required files present.
		// That means that we got new variant of the game.
		//
		// Without this check we would have erroneous checksum display
		// where only located files will be enlisted.
		//
		// Potentially this could rule out variants where some particular file
		// is really missing, but the developers should better know about such
		// cases.
		if (allFilesPresent) {
			gotAnyMatchesWithAllFiles = true;
			if (!matchedGameIds.size() || strcmp(matchedGameIds.back(), g->gameId) != 0)
				matchedGameIds.push_back(g->gameId);
		}

		if (!fileMissing) {
			debug(2, "Found game: %s (%s %s/%s) (%d)", g->gameId, g->extra,
			 getPlatformDescription(g->platform), getLanguageDescription(g->language), i);

			if (curFilesMatched > maxFilesMatched) {
				debug(2, " ... new best match, removing all previous candidates");
				maxFilesMatched = curFilesMatched;

				matched.clear();	// Remove any prior, lower ranked matches.
				matched.push_back(g);
			} else if (curFilesMatched == maxFilesMatched) {
				matched.push_back(g);
			} else {
				debug(2, " ... skipped");
			}

		} else {
			debug(5, "Skipping game: %s (%s %s/%s) (%d)", g->gameId, g->extra,
			 getPlatformDescription(g->platform), getLanguageDescription(g->language), i);
		}
	}

	// We didn't find a match
	if (matched.empty()) {
		if (!filesProps.empty() && gotAnyMatchesWithAllFiles) {
			reportUnknown(parent, filesProps, matchedGameIds);
		}

		// Filename based fallback
	}

	return matched;
}
Esempio n. 5
0
JNIEXPORT jobject JNICALL Java_fr_in2p3_cc_storage_treqs_hsm_hpssJNI_NativeBridge_getFileProperties(
    JNIEnv* env, jobject js, jstring jFileName) {

  const char * filename;

  int position;
  int storageLevel;
  char tape[HPSS_PV_NAME_SIZE + 1];
  unsigned long long size;

  int rc = -1;

  char message[1024];

  // JNI
  jstring jTapeName;
  jclass helperClass;
  jmethodID cid;
  jobject result = NULL;

  if (trace) {
    printf("> JNI getFileProperties\n");
  }

  memset((char*) tape, '\0', HPSS_PV_NAME_SIZE + 1);

  // Converts JavaString in char*.
  filename = (*env)->GetStringUTFChars(env, jFileName, JNI_FALSE);

  // Calls the broker.
  rc = getFileProperties(filename, &position, &storageLevel, tape, &size);

  // Release JNI component.
  (*env)->ReleaseStringUTFChars(env, jFileName, filename);

  // Throws an exception if there is a problem.
  if (rc != HPSS_E_NOERROR) {
    sprintf(message, "%d:getProperties", rc);
    throwJNIException(env, message);
  }
  if (cont) {
    if (debug) {
      printf("Preparing results\n");
    }
    // Prepares the value when the file is already in disk.
    if (storageLevel == 0) {
      // This is the value of the constant Constants.FILE_ON_DISK
      strcpy(tape, FILE_ON_DISK);
    }

    // Returns the elements to java and release JNI components.

    // Prepares the StorageLevel - StorageName
    jTapeName = (*env)->NewStringUTF(env, tape);
    if (jTapeName == NULL) {
      rc = -30002;
      sprintf(message, "%d:Problem creating the string - tapename", rc);
      throwJNIException(env, message);
    }
  }
  if (cont) {
    // Attempt to find the HSMHelper class.
    helperClass = (*env)->FindClass(env,
        "fr/in2p3/cc/storage/treqs/hsm/HSMHelperFileProperties");
    // If this class does not exist then return null.
    if (helperClass == NULL) {
      rc = -30003;
      sprintf(message, "%d:Class not found", rc);
      throwJNIException(env, message);
    }
  }
  if (cont) {
    // Get the method ID for the Helper(String, int, long) constructor */
    cid = (*env)->GetMethodID(env, helperClass, "<init>",
        "(Ljava/lang/String;IJ)V");
    if (cid == NULL) {
      rc = -30004;
      sprintf(message, "%d:Constructor not found", rc);
      throwJNIException(env, message);
    }
  }
  if (cont) {
    // Creates the object.
    result = (*env)->NewObject(env, helperClass, cid, jTapeName,
        (jint) position, (jlong) size);

    /* Free local references */
    (*env)->DeleteLocalRef(env, helperClass);
  }

  if (trace) {
    printf("< JNI getFileProperties - %d\n", rc);
  }

  return result;
}