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 import sys, os, traceback
from cStringIO import StringIO from cStringIO import StringIO
import zipfile
from aqt.qt import * from aqt.qt import *
from aqt.utils import showInfo, openFolder, isWin, openLink, \ from aqt.utils import showInfo, openFolder, isWin, openLink, \
askUser, restoreGeom, saveGeom askUser, restoreGeom, saveGeom, showWarning
from zipfile import ZipFile from zipfile import ZipFile
import aqt.forms import aqt.forms
import aqt import aqt
from aqt.downloader import download 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 # 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 # 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) open(path, "wb").write(data)
return return
# .zip file # .zip file
try:
z = ZipFile(StringIO(data)) z = ZipFile(StringIO(data))
except zipfile.BadZipFile:
showWarning(_("The download was corrupt. Please try again."))
return
base = self.addonsFolder() base = self.addonsFolder()
for n in z.namelist(): for n in z.namelist():
if n.endswith("/"): if n.endswith("/"):