コード例 #1
0
ファイル: detection.cpp プロジェクト: Coworker/scummvm
    virtual SaveStateList listSaves(const char *target) const {
        Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
        Common::String pattern = Common::String::format("%s??", target);

        // Get list of savefiles for target game
        Common::StringArray filenames = saveFileMan->listSavefiles(pattern);
        Common::Array<int> slots;
        for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {

            // Obtain the last 2 digits of the filename, since they correspond to the save slot
            int slotNum = atoi(file->c_str() + file->size() - 2);

            // Ensure save slot is within valid range
            if (slotNum >= 1 && slotNum <= 10) {
                slots.push_back(slotNum);
            }
        }

        // Sort save slot ids
        Common::sort<int>(slots.begin(), slots.end());

        // Load save index
        Common::String fileEpa = Common::String::format("%s.epa", target);
        Common::InSaveFile *epa = saveFileMan->openForLoading(fileEpa);

        // Get savegame names from index
        Common::String saveDesc;
        SaveStateList saveList;
        int line = 1;
        for (uint i = 0; i < slots.size(); i++) {
            // ignore lines corresponding to unused saveslots
            for (; line < slots[i]; line++)
                epa->readLine();

            // copy the name in the line corresponding to the save slot and truncate to 22 characters
            saveDesc = Common::String(epa->readLine().c_str(), 22);

            // handle cases where the save directory and save index are detectably out of sync
            if (saveDesc == "*")
                saveDesc = "No name specified.";

            // increment line number to keep it in sync with slot number
            line++;

            // Insert savegame name into list
            saveList.push_back(SaveStateDescriptor(slots[i], saveDesc));
        }
        delete epa;

        return saveList;
    }
