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.
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
* 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
|
|
|
*
|
2006-02-11 09:53:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-08-10 20:49:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/util.h"
|
2003-10-12 13:27:42 +00:00
|
|
|
#include "common/savefile.h"
|
2003-08-10 20:49:13 +00:00
|
|
|
|
2004-04-17 09:57:15 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
namespace Common {
|
|
|
|
|
2007-11-06 10:52:47 +00:00
|
|
|
bool SaveFileManager::renameSavefile(const char *oldFilename, const char *newFilename) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
outFile = openForSaving(newFilename);
|
|
|
|
|
|
|
|
if (buffer && outFile) {
|
|
|
|
inFile->read(buffer, size);
|
2007-12-10 18:59:18 +00:00
|
|
|
bool error = inFile->ioFailed();
|
|
|
|
delete inFile;
|
|
|
|
inFile = 0;
|
|
|
|
|
|
|
|
if (!error) {
|
2007-11-06 10:52:47 +00:00
|
|
|
outFile->write(buffer, size);
|
|
|
|
outFile->finalize();
|
|
|
|
if (!outFile->ioFailed()) {
|
|
|
|
success = removeSavefile(oldFilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-10 18:59:18 +00:00
|
|
|
|
2007-11-06 10:52:47 +00:00
|
|
|
free(buffer);
|
|
|
|
delete outFile;
|
|
|
|
delete inFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
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
|