change profile folder on windows and linux

onedrive seems to frequently screw up the permissions on the documents
folder. since we're stuck with more difficult to find folders on
mac/win, we may as well migrate linux as well, to a more
standards-compliant path.
This commit is contained in:
Damien Elmes 2017-02-22 18:37:05 +10:00
parent 91978e5ab8
commit 4c9a45bd0d

View file

@ -100,17 +100,33 @@ a flash drive.""" % self.base)
# Folder migration # Folder migration
###################################################################### ######################################################################
def _oldFolderLocation(self):
if isMac:
return os.path.expanduser("~/Documents/Anki")
elif isWin:
loc = QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation)
return os.path.join(loc, "Anki")
else:
p = os.path.expanduser("~/Anki")
if os.path.exists(p):
return p
else:
loc = QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation)
if loc[:-1] == QDesktopServices.storageLocation(
QDesktopServices.HomeLocation):
# occasionally "documentsLocation" will return the home
# folder because the Documents folder isn't configured
# properly; fall back to an English path
return os.path.expanduser("~/Documents/Anki")
else:
return os.path.join(loc, "Anki")
def maybeMigrateFolder(self): def maybeMigrateFolder(self):
if not isMac: oldBase = self._oldFolderLocation()
return
oldBase = os.path.expanduser("~/Documents/Anki")
if not os.path.exists(self.base) and os.path.exists(oldBase): if not os.path.exists(self.base) and os.path.exists(oldBase):
shutil.move(oldBase, self.base) shutil.move(oldBase, self.base)
# remove the old symlink if it exists
if os.path.exists(oldBase) and os.path.islink(oldBase):
os.remove(oldBase)
# Profile load/save # Profile load/save
###################################################################### ######################################################################
@ -227,28 +243,15 @@ and no other programs are accessing your profile folders, then try again."""))
def _defaultBase(self): def _defaultBase(self):
if isWin: if isWin:
if False: #qtmajor >= 5: return os.path.join(os.environ["APPDATA"], "Anki2")
loc = QStandardPaths.writeableLocation(QStandardPaths.DocumentsLocation)
else:
loc = QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation)
return os.path.join(loc, "Anki")
elif isMac: elif isMac:
return os.path.expanduser("~/Library/Application Support/Anki2") return os.path.expanduser("~/Library/Application Support/Anki2")
else: else:
# use Documents/Anki on new installs, ~/Anki on existing ones dataDir = os.environ.get(
p = os.path.expanduser("~/Anki") "XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
if os.path.exists(p): if not os.path.exists(dataDir):
return p os.makedirs(dataDir)
else: return os.path.join(dataDir, "Anki2")
loc = QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation)
if loc[:-1] == QDesktopServices.storageLocation(
QDesktopServices.HomeLocation):
# occasionally "documentsLocation" will return the home
# folder because the Documents folder isn't configured
# properly; fall back to an English path
return os.path.expanduser("~/Documents/Anki")
else:
return os.path.join(loc, "Anki")
def _loadMeta(self): def _loadMeta(self):
path = os.path.join(self.base, "prefs.db") path = os.path.join(self.base, "prefs.db")