Adding secure extraction of last edited project path to avoid crash if path is not well formatted
--- 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: