CLOUD: Make OutSaveFile start saves sync

It had to become a proxy class in order to do that.
finalize() starts the saves sync.
This commit is contained in:
Alexander Tkachev
2016-08-24 16:07:55 +06:00
parent 81106b0444
commit aee713141b
13 changed files with 49 additions and 12 deletions
@@ -56,7 +56,7 @@ Common::OutSaveFile *GBAMPSaveFileManager::openForSaving(const Common::String &f
Common::WriteStream *stream = DS::DSFileStream::makeFromPath(fileSpec, true);
// Use a write buffer
stream = Common::wrapBufferedWriteStream(stream, SAVE_BUFFER_SIZE);
return stream;
return new OutSaveFile(stream);
}
Common::InSaveFile *GBAMPSaveFileManager::openForLoading(const Common::String &filename) {
+1 -1
View File
@@ -106,7 +106,7 @@ public:
virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) {
OutFRAMSave *s = new OutFRAMSave(filename.c_str());
if (!s->err()) {
return compress ? Common::wrapCompressedWriteStream(s) : s;
return new OutSaveFile(compress ? Common::wrapCompressedWriteStream(s) : s);
} else {
delete s;
return 0;
+1 -1
View File
@@ -108,7 +108,7 @@ public:
virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) {
OutPAKSave *s = new OutPAKSave(filename.c_str());
if (!s->err()) {
return compress ? Common::wrapCompressedWriteStream(s) : s;
return new OutSaveFile(compress ? Common::wrapCompressedWriteStream(s) : s);
} else {
delete s;
return NULL;
+1 -1
View File
@@ -192,7 +192,7 @@ Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const Common::String &fil
}
_screen->wantAnim(false);
return compress ? Common::wrapCompressedWriteStream(sf) : sf;
return new OutSaveFile(compress ? Common::wrapCompressedWriteStream(sf) : sf);
}
bool Ps2SaveFileManager::removeSavefile(const Common::String &filename) {
+1 -1
View File
@@ -156,7 +156,7 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String
// Open the file for saving.
Common::WriteStream *const sf = fileNode.createWriteStream();
Common::OutSaveFile *const result = compress ? Common::wrapCompressedWriteStream(sf) : sf;
Common::OutSaveFile *const result = new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(sf) : sf);
// Add file to cache now that it exists.
_saveFileCache[filename] = Common::FSNode(fileNode.getPath());
+24
View File
@@ -23,9 +23,33 @@
#include "common/util.h"
#include "common/savefile.h"
#include "common/str.h"
#ifdef USE_CLOUD
#include "backends/cloud/cloudmanager.h"
#endif
namespace Common {
OutSaveFile::OutSaveFile(WriteStream *w): _wrapped(w) {}
OutSaveFile::~OutSaveFile() {}
bool OutSaveFile::err() const { return _wrapped->err(); }
void OutSaveFile::clearErr() { _wrapped->clearErr(); }
void OutSaveFile::finalize() {
_wrapped->finalize();
#ifdef USE_CLOUD
CloudMan.syncSaves();
#endif
}
bool OutSaveFile::flush() { return _wrapped->flush(); }
uint32 OutSaveFile::write(const void *dataPtr, uint32 dataSize) {
return _wrapped->write(dataPtr, dataSize);
}
bool SaveFileManager::copySavefile(const String &oldFilename, const String &newFilename) {
InSaveFile *inFile = 0;
OutSaveFile *outFile = 0;
+14 -1
View File
@@ -28,6 +28,7 @@
#include "common/stream.h"
#include "common/str-array.h"
#include "common/error.h"
#include "common/ptr.h"
namespace Common {
@@ -44,8 +45,20 @@ typedef SeekableReadStream InSaveFile;
* That typically means "save games", but also includes things like the
* IQ points in Indy3.
*/
typedef WriteStream OutSaveFile;
class OutSaveFile: public WriteStream {
protected:
ScopedPtr<WriteStream> _wrapped;
public:
OutSaveFile(WriteStream *w);
virtual ~OutSaveFile();
virtual bool err() const;
virtual void clearErr();
virtual void finalize();
virtual bool flush();
virtual uint32 write(const void *dataPtr, uint32 dataSize);
};
/**
* The SaveFileManager is serving as a factory for InSaveFile
+2 -2
View File
@@ -328,7 +328,7 @@ Common::Error EoBCoreEngine::saveGameStateIntern(int slot, const char *saveName,
fileName = getSavegameFilename(slot);
}
Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumbnail);
Common::OutSaveFile *out = new Common::OutSaveFile(openSaveForWriting(fileName, saveName, thumbnail));
if (!out)
return _saveFileMan->getError();
@@ -995,7 +995,7 @@ bool EoBCoreEngine::saveAsOriginalSaveFile(int slot) {
return false;
Common::FSNode nf = nd.getChild(_flags.gameID == GI_EOB1 ? "EOBDATA.SAV" : Common::String::format("EOBDATA%d.SAV", slot));
Common::WriteStream *out = nf.createWriteStream();
Common::OutSaveFile *out = new Common::OutSaveFile(nf.createWriteStream());
if (_flags.gameID == GI_EOB2) {
static const char tempStr[20] = "SCUMMVM EXPORT ";
+1 -1
View File
@@ -34,7 +34,7 @@ namespace Kyra {
Common::Error KyraEngine_HoF::saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumb) {
const char *fileName = getSavegameFilename(slot);
Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumb);
Common::OutSaveFile *out = new Common::OutSaveFile(openSaveForWriting(fileName, saveName, thumb));
if (!out)
return _saveFileMan->getError();
+1 -1
View File
@@ -241,7 +241,7 @@ Common::Error KyraEngine_LoK::saveGameStateIntern(int slot, const char *saveName
if (shouldQuit())
return Common::kNoError;
Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumb);
Common::OutSaveFile *out = new Common::OutSaveFile(openSaveForWriting(fileName, saveName, thumb));
if (!out)
return _saveFileMan->getError();
+1 -1
View File
@@ -335,7 +335,7 @@ Common::Error LoLEngine::loadGameState(int slot) {
Common::Error LoLEngine::saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail) {
const char *fileName = getSavegameFilename(slot);
Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumbnail);
Common::OutSaveFile *out = new Common::OutSaveFile(openSaveForWriting(fileName, saveName, thumbnail));
if (!out)
return _saveFileMan->getError();
+1 -1
View File
@@ -33,7 +33,7 @@ namespace Kyra {
Common::Error KyraEngine_MR::saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumb) {
const char *fileName = getSavegameFilename(slot);
Common::OutSaveFile *out = openSaveForWriting(fileName, saveName, thumb);
Common::OutSaveFile *out = new Common::OutSaveFile(openSaveForWriting(fileName, saveName, thumb));
if (!out)
return _saveFileMan->getError();
Binary file not shown.