From 8489f84937622eb449b15ffdeb93b3d437220f1b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 27 Sep 2018 11:35:21 +1000 Subject: [PATCH] catch .anki(2) imports --- aqt/importing.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/aqt/importing.py b/aqt/importing.py index 745bead41..a207f8ec6 100644 --- a/aqt/importing.py +++ b/aqt/importing.py @@ -12,8 +12,8 @@ import shutil from aqt.qt import * import anki.importing as importing -from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp,\ - askUser, tooltip +from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp, \ + askUser, tooltip, showInfo from anki.hooks import addHook, remHook import aqt.forms import aqt.modelchooser @@ -274,6 +274,16 @@ def onImport(mw): if not file: return 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) def importFile(mw, file): @@ -303,12 +313,7 @@ def importFile(mw, file): except Exception as e: msg = repr(str(e)) 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: msg = _("Import failed. Debugging info:\n") msg += str(traceback.format_exc())