fix install_update.py tk thread shit
This commit is contained in:
parent
cd3def12b1
commit
4097451216
@ -1,4 +1,4 @@
|
||||
import zipfile, tarfile, platform, os, time, shutil
|
||||
import zipfile, tarfile, platform, os, time, shutil, thread
|
||||
from Tkinter import Tk, HORIZONTAL
|
||||
from ttk import Label, Progressbar
|
||||
|
||||
@ -8,16 +8,18 @@ ext = {
|
||||
"Linux": "gz"
|
||||
}
|
||||
|
||||
|
||||
def extractzip(): # Mac
|
||||
def extractzip(progressbar): # Windows and Mac
|
||||
archive = zipfile.ZipFile("update.zip")
|
||||
if platform.system() == "Darwin": shutil.rmtree("AO2XP.app", ignore_errors=True) # delete the old app package.
|
||||
archive.extractall() # extract the new version
|
||||
#archive.extractall() # extract the new version
|
||||
for i in range(len(archive.filelist)):
|
||||
archive.extract(archive.filelist[i])
|
||||
progressbar["value"] = 100. * i / len(archive.filelist)
|
||||
|
||||
if os.path.exists("appbase"): # on a mac with the base folder moved out of .app Resources folder
|
||||
os.system("mv appbase AO2XP.app/Contents/Resources/") # put it back in place
|
||||
|
||||
def extractgz(): # Linux
|
||||
def extractgz(progressbar): # Linux
|
||||
archive = tarfile.open("update.tar.gz")
|
||||
archive.extractall()
|
||||
|
||||
@ -26,20 +28,29 @@ if os.path.exists("update." + ext[platform.system()]):
|
||||
window = Tk()
|
||||
window.title("AO2XP updater")
|
||||
window.wm_resizable(0,0)
|
||||
window.geometry("256x56")
|
||||
window.geometry("256x64")
|
||||
lb = Label(window)
|
||||
lb.pack()
|
||||
pb = Progressbar(orient=HORIZONTAL, mode="indeterminate")
|
||||
pb.pack()
|
||||
pb = Progressbar(window, orient=HORIZONTAL, length=100, mode="indeterminate")
|
||||
pb.pack(fill="x")
|
||||
pb.start()
|
||||
|
||||
lb["text"] = "Waiting 3 seconds for AO2XP to close..."
|
||||
time.sleep(3)
|
||||
lb["text"] = "Extracting update." + ext[platform.system()] + "..."
|
||||
globals()["extract" + ext[platform.system()]]() # call the extract function according to OS
|
||||
lb["text"] = "Done!\nYou can now start AO2XP."
|
||||
os.remove("update." + ext[platform.system()])
|
||||
time.sleep(4)
|
||||
def extractThread():
|
||||
time.sleep(0.1)
|
||||
lb["text"] = "Waiting 3 seconds for AO2XP to close..."
|
||||
time.sleep(3)
|
||||
pb.stop()
|
||||
pb["value"] = 0
|
||||
pb["mode"] = "determinate"
|
||||
lb["text"] = "Extracting update." + ext[platform.system()] + "..."
|
||||
globals()["extract" + ext[platform.system()]](pb) # call the extract function according to OS
|
||||
lb["text"] = "Done!\nYou can now start AO2XP."
|
||||
os.remove("update." + ext[platform.system()])
|
||||
time.sleep(4)
|
||||
window.destroy()
|
||||
|
||||
thread.start_new_thread(extractThread, ())
|
||||
window.mainloop()
|
||||
|
||||
else:
|
||||
print "This program will be automatically run by AO2XP to apply updates.\nYou do not need to run this yourself."
|
||||
|
Loading…
Reference in New Issue
Block a user