continue vanilla DL where it left off if cancelled
This commit is contained in:
parent
1edee085a1
commit
df8618f3d0
@ -1,5 +1,5 @@
|
|||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
import json, urllib, sys, requests, time, os, zipfile
|
import json, urllib, sys, requests, time, os, zipfile, sha
|
||||||
|
|
||||||
returncode = 4
|
returncode = 4
|
||||||
msgbox = ["", "", ""]
|
msgbox = ["", "", ""]
|
||||||
@ -18,7 +18,7 @@ def downloadVanilla():
|
|||||||
def setLabelText(msg):
|
def setLabelText(msg):
|
||||||
circus.setLabelText(msg)
|
circus.setLabelText(msg)
|
||||||
def showMessageBox(icon, title, msg):
|
def showMessageBox(icon, title, msg):
|
||||||
getattr(QtGui.QMessageBox, icon)(None, title, msg)
|
getattr(QtGui.QMessageBox, str(icon))(None, title, msg)
|
||||||
|
|
||||||
thr = downloadThread(circus)
|
thr = downloadThread(circus)
|
||||||
thr.progressValue.connect(setProgressValue)
|
thr.progressValue.connect(setProgressValue)
|
||||||
@ -53,33 +53,50 @@ class downloadThread(QtCore.QThread):
|
|||||||
manifest = json.load(urllib.urlopen("http://s3.wasabisys.com/ao-manifests/assets.json"))
|
manifest = json.load(urllib.urlopen("http://s3.wasabisys.com/ao-manifests/assets.json"))
|
||||||
except:
|
except:
|
||||||
self.showMessageBox.emit("critical", "Download failed", "Could not check for latest AO vanilla version.\nPlease check your internet connection.")
|
self.showMessageBox.emit("critical", "Download failed", "Could not check for latest AO vanilla version.\nPlease check your internet connection.")
|
||||||
|
self.finished.emit()
|
||||||
return
|
return
|
||||||
|
|
||||||
latest_version = manifest["versions"][0]["version"]
|
latest_version = manifest["versions"][0]["version"]
|
||||||
print latest_version
|
print latest_version
|
||||||
link = ""
|
link = ""
|
||||||
|
check_hash = ""
|
||||||
for actions in manifest["versions"][0]["full"]:
|
for actions in manifest["versions"][0]["full"]:
|
||||||
if actions["action"] == "dl":
|
if actions["action"] == "dl":
|
||||||
link = actions["url"]
|
link = actions["url"]
|
||||||
|
check_hash = actions["hash"]
|
||||||
print link
|
print link
|
||||||
break
|
break
|
||||||
|
|
||||||
#link = "http://somepeople.ddns.net/headbot/song.zip"
|
#link = "http://somepeople.ddns.net/headbot/song.zip"
|
||||||
self.labelText.emit("Downloading version '%s'..." % latest_version)
|
|
||||||
start = time.clock()
|
|
||||||
zip = requests.get(link, stream=True)
|
|
||||||
length = int(zip.headers.get("content-length"))
|
|
||||||
dl = 0
|
|
||||||
speed = 0.0
|
|
||||||
|
|
||||||
|
resume_bytes = 0
|
||||||
filename = os.path.basename(link)
|
filename = os.path.basename(link)
|
||||||
|
download_it = True
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
downloadfile = open(filename, "wb")
|
downloadfile = open(filename, "wb")
|
||||||
|
else:
|
||||||
|
existing_data = open(filename, "rb").read()
|
||||||
|
sha1 = sha.new(existing_data).hexdigest()
|
||||||
|
downloadfile = open(filename, "ab")
|
||||||
|
resume_bytes = len(existing_data)
|
||||||
|
print resume_bytes
|
||||||
|
del existing_data
|
||||||
|
|
||||||
|
if sha1 == check_hash: # don't download, the local file already exists
|
||||||
|
download_it = False
|
||||||
|
downloadfile.close()
|
||||||
|
|
||||||
|
if download_it:
|
||||||
|
self.labelText.emit("Downloading version '%s'..." % latest_version)
|
||||||
|
dl = 0
|
||||||
|
speed = 0.0
|
||||||
|
start = time.clock()
|
||||||
|
zip = requests.get(link, stream=True, headers={"Range": "bytes=%d-" % resume_bytes})
|
||||||
|
length = int(zip.headers.get("content-length"))
|
||||||
|
|
||||||
for noby in zip.iter_content(chunk_size=4096):
|
for noby in zip.iter_content(chunk_size=4096):
|
||||||
if not self.jm.isVisible():
|
if not self.jm.isVisible():
|
||||||
downloadfile.close()
|
downloadfile.close()
|
||||||
os.remove(filename)
|
|
||||||
returncode = 4
|
returncode = 4
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -112,6 +129,7 @@ class downloadThread(QtCore.QThread):
|
|||||||
zip.extract(f)
|
zip.extract(f)
|
||||||
self.progressValue.emit(100 * i / len(notheme_list))
|
self.progressValue.emit(100 * i / len(notheme_list))
|
||||||
zip.close()
|
zip.close()
|
||||||
|
os.remove(filename)
|
||||||
|
|
||||||
returncode = 0
|
returncode = 0
|
||||||
self.finished.emit()
|
self.finished.emit()
|
Loading…
Reference in New Issue
Block a user