initial zip check should display same zip error message

This commit is contained in:
Damien Elmes 2014-06-29 05:55:01 +09:00
parent ec5d4b2203
commit 0abcc7412f

View File

@ -317,7 +317,7 @@ backup, please see the 'Backups' section of the user manual."""))
try: try:
z.getinfo("collection.anki2") z.getinfo("collection.anki2")
except: except:
showWarning(_("The provided file is not a valid .apkg file.")) showWarning(invalidZipMsg())
return return
# we need to ask whether to import/replace # we need to ask whether to import/replace
if not setupApkgImport(mw, importer): if not setupApkgImport(mw, importer):
@ -326,12 +326,7 @@ backup, please see the 'Backups' section of the user manual."""))
try: try:
importer.run() importer.run()
except zipfile.BadZipfile: except zipfile.BadZipfile:
msg = _("""\ showWarning(invalidZipMsg())
This file does not appear to be a valid .apkg file. If you're getting this \
error from a file downloaded from AnkiWeb, chances are that your download \
failed. Please try again, and if the problem persists, please try again \
with a different browser.""")
showWarning(msg)
except Exception, e: except Exception, e:
err = repr(str(e)) err = repr(str(e))
if "invalidFile" in err: if "invalidFile" in err:
@ -357,6 +352,13 @@ Unable to import from a read-only file."""))
mw.progress.finish() mw.progress.finish()
mw.reset() mw.reset()
def invalidZipMsg():
return _("""\
This file does not appear to be a valid .apkg file. If you're getting this \
error from a file downloaded from AnkiWeb, chances are that your download \
failed. Please try again, and if the problem persists, please try again \
with a different browser.""")
def setupApkgImport(mw, importer): def setupApkgImport(mw, importer):
base = os.path.basename(importer.file).lower() base = os.path.basename(importer.file).lower()
full = (base == "collection.apkg") or re.match("backup-.*\\.apkg", base) full = (base == "collection.apkg") or re.match("backup-.*\\.apkg", base)