Ticket #3651: sword1_save.patch

File sword1_save.patch, 5.5 KB (added by lordhoto, 16 years ago)

patch against current svn

  • sword1.cpp

     
    339339        _logic->initialize();
    340340        _objectMan->initialize();
    341341        _mouse->initialize();
    342         _control = new Control(_saveFileMan, _resMan, _objectMan, _system, _mouse, _sound, _music);
     342        _control = new Control(this, _saveFileMan, _resMan, _objectMan, _system, _mouse, _sound, _music);
    343343
    344344        return 0;
    345345}
  • control.h

     
    4242class Mouse;
    4343class Music;
    4444class Sound;
     45class SwordEngine;
    4546
    4647#define MAX_BUTTONS 16
    4748
     
    8283
    8384class Control {
    8485public:
    85         Control(Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic);
     86        Control(SwordEngine *engine, Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic);
    8687        uint8 runPanel(void);
    8788        void doRestore(void);
    8889        void askForCd(void);
     
    134135        static const uint8 _languageStrings[8 * 20][43];
    135136        const uint8 (*_lStrings)[43];
    136137        Common::SaveFileManager *_saveFileMan;
     138        SwordEngine *_engine;
    137139        ObjectMan *_objMan;
    138140        ResMan *_resMan;
    139141        OSystem *_system;
  • control.cpp

     
    160160        draw();
    161161}
    162162
    163 Control::Control(Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic) {
     163Control::Control(SwordEngine *engine, Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic) {
     164        _engine = engine;
    164165        _saveFileMan = saveFileMan;
    165166        _resMan = pResMan;
    166167        _objMan = pObjMan;
     
    717718
    718719void Control::readSavegameDescriptions(void) {
    719720        Common::InSaveFile *inf;
    720         inf = _saveFileMan->openForLoading("SAVEGAME.INF");
     721        inf = _saveFileMan->openForLoading((_engine->getTargetName() + ".inf").c_str());
    721722        _saveScrollPos = _saveFiles = 0;
    722723        _selectedSavegame = 255;
    723724        for (uint8 cnt = 0; cnt < 64; cnt++) {
     
    761762
    762763void Control::writeSavegameDescriptions(void) {
    763764        Common::OutSaveFile *outf;
    764         outf = _saveFileMan->openForSaving("SAVEGAME.INF");
     765        outf = _saveFileMan->openForSaving((_engine->getTargetName() + ".inf").c_str());
    765766
    766767        if (!outf) {
    767768                // Display an error message, and do nothing
    768                 displayMessage(0, "Can't create SAVEGAME.INF. (%s)", _saveFileMan->popErrorDesc().c_str());
     769                displayMessage(0, "Can't create %s.inf. (%s)", _engine->getTargetName().c_str(), _saveFileMan->popErrorDesc().c_str());
    769770                return;
    770771        }
    771772
     
    784785        }
    785786        outf->finalize();
    786787        if (outf->ioFailed())
    787                 displayMessage(0, "Can't write to SAVEGAME.INF. Device full? (%s)", _saveFileMan->popErrorDesc().c_str());
     788                displayMessage(0, "Can't write to %s.inf. Device full? (%s)", _engine->getTargetName().c_str(), _saveFileMan->popErrorDesc().c_str());
    788789        delete outf;
    789790}
    790791
     
    947948}
    948949
    949950void Control::saveGameToFile(uint8 slot) {
    950         char fName[15];
     951        Common::String filename = _engine->getTargetName();
     952        char fName[5];
     953        snprintf(fName, 5, ".%03d", slot);
     954        filename += fName;
     955
    951956        uint16 cnt;
    952         sprintf(fName, "SAVEGAME.%03d", slot);
    953957        uint16 liveBuf[TOTAL_SECTIONS];
    954958        Common::OutSaveFile *outf;
    955         outf = _saveFileMan->openForSaving(fName);
     959        outf = _saveFileMan->openForSaving(filename.c_str());
    956960        if (!outf) {
    957961                // Display an error message and do nothing
    958                 displayMessage(0, "Unable to create file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str());
     962                displayMessage(0, "Unable to create file '%s'. (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str());
    959963                return;
    960964        }
    961965
     
    979983                outf->writeUint32LE(playerRaw[cnt2]);
    980984        outf->finalize();
    981985        if (outf->ioFailed())
    982                 displayMessage(0, "Couldn't write to file '%s'. Device full? (%s)", fName, _saveFileMan->popErrorDesc().c_str());
     986                displayMessage(0, "Couldn't write to file '%s'. Device full? (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str());
    983987        delete outf;
    984988}
    985989
    986990bool Control::restoreGameFromFile(uint8 slot) {
    987         char fName[15];
     991        Common::String filename = _engine->getTargetName();
     992        char fName[5];
     993        snprintf(fName, 5, ".%03d", slot);
     994        filename += fName;
     995
    988996        uint16 cnt;
    989         sprintf(fName, "SAVEGAME.%03d", slot);
    990997        Common::InSaveFile *inf;
    991         inf = _saveFileMan->openForLoading(fName);
     998        inf = _saveFileMan->openForLoading(filename.c_str());
    992999        if (!inf) {
    9931000                // Display an error message, and do nothing
    994                 displayMessage(0, "Can't open file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str());
     1001                displayMessage(0, "Can't open file '%s'. (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str());
    9951002                return false;
    9961003        }
    9971004
     
    10151022                playerBuf[cnt2] = inf->readUint32LE();
    10161023
    10171024        if (inf->ioFailed()) {
    1018                 displayMessage(0, "Can't read from file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str());
     1025                displayMessage(0, "Can't read from file '%s'. (%s)", filename.c_str(), _saveFileMan->popErrorDesc().c_str());
    10191026                delete inf;
    10201027                free(_restoreBuf);
    10211028                _restoreBuf = NULL;
  • sword1.h

     
    8080        void reinitialize(void);
    8181
    8282        uint32 _features;
     83
     84        Common::String getTargetName() const { return _targetName; }
    8385protected:
    8486        int go();
    8587        int init();