national special characters in username (vista64) fail for sabnzbd 4.11
Posted: July 8th, 2009, 6:27 pm
Hello...
I am from Germany and my name is "Jörg", so my Profile-dirs (Vista64) start with 'C:\\Users\\Jörg'
this special character 'ö' makes SABnzbd 4.11 fail to show the config page because the treatment of special characters in the GetProfileInfo function is wrong:
first bug: the 8bit ASCII conversion needed for CherryPy is only done when the Get_User_ShellFolders() failed - it must be done in any case, because this function also could have delivered UNICODE character(s) necessary to be converted...
second bug: when all failed, win32api.GetShortPathName() is called, BUT: with DEF_WORKDIR already appended - that function only works for existing pathnames, so when this directory doesn't exist yet (first call after installation) it fails!
here's how I changed it to work at least for me:
elif os.name == 'nt':
specials = Get_User_ShellFolders()
try:
sabnzbd.DIR_APPDATA = '%s' % specials['AppData']
sabnzbd.DIR_LCLDATA = '%s' % specials['Local AppData']
sabnzbd.DIR_HOME = specials['Personal']
except:
try:
if vista:
root = os.environ['AppData']
user = os.environ['USERPROFILE']
sabnzbd.DIR_APPDATA = '%s' % root.replace('\\Roaming', '\\Local')
sabnzbd.DIR_HOME = '%s\\Documents' % user
else:
root = os.environ['USERPROFILE']
sabnzbd.DIR_APPDATA = '%s' % root
sabnzbd.DIR_HOME = root
except:
pass
try:
# Conversion to 8bit ASCII required for CherryPy
sabnzbd.DIR_APPDATA = sabnzbd.DIR_APPDATA.encode('latin-1')
sabnzbd.DIR_HOME = sabnzbd.DIR_HOME.encode('latin-1')
ok = True
except:
# If unconvertible characters exist, use MSDOS name
try:
sabnzbd.DIR_APPDATA = win32api.GetShortPathName(sabnzbd.DIR_APPDATA)
sabnzbd.DIR_HOME = win32api.GetShortPathName(sabnzbd.DIR_HOME)
ok = True
except:
pass
sabnzbd.DIR_APPDATA = '%s\\%s' % (sabnzbd.DIR_APPDATA, DEF_WORKDIR.encode('latin-1'))
sabnzbd.DIR_HOME = '%s\\%s' % (sabnzbd.DIR_HOME, DEF_WORKDIR.encode('latin-1'))
sabnzbd.DIR_LCLDATA = sabnzbd.DIR_APPDATA
I am from Germany and my name is "Jörg", so my Profile-dirs (Vista64) start with 'C:\\Users\\Jörg'
this special character 'ö' makes SABnzbd 4.11 fail to show the config page because the treatment of special characters in the GetProfileInfo function is wrong:
first bug: the 8bit ASCII conversion needed for CherryPy is only done when the Get_User_ShellFolders() failed - it must be done in any case, because this function also could have delivered UNICODE character(s) necessary to be converted...
second bug: when all failed, win32api.GetShortPathName() is called, BUT: with DEF_WORKDIR already appended - that function only works for existing pathnames, so when this directory doesn't exist yet (first call after installation) it fails!
here's how I changed it to work at least for me:
elif os.name == 'nt':
specials = Get_User_ShellFolders()
try:
sabnzbd.DIR_APPDATA = '%s' % specials['AppData']
sabnzbd.DIR_LCLDATA = '%s' % specials['Local AppData']
sabnzbd.DIR_HOME = specials['Personal']
except:
try:
if vista:
root = os.environ['AppData']
user = os.environ['USERPROFILE']
sabnzbd.DIR_APPDATA = '%s' % root.replace('\\Roaming', '\\Local')
sabnzbd.DIR_HOME = '%s\\Documents' % user
else:
root = os.environ['USERPROFILE']
sabnzbd.DIR_APPDATA = '%s' % root
sabnzbd.DIR_HOME = root
except:
pass
try:
# Conversion to 8bit ASCII required for CherryPy
sabnzbd.DIR_APPDATA = sabnzbd.DIR_APPDATA.encode('latin-1')
sabnzbd.DIR_HOME = sabnzbd.DIR_HOME.encode('latin-1')
ok = True
except:
# If unconvertible characters exist, use MSDOS name
try:
sabnzbd.DIR_APPDATA = win32api.GetShortPathName(sabnzbd.DIR_APPDATA)
sabnzbd.DIR_HOME = win32api.GetShortPathName(sabnzbd.DIR_HOME)
ok = True
except:
pass
sabnzbd.DIR_APPDATA = '%s\\%s' % (sabnzbd.DIR_APPDATA, DEF_WORKDIR.encode('latin-1'))
sabnzbd.DIR_HOME = '%s\\%s' % (sabnzbd.DIR_HOME, DEF_WORKDIR.encode('latin-1'))
sabnzbd.DIR_LCLDATA = sabnzbd.DIR_APPDATA