示例#1
0
SaveStateList SaveLoad::listValidSaves(const Common::String &target) {
	SaveStateList list;

	// Get the list of savefiles
	Common::String pattern = Common::String::format("%s.0##", target.c_str());
	Common::StringArray savefiles = g_system->getSavefileManager()->listSavefiles(pattern);

	// Sort the list of filenames
	sort(savefiles.begin(), savefiles.end());

	// Fill the information for the existing savegames
	Common::StringArray::iterator it = savefiles.begin();
	while (it != savefiles.end()) {
		const char *ext = strrchr(it->c_str(), '.');
		if (!ext)
			continue;

		int slot = atoi(ext + 1);

		if (!isSlotValid(slot))
			continue;

		SaveStateDescriptor descriptor;
		Common::InSaveFile *file = SaveLoad::openForLoading(target, slot, &descriptor);
		if (file) {
			// It's a valid savefile, save the descriptor
			delete file;
			list.push_back(descriptor);
		}
		it++;
	}

	return list;
}
示例#2
0
uint32 BasePersistenceManager::getMaxUsedSlot() {
    Common::String saveMask = Common::String::format("%s.???", _savePrefix.c_str());
    Common::StringArray saves = g_system->getSavefileManager()->listSavefiles(saveMask);
    Common::StringArray::iterator it = saves.begin();
    int ret = -1;
    for (; it != saves.end(); ++it) {
        int num = -1;
        sscanf(it->c_str(), ".%d", &num);
        ret = MAX(ret, num);
    }
    return ret;
}
示例#3
0
void SagaEngine::fillSaveList() {

	int i;
	Common::InSaveFile *in;
	Common::StringArray filenames;
	char slot[3];
	int slotNumber;
	char *name;

	name = calcSaveFileName(MAX_SAVES);
	name[strlen(name) - 2] = '*';
	name[strlen(name) - 1] = 0;

	filenames = _saveFileMan->listSavefiles(name);

	for (i = 0; i < MAX_SAVES; i++) {
		_saveFiles[i].name[0] = 0;
		_saveFiles[i].slotNumber = (uint)-1;
	}

	_saveFilesCount = 0;

	for (Common::StringArray::iterator file = filenames.begin(); file != filenames.end(); ++file){
		//Obtain the last 2 digits of the filename, since they correspond to the save slot
		slot[0] = file->c_str()[file->size()-2];
		slot[1] = file->c_str()[file->size()-1];
		slot[2] = 0;

		slotNumber = atoi(slot);
		if (slotNumber >= 0 && slotNumber < MAX_SAVES) {
			name = calcSaveFileName(slotNumber);
			if ((in = _saveFileMan->openForLoading(name)) != NULL) {
				_saveHeader.type = in->readUint32BE();
				_saveHeader.size = in->readUint32LE();
				_saveHeader.version = in->readUint32LE();
				in->read(_saveHeader.name, sizeof(_saveHeader.name));

				if (_saveHeader.type != MKTAG('S','A','G','A')) {
					warning("SagaEngine::load wrong save %s format", name);
					i++;
					continue;
				}
				strcpy(_saveFiles[_saveFilesCount].name, _saveHeader.name);
				_saveFiles[_saveFilesCount].slotNumber = slotNumber;
				delete in;
				_saveFilesCount++;
			}
		}
	}

	qsort(_saveFiles, _saveFilesCount, sizeof(_saveFiles[0]), compareSaveFileData);
}