Handle SHGetFolder failing to return home directory on windows

This commit is contained in:
Kovid Goyal 2015-11-04 21:38:00 +05:30
parent 7459e67a2a
commit 2d71675fe1
2 changed files with 10 additions and 5 deletions

View File

@ -127,7 +127,10 @@ def get_library_path(gui_runner):
if library_path is None: # Need to migrate to new database layout
base = os.path.expanduser('~')
if iswindows:
try:
base = winutil.special_folder_path(winutil.CSIDL_PERSONAL)
except ValueError:
base = None
if not base or not os.path.exists(base):
from PyQt5.Qt import QDir
base = unicode(QDir.homePath()).replace('/', os.sep)

View File

@ -12,7 +12,7 @@ from contextlib import closing
from PyQt5.Qt import (QWizard, QWizardPage, QPixmap, Qt, QAbstractListModel,
QItemSelectionModel, QObject, QTimer, pyqtSignal, QItemSelection)
QItemSelectionModel, QObject, QTimer, pyqtSignal, QItemSelection, QDir)
from calibre import __appname__, patheq
from calibre.library.move import MoveLibrary
from calibre.constants import (filesystem_encoding, iswindows, plugins,
@ -805,7 +805,10 @@ class LibraryPage(QWizardPage, LibraryUI):
fname = _('Calibre Library')
base = os.path.expanduser(u'~')
if iswindows:
try:
x = winutil.special_folder_path(winutil.CSIDL_PERSONAL)
except ValueError:
x = QDir.homePath().replace('/', os.sep)
if x and os.access(x, os.W_OK):
base = x
@ -837,8 +840,7 @@ class LibraryPage(QWizardPage, LibraryUI):
newloc = unicode(self.location.text())
try:
dln = self.default_library_name
if (dln and os.path.exists(dln) and not os.listdir(dln) and newloc
!= dln):
if (dln and os.path.exists(dln) and not os.listdir(dln) and newloc != dln):
os.rmdir(dln)
except:
pass