Patch #1825132: SAVEFILEMAN: renameSavefile implementation
svn-id: r29433
This commit is contained in:
parent
83802f795b
commit
3598192859
2 changed files with 44 additions and 0 deletions
|
@ -32,6 +32,42 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
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);
|
||||
if (!inFile->ioFailed()) {
|
||||
outFile->write(buffer, size);
|
||||
outFile->finalize();
|
||||
if (!outFile->ioFailed()) {
|
||||
success = removeSavefile(oldFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
delete outFile;
|
||||
delete inFile;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
const char *SaveFileManager::getSavePath() const {
|
||||
|
||||
#if defined(PALMOS_MODE) || defined(__PSP__)
|
||||
|
|
|
@ -131,6 +131,14 @@ public:
|
|||
*/
|
||||
virtual bool removeSavefile(const char *filename) = 0;
|
||||
|
||||
/**
|
||||
* Renames the given savefile.
|
||||
* @param oldFilename Old filename.
|
||||
* @param newFilename New filename.
|
||||
* @return true if no error ocurred. false otherwise.
|
||||
*/
|
||||
virtual bool renameSavefile(const char *oldFilename, const char *newFilename);
|
||||
|
||||
/**
|
||||
* Request a list of available savegames with a given regex.
|
||||
* @param regex Regular expression to match. Wildcards like * or ? are available.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue