catch corrupt add-on downloads

This commit is contained in:
Damien Elmes 2015-01-05 11:47:05 +10:00
parent 360ef43460
commit 0262da2700

View File

@ -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("/"):