Ticket #8740: renameSavefile-alt.patch
File renameSavefile-alt.patch, 1.7 KB (added by , 17 years ago) |
---|
-
common/savefile.h
132 132 virtual bool removeSavefile(const char *filename) = 0; 133 133 134 134 /** 135 * Renames the given savefile. 136 * @param oldFilename Old filename. 137 * @param newFilename New filename. 138 * @return true if no error ocurred. false otherwise. 139 */ 140 virtual bool renameSavefile(const char *oldFilename, const char *newFilename); 141 142 /** 135 143 * Request a list of available savegames with a given regex. 136 144 * @param regex Regular expression to match. Wildcards like * or ? are available. 137 145 * returns a list of strings for all present file names. -
backends/saves/savefile.cpp
32 32 33 33 namespace Common { 34 34 35 bool SaveFileManager::renameSavefile(const char *oldFilename, const char *newFilename) { 36 37 InSaveFile *inFile = 0; 38 OutSaveFile *outFile = 0; 39 uint32 size = 0; 40 void *buffer = 0; 41 bool success = false; 42 43 inFile = openForLoading(oldFilename); 44 45 if (inFile) { 46 size = inFile->size(); 47 buffer = malloc(size); 48 assert(buffer); 49 50 outFile = openForSaving(newFilename); 51 52 if (buffer && outFile) { 53 inFile->read(buffer, size); 54 if (!inFile->ioFailed()) { 55 outFile->write(buffer, size); 56 outFile->finalize(); 57 if (!outFile->ioFailed()) { 58 success = removeSavefile(oldFilename); 59 } 60 } 61 } 62 63 free(buffer); 64 delete outFile; 65 delete inFile; 66 } 67 68 return success; 69 } 70 35 71 const char *SaveFileManager::getSavePath() const { 36 72 37 73 #if defined(PALMOS_MODE) || defined(__PSP__)