Пример #1
0
Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName, DraciEngine &vm) {
	Common::String filename = vm.getSavegameFile(saveGameIdx);
	Common::SaveFileManager *saveMan = g_system->getSavefileManager();
	Common::OutSaveFile *f = saveMan->openForSaving(filename);
	if (f == NULL)
		return Common::kNoGameDataFoundError;

	TimeDate curTime;
	vm._system->getTimeAndDate(curTime);

	// Save the savegame header
	DraciSavegameHeader header;
	header.saveName = saveName;
	header.date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
	header.time = ((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF);
	header.playtime = vm.getTotalPlayTime() / 1000;
	writeSavegameHeader(f, header);

	if (f->err()) {
		delete f;
		saveMan->removeSavefile(filename);
		return Common::kWritingFailed;
	} else {
		// Create the remainder of the savegame
		Common::Serializer s(NULL, f);
		vm._game->DoSync(s);

		f->finalize();
		delete f;
		return Common::kNoError;
	}
}
Пример #2
0
void DrasculaEngine::saveGame(char gameName[]) {
	Common::OutSaveFile *out;
	int l;

	if (!(out = _saveFileMan->openForSaving(gameName))) {
		error("Unable to open the file");
	}
	out->writeSint32LE(currentChapter);
	out->write(currentData, 20);
	out->writeSint32LE(curX);
	out->writeSint32LE(curY);
	out->writeSint32LE(trackProtagonist);

	for (l = 1; l < ARRAYSIZE(inventoryObjects); l++) {
		out->writeSint32LE(inventoryObjects[l]);
	}

	for (l = 0; l < NUM_FLAGS; l++) {
		out->writeSint32LE(flags[l]);
	}

	out->writeSint32LE(takeObject);
	out->writeSint32LE(pickedObject);

	out->finalize();
	if (out->err())
		warning("Can't write file '%s'. (Disk full?)", gameName);

	delete out;
}
Пример #3
0
Common::Error SaveLoadManager::saveGame(int slot, const Common::String &saveName) {
	/* Pack any necessary data into the savegame data structure */
	// Set the selected slot number
	_vm->_globals->_saveData->_data[svLastSavegameSlot] = slot;

	// Set up the inventory
	for (int i = 0; i < 35; ++i)
		_vm->_globals->_saveData->_inventory[i] = _vm->_globals->_inventory[i];

	_vm->_globals->_saveData->_mapCarPosX = _vm->_objectsMan->_mapCarPosX;
	_vm->_globals->_saveData->_mapCarPosY = _vm->_objectsMan->_mapCarPosY;

	/* Create the savegame */
	Common::OutSaveFile *savefile = g_system->getSavefileManager()->openForSaving(_vm->generateSaveName(slot));
	if (!savefile)
		return Common::kCreatingFileFailed;

	// Set up the serializer
	Common::Serializer serializer(NULL, savefile);

	// Write out the savegame header
	hopkinsSavegameHeader header;
	header._saveName = saveName;
	header._version = HOPKINS_SAVEGAME_VERSION;
	writeSavegameHeader(savefile, header);

	// Write out the savegame data
	syncSavegameData(serializer, header._version);

	// Save file complete
	savefile->finalize();
	delete savefile;

	return Common::kNoError;
}
Пример #4
0
bool AvalancheEngine::saveGame(const int16 slot, const Common::String &desc) {
	Common::String fileName = getSaveFileName(slot);
	Common::OutSaveFile *f = g_system->getSavefileManager()->openForSaving(fileName);
	if (!f) {
		warning("Can't create file '%s', game not saved.", fileName.c_str());
		return false;
	}

	f->writeUint32LE(MKTAG('A', 'V', 'A', 'L'));

	// Write version. We can't restore from obsolete versions.
	f->writeByte(kSavegameVersion);

	f->writeUint32LE(desc.size());
	f->write(desc.c_str(), desc.size());
	Graphics::saveThumbnail(*f);

	TimeDate t;
	_system->getTimeAndDate(t);
	f->writeSint16LE(t.tm_mday);
	f->writeSint16LE(t.tm_mon);
	f->writeSint16LE(t.tm_year);

	_totalTime += getTimeInSeconds() - _startTime;

	Common::Serializer sz(NULL, f);
	synchronize(sz);
	f->finalize();
	delete f;

	return true;
}
Пример #5
0
Common::Error SavesManager::saveGameState(int slot, const Common::String &desc) {
	Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving(
		generateSaveName(slot));
	if (!out)
		return Common::kCreatingFileFailed;

	// Push map and party data to the save archives
	Map &map = *g_vm->_map;
	map.saveMaze();

	// Write the savegame header
	XeenSavegameHeader header;
	header._saveName = desc;
	writeSavegameHeader(out, header);

	// Loop through saving the sides' save archives
	SaveArchive *archives[2] = { File::_xeenSave, File::_darkSave };
	for (int idx = 0; idx < 2; ++idx) {
		if (archives[idx]) {
			archives[idx]->save(*out);
		} else {
			// Side isn't present
			out->writeUint32LE(0);
		}
	}

	// Write out miscellaneous
	FileManager &files = *g_vm->_files;
	files.save(*out);

	out->finalize();
	delete out;

	return Common::kNoError;
}
Пример #6
0
Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName) {
	const char *filename = _vm->getSavegameFile(saveGameIdx);
	Common::SaveFileManager *saveMan = g_system->getSavefileManager();
	Common::OutSaveFile *f = saveMan->openForSaving(filename);
	if (f == NULL)
		return Common::kNoGameDataFoundError;

	// Save the savegame header
	CruiseSavegameHeader header;
	header.saveName = saveName;
	writeSavegameHeader(f, header);

	if (f->err()) {
		delete f;
		saveMan->removeSavefile(filename);
		return Common::kWritingFailed;
	} else {
		// Create the remainder of the savegame
		Common::Serializer s(NULL, f);
		DoSync(s);

		f->finalize();
		delete f;
		return Common::kNoError;
	}
}
Пример #7
0
bool StarTrekEngine::saveGame(int slot, Common::String desc) {
	Common::String filename = getSavegameFilename(slot);
	Common::OutSaveFile *out;

	if (!(out = _saveFileMan->openForSaving(filename))) {
		warning("Can't create file '%s', game not saved", filename.c_str());
		return false;
	} else {
		debug(3, "Successfully opened %s for writing", filename.c_str());
	}

	SavegameMetadata meta;
	meta.version = CURRENT_SAVEGAME_VERSION;
	memset(meta.description, 0, sizeof(meta.description));
	strncpy(meta.description, desc.c_str(), SAVEGAME_DESCRIPTION_LEN);

	TimeDate curTime;
	_system->getTimeAndDate(curTime);
	meta.setSaveTimeAndDate(curTime);
	meta.playTime = g_engine->getTotalPlayTime();

	if (!saveOrLoadMetadata(nullptr, out, &meta)) {
		delete out;
		return false;
	}
	if (!saveOrLoadGameData(nullptr, out, &meta)) {
		delete out;
		return false;
	}

	out->finalize();
	delete out;
	return true;
}
Пример #8
0
void SaveManager::saveGame(uint slot, const Common::String &saveName, Common::MemoryWriteStreamDynamic *stream) {
	Common::SaveFileManager *saveFileManager = g_system->getSavefileManager();
	Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot));

	writeSaveGameHeader(file, saveName);

	file->write(stream->getData(), stream->size());

	file->finalize();
	delete file;
}
Пример #9
0
void SaveManager::autoSave() {
	Common::OutSaveFile *file = g_system->getSavefileManager()->openForSaving(_engine->generateAutoSaveFileName());

	writeSaveGameHeader(file, "auto");

	_engine->getScriptManager()->serialize(file);

	// Cleanup
	file->finalize();
	delete file;
}
Пример #10
0
bool SaveLoadManager::save(const Common::String &file, const void *buf, size_t n) {
	Common::OutSaveFile *savefile = g_system->getSavefileManager()->openForSaving(file);

	if (savefile) {
		size_t bytesWritten = savefile->write(buf, n);
		savefile->finalize();
		delete savefile;

		return bytesWritten == n;
	} else
		return false;
}
Пример #11
0
/**
 * DoSave
 */
static void DoSave() {
	Common::OutSaveFile *f;
	const char *fname;

	// Next getList() must do its stuff again
	NeedLoad = true;

	if (SaveSceneName == NULL)
		SaveSceneName = NewName();
	if (SaveSceneDesc[0] == 0)
		SaveSceneDesc = "unnamed";

	fname = SaveSceneName;

	f = _vm->getSaveFileMan()->openForSaving(fname);
	Common::Serializer s(0, f);

	if (f == NULL)
		goto save_failure;

	// Write out a savegame header
	SaveGameHeader hdr;
	hdr.id = SAVEGAME_ID;
	hdr.size = SAVEGAME_HEADER_SIZE;
	hdr.ver = CURRENT_VER;
	memcpy(hdr.desc, SaveSceneDesc, SG_DESC_LEN);
	hdr.desc[SG_DESC_LEN - 1] = 0;
	g_system->getTimeAndDate(hdr.dateTime);
	if (!syncSaveGameHeader(s, hdr) || f->err()) {
		goto save_failure;
	}

	DoSync(s);

	// Write out the special Id for Discworld savegames
	f->writeUint32LE(0xFEEDFACE);
	if (f->err())
		goto save_failure;

	f->finalize();
	delete f;
	return;

save_failure:
	if (f) {
		delete f;
		_vm->getSaveFileMan()->removeSavefile(fname);
	}
	GUI::MessageDialog dialog("Failed to save game state to file.");
	dialog.runModal();
}
Пример #12
0
void SaveManager::saveGame(uint slot, const Common::String &saveName) {
	// The games only support 20 slots
	//assert(slot <= 1 && slot <= 20);

	Common::SaveFileManager *saveFileManager = g_system->getSavefileManager();
	Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot));

	writeSaveGameHeader(file, saveName);

	_engine->getScriptManager()->serialize(file);

	file->finalize();
	delete file;
}
Пример #13
0
Common::Error Saver::save(int slot, const Common::String &saveName) {
	assert(!getMacroRestoreFlag());
	Common::StackLock slock1(g_globals->_soundManager._serverDisabledMutex);

	// Signal any objects registered for notification
	_saveNotifiers.notify(false);

	// Set fields
	_macroSaveFlag = true;
	_saveSlot = slot;

	// Try and create the save file
	Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(g_vm->generateSaveName(slot));
	if (!saveFile)
		return Common::kCreatingFileFailed;

	// Set up the serializer
	Serializer serializer(NULL, saveFile);
	serializer.setSaveVersion(TSAGE_SAVEGAME_VERSION);

	// Write out the savegame header
	tSageSavegameHeader header;
	header.saveName = saveName;
	header.version = TSAGE_SAVEGAME_VERSION;
	writeSavegameHeader(saveFile, header);

	// Save out objects that need to come at the start of the savegame
	for (SynchronizedList<SaveListener *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
		(*i)->listenerSynchronize(serializer);
	}

	// Save each registered SaveObject descendant object into the savegame file
	for (SynchronizedList<SavedObject *>::iterator i = _objList.begin(); i != _objList.end(); ++i) {
		SavedObject *so = *i;
		serializer.validate(so->getClassName());
		so->synchronize(serializer);
	}

	// Save file complete
	saveFile->writeString("END");
	saveFile->finalize();
	delete saveFile;

	// Final post-save notification
	_macroSaveFlag = false;
	_saveNotifiers.notify(true);

	return Common::kNoError;
}
Пример #14
0
bool BasePersistenceManager::saveFile(const Common::String &filename) {
    byte *prefixBuffer = _richBuffer;
    uint32 prefixSize = _richBufferSize;
    byte *buffer = ((Common::MemoryWriteStreamDynamic *)_saveStream)->getData();
    uint32 bufferSize = ((Common::MemoryWriteStreamDynamic *)_saveStream)->size();

    Common::SaveFileManager *saveMan = ((WintermuteEngine *)g_engine)->getSaveFileMan();
    Common::OutSaveFile *file = saveMan->openForSaving(filename);
    file->write(prefixBuffer, prefixSize);
    file->write(buffer, bufferSize);
    bool retVal = !file->err();
    file->finalize();
    delete file;
    return retVal;
}
Пример #15
0
/**
 * This test creates a savefile for the given testbed-state and could be reloaded using the saveFile API.
 * It is intended to test saving and loading from savefiles.
 */
