changeset 421:293e812316c0

Fixed a bug where the editor would exit because of a boost exception when browsing to a directory that the user does not have access to. The vfs now catches the boost exception and throws a FIFE exception. Updated the filebrowser to catch the exception and display a warning to the user. fixes[t:413]
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 11 Feb 2010 04:18:42 +0000
parents 2d01d25222bd
children 9d94f4676d17
files engine/core/vfs/vfsdirectory.cpp engine/python/fife/extensions/filebrowser.py
diffstat 2 files changed, 32 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/vfs/vfsdirectory.cpp	Mon Feb 08 16:28:03 2010 +0000
+++ b/engine/core/vfs/vfsdirectory.cpp	Thu Feb 11 04:18:42 2010 +0000
@@ -33,7 +33,7 @@
 #include "vfs/raw/rawdata.h"
 #include "vfs/raw/rawdatafile.h"
 #include "util/log/logger.h"
-
+#include "util/base/exception.h"
 #include "vfsdirectory.h"
 
 namespace bfs = boost::filesystem;
@@ -84,19 +84,24 @@
 			dir.append(path);
 		}
 
-		bfs::path boost_path(dir);
-		if (!bfs::exists(boost_path) || !bfs::is_directory(boost_path))
-			return list;
+		try {
+			bfs::path boost_path(dir);
+			if (!bfs::exists(boost_path) || !bfs::is_directory(boost_path))
+				return list;
 
-		bfs::directory_iterator end;
-		for (bfs::directory_iterator i(boost_path); i != end; ++i) {
-			if (bfs::is_directory(*i) != directorys)
-				continue;
+			bfs::directory_iterator end;
+			for	(bfs::directory_iterator i(boost_path); i != end; ++i) {
+				if (bfs::is_directory(*i) != directorys)
+					continue;
 
-			// This only works with boost 1.34 and up
-			// list.insert(i->path().leaf());
-			// This one should be ok with both 1.33 and above
-			list.insert(i->leaf());
+				// This only works with boost 1.34 and up
+				// list.insert(i->path().leaf());
+				// This one should be ok with both 1.33 and above
+				list.insert(i->leaf());
+			}
+		}
+		catch (const bfs::filesystem_error& ex) {
+			throw Exception(ex.what());
 		}
 
 		return list;
--- a/engine/python/fife/extensions/filebrowser.py	Mon Feb 08 16:28:03 2010 +0000
+++ b/engine/python/fife/extensions/filebrowser.py	Thu Feb 11 04:18:42 2010 +0000
@@ -72,6 +72,7 @@
 		self._widget.show()
 		
 	def setDirectory(self, path):
+		path_copy = self.path
 		self.path = path
 		if not self._widget: return
 		
@@ -86,15 +87,24 @@
 					newList.append(unicode(i, fs_encoding, 'replace'))
 					print "WARNING: Could not decode item:", i
 			return newList
+	
+		dir_list_copy = list(self.dir_list)
+		file_list_copy = list(self.file_list)
 
 		self.dir_list = []
 		self.file_list = []
 		
-		dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(self.path))
-		file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(self.path))
-				
-		self.dir_list = decodeList(dir_list)
-		self.file_list = decodeList(file_list)
+		try:
+			dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(self.path))
+			file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(self.path))
+			self.dir_list = decodeList(dir_list)
+			self.file_list = decodeList(file_list)
+		except:
+			self.path = path_copy
+			self.dir_list = list(dir_list_copy)
+			self.file_list = list(file_list_copy)
+			print "WARNING: Tried to browse to directory that is not accessible!"
+
 		self._widget.distributeInitialData({
 			'dirList'  : self.dir_list,
 			'fileList' : self.file_list