Ticket #8762: getsavepath3.patch
File getsavepath3.patch, 17.7 KB (added by , 17 years ago) |
---|
-
home/david/Projects/scummvm/backends/platform/ds/arm9/source/gbampsave.h
Property changes on: /home/david/Projects/scummvm ___________________________________________________________________ Name: svn:ignore - config.log scummvm scummvm-static config.h config.mk .gdb_history dumps Credits.rtf *.mshark + .project config.h config.mk reconf.sh scummvm plugins
24 24 #define _GBAMPSAVE_H_ 25 25 26 26 #include "system.h" 27 #include " common/savefile.h"27 #include "saves/default/default-saves.h" 28 28 #include "ds-fs.h" 29 29 30 30 #define SAVE_BUFFER_SIZE 100000 … … 58 58 }; 59 59 60 60 61 class GBAMPSaveFileManager : public Common::SaveFileManager { 62 63 61 class GBAMPSaveFileManager : public DefaultSaveFileManager { 64 62 public: 65 63 GBAMPSaveFileManager(); 66 64 ~GBAMPSaveFileManager(); … … 81 79 void listFiles(); 82 80 }; 83 81 84 85 82 #endif -
home/david/Projects/scummvm/backends/platform/ps2/savefile.cpp
484 484 _screen->wantAnim(false); 485 485 } 486 486 487 const char *Ps2SaveFileManager::getSavePath(void) const {488 return "mc0:";489 }490 491 487 bool Ps2SaveFileManager::setupIcon(const char *dest, const char *ico, const char *descr1, const char *descr2) { 492 488 mcIcon icon_sys; 493 489 memset(&icon_sys, 0, sizeof(mcIcon)); -
home/david/Projects/scummvm/backends/platform/ps2/savefile.h
42 42 virtual Common::OutSaveFile *openForSaving(const char *filename); 43 43 virtual void listSavefiles(const char *prefix, bool *marks, int num); 44 44 45 /** Get the path to the save game directory. */46 virtual const char *getSavePath() const;47 48 45 void writeSaveNonblocking(char *name, void *buf, uint32 size); 49 46 void saveThread(void); 50 47 void quit(void); 48 51 49 private: 52 50 bool setupIcon(const char *dest, const char *ico, const char *descr1, const char *descr2); 53 51 -
home/david/Projects/scummvm/backends/saves/default/default-saves.cpp
29 29 #include "common/util.h" 30 30 #include "common/fs.h" 31 31 #include "common/file.h" 32 #include "common/config-manager.h" 32 33 #include "backends/saves/default/default-saves.h" 33 34 #include "backends/saves/compressed/compressed-saves.h" 34 35 … … 128 129 return results; 129 130 } 130 131 131 Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) { 132 char buf[256]; 133 join_paths(filename, getSavePath(), buf, sizeof(buf)); 134 135 StdioSaveFile *sf = new StdioSaveFile(buf, false); 136 137 if (!sf->isOpen()) { 138 delete sf; 139 sf = 0; 140 } 141 return wrapInSaveFile(sf); 142 } 143 144 Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) { 145 char buf[256]; 146 147 // Ensure that the savepath exists and is writeable. If not, generate 148 // an appropriate error 149 const char *savePath = getSavePath(); 132 void DefaultSaveFileManager::checkPath(const char *path) { 133 clearError(); 134 Common::String pathStr(path); 150 135 151 136 #if defined(UNIX) || defined(__SYMBIAN32__) 152 137 struct stat sb; 153 clearError();154 138 155 139 // Check whether the dir exists 156 if (stat( savePath, &sb) == -1) {140 if (stat(path, &sb) == -1) { 157 141 // The dir does not exist, or stat failed for some other reason. 158 142 // If the problem was that the path pointed to nothing, try 159 143 // to create the dir (ENOENT case). … … 159 143 // to create the dir (ENOENT case). 160 144 switch (errno) { 161 145 case EACCES: 162 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied"));146 setError(SFM_DIR_ACCESS, "Search or write permission denied: "+pathStr); 163 147 break; 164 148 #if !defined(__SYMBIAN32__) 165 149 case ELOOP: 166 setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path"));150 setError(SFM_DIR_LOOP, "Too many symbolic links encountered while traversing the path: "+pathStr); 167 151 break; 168 152 #endif 169 153 case ENAMETOOLONG: 170 setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long"));154 setError(SFM_DIR_NAMETOOLONG, "The path name is too long: "+pathStr); 171 155 break; 172 156 case ENOENT: 173 if (mkdir( savePath, 0755) != 0) {157 if (mkdir(path, 0755) != 0) { 174 158 // mkdir could fail for various reasons: The parent dir doesn't exist, 175 159 // or is not writeable, the path could be completly bogus, etc. 176 warning("mkdir for '%s' failed!", savePath);160 warning("mkdir for '%s' failed!", path); 177 161 perror("mkdir"); 178 162 179 163 switch (errno) { … … 178 162 179 163 switch (errno) { 180 164 case EACCES: 181 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied"));165 setError(SFM_DIR_ACCESS, "Search or write permission denied: "+pathStr); 182 166 break; 183 167 case EMLINK: 184 setError(SFM_DIR_LINKMAX, Common::String("The link count of the parent directory would exceed {LINK_MAX}"));168 setError(SFM_DIR_LINKMAX, "The link count of the parent directory would exceed {LINK_MAX}: "+pathStr); 185 169 break; 186 170 #if !defined(__SYMBIAN32__) 187 171 case ELOOP: 188 setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path"));172 setError(SFM_DIR_LOOP, "Too many symbolic links encountered while traversing the path: "+pathStr); 189 173 break; 190 174 #endif 191 175 case ENAMETOOLONG: 192 setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long"));176 setError(SFM_DIR_NAMETOOLONG, "The path name is too long: "+pathStr); 193 177 break; 194 178 case ENOENT: 195 setError(SFM_DIR_NOENT, Common::String("A component of the path does not exist, or the path is an empty string"));179 setError(SFM_DIR_NOENT, "A component of the path does not exist, or the path is an empty string: "+pathStr); 196 180 break; 197 181 case ENOTDIR: 198 setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory"));182 setError(SFM_DIR_NOTDIR, "A component of the path prefix is not a directory: "+pathStr); 199 183 break; 200 184 case EROFS: 201 setError(SFM_DIR_ROFS, Common::String("The parent directory resides on a read-only file system"));185 setError(SFM_DIR_ROFS, "The parent directory resides on a read-only file system:"+pathStr); 202 186 break; 203 187 } 204 205 return 0;206 188 } 207 189 break; 208 190 case ENOTDIR: 209 setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory"));191 setError(SFM_DIR_NOTDIR, "A component of the path prefix is not a directory: "+pathStr); 210 192 break; 211 193 } 212 194 } else { … … 212 194 } else { 213 195 // So stat() succeeded. But is the path actually pointing to a directory? 214 196 if (!S_ISDIR(sb.st_mode)) { 215 setError(SFM_DIR_NOTDIR, Common::String("The given savepath is not a directory")); 216 217 return 0; 197 setError(SFM_DIR_NOTDIR, "The given savepath is not a directory: "+pathStr); 218 198 } 219 199 } 220 200 #endif 201 } 221 202 222 join_paths(filename, savePath, buf, sizeof(buf)); 203 Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) { 204 // Ensure that the savepath is valid. If not, generate an appropriate error. 205 char buf[256]; 206 const char *savePath = getSavePath(); 207 checkPath(savePath); 208 209 if (getError() == SFM_NO_ERROR) { 210 join_paths(filename, savePath, buf, sizeof(buf)); 211 StdioSaveFile *sf = new StdioSaveFile(buf, false); 212 213 if (!sf->isOpen()) { 214 delete sf; 215 sf = 0; 216 } 217 218 return wrapInSaveFile(sf); 219 } else { 220 return 0; 221 } 222 } 223 223 224 StdioSaveFile *sf = new StdioSaveFile(buf, true); 224 Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) { 225 // Ensure that the savepath is valid. If not, generate an appropriate error. 226 char buf[256]; 227 const char *savePath = getSavePath(); 228 checkPath(savePath); 225 229 226 if (!sf->isOpen()) { 227 delete sf; 228 sf = 0; 230 if (getError() == SFM_NO_ERROR) { 231 join_paths(filename, savePath, buf, sizeof(buf)); 232 StdioSaveFile *sf = new StdioSaveFile(buf, true); 233 234 if (!sf->isOpen()) { 235 delete sf; 236 sf = 0; 237 } 238 239 return wrapOutSaveFile(sf); 240 } else { 241 return 0; 229 242 } 230 231 return wrapOutSaveFile(sf);232 243 } 233 244 234 245 bool DefaultSaveFileManager::removeSavefile(const char *filename) { … … 233 244 234 245 bool DefaultSaveFileManager::removeSavefile(const char *filename) { 235 246 char buf[256]; 247 clearError(); 248 Common::String filenameStr; 236 249 join_paths(filename, getSavePath(), buf, sizeof(buf)); 237 250 238 251 if (remove(buf) != 0) { … … 238 251 if (remove(buf) != 0) { 239 252 #ifndef _WIN32_WCE 240 253 if (errno == EACCES) 241 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied"));254 setError(SFM_DIR_ACCESS, "Search or write permission denied: "+filenameStr); 242 255 243 256 if (errno == ENOENT) 244 setError(SFM_DIR_NOENT, Common::String("A component of the path does not exist, or the path is an empty string"));257 setError(SFM_DIR_NOENT, "A component of the path does not exist, or the path is an empty string: "+filenameStr); 245 258 #endif 246 259 return false; 247 260 } else { … … 249 262 } 250 263 } 251 264 265 const char *DefaultSaveFileManager::getSavePath() const { 266 267 #if defined(PALMOS_MODE) || defined(__PSP__) 268 return SCUMMVM_SAVEPATH; 269 #else 270 271 const char *dir = NULL; 272 273 // Try to use game specific savepath from config 274 dir = ConfMan.get("savepath").c_str(); 275 276 // Work around a bug (#999122) in the original 0.6.1 release of 277 // ScummVM, which would insert a bad savepath value into config files. 278 if (0 == strcmp(dir, "None")) { 279 ConfMan.removeKey("savepath", ConfMan.getActiveDomainName()); 280 ConfMan.flushToDisk(); 281 dir = ConfMan.get("savepath").c_str(); 282 } 283 284 #ifdef _WIN32_WCE 285 if (dir[0] == 0) 286 dir = ConfMan.get("path").c_str(); 287 #endif 288 289 assert(dir); 290 291 return dir; 292 #endif 293 } 294 252 295 #endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER) -
home/david/Projects/scummvm/backends/saves/default/default-saves.h
29 29 #include "common/savefile.h" 30 30 #include "common/str.h" 31 31 32 /** 33 * Provides a default savefile manager implementation for common platforms. 34 */ 32 35 class DefaultSaveFileManager : public Common::SaveFileManager { 33 36 public: 34 37 virtual Common::StringList listSavefiles(const char *regex); … … 35 38 virtual Common::InSaveFile *openForLoading(const char *filename); 36 39 virtual Common::OutSaveFile *openForSaving(const char *filename); 37 40 virtual bool removeSavefile(const char *filename); 41 42 protected: 43 /** 44 * Get the path to the savegame directory. 45 * Should only be used internally since some platforms 46 * might implement savefiles in a completely different way. 47 */ 48 virtual const char *getSavePath() const; 49 50 /** 51 * Checks the given path for read access, existence, etc. 52 * Sets the internal error and error message accordingly. 53 */ 54 void checkPath(const char *path); 38 55 }; 39 56 40 57 #endif -
home/david/Projects/scummvm/backends/saves/savefile.cpp
24 24 */ 25 25 26 26 #include "common/util.h" 27 #include "common/config-manager.h"28 27 #include "common/savefile.h" 29 28 30 29 #include <stdio.h> … … 72 71 return success; 73 72 } 74 73 75 const char *SaveFileManager::getSavePath() const { 76 77 #if defined(PALMOS_MODE) || defined(__PSP__) 78 return SCUMMVM_SAVEPATH; 79 #else 80 81 const char *dir = NULL; 82 83 // Try to use game specific savepath from config 84 dir = ConfMan.get("savepath").c_str(); 85 86 // Work around a bug (#999122) in the original 0.6.1 release of 87 // ScummVM, which would insert a bad savepath value into config files. 88 if (0 == strcmp(dir, "None")) { 89 ConfMan.removeKey("savepath", ConfMan.getActiveDomainName()); 90 ConfMan.flushToDisk(); 91 dir = ConfMan.get("savepath").c_str(); 92 } 93 94 #ifdef _WIN32_WCE 95 if (dir[0] == 0) 96 dir = ConfMan.get("path").c_str(); 97 #endif 98 99 assert(dir); 100 101 return dir; 102 #endif 74 String SaveFileManager::popErrorDesc() { 75 String err = _errorDesc; 76 clearError(); 77 78 return err; 103 79 } 104 80 105 81 } // End of namespace Common -
home/david/Projects/scummvm/common/savefile.h
109 109 * @return A string describing the last error. 110 110 */ 111 111 virtual String getErrorDesc() { return _errorDesc; } 112 112 113 /** 114 * Returns the last ocurred error description. If none ocurred, returns 0. 115 * Also clears the last error state and description. 116 * 117 * @return A string describing the last error. 118 */ 119 virtual String popErrorDesc(); 120 113 121 /** 114 122 * Open the file with name filename in the given directory for saving. 115 123 * @param filename the filename … … 145 153 * returns a list of strings for all present file names. 146 154 */ 147 155 virtual Common::StringList listSavefiles(const char *regex) = 0; 148 149 /**150 * Get the path to the save game directory.151 * Should only be used for error messages, *never* to construct file paths152 * from it, since that is highly unportable!153 */154 virtual const char *getSavePath() const;155 156 }; 156 157 157 158 } // End of namespace Common -
home/david/Projects/scummvm/engines/sky/control.cpp
944 944 refreshNames = true; 945 945 } 946 946 if (clickRes == NO_DISK_SPACE) { 947 displayMessage(0, "Could not save game in directory '%s'", _saveFileMan->getSavePath());947 displayMessage(0, "Could not save the game. (%s)", _saveFileMan->popErrorDesc().c_str()); 948 948 quitPanel = true; 949 949 } 950 950 if ((clickRes == CANCEL_PRESSED) || (clickRes == GAME_RESTORED)) … … 1153 1153 delete outf; 1154 1154 } 1155 1155 if (ioFailed) 1156 displayMessage(NULL, "Unable to store Savegame names to file SKY-VM.SAV in directory %s", _saveFileMan->getSavePath());1156 displayMessage(NULL, "Unable to store Savegame names to file SKY-VM.SAV. (%s)", _saveFileMan->popErrorDesc().c_str()); 1157 1157 free(tmpBuf); 1158 1158 } 1159 1159 … … 1167 1167 1168 1168 outf = _saveFileMan->openForSaving(fName); 1169 1169 if (outf == NULL) { 1170 displayMessage(0, "Unable to create autosave file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());1170 displayMessage(0, "Unable to create autosave file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str()); 1171 1171 return; 1172 1172 } 1173 1173 uint8 *saveData = (uint8 *)malloc(0x20000); … … 1177 1177 outf->finalize(); 1178 1178 1179 1179 if (outf->ioFailed()) 1180 displayMessage(0, "Unable to write autosave file '%s' in directory '%s'. Disk full?", fName, _saveFileMan->getSavePath());1180 displayMessage(0, "Unable to write autosave file '%s'. Disk full?", fName, _saveFileMan->popErrorDesc().c_str()); 1181 1181 1182 1182 delete outf; 1183 1183 free(saveData); -
home/david/Projects/scummvm/engines/sword1/control.cpp
738 738 739 739 if (!outf) { 740 740 // Display an error message, and do nothing 741 displayMessage(0, "Can't create SAVEGAME.INF in directory '%s'", _saveFileMan->getSavePath());741 displayMessage(0, "Can't create SAVEGAME.INF. (%s)", _saveFileMan->popErrorDesc().c_str()); 742 742 return; 743 743 } 744 744 … … 757 757 } 758 758 outf->finalize(); 759 759 if (outf->ioFailed()) 760 displayMessage(0, "Can't write to SAVEGAME.INF in directory '%s'. Device full?", _saveFileMan->getSavePath());760 displayMessage(0, "Can't write to SAVEGAME.INF. Device full? (%s)", _saveFileMan->popErrorDesc().c_str()); 761 761 delete outf; 762 762 } 763 763 … … 928 928 outf = _saveFileMan->openForSaving(fName); 929 929 if (!outf) { 930 930 // Display an error message and do nothing 931 displayMessage(0, "Unable to create file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());931 displayMessage(0, "Unable to create file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str()); 932 932 return; 933 933 } 934 934 … … 952 952 outf->writeUint32LE(playerRaw[cnt2]); 953 953 outf->finalize(); 954 954 if (outf->ioFailed()) 955 displayMessage(0, "Couldn't write to file '%s' in directory '%s'. Device full?", fName, _saveFileMan->getSavePath());955 displayMessage(0, "Couldn't write to file '%s'. Device full? (%s)", fName, _saveFileMan->popErrorDesc().c_str()); 956 956 delete outf; 957 957 } 958 958 … … 964 964 inf = _saveFileMan->openForLoading(fName); 965 965 if (!inf) { 966 966 // Display an error message, and do nothing 967 displayMessage(0, "Can't open file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());967 displayMessage(0, "Can't open file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str()); 968 968 return false; 969 969 } 970 970 … … 988 988 playerBuf[cnt2] = inf->readUint32LE(); 989 989 990 990 if (inf->ioFailed()) { 991 displayMessage(0, "Can't read from file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());991 displayMessage(0, "Can't read from file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str()); 992 992 delete inf; 993 993 free(_restoreBuf); 994 994 _restoreBuf = NULL;