2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-08-10 20:49:13 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 02:34:18 +01:00
|
|
|
*
|
2003-08-10 20:49:13 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:18 +01:00
|
|
|
*
|
2003-08-10 20:49:13 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-08-10 20:49:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/util.h"
|
2003-10-12 13:27:42 +00:00
|
|
|
#include "common/savefile.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/str.h"
|
2016-10-17 18:45:12 +02:00
|
|
|
#if defined(USE_CLOUD) && defined(USE_LIBCURL)
|
2016-06-18 18:49:46 +06:00
|
|
|
#include "backends/cloud/cloudmanager.h"
|
|
|
|
#endif
|
2004-04-17 09:57:15 +00:00
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
namespace Common {
|
|
|
|
|
2016-06-18 18:49:46 +06:00
|
|
|
OutSaveFile::OutSaveFile(WriteStream *w): _wrapped(w) {}
|
|
|
|
|
2019-01-05 11:55:21 +01:00
|
|
|
OutSaveFile::~OutSaveFile() {
|
|
|
|
delete _wrapped;
|
|
|
|
}
|
2016-06-18 18:49:46 +06:00
|
|
|
|
|
|
|
bool OutSaveFile::err() const { return _wrapped->err(); }
|
|
|
|
|
|
|
|
void OutSaveFile::clearErr() { _wrapped->clearErr(); }
|
|
|
|
|
|
|
|
void OutSaveFile::finalize() {
|
|
|
|
_wrapped->finalize();
|
2016-10-17 18:45:12 +02:00
|
|
|
#if defined(USE_CLOUD) && defined(USE_LIBCURL)
|
2016-06-18 18:49:46 +06:00
|
|
|
CloudMan.syncSaves();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OutSaveFile::flush() { return _wrapped->flush(); }
|
|
|
|
|
|
|
|
uint32 OutSaveFile::write(const void *dataPtr, uint32 dataSize) {
|
|
|
|
return _wrapped->write(dataPtr, dataSize);
|
|
|
|
}
|
|
|
|
|
2016-08-24 16:24:16 +06:00
|
|
|
int32 OutSaveFile::pos() const {
|
|
|
|
return _wrapped->pos();
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:50:28 -08:00
|
|
|
bool SaveFileManager::copySavefile(const String &oldFilename, const String &newFilename, bool compress) {
|
2007-11-06 10:52:47 +00:00
|
|
|
InSaveFile *inFile = 0;
|
|
|
|
OutSaveFile *outFile = 0;
|
|
|
|
uint32 size = 0;
|
|
|
|
void *buffer = 0;
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
inFile = openForLoading(oldFilename);
|
|
|
|
|
|
|
|
if (inFile) {
|
|
|
|
size = inFile->size();
|
|
|
|
buffer = malloc(size);
|
|
|
|
assert(buffer);
|
|
|
|
|
2019-12-09 22:50:28 -08:00
|
|
|
outFile = openForSaving(newFilename, compress);
|
2007-11-06 10:52:47 +00:00
|
|
|
|
|
|
|
if (buffer && outFile) {
|
|
|
|
inFile->read(buffer, size);
|
2009-05-19 11:42:14 +00:00
|
|
|
bool error = inFile->err();
|
2007-12-10 18:59:18 +00:00
|
|
|
delete inFile;
|
|
|
|
inFile = 0;
|
|
|
|
|
|
|
|
if (!error) {
|
2007-11-06 10:52:47 +00:00
|
|
|
outFile->write(buffer, size);
|
|
|
|
outFile->finalize();
|
2011-03-21 12:24:16 -04:00
|
|
|
|
|
|
|
success = !outFile->err();
|
2007-11-06 10:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-10 18:59:18 +00:00
|
|
|
|
2007-11-06 10:52:47 +00:00
|
|
|
free(buffer);
|
|
|
|
delete outFile;
|
|
|
|
delete inFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:50:28 -08:00
|
|
|
bool SaveFileManager::renameSavefile(const String &oldFilename, const String &newFilename, bool compress) {
|
|
|
|
if (!copySavefile(oldFilename, newFilename, compress))
|
2011-03-21 12:24:16 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return removeSavefile(oldFilename);
|
|
|
|
}
|
|
|
|
|
2007-12-28 07:37:04 +00:00
|
|
|
String SaveFileManager::popErrorDesc() {
|
|
|
|
String err = _errorDesc;
|
|
|
|
clearError();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-12-28 07:37:04 +00:00
|
|
|
return err;
|
2004-11-27 00:26:11 +00:00
|
|
|
}
|
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
} // End of namespace Common
|