catch .anki(2) imports

This commit is contained in:
Damien Elmes 2018-09-27 11:35:21 +10:00
parent f3a6472c5c
commit 8489f84937

View file

@ -13,7 +13,7 @@ import shutil
from aqt.qt import * from aqt.qt import *
import anki.importing as importing import anki.importing as importing
from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp, \ from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp, \
askUser, tooltip askUser, tooltip, showInfo
from anki.hooks import addHook, remHook from anki.hooks import addHook, remHook
import aqt.forms import aqt.forms
import aqt.modelchooser import aqt.modelchooser
@ -274,6 +274,16 @@ def onImport(mw):
if not file: if not file:
return return
file = str(file) file = str(file)
head, ext = os.path.splitext(file)
ext = ext.lower()
if ext == ".anki":
showInfo(_(".anki files are from a very old version of Anki. You can import them with Anki 2.0, available on the Anki website."))
return
elif ext == ".anki2":
showInfo(_(".anki2 files are not directly importable - please import the .apkg or .zip file you have received instead."))
return
importFile(mw, file) importFile(mw, file)
def importFile(mw, file): def importFile(mw, file):
@ -303,11 +313,6 @@ def importFile(mw, file):
except Exception as e: except Exception as e:
msg = repr(str(e)) msg = repr(str(e))
if msg == "'unknownFormat'": if msg == "'unknownFormat'":
if file.endswith(".anki2"):
showWarning(_("""\
.anki2 files are not designed for importing. If you're trying to restore from a \
backup, please see the 'Backups' section of the user manual."""))
else:
showWarning(_("Unknown file format.")) showWarning(_("Unknown file format."))
else: else:
msg = _("Import failed. Debugging info:\n") msg = _("Import failed. Debugging info:\n")