mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 14:17:13 -05:00
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:
parent
0f04744f7e
commit
57c8e43327
1 changed files with 28 additions and 23 deletions
|
|
@ -98,18 +98,33 @@ a flash drive.""" % self.base)
|
||||||
# Folder migration
|
# Folder migration
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
def _oldFolderLocation(self):
|
||||||
|
if isMac:
|
||||||
|
return os.path.expanduser("~/Documents/Anki")
|
||||||
|
elif isWin:
|
||||||
|
loc = QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
|
||||||
|
return os.path.join(loc, "Anki")
|
||||||
|
else:
|
||||||
|
p = os.path.expanduser("~/Anki")
|
||||||
|
if os.path.exists(p):
|
||||||
|
return p
|
||||||
|
else:
|
||||||
|
loc = QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
|
||||||
|
if loc[:-1] == QStandardPaths.writableLocation(
|
||||||
|
QStandardPaths.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
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
@ -233,25 +248,15 @@ and no other programs are accessing your profile folders, then try again."""))
|
||||||
|
|
||||||
def _defaultBase(self):
|
def _defaultBase(self):
|
||||||
if isWin:
|
if isWin:
|
||||||
loc = QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
|
return os.path.join(os.environ["APPDATA"], "Anki2")
|
||||||
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 = QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
|
|
||||||
if loc[:-1] == QStandardPaths.writableLocation(
|
|
||||||
QStandardPaths.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, "prefs21.db")
|
path = os.path.join(self.base, "prefs21.db")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue