ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

savefile.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/util.h"
00024 #include "common/savefile.h"
00025 #include "common/str.h"
00026 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
00027 #include "backends/cloud/cloudmanager.h"
00028 #endif
00029 
00030 namespace Common {
00031 
00032 OutSaveFile::OutSaveFile(WriteStream *w): _wrapped(w) {}
00033 
00034 OutSaveFile::~OutSaveFile() {
00035     delete _wrapped;
00036 }
00037 
00038 bool OutSaveFile::err() const { return _wrapped->err(); }
00039 
00040 void OutSaveFile::clearErr() { _wrapped->clearErr(); }
00041 
00042 void OutSaveFile::finalize() {
00043     _wrapped->finalize();
00044 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
00045     CloudMan.syncSaves();
00046 #endif
00047 }
00048 
00049 bool OutSaveFile::flush() { return _wrapped->flush(); }
00050 
00051 uint32 OutSaveFile::write(const void *dataPtr, uint32 dataSize) {
00052     return _wrapped->write(dataPtr, dataSize);
00053 }
00054 
00055 int32 OutSaveFile::pos() const {
00056     return _wrapped->pos();
00057 }
00058 
00059 bool SaveFileManager::copySavefile(const String &oldFilename, const String &newFilename) {
00060     InSaveFile *inFile = 0;
00061     OutSaveFile *outFile = 0;
00062     uint32 size = 0;
00063     void *buffer = 0;
00064     bool success = false;
00065 
00066     inFile = openForLoading(oldFilename);
00067 
00068     if (inFile) {
00069         size = inFile->size();
00070         buffer = malloc(size);
00071         assert(buffer);
00072 
00073         outFile = openForSaving(newFilename);
00074 
00075         if (buffer && outFile) {
00076             inFile->read(buffer, size);
00077             bool error = inFile->err();
00078             delete inFile;
00079             inFile = 0;
00080 
00081             if (!error) {
00082                 outFile->write(buffer, size);
00083                 outFile->finalize();
00084 
00085                 success = !outFile->err();
00086             }
00087         }
00088 
00089         free(buffer);
00090         delete outFile;
00091         delete inFile;
00092     }
00093 
00094     return success;
00095 }
00096 
00097 bool SaveFileManager::renameSavefile(const String &oldFilename, const String &newFilename) {
00098     if (!copySavefile(oldFilename, newFilename))
00099         return false;
00100 
00101     return removeSavefile(oldFilename);
00102 }
00103 
00104 String SaveFileManager::popErrorDesc() {
00105     String err = _errorDesc;
00106     clearError();
00107 
00108     return err;
00109 }
00110 
00111 } // End of namespace Common


Generated on Sat Mar 23 2019 05:02:07 for ResidualVM by doxygen 1.7.1
curved edge   curved edge