mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle SHGetFolder failing to return home directory on windows
This commit is contained in:
parent
7459e67a2a
commit
2d71675fe1
@ -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:
|
||||
base = winutil.special_folder_path(winutil.CSIDL_PERSONAL)
|
||||
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)
|
||||
|
@ -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:
|
||||
x = winutil.special_folder_path(winutil.CSIDL_PERSONAL)
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user