mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
catch corrupt add-on downloads
This commit is contained in:
parent
360ef43460
commit
0262da2700
1 changed files with 8 additions and 2 deletions
|
@ -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
|
||||||
z = ZipFile(StringIO(data))
|
try:
|
||||||
|
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("/"):
|
||||||
|
|
Loading…
Reference in a new issue