diff --git a/aqt/profiles.py b/aqt/profiles.py index d72b0fb98..236287791 100644 --- a/aqt/profiles.py +++ b/aqt/profiles.py @@ -100,17 +100,33 @@ a flash drive.""" % self.base) # 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): - if not isMac: - return - oldBase = os.path.expanduser("~/Documents/Anki") + oldBase = self._oldFolderLocation() + if not os.path.exists(self.base) and os.path.exists(oldBase): 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 ###################################################################### @@ -227,28 +243,15 @@ and no other programs are accessing your profile folders, then try again.""")) def _defaultBase(self): if isWin: - if False: #qtmajor >= 5: - loc = QStandardPaths.writeableLocation(QStandardPaths.DocumentsLocation) - else: - loc = QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation) - return os.path.join(loc, "Anki") + return os.path.join(os.environ["APPDATA"], "Anki2") elif isMac: return os.path.expanduser("~/Library/Application Support/Anki2") else: - # use Documents/Anki on new installs, ~/Anki on existing ones - 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") + dataDir = os.environ.get( + "XDG_DATA_HOME", os.path.expanduser("~/.local/share")) + if not os.path.exists(dataDir): + os.makedirs(dataDir) + return os.path.join(dataDir, "Anki2") def _loadMeta(self): path = os.path.join(self.base, "prefs.db")