Ticket #8762: getsavepath.patch

File getsavepath.patch, 8.5 KB (added by SF/david_corrales, 12 years ago)

Initial version

  • home/david/Projects/scummvm/backends/saves/default/default-saves.cpp

    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
    
    
     
    2929#include "common/util.h"
    3030#include "common/fs.h"
    3131#include "common/file.h"
     32#include "common/config-manager.h"
    3233#include "backends/saves/default/default-saves.h"
    3334#include "backends/saves/compressed/compressed-saves.h"
    3435
     
    249250        }
    250251}
    251252
     253const char *DefaultSaveFileManager::getSavePath() const {
     254
     255#if defined(PALMOS_MODE) || defined(__PSP__)
     256        return SCUMMVM_SAVEPATH;
     257#else
     258
     259        const char *dir = NULL;
     260
     261        // Try to use game specific savepath from config
     262        dir = ConfMan.get("savepath").c_str();
     263
     264        // Work around a bug (#999122) in the original 0.6.1 release of
     265        // ScummVM, which would insert a bad savepath value into config files.
     266        if (0 == strcmp(dir, "None")) {
     267                ConfMan.removeKey("savepath", ConfMan.getActiveDomainName());
     268                ConfMan.flushToDisk();
     269                dir = ConfMan.get("savepath").c_str();
     270        }
     271
     272#ifdef _WIN32_WCE
     273        if (dir[0] == 0)
     274                dir = ConfMan.get("path").c_str();
     275#endif
     276
     277        assert(dir);
     278
     279        return dir;
     280#endif
     281}
     282
    252283#endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
  • home/david/Projects/scummvm/backends/saves/default/default-saves.h

     
    2929#include "common/savefile.h"
    3030#include "common/str.h"
    3131
     32/**
     33 * Provides a default savefile manager implementation for common platforms.
     34 */
    3235class DefaultSaveFileManager : public Common::SaveFileManager {
    3336public:
    3437        virtual Common::StringList listSavefiles(const char *regex);
     
    3538        virtual Common::InSaveFile *openForLoading(const char *filename);
    3639        virtual Common::OutSaveFile *openForSaving(const char *filename);
    3740        virtual bool removeSavefile(const char *filename);
     41
     42protected:
     43        /**
     44         * Get the path to the save game 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;
    3849};
    3950
    4051#endif
  • home/david/Projects/scummvm/backends/saves/savefile.cpp

     
    2424 */
    2525
    2626#include "common/util.h"
    27 #include "common/config-manager.h"
    2827#include "common/savefile.h"
    2928
    3029#include <stdio.h>
     
    7271        return success;
    7372}
    7473
    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
     74String SaveFileManager::popErrorDesc() {
     75        String err = _errorDesc;
     76        clearError();
     77       
     78        return err;
    10379}
    10480
    10581} // End of namespace Common
  • home/david/Projects/scummvm/common/savefile.h

     
    109109         * @return A string describing the last error.
    110110         */
    111111        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       
    113121        /**
    114122         * Open the file with name filename in the given directory for saving.
    115123         * @param filename      the filename
     
    145153         * returns a list of strings for all present file names.
    146154         */
    147155        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 paths
    152          * from it, since that is highly unportable!
    153          */
    154         virtual const char *getSavePath() const;
    155156};
    156157
    157158} // End of namespace Common
  • home/david/Projects/scummvm/engines/sky/control.cpp

     
    944944                                                refreshNames = true;
    945945                                        }
    946946                                        if (clickRes == NO_DISK_SPACE) {
    947                                                 displayMessage(0, "Could not save game in directory '%s'", _saveFileMan->getSavePath());
     947                                                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    948948                                                quitPanel = true;
    949949                                        }
    950950                                        if ((clickRes == CANCEL_PRESSED) || (clickRes == GAME_RESTORED))
     
    11531153                delete outf;
    11541154        }
    11551155        if (ioFailed)
    1156                 displayMessage(NULL, "Unable to store Savegame names to file SKY-VM.SAV in directory %s", _saveFileMan->getSavePath());
     1156                displayMessage(NULL, _saveFileMan->popErrorDesc().c_str());
    11571157        free(tmpBuf);
    11581158}
    11591159
     
    11671167
    11681168        outf = _saveFileMan->openForSaving(fName);
    11691169        if (outf == NULL) {
    1170                 displayMessage(0, "Unable to create autosave file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());
     1170                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    11711171                return;
    11721172        }
    11731173        uint8 *saveData = (uint8 *)malloc(0x20000);
     
    11771177        outf->finalize();
    11781178
    11791179        if (outf->ioFailed())
    1180                 displayMessage(0, "Unable to write autosave file '%s' in directory '%s'. Disk full?", fName, _saveFileMan->getSavePath());
     1180                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    11811181
    11821182        delete outf;
    11831183        free(saveData);
  • home/david/Projects/scummvm/engines/sword1/control.cpp

     
    738738
    739739        if (!outf) {
    740740                // Display an error message, and do nothing
    741                 displayMessage(0, "Can't create SAVEGAME.INF in directory '%s'", _saveFileMan->getSavePath());
     741                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    742742                return;
    743743        }
    744744
     
    757757        }
    758758        outf->finalize();
    759759        if (outf->ioFailed())
    760                 displayMessage(0, "Can't write to SAVEGAME.INF in directory '%s'. Device full?", _saveFileMan->getSavePath());
     760                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    761761        delete outf;
    762762}
    763763
     
    928928        outf = _saveFileMan->openForSaving(fName);
    929929        if (!outf) {
    930930                // Display an error message and do nothing
    931                 displayMessage(0, "Unable to create file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());
     931                displayMessage(0, _saveFileMan->getErrorDesc().c_str());
    932932                return;
    933933        }
    934934
     
    952952                outf->writeUint32LE(playerRaw[cnt2]);
    953953        outf->finalize();
    954954        if (outf->ioFailed())
    955                 displayMessage(0, "Couldn't write to file '%s' in directory '%s'. Device full?", fName, _saveFileMan->getSavePath());
     955                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    956956        delete outf;
    957957}
    958958
     
    964964        inf = _saveFileMan->openForLoading(fName);
    965965        if (!inf) {
    966966                // Display an error message, and do nothing
    967                 displayMessage(0, "Can't open file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());
     967                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    968968                return false;
    969969        }
    970970
     
    988988                playerBuf[cnt2] = inf->readUint32LE();
    989989
    990990        if (inf->ioFailed()) {
    991                 displayMessage(0, "Can't read from file '%s' in directory '%s'", fName, _saveFileMan->getSavePath());
     991                displayMessage(0, _saveFileMan->popErrorDesc().c_str());
    992992                delete inf;
    993993                free(_restoreBuf);
    994994                _restoreBuf = NULL;