summaryrefslogtreecommitdiff
path: root/appdirs.py
diff options
context:
space:
mode:
authorCaleb P. Burns <cpburnz@gmail.com>2014-04-26 22:33:14 -0400
committercaleb <caleb@partsgiant.com>2014-05-07 13:48:29 -0400
commite5ba04c47b970930e31fe63aec05a08adada8a53 (patch)
treeae33e9c3b5259d4b8acbec685f5217207e98abbf /appdirs.py
parentab4657d478a0874b4e7068f3ada7e1814fbd3faf (diff)
downloadappdirs-e5ba04c47b970930e31fe63aec05a08adada8a53.tar.gz
Update appdirs.py
Jython on Windows has neither `ctypes.windll` no `_winreg`, but this can be patched using `jna`.
Diffstat (limited to 'appdirs.py')
-rw-r--r--appdirs.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/appdirs.py b/appdirs.py
index 8a9536c..190ede5 100644
--- a/appdirs.py
+++ b/appdirs.py
@@ -479,16 +479,45 @@ def _get_win_folder_with_ctypes(csidl_name):
return buf.value
+def _get_win_folder_with_jna(csidl_name):
+ import array
+ from com.sun import jna
+ from com.sun.jan.platform import win32
+
+ buf = array.zeros('c', win32.WinDef.MAX_PATH * 2)
+ shell = win32.Shell32.INSTANCE
+ shell.SHGetFolderPath(None, getattr(win32.ShlObj, csidl_name), None, win32.ShlObj.SHGFP_TYPE_CURRENT, buf)
+ dir = jna.Native.toString(buf.tostring()).rstrip(u"\0")
+
+ # Downgrade to short path name if have highbit chars. See
+ # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
+ has_high_char = False
+ for c in dir:
+ if ord(c) > 255:
+ has_high_char = True
+ break
+ if has_high_char:
+ buf = array.zeros('c', win32.WinDef.MAX_PATH * 2)
+ kernel = win32.Kernel32.INSTANCE
+ if kernal.GetShortPathName(dir, buf, win32.WinDef.MAX_PATH * 2):
+ dir = jna.Native.toString(buf.tostring()).rstrip(u"\0")
+
+ return dir
+
if system == "win32":
try:
import win32com.shell
_get_win_folder = _get_win_folder_with_pywin32
except ImportError:
try:
- import ctypes
+ from ctypes import windll
_get_win_folder = _get_win_folder_with_ctypes
except ImportError:
- _get_win_folder = _get_win_folder_from_registry
+ try:
+ import com.sun.jna
+ _get_win_folder = _get_win_folder_with_jna
+ except ImportError:
+ _get_win_folder = _get_win_folder_from_registry
#---- self test code