[Scummvm-cvs-logs] SF.net SVN: scummvm: [22168] scummvm/trunk/engines/sword2

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Tue Apr 25 23:13:01 CEST 2006


Revision: 22168
Author:   eriktorbjorn
Date:     2006-04-25 23:12:03 -0700 (Tue, 25 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22168&view=rev

Log Message:
-----------
If the resource manager fails to initialize itself properly, instead of
printing a fatal error, use the new GUIErrorMessage function and return to
the launcher. Also, verify that all files that should be present on "CD 0"
(i.e. on the hard disk) are present at startup, at least. (Any other missing
CLU file is already requested with an "Insert CD" message.)

Modified Paths:
--------------
    scummvm/trunk/engines/sword2/resman.cpp
    scummvm/trunk/engines/sword2/resman.h
    scummvm/trunk/engines/sword2/sword2.cpp
Modified: scummvm/trunk/engines/sword2/resman.cpp
===================================================================
--- scummvm/trunk/engines/sword2/resman.cpp	2006-04-26 05:59:58 UTC (rev 22167)
+++ scummvm/trunk/engines/sword2/resman.cpp	2006-04-26 06:12:03 UTC (rev 22168)
@@ -61,10 +61,31 @@
 };
 
 ResourceManager::ResourceManager(Sword2Engine *vm) {
+	_vm = vm;
+
+	_totalClusters = 0;
+	_resConvTable = NULL;
+	_cacheStart = NULL;
+	_cacheEnd = NULL;
+	_usedMem = 0;
+}
+
+ResourceManager::~ResourceManager() {
+	Resource *res = _cacheStart;
+	while (res) {
+		_vm->_memory->memFree(res->ptr);
+		res = res->next;
+	}
+	for (uint i = 0; i < _totalClusters; i++)
+		free(_resFiles[i].entryTab);
+	free(_resList);
+	free(_resConvTable);
+}
+
+    
+bool ResourceManager::init() {
 	uint32 i, j;
 
-	_vm = vm;
-
 	// Until proven differently, assume we're on CD 1. This is so the start
 	// dialog will be able to play any music at all.
 
@@ -77,27 +98,30 @@
 
 	Common::File file;
 
-	_totalClusters = 0;
-	_resConvTable = NULL;
+	if (!file.open("resource.inf")) {
+		_vm->GUIErrorMessage("Broken Sword 2: Cannot open resource.inf");
+		return false;
+	}
 
-	if (!file.open("resource.inf"))
-		error("Cannot open resource.inf");
-
 	// The resource.inf file is a simple text file containing the names of
 	// all the resource files.
 
 	while (file.readLine(_resFiles[_totalClusters].fileName, sizeof(_resFiles[_totalClusters].fileName))) {
 		_resFiles[_totalClusters].numEntries = -1;
 		_resFiles[_totalClusters].entryTab = NULL;
-		if (++_totalClusters >= MAX_res_files)
-			error("Too many entries in resource.inf");
+		if (++_totalClusters >= MAX_res_files) {
+			_vm->GUIErrorMessage("Broken Sword 2: Too many entries in resource.inf");
+			return false;
+		}
 	}
 
 	file.close();
 
 	// Now load in the binary id to res conversion table
-	if (!file.open("resource.tab"))
-		error("Cannot open resource.tab");
+	if (!file.open("resource.tab")) {
+		_vm->GUIErrorMessage("Broken Sword 2: Cannot open resource.tab");
+		return false;
+	}
 
 	// Find how many resources
 	uint32 size = file.size();
@@ -112,13 +136,16 @@
 
 	if (file.ioFailed()) {
 		file.close();
-		error("Cannot read resource.tab");
+		_vm->GUIErrorMessage("Broken Sword 2: Cannot read resource.tab");
+		return false;
 	}
 
 	file.close();
 
-	if (!file.open("cd.inf"))
-		error("Cannot open cd.inf");
+	if (!file.open("cd.inf")) {
+		_vm->GUIErrorMessage("Broken Sword 2: Cannot open cd.inf");
+		return false;
+	}
 
 	CdInf *cdInf = new CdInf[_totalClusters];
 
@@ -127,8 +154,12 @@
 
 		cdInf[i].cd = file.readByte();
 
-		if (file.ioFailed())
-			error("Cannot read cd.inf");
+		if (file.ioFailed()) {
+			delete cdInf;
+			file.close();
+			_vm->GUIErrorMessage("Broken Sword 2: Cannot read cd.inf");
+			return false;
+		}
 
 		// It has been reported that there are two different versions
 		// of the cd.inf file: One where all clusters on CD also have
@@ -144,6 +175,18 @@
 			cdInf[i].cd = 2;
 		else
 			cdInf[i].cd = 0;
+
+		// Any file on "CD 0" may be needed at all times. Verify that
+		// it exists. Any other missing cluster will be requested with
+		// an "insert CD" message. Of course, the file may still vanish
+		// during game-play (oh, that wascally wabbit!) in which case
+		// the resource manager will print a fatal error.
+
+		if (!Common::File::exists((char *)cdInf[i].clusterName)) {
+			_vm->GUIErrorMessage("Broken Sword 2: Cannot find " + Common::String((char *)cdInf[i].clusterName));
+			delete [] cdInf;
+			return false;
+		}
 	}
 
 	file.close();
