OSDN Git Service

windows: use AppData folder for settings
authorTumagonx <mr_tiar@gmail.com>
Mon, 7 Feb 2011 09:01:10 +0000 (10:01 +0100)
committerMartin Renold <martinxyz@gmx.ch>
Tue, 15 Feb 2011 07:22:06 +0000 (08:22 +0100)
https://gna.org/bugs/?17662

"In Windows I expect Local AppData folder for saving settings,
in pygobject there is glib.get_user_config_dir() but it has windows
issue that just recently fixed (Glib 2.27.x ?) otherwise it seems to
conform XDG spec too."

mypaint.py

index 49b3fec..afac3eb 100644 (file)
@@ -73,8 +73,27 @@ 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':                                  
+        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:
+            localappdatapath = _winreg.QueryValueEx(ShellKey, "Local AppData")[0]
+        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)