Browse Source

Improved the error message when physfs fails to open a filepath.

Alex Szpakowski 11 years ago
parent
commit
028108ea64
1 changed files with 17 additions and 4 deletions
  1. 17 4
      src/modules/filesystem/physfs/File.cpp

+ 17 - 4
src/modules/filesystem/physfs/File.cpp

@@ -69,23 +69,36 @@ bool File::open(Mode mode)
 	if (file != 0)
 	if (file != 0)
 		return false;
 		return false;
 
 
-	this->mode = mode;
+	PHYSFS_getLastError(); // Clear the error buffer.
+	PHYSFS_File *handle = nullptr;
 
 
 	switch (mode)
 	switch (mode)
 	{
 	{
 	case READ:
 	case READ:
-		file = PHYSFS_openRead(filename.c_str());
+		handle = PHYSFS_openRead(filename.c_str());
 		break;
 		break;
 	case APPEND:
 	case APPEND:
-		file = PHYSFS_openAppend(filename.c_str());
+		handle = PHYSFS_openAppend(filename.c_str());
 		break;
 		break;
 	case WRITE:
 	case WRITE:
-		file = PHYSFS_openWrite(filename.c_str());
+		handle = PHYSFS_openWrite(filename.c_str());
 		break;
 		break;
 	default:
 	default:
 		break;
 		break;
 	}
 	}
 
 
+	if (handle == nullptr)
+	{
+		const char *err = PHYSFS_getLastError();
+		if (err == nullptr)
+			err = "unknown error";
+		throw love::Exception("Could not open file %s (%s)", filename.c_str(), err);
+	}
+
+	file = handle;
+
+	this->mode = mode;
+
 	if (file != 0 && !setBuffer(bufferMode, bufferSize))
 	if (file != 0 && !setBuffer(bufferMode, bufferSize))
 	{
 	{
 		// Revert to buffer defaults if we don't successfully set the buffer.
 		// Revert to buffer defaults if we don't successfully set the buffer.