Ticket #8762: getsavepath2.patch
File getsavepath2.patch, 17.3 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.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: 50 /** Get the path to the save game directory. */ 51 virtual const char *getSavePath() const; 52 52 53 bool setupIcon(const char *dest, const char *ico, const char *descr1, const char *descr2); 53 54 54 55 bool mcReadyForDir(const char *dir); -
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(); 150 134 151 135 #if defined(UNIX) || defined(__SYMBIAN32__) 152 136 struct stat sb; 153 clearError();154 137 155 138 // Check whether the dir exists 156 if (stat( savePath, &sb) == -1) {139 if (stat(path, &sb) == -1) { 157 140 // The dir does not exist, or stat failed for some other reason. 158 141 // If the problem was that the path pointed to nothing, try 159 142 // to create the dir (ENOENT case). … … 159 142 // to create the dir (ENOENT case). 160 143 switch (errno) { 161 144 case EACCES: 162 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied "));145 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied: ")+path); 163 146 break; 164 147 #if !defined(__SYMBIAN32__) 165 148 case ELOOP: 166 setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path "));149 setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path: ")+path); 167 150 break; 168 151 #endif 169 152 case ENAMETOOLONG: 170 setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long "));153 setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long: ")+path); 171 154 break; 172 155 case ENOENT: 173 if (mkdir( savePath, 0755) != 0) {156 if (mkdir(path, 0755) != 0) { 174 157 // mkdir could fail for various reasons: The parent dir doesn't exist, 175 158 // or is not writeable, the path could be completly bogus, etc. 176 warning("mkdir for '%s' failed!", savePath);159 warning("mkdir for '%s' failed!", path); 177 160 perror("mkdir"); 178 161 179 162 switch (errno) { … … 178 161 179 162 switch (errno) { 180 163 case EACCES: 181 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied "));164 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied: ")+path); 182 165 break; 183 166 case EMLINK: 184 setError(SFM_DIR_LINKMAX, Common::String("The link count of the parent directory would exceed {LINK_MAX} "));167 setError(SFM_DIR_LINKMAX, Common::String("The link count of the parent directory would exceed {LINK_MAX}: ")+path); 185 168 break; 186 169 #if !defined(__SYMBIAN32__) 187 170 case ELOOP: 188 setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path "));171 setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path: ")+path); 189 172 break; 190 173 #endif 191 174 case ENAMETOOLONG: 192 setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long "));175 setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long: ")+path); 193 176 break; 194 177 case ENOENT: 195 setError(SFM_DIR_NOENT, Common::String("A component of the path does not exist, or the path is an empty string "));178 setError(SFM_DIR_NOENT, Common::String("A component of the path does not exist, or the path is an empty string: ")+path); 196 179 break; 197 180 case ENOTDIR: 198 setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory "));181 setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory: ")+path); 199 182 break; 200 183 case EROFS: 201 setError(SFM_DIR_ROFS, Common::String("The parent directory resides on a read-only file system "));184 setError(SFM_DIR_ROFS, Common::String("The parent directory resides on a read-only file system:")+path); 202 185 break; 203 186 } 204 205 return 0;206 187 } 207 188 break; 208 189 case ENOTDIR: 209 setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory "));190 setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory: ")+path); 210 191 break; 211 192 } 212 193 } else { … … 212 193 } else { 213 194 // So stat() succeeded. But is the path actually pointing to a directory? 214 195 if (!S_ISDIR(sb.st_mode)) { 215 setError(SFM_DIR_NOTDIR, Common::String("The given savepath is not a directory")); 216 217 return 0; 196 setError(SFM_DIR_NOTDIR, Common::String("The given savepath is not a directory: ")+path); 218 197 } 219 198 } 220 199 #endif 200 } 221 201 222 join_paths(filename, savePath, buf, sizeof(buf)); 202 Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) { 203 // Ensure that the savepath is valid. If not, generate an appropriate error. 204 char buf[256]; 205 const char *savePath = getSavePath(); 206 checkPath(savePath); 207 208 if (getError() == SFM_NO_ERROR) { 209 join_paths(filename, savePath, buf, sizeof(buf)); 210 StdioSaveFile *sf = new StdioSaveFile(buf, false); 211 212 if (!sf->isOpen()) { 213 delete sf; 214 sf = 0; 215 } 216 217 return wrapInSaveFile(sf); 218 } else { 219 return 0; 220 } 221 } 223 222 224 StdioSaveFile *sf = new StdioSaveFile(buf, true); 223 Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) { 224 // Ensure that the savepath is valid. If not, generate an appropriate error. 225 char buf[256]; 226 const char *savePath = getSavePath(); 227 checkPath(savePath); 225 228 226 if (!sf->isOpen()) { 227 delete sf; 228 sf = 0; 229 if (getError() == SFM_NO_ERROR) { 230 join_paths(filename, savePath, buf, sizeof(buf)); 231 StdioSaveFile *sf = new StdioSaveFile(buf, true); 232 233 if (!sf->isOpen()) { 234 delete sf; 235 sf = 0; 236 } 237 238 return wrapOutSaveFile(sf); 239 } else { 240 return 0; 229 241 } 230 231 return wrapOutSaveFile(sf);232 242 } 233 243 234 244 bool DefaultSaveFileManager::removeSavefile(const char *filename) { … … 233 243 234 244 bool DefaultSaveFileManager::removeSavefile(const char *filename) { 235 245 char buf[256]; 246 clearError(); 236 247 join_paths(filename, getSavePath(), buf, sizeof(buf)); 237 248 238 249 if (remove(buf) != 0) { … … 238 249 if (remove(buf) != 0) { 239 250 #ifndef _WIN32_WCE 240 251 if (errno == EACCES) 241 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied "));252 setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied: ")+filename); 242 253 243 254 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 "));255 setError(SFM_DIR_NOENT, Common::String("A component of the path does not exist, or the path is an empty string: ")+filename); 245 256 #endif 246 257 return false; 247 258 } else { … … 249 260 } 250 261 } 251 262 263 const char *DefaultSaveFileManager::getSavePath() const { 264 265 #if defined(PALMOS_MODE) || defined(__PSP__) 266 return SCUMMVM_SAVEPATH; 267 #else 268 269 const char *dir = NULL; 270 271 // Try to use game specific savepath from config 272 dir = ConfMan.get("savepath").c_str(); 273 274 // Work around a bug (#999122) in the original 0.6.1 release of 275 // ScummVM, which would insert a bad savepath value into config files. 276 if (0 == strcmp(dir, "None")) { 277 ConfMan.removeKey("savepath", ConfMan.getActiveDomainName()); 278 ConfMan.flushToDisk(); 279 dir = ConfMan.get("savepath").c_str(); 280 } 281 282 #ifdef _WIN32_WCE 283 if (dir[0] == 0) 284 dir = ConfMan.get("path").c_str(); 285 #endif 286 287 assert(dir); 288 289 return dir; 290 #endif 291 } 292 252 293 #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;