From 697c6fd8e4d094be947c641a950b5de7db9a844e Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 2 Jul 2019 22:47:22 +0200 Subject: [PATCH] possible fix badZipFile on android --- platformcode/updater.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/platformcode/updater.py b/platformcode/updater.py index bb75740f..4e96e46e 100644 --- a/platformcode/updater.py +++ b/platformcode/updater.py @@ -157,10 +157,10 @@ def calcCurrHash(): break else: logger.info('Non sono riuscito a trovare il commit attuale, scarico lo zip') - updateFromZip() + hash = updateFromZip() # se ha scaricato lo zip si trova di sicuro all'ultimo commit localCommitFile = open(addonDir + trackingFile, 'w') - localCommitFile.write(lastCommitSha) + localCommitFile.write(hash if hash else lastCommitSha) localCommitFile.close() @@ -203,17 +203,20 @@ def updateFromZip(): remotefilename = 'https://github.com/' + user + "/" + repo + "/archive/" + branch + ".zip" localfilename = xbmc.translatePath("special://home/addons/") + "plugin.video.kod.update.zip" - logger.info("kodiondemand.core.updater remotefilename=%s" % remotefilename) - logger.info("kodiondemand.core.updater localfilename=%s" % localfilename) - logger.info("kodiondemand.core.updater descarga fichero...") + logger.info("remotefilename=%s" % remotefilename) + logger.info("localfilename=%s" % localfilename) import urllib urllib.urlretrieve(remotefilename, localfilename) # Lo descomprime - logger.info("kodiondemand.core.updater descomprime fichero...") + logger.info("decompressione...") destpathname = xbmc.translatePath("special://home/addons/") - logger.info("kodiondemand.core.updater destpathname=%s" % destpathname) + logger.info("destpathname=%s" % destpathname) + + # fix per android -> badZip file + hash = fixZipGetHash(localfilename) + unzipper = ziptools() unzipper.extract(localfilename, destpathname) @@ -228,6 +231,26 @@ def updateFromZip(): # os.remove(temp_dir) platformtools.dialog_notification('Kodi on Demand', 'Aggiornamento completato!') + return hash + + +# https://stackoverflow.com/questions/3083235/unzipping-file-results-in-badzipfile-file-is-not-a-zip-file +def fixZipGetHash(zipFile): + f = open(zipFile, 'r+b') + data = f.read() + pos = data.find('\x50\x4b\x05\x06') # End of central directory signature + hash = '' + if pos > 0: + f.seek(pos + 20) # +20: see secion V.I in 'ZIP format' link above. + hash = f.read()[2:] + f.seek(pos + 20) + f.truncate() + f.write( + '\x00\x00') # Zip file comment length: 0 byte length; tell zip applications to stop reading. + f.seek(0) + + return hash + class ziptools: def extract(self, file, dir, folder_to_extract="", overwrite_question=False, backup=False):