OSDN Git Service

windows: code cleanup
authorMartin Renold <martinxyz@gmx.ch>
Mon, 7 Feb 2011 09:09:11 +0000 (10:09 +0100)
committerMartin Renold <martinxyz@gmx.ch>
Tue, 15 Feb 2011 07:22:06 +0000 (08:22 +0100)
Use raw string for backslashes.
Fix exception handling. As it was before, in the case
of an exception the use of "localappdatapath" later would
have triggered another (fatal) exception.
Don't bother closing handles manually, python destructors do this
for us.
Set the path on windows independent of the result of expanduser('~').

mypaint.py

index afac3eb..ecf12cb 100644 (file)
@@ -73,27 +73,18 @@ def get_paths():
     homepath =  helpers.expanduser_unicode(u'~')
     if homepath == '~':
         confpath = join(prefix, 'UserData')
+    else:                                            
+        confpath = join(homepath, '.mypaint/')
     #Workaround before glib.get_user_config_dir() fixed in upstream
-    elif sys.platform == 'win32':                                  
+    if sys.platform == 'win32':                                  
         import _winreg
         try:
             HKCU = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
-        except WindowsError:
-            print "Can't connect to local registry"
-        try:
-            ShellKey = _winreg.OpenKey(HKCU, "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
-        except WindowsError:
-            print "Can't open Shell Folders key"
-            HKCU.Close()
-        try:
+            ShellKey = _winreg.OpenKey(HKCU, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
             localappdatapath = _winreg.QueryValueEx(ShellKey, "Local AppData")[0]
+            confpath = join(localappdatapath, 'mypaint/')
         except WindowsError:
             print "Can't retrive Local Application Data Path from registry"
-            HKCU.Close()
-            ShellKey.Close()
-        confpath = join(localappdatapath, 'mypaint/')
-    else:                                            
-        confpath = join(homepath, '.mypaint/')
 
     assert isinstance(datapath, unicode)
     assert isinstance(confpath, unicode)