mirror of
https://github.com/libretro/scummvm.git
synced 2025-05-13 09:36:21 +00:00
Added finalize() method to Common::OutSaveFile (which by default just flushes the stream), changed engines to call that before deleting OutSaveFile instances (instead of just flushing)
svn-id: r25660
This commit is contained in:
parent
7d5d6c2f91
commit
b8aeefaffb
@ -41,7 +41,20 @@ class InSaveFile : public SeekableReadStream {};
|
||||
* That typically means "save games", but also includes things like the
|
||||
* IQ points in Indy3.
|
||||
*/
|
||||
class OutSaveFile : public WriteStream {};
|
||||
class OutSaveFile : public WriteStream {
|
||||
public:
|
||||
/**
|
||||
* Close this savefile, to be called right before destruction of this
|
||||
* savefile. The idea is that this ways, I/O errors that occur
|
||||
* during closing/flushing of the file can still be handled by the
|
||||
* game engine.
|
||||
*
|
||||
* By default, this just flushes the stream.
|
||||
*/
|
||||
virtual void finalize() {
|
||||
flush();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Convenience intermediate class, to be removed.
|
||||
|
@ -200,7 +200,7 @@ int AgiEngine::saveGame(const char *fileName, const char *description) {
|
||||
}
|
||||
out->writeByte(0);
|
||||
|
||||
out->flush();
|
||||
out->finalize();
|
||||
if (out->ioFailed())
|
||||
warning("Can't write file '%s'. (Disk full?)", fileName);
|
||||
else
|
||||
|
@ -649,7 +649,7 @@ bool AGOSEngine::loadGame_e1(const char *filename, bool restartMode) {
|
||||
}
|
||||
|
||||
bool AGOSEngine::saveGame_e1(const char *filename) {
|
||||
Common::WriteStream *f;
|
||||
Common::OutSaveFile *f;
|
||||
uint item_index, num_item, i;
|
||||
TimeEvent *te;
|
||||
uint32 curTime = 0;
|
||||
@ -717,7 +717,7 @@ bool AGOSEngine::saveGame_e1(const char *filename) {
|
||||
f->writeUint16BE(readVariable(i));
|
||||
}
|
||||
|
||||
f->flush();
|
||||
f->finalize();
|
||||
bool result = !f->ioFailed();
|
||||
|
||||
delete f;
|
||||
@ -873,7 +873,7 @@ bool AGOSEngine::loadGame(const char *filename, bool restartMode) {
|
||||
}
|
||||
|
||||
bool AGOSEngine::saveGame(uint slot, const char *caption) {
|
||||
Common::WriteStream *f;
|
||||
Common::OutSaveFile *f;
|
||||
uint item_index, num_item, i, j;
|
||||
TimeEvent *te;
|
||||
uint32 curTime = 0;
|
||||
@ -988,7 +988,7 @@ bool AGOSEngine::saveGame(uint slot, const char *caption) {
|
||||
f->writeUint16BE(_superRoomNumber);
|
||||
}
|
||||
|
||||
f->flush();
|
||||
f->finalize();
|
||||
bool result = !f->ioFailed();
|
||||
|
||||
delete f;
|
||||
|
@ -295,7 +295,7 @@ void GobEngine::saveGameData(enum SaveFiles sFile, int16 dataVar, int32 size, in
|
||||
|
||||
retSize = writeDataEndian(*out, buf, _global->_inter_variablesSizes + dataVar, size);
|
||||
|
||||
out->flush();
|
||||
out->finalize();
|
||||
|
||||
if (out->ioFailed() || (retSize != size))
|
||||
warning("Can't write file \"%s\"", sName);
|
||||
@ -329,7 +329,7 @@ bool GobEngine::saveGame(int saveSlot, int16 dataVar, int32 size, int32 offset)
|
||||
}
|
||||
writeDataEndian(*out, _saveIndex + saveSlot * 40, _saveIndexSizes + saveSlot * 40, 40);
|
||||
writeDataEndian(*out, varBuf, sizeBuf, size);
|
||||
out->flush();
|
||||
out->finalize();
|
||||
if (out->ioFailed()) {
|
||||
warning("Can't save to slot %d", saveSlot);
|
||||
return false;
|
||||
|
@ -362,7 +362,7 @@ void KyraEngine::saveGame(const char *fileName, const char *saveName) {
|
||||
|
||||
out->writeByte(_curSfxFile);
|
||||
|
||||
out->flush();
|
||||
out->finalize();
|
||||
|
||||
// check for errors
|
||||
if (out->ioFailed())
|
||||
|
@ -249,7 +249,7 @@ void QueenEngine::saveGameState(uint16 slot, const char *desc) {
|
||||
|
||||
// write save data
|
||||
file->write(saveData, dataSize);
|
||||
file->flush();
|
||||
file->finalize();
|
||||
|
||||
// check for errors
|
||||
if (file->ioFailed()) {
|
||||
|
@ -211,7 +211,7 @@ void SagaEngine::save(const char *fileName, const char *saveName) {
|
||||
out->writeSint16LE(_isoMap->getMapPosition().x);
|
||||
out->writeSint16LE(_isoMap->getMapPosition().y);
|
||||
|
||||
out->flush();
|
||||
out->finalize();
|
||||
|
||||
// TODO: Check out->ioFailed()
|
||||
|
||||
|
@ -109,7 +109,7 @@ bool ScummEngine::saveState(int slot, bool compat) {
|
||||
|
||||
Serializer ser(0, out, CURRENT_VER);
|
||||
saveOrLoad(&ser);
|
||||
out->flush();
|
||||
out->finalize();
|
||||
if (out->ioFailed()) {
|
||||
delete out;
|
||||
debug(1, "State save as '%s' FAILED", filename);
|
||||
|
@ -1138,7 +1138,7 @@ void Control::saveDescriptions(uint8 *srcBuf) {
|
||||
bool ioFailed = true;
|
||||
if (outf) {
|
||||
outf->write(tmpBuf, tmpPos - tmpBuf);
|
||||
outf->flush();
|
||||
outf->finalize();
|
||||
if (!outf->ioFailed())
|
||||
ioFailed = false;
|
||||
delete outf;
|
||||
@ -1165,7 +1165,7 @@ void Control::doAutoSave(void) {
|
||||
uint32 fSize = prepareSaveData(saveData);
|
||||
|
||||
outf->write(saveData, fSize);
|
||||
outf->flush();
|
||||
outf->finalize();
|
||||
|
||||
if (outf->ioFailed())
|
||||
displayMessage(0, "Unable to write autosave file '%s' in directory '%s'. Disk full?", fName, _saveFileMan->getSavePath());
|
||||
@ -1187,7 +1187,7 @@ uint16 Control::saveGameToFile(void) {
|
||||
uint32 fSize = prepareSaveData(saveData);
|
||||
|
||||
uint32 writeRes = outf->write(saveData, fSize);
|
||||
outf->flush();
|
||||
outf->finalize();
|
||||
if (outf->ioFailed())
|
||||
writeRes = 0;
|
||||
free(saveData);
|
||||
|
@ -763,7 +763,7 @@ void Control::writeSavegameDescriptions(void) {
|
||||
else
|
||||
outf->writeByte(255);
|
||||
}
|
||||
outf->flush();
|
||||
outf->finalize();
|
||||
if (outf->ioFailed())
|
||||
displayMessage(0, "Can't write to SAVEGAME.INF in directory '%s'. Device full?", _saveFileMan->getSavePath());
|
||||
delete outf;
|
||||
@ -958,7 +958,7 @@ void Control::saveGameToFile(uint8 slot) {
|
||||
uint32 *playerRaw = (uint32*)cpt;
|
||||
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++)
|
||||
outf->writeUint32LE(playerRaw[cnt2]);
|
||||
outf->flush();
|
||||
outf->finalize();
|
||||
if (outf->ioFailed())
|
||||
displayMessage(0, "Couldn't write to file '%s' in directory '%s'. Device full?", fName, _saveFileMan->getSavePath());
|
||||
delete outf;
|
||||
|
@ -132,7 +132,7 @@ uint32 Sword2Engine::saveData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
|
||||
}
|
||||
|
||||
out->write(buffer, bufferSize);
|
||||
out->flush();
|
||||
out->finalize();
|
||||
|
||||
if (!out->ioFailed()) {
|
||||
delete out;
|
||||
|
@ -344,7 +344,7 @@ bool ToucheEngine::saveGameState(int num, const char *description) {
|
||||
strncpy(headerDescription, description, kGameStateDescriptionLen - 1);
|
||||
f->write(headerDescription, kGameStateDescriptionLen);
|
||||
saveGameStateData(f);
|
||||
f->flush();
|
||||
f->finalize();
|
||||
if (!f->ioFailed()) {
|
||||
saveOk = true;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user