[Scummvm-cvs-logs] CVS: scummvm/sword1 control.cpp,1.26.2.2,1.26.2.3 control.h,1.12.2.1,1.12.2.2

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Sun Jul 18 10:49:03 CEST 2004


Update of /cvsroot/scummvm/scummvm/sword1
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27182

Modified Files:
      Tag: branch-0-6-0
	control.cpp control.h 
Log Message:
Backported Fingolfin's fix for bug #920491; game crashes when savepath is
invalid.


Index: control.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/control.cpp,v
retrieving revision 1.26.2.2
retrieving revision 1.26.2.3
diff -u -d -r1.26.2.2 -r1.26.2.3
--- control.cpp	18 Jul 2004 17:09:05 -0000	1.26.2.2
+++ control.cpp	18 Jul 2004 17:48:25 -0000	1.26.2.3
@@ -19,20 +19,23 @@
  *
  */
 
-#include "stdafx.h"
-#include "control.h"
-#include "common/util.h"
 #include "common/file.h"
-#include "logic.h"
-#include "sworddefs.h"
-#include "swordres.h"
-#include "resman.h"
-#include "objectman.h"
-#include "sword1.h"
+#include "common/stdafx.h"
 #include "common/util.h"
-#include "mouse.h"
-#include "music.h"
-#include "sound.h"
+#include "common/util.h"
+
+#include "gui/message.h"
+
+#include "sword1/control.h"
+#include "sword1/logic.h"
+#include "sword1/mouse.h"
+#include "sword1/music.h"
+#include "sword1/objectman.h"
+#include "sword1/resman.h"
+#include "sword1/sound.h"
+#include "sword1/sword1.h"
+#include "sword1/sworddefs.h"
+#include "sword1/swordres.h"
 
 namespace Sword1 {
 
@@ -701,10 +704,36 @@
 	delete mgr;
 }
 
+int Control::displayMessage(const char *altButton, const char *message, ...) {
+#ifdef __PALM_OS__
+	char buf[256]; // 1024 is too big overflow the stack
+#else
+	char buf[1024];
+#endif
+	va_list va;
+
+	va_start(va, message);
+	vsprintf(buf, message, va);
+	va_end(va);
+
+	GUI::MessageDialog dialog(buf, "OK", altButton);
+	int result = dialog.runModal();
+	_mouse->setPointer(MSE_POINTER, 0);
+	return result;
+}
+
 void Control::writeSavegameDescriptions(void) {
 	SaveFileManager *mgr = _system->get_savefile_manager();
 	SaveFile *outf;
 	outf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_WRITE);
+
+	if (!outf) {
+		delete mgr;
+		// Display an error message, and do nothing
+		displayMessage(0, "Unable to write to path '%s'", _savePath);
+		return;
+	}
+
 	// if the player accidently clicked the last slot and then deselected it again,
 	// we'd still have _saveFiles == 64, so get rid of the empty end.
 	while (strlen((char*)_saveNames[_saveFiles - 1]) == 0)
@@ -884,8 +913,12 @@
 	SaveFileManager *mgr = _system->get_savefile_manager();
 	SaveFile *outf;
 	outf = mgr->open_savefile(fName, _savePath, SAVEFILE_WRITE);
-	if (!outf->isOpen())
-		error("unable to create file %s", fName);
+	if (!outf || !outf->isOpen()) {
+		delete mgr;
+		// Display an error message, and do nothing
+		displayMessage(0, "Unable to create file '%s' in directory '%s'", fName, _savePath);
+		return;
+	}
 
 	_objMan->saveLiveList(liveBuf);
 	for (cnt = 0; cnt < TOTAL_SECTIONS; cnt++)
@@ -916,9 +949,10 @@
 	SaveFileManager *mgr = _system->get_savefile_manager();
 	SaveFile *inf;
 	inf = mgr->open_savefile(fName, _savePath, SAVEFILE_READ);
-	if ((!inf) || (!inf->isOpen())) {
-		warning("Can't open file %s in directory %s", fName, _savePath);
+	if (!inf || !inf->isOpen()) {
 		delete mgr;
+		// Display an error message, and do nothing
+		displayMessage(0, "Can't open file '%s' in directory '%s'", fName, _savePath);
 		return false;
 	}
 

Index: control.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/control.h,v
retrieving revision 1.12.2.1
retrieving revision 1.12.2.2
diff -u -d -r1.12.2.1 -r1.12.2.2
--- control.h	18 Jul 2004 17:09:05 -0000	1.12.2.1
+++ control.h	18 Jul 2004 17:48:25 -0000	1.12.2.2
@@ -74,6 +74,8 @@
 	void askForCd(void);
 	bool savegamesExist(void);
 private:
+	int displayMessage(const char* altButton, const char *message, ...);
+
 	void saveGameToFile(uint8 slot);
 	bool restoreGameFromFile(uint8 slot);
 	void readSavegameDescriptions(void);





More information about the Scummvm-git-logs mailing list