Browse Source

Default base folder for Windows is now the %USERPROFILE% folder.

Before, %USERPROFILE%\Documents was used.
The default download folders should be based on %USERPROFILE%\Downloads.
The other folders will land in %USERPROFILE%.
Also removed the obsolete option to have the INI file in the program folder. The latter now needs an explicit -f parameter.
pull/199/head
shypike 10 years ago
parent
commit
c148b990fc
  1. 20
      SABnzbd.py
  2. 43
      sabnzbd/misc.py

20
SABnzbd.py

@ -86,7 +86,7 @@ import sabnzbd.lang
import sabnzbd.interface import sabnzbd.interface
from sabnzbd.constants import * from sabnzbd.constants import *
import sabnzbd.newsunpack import sabnzbd.newsunpack
from sabnzbd.misc import get_user_shellfolders, real_path, \ from sabnzbd.misc import real_path, \
check_latest_version, exit_sab, \ check_latest_version, exit_sab, \
split_host, get_ext, create_https_certificates, \ split_host, get_ext, create_https_certificates, \
windows_variant, ip_extract, set_serv_parms, get_serv_parms, globber_full windows_variant, ip_extract, set_serv_parms, get_serv_parms, globber_full
@ -423,11 +423,13 @@ def GetProfileInfo(vista_plus):
pass pass
ok = True ok = True
elif sabnzbd.WIN32: elif sabnzbd.WIN32:
specials = get_user_shellfolders()
try: try:
sabnzbd.DIR_APPDATA = '%s\\%s' % (specials['AppData'], DEF_WORKDIR) from win32com.shell import shell, shellcon
sabnzbd.DIR_LCLDATA = '%s\\%s' % (specials['Local AppData'], DEF_WORKDIR) path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, None, 0)
sabnzbd.DIR_HOME = specials['Personal'] sabnzbd.DIR_APPDATA = os.path.join(path, DEF_WORKDIR)
path = shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, None, 0)
sabnzbd.DIR_LCLDATA = os.path.join(path, DEF_WORKDIR)
sabnzbd.DIR_HOME = os.environ['USERPROFILE']
ok = True ok = True
except: except:
try: try:
@ -435,7 +437,7 @@ def GetProfileInfo(vista_plus):
root = os.environ['AppData'] root = os.environ['AppData']
user = os.environ['USERPROFILE'] user = os.environ['USERPROFILE']
sabnzbd.DIR_APPDATA = '%s\\%s' % (root.replace('\\Roaming', '\\Local'), DEF_WORKDIR) sabnzbd.DIR_APPDATA = '%s\\%s' % (root.replace('\\Roaming', '\\Local'), DEF_WORKDIR)
sabnzbd.DIR_HOME = '%s\\Documents' % user sabnzbd.DIR_HOME = user
else: else:
root = os.environ['USERPROFILE'] root = os.environ['USERPROFILE']
sabnzbd.DIR_APPDATA = '%s\\%s' % (root, DEF_WORKDIR) sabnzbd.DIR_APPDATA = '%s\\%s' % (root, DEF_WORKDIR)
@ -1081,11 +1083,9 @@ def main():
# No ini file given, need profile data # No ini file given, need profile data
GetProfileInfo(vista_plus) GetProfileInfo(vista_plus)
# Find out where INI file is # Find out where INI file is
inifile = os.path.abspath(sabnzbd.DIR_PROG + '/' + DEF_INI_FILE) inifile = os.path.abspath(sabnzbd.DIR_LCLDATA + '/' + DEF_INI_FILE)
if not os.path.exists(inifile) and not os.path.exists(inifile + '.bak'):
inifile = os.path.abspath(sabnzbd.DIR_LCLDATA + '/' + DEF_INI_FILE)
# If INI file at non-std location, then use program dir as $HOME # If INI file at non-std location, then use INI location as $HOME
if sabnzbd.DIR_LCLDATA != os.path.dirname(inifile): if sabnzbd.DIR_LCLDATA != os.path.dirname(inifile):
sabnzbd.DIR_HOME = os.path.dirname(inifile) sabnzbd.DIR_HOME = os.path.dirname(inifile)

43
sabnzbd/misc.py

@ -427,49 +427,6 @@ def create_real_path(name, loc, path, umask=False, writable=True):
else: else:
return (False, "") return (False, "")
################################################################################
# get_user_shellfolders
#
# Return a dictionary with Windows Special Folders
# Read info from the registry
################################################################################
def get_user_shellfolders():
""" Return a dictionary with Windows Special Folders
"""
import _winreg
values = {}
# Open registry hive
try:
hive = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
except WindowsError:
logging.error(T('Cannot connect to registry hive HKEY_CURRENT_USER.'))
return values
# Then open the registry key where Windows stores the Shell Folder locations
try:
key = _winreg.OpenKey(hive, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
except WindowsError:
logging.error(T('Cannot open registry key "%s".'), r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
_winreg.CloseKey(hive)
return values
try:
for i in range(0, _winreg.QueryInfoKey(key)[1]):
name, value, val_type = _winreg.EnumValue(key, i)
values[name] = value
i += 1
_winreg.CloseKey(key)
_winreg.CloseKey(hive)
return values
except WindowsError:
# On error, return empty dict.
logging.error(T('Failed to read registry keys for special folders'))
_winreg.CloseKey(key)
_winreg.CloseKey(hive)
return {}
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
def windows_variant(): def windows_variant():

Loading…
Cancel
Save