Adding secure extraction of last edited project path to avoid crash if path is not well formatted
authorlaurent
Wed, 18 Jul 2012 01:05:06 +0200
changeset 790 52d3a084d2b2
parent 789 b1b1a8f85e2f
child 791 67b47775ba21
Adding secure extraction of last edited project path to avoid crash if path is not well formatted
Beremiz.py
--- a/Beremiz.py	Wed Jul 18 00:44:29 2012 +0200
+++ b/Beremiz.py	Wed Jul 18 01:05:06 2012 +0200
@@ -440,8 +440,11 @@
             projectOpen = DecodeFileSystemPath(projectOpen, False)
         
         if ctr is None and projectOpen is None and self.Config.HasEntry("currenteditedproject"):
-            projectOpen = DecodeFileSystemPath(self.Config.Read("currenteditedproject"))
-            if projectOpen == "":
+            try:
+                projectOpen = DecodeFileSystemPath(self.Config.Read("currenteditedproject"))
+                if projectOpen == "":
+                    projectOpen = None
+            except:
                 projectOpen = None
         
         if projectOpen is not None and os.path.isdir(projectOpen):
@@ -806,10 +809,10 @@
         if self.CTR is not None and not self.CheckSaveBeforeClosing():
             return
         
-        if not self.Config.HasEntry("lastopenedfolder"):
+        try:
+            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
+        except:
             defaultpath = os.path.expanduser("~")
-        else:
-            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
         
         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
         if dialog.ShowModal() == wx.ID_OK:
@@ -841,10 +844,10 @@
         if self.CTR is not None and not self.CheckSaveBeforeClosing():
             return
         
-        if not self.Config.HasEntry("lastopenedfolder"):
+        try:
+            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
+        except:
             defaultpath = os.path.expanduser("~")
-        else:
-            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
         
         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
         if dialog.ShowModal() == wx.ID_OK: