Skip to content

Commit c83a9f3

Browse files
committed
Try to get %APPDATA% from registry like ActiveState's appdirs does
1 parent e95c43b commit c83a9f3

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/paths.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ def get_short_path_name(long_name):
5353
output_buf_size = needed
5454

5555

56+
# https://github.com/ActiveState/appdirs/blob/master/appdirs.py
57+
def _get_win_appdata_from_registry():
58+
"""This is a fallback technique at best. I'm not sure if using the
59+
registry for this guarantees us the correct answer for all CSIDL_*
60+
names.
61+
"""
62+
import _winreg
63+
64+
key = _winreg.OpenKey(
65+
_winreg.HKEY_CURRENT_USER,
66+
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
67+
)
68+
dir, type = _winreg.QueryValueEx(key, "AppData")
69+
return dir
70+
71+
5672
def lookupExeFolder():
5773
"""Returns executable folder path"""
5874
if frozen:
@@ -88,8 +104,8 @@ def lookupAppdataFolder():
88104
'Could not find home folder, please report this message'
89105
' and your OS X version to the BitMessage Github.')
90106
elif sys.platform.startswith('win'):
91-
dataFolder = get_short_path_name(
92-
os.path.join(os.environ['APPDATA'], APPNAME) + os.path.sep)
107+
dataFolder = os.path.join(
108+
_get_win_appdata_from_registry(), APPNAME) + os.path.sep
93109
else:
94110
try:
95111
dataFolder = os.path.join(os.environ['XDG_CONFIG_HOME'], APPNAME)

0 commit comments

Comments
 (0)