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 import __appname__, patheq
|
||||||
from calibre.library.database2 import LibraryDatabase2
|
from calibre.library.database2 import LibraryDatabase2
|
||||||
from calibre.library.move import MoveLibrary
|
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.send_email import smtp_prefs
|
||||||
from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI
|
from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI
|
||||||
from calibre.gui2.wizard.library_ui import Ui_WizardPage as LibraryUI
|
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.gui2.dialogs.progress import ProgressDialog
|
||||||
from calibre.customize.ui import device_plugins
|
from calibre.customize.ui import device_plugins
|
||||||
|
|
||||||
|
if iswindows:
|
||||||
|
winutil = plugins['winutil'][0]
|
||||||
|
|
||||||
# Devices {{{
|
# Devices {{{
|
||||||
|
|
||||||
class Device(object):
|
class Device(object):
|
||||||
@ -751,19 +754,20 @@ class LibraryPage(QWizardPage, LibraryUI):
|
|||||||
self.default_library_name = None
|
self.default_library_name = None
|
||||||
if not lp:
|
if not lp:
|
||||||
fname = _('Calibre Library')
|
fname = _('Calibre Library')
|
||||||
if isinstance(fname, unicode):
|
base = os.path.expanduser(u'~')
|
||||||
try:
|
if iswindows:
|
||||||
fname = fname.encode(filesystem_encoding)
|
x = winutil.special_folder_path(winutil.CSIDL_PERSONAL)
|
||||||
except:
|
if x and os.access(x, os.W_OK):
|
||||||
fname = 'Calibre Library'
|
base = x
|
||||||
lp = os.path.expanduser('~'+os.sep+fname)
|
|
||||||
|
lp = os.path.join(base, fname)
|
||||||
self.default_library_name = lp
|
self.default_library_name = lp
|
||||||
if not os.path.exists(lp):
|
if not os.path.exists(lp):
|
||||||
try:
|
try:
|
||||||
os.makedirs(lp)
|
os.makedirs(lp)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
lp = os.path.expanduser('~')
|
lp = os.path.expanduser(u'~')
|
||||||
self.location.setText(lp)
|
self.location.setText(lp)
|
||||||
|
|
||||||
def isComplete(self):
|
def isComplete(self):
|
||||||
@ -779,12 +783,10 @@ class LibraryPage(QWizardPage, LibraryUI):
|
|||||||
oldloc = prefs['library_path']
|
oldloc = prefs['library_path']
|
||||||
newloc = unicode(self.location.text())
|
newloc = unicode(self.location.text())
|
||||||
try:
|
try:
|
||||||
newloce = newloc.encode(filesystem_encoding)
|
dln = self.default_library_name
|
||||||
if self.default_library_name is not None and \
|
if (dln and os.path.exists(dln) and not os.listdir(dln) and newloc
|
||||||
os.path.exists(self.default_library_name) and \
|
!= dln):
|
||||||
not os.listdir(self.default_library_name) and \
|
os.rmdir(dln)
|
||||||
newloce != self.default_library_name:
|
|
||||||
os.rmdir(self.default_library_name)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if not os.path.exists(newloc):
|
if not os.path.exists(newloc):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user