bool SaveGametests::writeDataToFile(const char *fileName, const char *msg) {
	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
	Common::OutSaveFile *saveFile = saveFileMan->openForSaving(fileName);

	if (!saveFile) {
		Testsuite::logDetailedPrintf("Can't open saveFile %s\n", fileName);
		return false;
	}

	saveFile->writeString(msg);
	saveFile->finalize();
	delete saveFile;

	return true;
}
Пример #16
0
void Game::saveGame(int slotNumber, const Common::String &saveName) {
	Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving(
		_vm->generateSaveName(slotNumber));

	MADSSavegameHeader header;
	header._saveName = saveName;
	writeSavegameHeader(out, header);

	Common::Serializer s(nullptr, out);
	synchronize(s, true);
	synchronize(s, false);

	out->finalize();
	delete out;
}
Пример #17
0
int16 GameDatabaseV2::savegame(const char *filename, const char *description, int16 version) {
	Common::OutSaveFile *out;
	int16 result = 0;
	if (!(out = g_system->getSavefileManager()->openForSaving(filename))) {
		warning("Can't create file '%s', game not saved", filename);
		return 6;
	}
	// Variable 0 is not saved
	out->write(_gameState + 2, _gameStateSize - 2);
	for (uint i = 0; i < _objects.size(); i++)
		_objects[i]->save(*out);
	out->finalize();
	delete out;
	return result;
}
Пример #18
0
void SkyMetaEngine::removeSaveState(const char *target, int slot) const {
	if (slot == 0)	// do not delete the auto save
		return;

	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
	char fName[20];
	sprintf(fName,"SKY-VM.%03d", slot - 1);
	saveFileMan->removeSavefile(fName);

	// Load current save game descriptions
	Common::StringArray savenames;
	savenames.resize(MAX_SAVE_GAMES+1);
	Common::InSaveFile *inf;
	inf = saveFileMan->openForLoading("SKY-VM.SAV");
	if (inf != NULL) {
		char *tmpBuf =  new char[MAX_SAVE_GAMES * MAX_TEXT_LEN];
		char *tmpPtr = tmpBuf;
		inf->read(tmpBuf, MAX_SAVE_GAMES * MAX_TEXT_LEN);
		for (int i = 0; i < MAX_SAVE_GAMES; ++i) {
			savenames[i] = tmpPtr;
			tmpPtr += savenames[i].size() + 1;
		}
		delete inf;
		delete[] tmpBuf;
	}

	// Update the save game description at the given slot
	savenames[slot - 1] = "";

	// Save the updated descriptions
	Common::OutSaveFile *outf;

	outf = saveFileMan->openForSaving("SKY-VM.SAV");
	bool ioFailed = true;
	if (outf) {
		for (uint16 cnt = 0; cnt < MAX_SAVE_GAMES; cnt++) {
			outf->write(savenames[cnt].c_str(), savenames[cnt].size() + 1);
		}
		outf->finalize();
		if (!outf->err())
			ioFailed = false;
		delete outf;
	}
	if (ioFailed)
		warning("Unable to store Savegame names to file SKY-VM.SAV. (%s)", saveFileMan->popErrorDesc().c_str());
}
Пример #19
0
void CGEEngine::saveGame(int slotNumber, const Common::String &desc) {
	// Set up the serializer
	Common::String slotName = generateSaveName(slotNumber);
	Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(slotName);

	// Write out the ScummVM savegame header
	SavegameHeader header;
	header.saveName = desc;
	header.version = kSavegameVersion;
	writeSavegameHeader(saveFile, header);

	// Write out the data of the savegame
	syncGame(NULL, saveFile, false);

	// Finish writing out game data
	saveFile->finalize();
	delete saveFile;
}
Пример #20
0
Common::Error XeenEngine::saveGameState(int slot, const Common::String &desc) {
	Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving(
		generateSaveName(slot));
	if (!out)
		return Common::kCreatingFileFailed;

	XeenSavegameHeader header;
	header._saveName = desc;
	writeSavegameHeader(out, header);

	Common::Serializer s(nullptr, out);
	synchronize(s);

	out->finalize();
	delete out;

	return Common::kNoError;
}
Пример #21
0
bool LabEngine::saveGame(int slot, const Common::String desc) {
	Common::String fileName = generateSaveFileName(slot);
	Common::SaveFileManager *saveFileManager = _system->getSavefileManager();
	Common::OutSaveFile *file = saveFileManager->openForSaving(fileName);

	if (!file)
		return false;

	// Load scene pic
	_graphics->readPict(getPictName(false));


	writeSaveGameHeader(file, desc);
	file->writeUint16LE(_roomNum);
	file->writeUint16LE(getDirection());
	file->writeUint16LE(getQuarters());

	// Conditions
	for (int i = 0; i < _conditions->_lastElement / (8 * 2); i++)
		file->writeUint16LE(_conditions->_array[i]);

	// Rooms found
	for (int i = 0; i < _roomsFound->_lastElement / (8 * 2); i++)
		file->writeUint16LE(_roomsFound->_array[i]);

	_specialLocks->save(file);

	// Breadcrumbs
	for (uint i = 0; i < MAX_CRUMBS; i++) {
		file->writeUint16LE(_breadCrumbs[i]._crumbRoomNum);
		file->writeUint16LE(_breadCrumbs[i]._crumbDirection);
	}

	file->flush();
	file->finalize();
	delete file;

	_mainDisplay = true;
	_alternate = false;
	_event->simulateEvent();
	_graphics->screenUpdate();

	return true;
}
Пример #22
0
Common::Error QueenEngine::saveGameState(int slot, const char *desc) {
	debug(3, "Saving game to slot %d", slot);
	char name[20];
	Common::Error err = Common::kNoError;
	makeGameStateName(slot, name);
	Common::OutSaveFile *file = _saveFileMan->openForSaving(name);
	if (file) {
		// save data
		byte *saveData = new byte[SAVESTATE_MAX_SIZE];
		byte *p = saveData;
		_bam->saveState(p);
		_grid->saveState(p);
		_logic->saveState(p);
		_sound->saveState(p);
		uint32 dataSize = p - saveData;
		assert(dataSize < SAVESTATE_MAX_SIZE);

		// write header
		file->writeUint32BE('SCVM');
		file->writeUint32BE(SAVESTATE_CUR_VER);
		file->writeUint32BE(0);
		file->writeUint32BE(dataSize);
		char description[32];
		Common::strlcpy(description, desc, sizeof(description));
		file->write(description, sizeof(description));

		// write save data
		file->write(saveData, dataSize);
		file->finalize();

		// check for errors
		if (file->err()) {
			warning("Can't write file '%s'. (Disk full?)", name);
			err = Common::kWritingFailed;
		}
		delete[] saveData;
		delete file;
	} else {
		warning("Can't create file '%s', game not saved", name);
		err = Common::kCreatingFileFailed;
	}

	return err;
}
Пример #23
0
bool MystGameState::save(const Common::String &fname) {
    Common::String filename(fname);
    // Make sure we have the right extension
    if (!filename.hasSuffix(".mys") && !filename.hasSuffix(".MYS"))
        filename += ".mys";

    Common::OutSaveFile *saveFile = _saveFileMan->openForSaving(filename);
    if (!saveFile)
        return false;

    debugC(kDebugSaveLoad, "Saving game to '%s'", filename.c_str());

    Common::Serializer s(0, saveFile);
    syncGameState(s, _vm->getFeatures() & GF_ME);
    saveFile->finalize();
    delete saveFile;

    return true;
}
Пример #24
0
int16 GameDatabaseV3::savegame(const char *filename, const char *description, int16 version) {
	Common::OutSaveFile *out;
	char desc[64];
	int16 result = 0;
	uint32 size = 4 + 4 + 2 + _gameStateSize;
	if (!(out = g_system->getSavefileManager()->openForSaving(filename))) {
		warning("Can't create file '%s', game not saved", filename);
		return 6;
	}
	Common::strlcpy(desc, description, 64);
	out->writeUint32BE(MKTAG('S','G','A','M'));
	out->writeUint32LE(size);
	out->writeUint16LE(version);
	out->write(desc, 64);
	out->write(_gameState, _gameStateSize);
	out->finalize();
	delete out;
	return result;
}
Пример #25
0
uint32 Sword2Engine::saveData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
	char *saveFileName = getSaveFileName(slotNo);

	Common::OutSaveFile *out;

	if (!(out = _saveFileMan->openForSaving(saveFileName))) {
		return SR_ERR_FILEOPEN;
	}

	out->write(buffer, bufferSize);
	out->finalize();

	if (!out->err()) {
		delete out;
		return SR_OK;
	}

	delete out;
	return SR_ERR_WRITEFAIL;
}
Пример #26
0
bool NeverhoodEngine::savegame(const char *filename, const char *description) {

	Common::OutSaveFile *out;
	if (!(out = g_system->getSavefileManager()->openForSaving(filename))) {
		warning("Can't create file '%s', game not saved", filename);
		return false;
	}

	TimeDate curTime;
	g_system->getTimeAndDate(curTime);

	// Header start
	out->writeUint32LE(NEVERHOOD_SAVEGAME_VERSION);

	byte descriptionLen = strlen(description);
	out->writeByte(descriptionLen);
	out->write(description, descriptionLen);

	Graphics::saveThumbnail(*out);

	// Not used yet, reserved for future usage
	out->writeByte(0);
	out->writeUint32LE(0);
	uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
	uint32 saveTime = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
	uint32 playTime = g_engine->getTotalPlayTime() / 1000;
	out->writeUint32LE(saveDate);
	out->writeUint32LE(saveTime);
	out->writeUint32LE(playTime);
	// Header end

	_gameVars->setGlobalVar(V_CURRENT_SCENE, _gameState.sceneNum);
	_gameVars->setGlobalVar(V_CURRENT_SCENE_WHICH, _gameState.which);

	_gameVars->saveState(out);

	out->finalize();
	delete out;
	return true;
}
Пример #27
0
Common::Error ToucheEngine::saveGameState(int num, const Common::String &description) {
	bool saveOk = false;
	Common::String gameStateFileName = generateGameStateFileName(_targetName.c_str(), num);
	Common::OutSaveFile *f = _saveFileMan->openForSaving(gameStateFileName);
	if (f) {
		f->writeUint16LE(kCurrentGameStateVersion);
		f->writeUint16LE(0);
		char headerDescription[kGameStateDescriptionLen];
		memset(headerDescription, 0, kGameStateDescriptionLen);
		strncpy(headerDescription, description.c_str(), kGameStateDescriptionLen - 1);
		f->write(headerDescription, kGameStateDescriptionLen);
		saveGameStateData(f);
		f->finalize();
		if (!f->err()) {
			saveOk = true;
		} else {
			warning("Can't write file '%s'", gameStateFileName.c_str());
		}
		delete f;
	}
	return saveOk ? Common::kNoError : Common::kUnknownError;
}
Пример #28
0
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;
	}
}
Пример #29
0
void SaveManager::saveGame(uint slot, const Common::String &saveName, bool useSaveBuffer) {
	if (!_tempSave && useSaveBuffer)
		return;

	Common::SaveFileManager *saveFileManager = g_system->getSavefileManager();
	Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot));

	writeSaveGameHeader(file, saveName, useSaveBuffer);

	if (useSaveBuffer)
		file->write(_tempSave->getData(), _tempSave->size());
	else
		_engine->getScriptManager()->serialize(file);

	file->finalize();
	delete file;

	if (useSaveBuffer)
		flushSaveBuffer();

	_lastSaveTime = g_system->getMillis();
}
Пример #30
0
Common::Error SciEngine::saveGameState(int slot, const Common::String &desc) {
	Common::String fileName = Common::String::format("%s.%03d", _targetName.c_str(), slot);
	Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
	Common::OutSaveFile *out = saveFileMan->openForSaving(fileName);
	const char *version = "";
	if (!out) {
		warning("Opening savegame \"%s\" for writing failed", fileName.c_str());
		return Common::kWritingFailed;
	}

	if (!gamestate_save(_gamestate, out, desc, version)) {
		warning("Saving the game state to '%s' failed", fileName.c_str());
		return Common::kWritingFailed;
	} else {
		out->finalize();
		if (out->err()) {
			warning("Writing the savegame failed");
			return Common::kWritingFailed;
		}
		delete out;
	}

	return Common::kNoError;
}