@@ -154,8 +197,11 @@
 				break;
 		}
 
-		if (j == _totalClusters)
-			error("%s is not in cd.inf", _resFiles[i].fileName);
+		if (j == _totalClusters) {
+			delete [] cdInf;
+			_vm->GUIErrorMessage(Common::String(_resFiles[i].fileName) + " is not in cd.inf");
+			return false;
+		}
 
 		_resFiles[i].cd = cdInf[j].cd;
 	}
@@ -174,20 +220,8 @@
 		_resList[i].refCount = 0;
 		_resList[i].prev = _resList[i].next = NULL;
 	}
-	_cacheStart = _cacheEnd = NULL;
-	_usedMem = 0;
-}
 
-ResourceManager::~ResourceManager() {
-	Resource *res = _cacheStart;
-	while (res) {
-		_vm->_memory->memFree(res->ptr);
-		res = res->next;
-	}
-	for (uint i = 0; i < _totalClusters; i++)
-		free(_resFiles[i].entryTab);
-	free(_resList);
-	free(_resConvTable);
+	return true;
 }
 
 /**

Modified: scummvm/trunk/engines/sword2/resman.h
===================================================================
--- scummvm/trunk/engines/sword2/resman.h	2006-04-26 05:59:58 UTC (rev 22167)
+++ scummvm/trunk/engines/sword2/resman.h	2006-04-26 06:12:03 UTC (rev 22168)
@@ -74,6 +74,8 @@
 	ResourceManager(Sword2Engine *vm);	// read in the config file
 	~ResourceManager();
 
+	bool init();
+
 	uint32 getNumResFiles() { return _totalResFiles; }
 	uint32 getNumClusters() { return _totalClusters; }
 	ResourceFile *getResFiles() { return _resFiles; }

Modified: scummvm/trunk/engines/sword2/sword2.cpp
===================================================================
--- scummvm/trunk/engines/sword2/sword2.cpp	2006-04-26 05:59:58 UTC (rev 22167)
+++ scummvm/trunk/engines/sword2/sword2.cpp	2006-04-26 06:12:03 UTC (rev 22168)
@@ -244,6 +244,15 @@
 	// Get some falling RAM and put it in your pocket, never let it slip
 	// away
 
+	_debugger = NULL;
+	_sound = NULL;
+	_fontRenderer = NULL;
+	_screen = NULL;
+	_mouse = NULL;
+	_logic = NULL;
+	_resman = NULL;
+	_memory = NULL;
+
 	_system->beginGFXTransaction();
 		initCommonGFX(true);
 		_screen = new Screen(this, 640, 480);
@@ -258,6 +267,10 @@
 
 	_memory = new MemoryManager(this);
 	_resman = new ResourceManager(this);
+
+	if (!_resman->init())
+		return 1;
+
 	_logic = new Logic(this);
 	_fontRenderer = new FontRenderer(this);
 	_sound = new Sound(this);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list