mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #934840 (Win7: change default library location for backup [Enhancement])
This commit is contained in:
parent
721da3ba8a
commit
0cb571527d
@ -16,7 +16,7 @@ from PyQt4.Qt import (QWizard, QWizardPage, QPixmap, Qt, QAbstractListModel,
|
||||
from calibre import __appname__, patheq
|
||||
from calibre.library.database2 import LibraryDatabase2
|
||||
from calibre.library.move import MoveLibrary
|
||||
from calibre.constants import filesystem_encoding, iswindows
|
||||
from calibre.constants import filesystem_encoding, iswindows, plugins
|
||||
from calibre.gui2.wizard.send_email import smtp_prefs
|
||||
from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI
|
||||
from calibre.gui2.wizard.library_ui import Ui_WizardPage as LibraryUI
|
||||
@ -30,6 +30,9 @@ from calibre.gui2 import NONE, choose_dir, error_dialog
|
||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||
from calibre.customize.ui import device_plugins
|
||||
|
||||
if iswindows:
|
||||
winutil = plugins['winutil'][0]
|
||||
|
||||
# Devices {{{
|
||||
|
||||
class Device(object):
|
||||
@ -751,19 +754,20 @@ class LibraryPage(QWizardPage, LibraryUI):
|
||||
self.default_library_name = None
|
||||
if not lp:
|
||||
fname = _('Calibre Library')
|
||||
if isinstance(fname, unicode):
|
||||
try:
|
||||
fname = fname.encode(filesystem_encoding)
|
||||
except:
|
||||
fname = 'Calibre Library'
|
||||
lp = os.path.expanduser('~'+os.sep+fname)
|
||||
base = os.path.expanduser(u'~')
|
||||
if iswindows:
|
||||
x = winutil.special_folder_path(winutil.CSIDL_PERSONAL)
|
||||
if x and os.access(x, os.W_OK):
|
||||
base = x
|
||||
|
||||
lp = os.path.join(base, fname)
|
||||
self.default_library_name = lp
|
||||
if not os.path.exists(lp):
|
||||
try:
|
||||
os.makedirs(lp)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
lp = os.path.expanduser('~')
|
||||
lp = os.path.expanduser(u'~')
|
||||
self.location.setText(lp)
|
||||
|
||||
def isComplete(self):
|
||||
@ -779,12 +783,10 @@ class LibraryPage(QWizardPage, LibraryUI):
|
||||
oldloc = prefs['library_path']
|
||||
newloc = unicode(self.location.text())
|
||||
try:
|
||||
newloce = newloc.encode(filesystem_encoding)
|
||||
if self.default_library_name is not None and \
|
||||
os.path.exists(self.default_library_name) and \
|
||||
not os.listdir(self.default_library_name) and \
|
||||
newloce != self.default_library_name:
|
||||
os.rmdir(self.default_library_name)
|
||||
dln = self.default_library_name
|
||||
if (dln and os.path.exists(dln) and not os.listdir(dln) and newloc
|
||||
!= dln):
|
||||
os.rmdir(dln)
|
||||
except:
|
||||
pass
|
||||
if not os.path.exists(newloc):
|
||||
|
Loading…
x
Reference in New Issue
Block a user