From 0262da270082e69fd933b4f3b3102c9a03fcb014 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 5 Jan 2015 11:47:05 +1000 Subject: [PATCH] catch corrupt add-on downloads --- aqt/addons.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aqt/addons.py b/aqt/addons.py index b3a8d6161..45f1bcd7d 100644 --- a/aqt/addons.py +++ b/aqt/addons.py @@ -4,13 +4,15 @@ import sys, os, traceback from cStringIO import StringIO +import zipfile from aqt.qt import * from aqt.utils import showInfo, openFolder, isWin, openLink, \ - askUser, restoreGeom, saveGeom + askUser, restoreGeom, saveGeom, showWarning from zipfile import ZipFile import aqt.forms import aqt from aqt.downloader import download +from anki.lang import _ # in the future, it would be nice to save the addon id and unzippped file list # to the config so that we can clear up all files and check for updates @@ -122,7 +124,11 @@ class AddonManager(object): open(path, "wb").write(data) return # .zip file - z = ZipFile(StringIO(data)) + try: + z = ZipFile(StringIO(data)) + except zipfile.BadZipFile: + showWarning(_("The download was corrupt. Please try again.")) + return base = self.addonsFolder() for n in z.namelist(): if n.endswith("/"):