コード例 #2
0
ファイル: saveload.cpp プロジェクト: peres/scummvm
void SaveLoad_ns::getGamePartProgress(bool *complete, int size) {
	assert(complete && size >= 3);

	Common::InSaveFile *inFile = getInSaveFile(SPECIAL_SAVESLOT);
	Common::String s = inFile->readLine();
	delete inFile;

	complete[0] = s.contains("dino");
	complete[1] = s.contains("donna");
	complete[2] = s.contains("dough");
}
コード例 #3
0
ファイル: savegame.cpp プロジェクト: AReim1982/scummvm
bool SaveGametests::readAndVerifyData(const char *fileName, const char *expected) {
	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
	Common::InSaveFile *loadFile = saveFileMan->openForLoading(fileName);

	if (!loadFile) {
		Testsuite::logDetailedPrintf("Can't open save File to load\n");
		return false;
	}

	Common::String lineToRead = loadFile->readLine();
	delete loadFile;

	if (lineToRead.equals(expected)) {
		return true;
	}

	return false;
}
コード例 #4
0
ファイル: saveload.cpp プロジェクト: peres/scummvm
void SaveLoad_ns::setPartComplete(const char *part) {
	Common::String s;
	bool alreadyPresent = false;

	Common::InSaveFile *inFile = getInSaveFile(SPECIAL_SAVESLOT);
	if (inFile) {
		s = inFile->readLine();
		delete inFile;

		if (s.contains(part)) {
			alreadyPresent = true;
		}
	}

	if (!alreadyPresent) {
		Common::OutSaveFile *outFile = getOutSaveFile(SPECIAL_SAVESLOT);
		outFile->writeString(s);
		outFile->writeString(part);
		outFile->finalize();
		delete outFile;
	}
}
コード例 #5
0
ファイル: saveload.cpp プロジェクト: peres/scummvm
void SaveLoad_ns::doLoadGame(uint16 slot) {
	_vm->cleanupGame();

	Common::InSaveFile *f = getInSaveFile(slot);
	if (!f) return;

	Common::String s, character, location;

	// scrap the line with the savefile name
	f->readLine();

	character = f->readLine();
	location = f->readLine();

	s = f->readLine();
	_vm->_location._startPosition.x = atoi(s.c_str());

	s = f->readLine();
	_vm->_location._startPosition.y = atoi(s.c_str());

	s = f->readLine();
	_vm->_score = atoi(s.c_str());

	s = f->readLine();
	_globalFlags = atoi(s.c_str());

	s = f->readLine();
	_vm->_numLocations = atoi(s.c_str());

	uint16 _si;
	for (_si = 0; _si < _vm->_numLocations; _si++) {
		s = f->readLine();
		strcpy(_vm->_locationNames[_si], s.c_str());

		s = f->readLine();
		_vm->_localFlags[_si] = atoi(s.c_str());
	}

	_vm->cleanInventory(false);
	ItemName name;
	uint32 value;

	for (_si = 0; _si < 30; _si++) {
		s = f->readLine();
		value = atoi(s.c_str());

		s = f->readLine();
		name = atoi(s.c_str());

		_vm->addInventoryItem(name, value);
	}

	delete f;

	// force reload of character to solve inventory
	// bugs, but it's a good maneuver anyway
	strcpy(_vm->_characterName1, "null");

	char tmp[PATH_LEN];
	sprintf(tmp, "%s.%s" , location.c_str(), character.c_str());
	_vm->scheduleLocationSwitch(tmp);
}
コード例 #6
0
ファイル: saveload.cpp プロジェクト: Templier/scummvm-test
bool DrasculaEngine::saveLoadScreen() {
	char names[10][23];
	char file[50];
	char fileEpa[50];
	int n, n2, num_sav = 0, y = 27;
	Common::InSaveFile *sav;

	clearRoom();

	snprintf(fileEpa, 50, "%s.epa", _targetName.c_str());
	if (!(sav = _saveFileMan->openForLoading(fileEpa))) {
		Common::OutSaveFile *epa;
		if (!(epa = _saveFileMan->openForSaving(fileEpa)))
			error("Can't open %s file", fileEpa);
		for (n = 0; n < NUM_SAVES; n++)
			epa->writeString("*\n");
		epa->finalize();
		delete epa;
		if (!(sav = _saveFileMan->openForLoading(fileEpa))) {
			error("Can't open %s file", fileEpa);
		}
	}
	for (n = 0; n < NUM_SAVES; n++) {
		strncpy(names[n], sav->readLine().c_str(), 23);
		names[n][22] = '\0';	// make sure the savegame name is 0-terminated
	}
	delete sav;

	loadPic("savescr.alg", bgSurface, HALF_PAL);

	color_abc(kColorLightGreen);

	select[0] = 0;

	_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
	setCursor(kCursorCrosshair);

	while (!shouldQuit()) {
		y = 27;
		copyBackground();
		for (n = 0; n < NUM_SAVES; n++) {
			print_abc(names[n], 116, y);
			y = y + 9;
		}
		print_abc(select, 117, 15);
		updateScreen();
		y = 27;

		updateEvents();

		if (leftMouseButton == 1) {
			delay(50);
			for (n = 0; n < NUM_SAVES; n++) {
				if (mouseX > 115 && mouseY > y + (9 * n) && mouseX < 115 + 175 && mouseY < y + 10 + (9 * n)) {
					strcpy(select, names[n]);

					if (strcmp(select, "*"))
						selectionMade = 1;
					else {
						enterName();
						strcpy(names[n], select);
						if (selectionMade == 1) {
							snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1);
							saveGame(file);
							Common::OutSaveFile *tsav;
							if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
								error("Can't open %s file", fileEpa);
							}
							for (n = 0; n < NUM_SAVES; n++) {
								tsav->writeString(names[n]);
								tsav->writeString("\n");
							}
							tsav->finalize();
							delete tsav;
						}
					}

					print_abc(select, 117, 15);
					y = 27;
					for (n2 = 0; n2 < NUM_SAVES; n2++) {
						print_abc(names[n2], 116, y);
						y = y + 9;
					}
					if (selectionMade == 1) {
						snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1);
					}
					num_sav = n;
				}
			}

			if (mouseX > 117 && mouseY > 15 && mouseX < 295 && mouseY < 24 && selectionMade == 1) {
				enterName();
				strcpy(names[num_sav], select);
				print_abc(select, 117, 15);
				y = 27;
				for (n2 = 0; n2 < NUM_SAVES; n2++) {
					print_abc(names[n2], 116, y);
					y = y + 9;
				}

				if (selectionMade == 1) {
					snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1);
					saveGame(file);
					Common::OutSaveFile *tsav;
					if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
						error("Can't open %s file", fileEpa);
					}
					for (n = 0; n < NUM_SAVES; n++) {
						tsav->writeString(names[n]);
						tsav->writeString("\n");
					}
					tsav->finalize();
					delete tsav;
				}
			}

			if (mouseX > 125 && mouseY > 123 && mouseX < 199 && mouseY < 149 && selectionMade == 1) {
				if (!loadGame(file)) {
					_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
					return false;
				}
				break;
			} else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) {
				saveGame(file);
				Common::OutSaveFile *tsav;
				if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
					error("Can't open %s file", fileEpa);
				}
				for (n = 0; n < NUM_SAVES; n++) {
					tsav->writeString(names[n]);
					tsav->writeString("\n");
				}
				tsav->finalize();
				delete tsav;
			} else if (mouseX > 168 && mouseY > 154 && mouseX < 242 && mouseY < 180)
				break;
			else if (selectionMade == 0) {
				print_abc("Please select a slot", 117, 15);
			}
			updateScreen();
			delay(200);
		}
		y = 26;

		delay(5);
	}

	selectVerb(kVerbNone);

	clearRoom();
	loadPic(roomNumber, bgSurface, HALF_PAL);
	selectionMade = 0;

	_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);

	return true;
}