aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scumm/dialogs.cpp10
-rw-r--r--scumm/script_v5.cpp15
-rw-r--r--scumm/script_v8.cpp8
-rw-r--r--simon/simon.cpp26
-rw-r--r--sky/control.cpp30
-rw-r--r--sword1/control.cpp23
-rw-r--r--sword2/save_rest.cpp24
7 files changed, 66 insertions, 70 deletions
diff --git a/scumm/dialogs.cpp b/scumm/dialogs.cpp
index d21d5ac86f..b4cf20869f 100644
--- a/scumm/dialogs.cpp
+++ b/scumm/dialogs.cpp
@@ -44,6 +44,8 @@
#include "backends/wince/CEKeysDialog.h"
#endif
+#include <memory>
+
using GUI::CommandSender;
using GUI::StaticTextWidget;
using GUI::kButtonWidth;
@@ -255,19 +257,17 @@ Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
uint i = saveMode ? 1 : 0;
bool avail_saves[81];
- SaveFileManager *mgr = OSystem::instance()->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(OSystem::instance()->get_savefile_manager());
- scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves), mgr);
+ scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves), mgr.get());
for (; i < ARRAYSIZE(avail_saves); i++) {
if (avail_saves[i])
- scumm->getSavegameName(i, name, mgr);
+ scumm->getSavegameName(i, name, mgr.get());
else
name[0] = 0;
l.push_back(name);
}
- delete mgr;
-
return l;
}
diff --git a/scumm/script_v5.cpp b/scumm/script_v5.cpp
index 762ba2a678..a5d465d48a 100644
--- a/scumm/script_v5.cpp
+++ b/scumm/script_v5.cpp
@@ -29,6 +29,8 @@
#include "scumm/sound.h"
#include "scumm/verbs.h"
+#include <memory>
+
namespace Scumm {
#define OPCODE(x) { &ScummEngine_v5::x, #x }
@@ -1172,8 +1174,9 @@ void ScummEngine_v5::o5_saveLoadGame() {
case 0xC0: // test if save exists
bool avail_saves[100];
char filename[256];
- SaveFileManager *mgr = _system->get_savefile_manager();
- listSavegames(avail_saves, ARRAYSIZE(avail_saves), mgr);
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
+ listSavegames(avail_saves, ARRAYSIZE(avail_saves), mgr.get());
makeSavegameName(filename, slot, false);
if (avail_saves[slot] && (mgr->open_savefile(filename, getSavePath(), false)))
result = 6; // save file exists
@@ -1938,7 +1941,8 @@ void ScummEngine_v5::o5_roomOps() {
s = filename;
while ((*s++ = fetchScriptByte()));
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
file = mgr->open_savefile(filename, getSavePath(), true);
if (file != NULL) {
byte *ptr;
@@ -1946,7 +1950,6 @@ void ScummEngine_v5::o5_roomOps() {
file->write(ptr, resStrLen(ptr) + 1);
delete file;
}
- delete mgr;
break;
}
case 14: // SO_LOAD_STRING
@@ -1958,7 +1961,8 @@ void ScummEngine_v5::o5_roomOps() {
s = filename;
while ((*s++ = fetchScriptByte()));
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
file = mgr->open_savefile(filename, getSavePath(), false);
if (file != NULL) {
byte *ptr;
@@ -1974,7 +1978,6 @@ void ScummEngine_v5::o5_roomOps() {
free(ptr);
delete file;
}
- delete mgr;
break;
}
case 15: // SO_ROOM_TRANSFORM
diff --git a/scumm/script_v8.cpp b/scumm/script_v8.cpp
index 7fa51a71cf..94c26b920f 100644
--- a/scumm/script_v8.cpp
+++ b/scumm/script_v8.cpp
@@ -34,6 +34,7 @@
#include "scumm/smush/smush_player.h"
#include "sound/mixer.h"
+#include <memory>
namespace Scumm {
@@ -1322,7 +1323,7 @@ void ScummEngine_v8::o8_kernelSetFunctions() {
warning("o8_kernelSetFunctions: clearTextQueue()");
break;
case 25: { // saveGameReadName
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
char *address = (char*)getStringAddress(args[2]);
char name[30];
@@ -1330,13 +1331,14 @@ void ScummEngine_v8::o8_kernelSetFunctions() {
warning("o8_kernelSetFunctions: saveGameReadName failed finding slot string %d", args[2]);
break;
}
- getSavegameName(args[1] - 1, name, mgr);
+ getSavegameName(args[1] - 1, name, mgr.get());
if (strlen(name) > 0 && strlen(name) < 30)
strcpy(address, name);
break;
}
case 26: { // saveGame?
- //SaveFileManager *mgr = _system->get_savefile_manager();
+ //const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
//char *address = (char*)getStringAddress(args[2]);
char address[30];
warning("o8_kernelSetFunctions: saveGame?(%d, %s)", args[1], address);
diff --git a/simon/simon.cpp b/simon/simon.cpp
index b2584b496c..9d30c14b47 100644
--- a/simon/simon.cpp
+++ b/simon/simon.cpp
@@ -42,6 +42,8 @@
#include <errno.h>
#include <time.h>
+#include <memory>
+
#ifdef __PALM_OS__
#include "globals.h"
#endif
@@ -2623,7 +2625,8 @@ int SimonEngine::count_savegames() {
uint i = 1;
bool marks[256];
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
char *prefix = gen_savename(999);
prefix[strlen(prefix)-3] = '\0';
mgr->list_savefiles(prefix, getSavePath(), marks, 256);
@@ -2637,7 +2640,6 @@ int SimonEngine::count_savegames() {
} else
break;
}
- delete mgr;
return i;
}
@@ -2651,7 +2653,8 @@ int SimonEngine::display_savegame_list(int curpos, bool load, char *dst) {
slot = curpos;
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
while (curpos + 6 > slot) {
if(!(in = mgr->open_savefile(gen_savename(slot), getSavePath(), false)))
@@ -2685,8 +2688,6 @@ int SimonEngine::display_savegame_list(int curpos, bool load, char *dst) {
}
}
- delete mgr;
-
return slot - curpos;
}
@@ -4806,11 +4807,11 @@ bool SimonEngine::save_game(uint slot, char *caption) {
errno = 0;
#endif
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
f = mgr->open_savefile(gen_savename(slot), getSavePath(), true);
if (f == NULL) {
- delete mgr;
_lock_word &= ~0x100;
return false;
}
@@ -4881,7 +4882,6 @@ bool SimonEngine::save_game(uint slot, char *caption) {
f->writeUint16BE(_bit_array[i]);
delete f;
- delete mgr;
_lock_word &= ~0x100;
@@ -4892,9 +4892,9 @@ char *SimonEngine::gen_savename(int slot) {
static char buf[15];
if (_game & GF_SIMON2) {
- sprintf(buf, "simon2.%.3d", slot);
+ sprintf(buf, "simon2.%.3d", slot);
} else {
- sprintf(buf, "simon1.%.3d", slot);
+ sprintf(buf, "simon1.%.3d", slot);
}
return buf;
}
@@ -4910,11 +4910,11 @@ bool SimonEngine::load_game(uint slot) {
errno = 0;
#endif
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
f = mgr->open_savefile(gen_savename(slot), getSavePath(), false);
if (f == NULL) {
- delete mgr;
_lock_word &= ~0x100;
return false;
}
@@ -4925,7 +4925,6 @@ bool SimonEngine::load_game(uint slot) {
if (f->readUint32BE() != 0xFFFFFFFF || num != _itemarray_inited - 1) {
delete f;
- delete mgr;
_lock_word &= ~0x100;
return false;
}
@@ -5003,7 +5002,6 @@ bool SimonEngine::load_game(uint slot) {
_bit_array[i] = f->readUint16BE();
delete f;
- delete mgr;
_no_parent_notify = false;
diff --git a/sky/control.cpp b/sky/control.cpp
index 8afbc5ebcf..6f43b3f0ea 100644
--- a/sky/control.cpp
+++ b/sky/control.cpp
@@ -35,6 +35,7 @@
#include "sky/struc.h"
#include "sky/text.h"
+#include <memory>
namespace Sky {
@@ -783,13 +784,13 @@ bool Control::autoSaveExists(void) {
strcpy(fName, "SKY-VM-CD.ASD");
else
sprintf(fName, "SKY-VM%03d.ASD", SkyEngine::_systemVars.gameVersion);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
f = mgr->open_savefile(fName, _savePath, false);
if (f != NULL) {
test = true;
delete f;
}
- delete mgr;
return test;
}
@@ -1003,7 +1004,8 @@ void Control::loadDescriptions(uint8 *destBuf) {
memset(destBuf, 0, MAX_SAVE_GAMES * MAX_TEXT_LEN);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *inf;
inf = mgr->open_savefile("SKY-VM.SAV",_savePath,false);
if (inf != NULL) {
@@ -1028,7 +1030,6 @@ void Control::loadDescriptions(uint8 *destBuf) {
destPos += MAX_TEXT_LEN;
}
}
- delete mgr;
}
bool Control::loadSaveAllowed(void) {
@@ -1064,13 +1065,13 @@ void Control::saveDescriptions(uint8 *srcBuf) {
srcPos += MAX_TEXT_LEN;
}
SaveFile *outf;
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
outf = mgr->open_savefile("SKY-VM.SAV", _savePath, true);
if (outf != NULL) {
outf->write(tmpBuf, tmpPos - tmpBuf);
delete outf;
}
- delete mgr;
free(tmpBuf);
}
@@ -1081,11 +1082,11 @@ void Control::doAutoSave(void) {
else
sprintf(fName, "SKY-VM%03d.ASD", SkyEngine::_systemVars.gameVersion);
SaveFile *outf;
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
outf = mgr->open_savefile(fName, _savePath, true);
if (outf == NULL) {
warning("Can't create file %s for autosaving", fName);
- delete mgr;
return;
}
uint8 *saveData = (uint8 *)malloc(0x20000);
@@ -1094,7 +1095,6 @@ void Control::doAutoSave(void) {
if (outf->write(saveData, fSize) != fSize)
warning("Can't write file %s for autosaving. Disk full?", fName);
delete outf;
- delete mgr;
free(saveData);
}
@@ -1102,11 +1102,11 @@ uint16 Control::saveGameToFile(void) {
char fName[20];
sprintf(fName,"SKY-VM.%03d", _selectedGame);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *outf;
outf = mgr->open_savefile(fName, _savePath, true);
if (outf == NULL) {
- delete mgr;
return NO_DISK_SPACE;
}
@@ -1116,11 +1116,9 @@ uint16 Control::saveGameToFile(void) {
if (outf->write(saveData, fSize) != fSize) {
free(saveData);
delete outf;
- delete mgr;
return NO_DISK_SPACE;
}
delete outf;
- delete mgr;
free(saveData);
return GAME_SAVED;
}
@@ -1509,11 +1507,11 @@ uint16 Control::restoreGameFromFile(bool autoSave) {
} else
sprintf(fName,"SKY-VM.%03d", _selectedGame);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *inf;
inf = mgr->open_savefile(fName, _savePath, false);
if (inf == NULL) {
- delete mgr;
return RESTORE_FAILED;
}
@@ -1526,14 +1524,12 @@ uint16 Control::restoreGameFromFile(bool autoSave) {
warning("Can't read from file!");
free(saveData);
delete inf;
- delete mgr;
return RESTORE_FAILED;
}
uint16 res = parseSaveData(saveData);
SkyEngine::_systemVars.pastIntro = true;
delete inf;
- delete mgr;
free(saveData);
return res;
}
diff --git a/sword1/control.cpp b/sword1/control.cpp
index 047a91c3c0..da8db4bffe 100644
--- a/sword1/control.cpp
+++ b/sword1/control.cpp
@@ -37,6 +37,8 @@
#include "sword1/sworddefs.h"
#include "sword1/swordres.h"
+#include <memory>
+
namespace Sword1 {
#define SAVEFILE_WRITE true
@@ -665,7 +667,8 @@ bool Control::restoreFromFile(void) {
}
void Control::readSavegameDescriptions(void) {
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *inf;
inf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_READ);
_saveScrollPos = _saveFiles = 0;
@@ -692,7 +695,6 @@ void Control::readSavegameDescriptions(void) {
for (uint8 cnt = 0; cnt < 64; cnt++)
_saveNames[cnt][0] = '\0';
delete inf;
- delete mgr;
}
int Control::displayMessage(const char *altButton, const char *message, ...) {
@@ -712,7 +714,8 @@ int Control::displayMessage(const char *altButton, const char *message, ...) {
}
void Control::writeSavegameDescriptions(void) {
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *outf;
outf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_WRITE);
@@ -734,18 +737,17 @@ void Control::writeSavegameDescriptions(void) {
outf->writeByte(255);
}
delete outf;
- delete mgr;
}
bool Control::savegamesExist(void) {
bool retVal = false;
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *inf;
inf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_READ);
if (inf && inf->isOpen())
retVal = true;
delete inf;
- delete mgr;
return retVal;
}
@@ -898,7 +900,8 @@ void Control::saveGameToFile(uint8 slot) {
uint16 cnt;
sprintf(fName, "SAVEGAME.%03d", slot);
uint16 liveBuf[TOTAL_SECTIONS];
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *outf;
outf = mgr->open_savefile(fName, _savePath, SAVEFILE_WRITE);
if (!outf || !outf->isOpen()) {
@@ -926,20 +929,19 @@ void Control::saveGameToFile(uint8 slot) {
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++)
outf->writeUint32LE(playerRaw[cnt2]);
delete outf;
- delete mgr;
}
bool Control::restoreGameFromFile(uint8 slot) {
char fName[15];
uint16 cnt;
sprintf(fName, "SAVEGAME.%03d", slot);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *inf;
inf = mgr->open_savefile(fName, _savePath, SAVEFILE_READ);
if (!inf || !inf->isOpen()) {
// Display an error message, and do nothing
displayMessage(0, "Can't open file '%s' in directory '%s'", fName, _savePath);
- delete mgr;
return false;
}
@@ -963,7 +965,6 @@ bool Control::restoreGameFromFile(uint8 slot) {
playerBuf[cnt2] = inf->readUint32LE();
delete inf;
- delete mgr;
return true;
}
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index 6c3feed16d..a3ecbc22a2 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -33,6 +33,8 @@
#include "sword2/logic.h"
#include "sword2/resman.h"
+#include <memory>
+
namespace Sword2 {
// A savegame consists of a header and the global variables
@@ -163,18 +165,17 @@ uint32 Sword2Engine::saveData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *out;
if (!(out = mgr->open_savefile(saveFileName, getSavePath(), true))) {
- delete mgr;
return SR_ERR_FILEOPEN;
}
uint32 itemsWritten = out->write(buffer, bufferSize);
delete out;
- delete mgr;
if (itemsWritten == bufferSize)
return SR_OK;
@@ -213,12 +214,12 @@ uint32 Sword2Engine::restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize)
sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *in;
if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
// error: couldn't open file
- delete mgr;
return SR_ERR_FILEOPEN;
}
@@ -226,14 +227,11 @@ uint32 Sword2Engine::restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize)
uint32 itemsRead = in->read(buffer, bufferSize);
delete in;
- delete mgr;
if (itemsRead != bufferSize) {
// We didn't get all of it. At the moment we have no way of
// knowing why, so assume that it's an incompatible savegame.
- delete in;
- delete mgr;
return SR_ERR_INCOMPATIBLE;
}
@@ -363,11 +361,11 @@ uint32 Sword2Engine::getSaveDescription(uint16 slotNo, byte *description) {
sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *in;
if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
- delete mgr;
return SR_ERR_FILEOPEN;
}
@@ -375,7 +373,6 @@ uint32 Sword2Engine::getSaveDescription(uint16 slotNo, byte *description) {
in->read(&dummy, sizeof(dummy));
delete in;
- delete mgr;
strcpy((char *) description, dummy.description);
return SR_OK;
@@ -393,16 +390,15 @@ bool Sword2Engine::saveExists(uint16 slotNo) {
sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
SaveFile *in;
if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
- delete mgr;
return false;
}
delete in;
- delete mgr;
return true;
}