AO2XP/install_update.py

58 lines
2.0 KiB
Python
Raw Permalink Normal View History

2021-06-22 19:55:15 -04:00
import zipfile, tarfile, platform, os, time, shutil, thread
2021-06-22 18:56:22 -04:00
from Tkinter import Tk, HORIZONTAL
from ttk import Label, Progressbar
2021-06-21 22:57:55 -04:00
ext = {
"Windows": "zip",
"Darwin": "zip",
"Linux": "gz"
}
2021-06-22 19:55:15 -04:00
def extractzip(progressbar): # Windows and Mac
2021-06-21 22:57:55 -04:00
archive = zipfile.ZipFile("update.zip")
if platform.system() == "Darwin": shutil.rmtree("AO2XP.app", ignore_errors=True) # delete the old app package.
2021-06-22 19:55:15 -04:00
#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)
2021-06-21 22:57:55 -04:00
if os.path.exists("appbase"): # on a mac with the base folder moved out of .app Resources folder
2021-06-22 20:37:03 -04:00
os.system("mv appbase AO2XP.app/Contents/Resources/base") # put it back in place
2021-06-22 19:55:15 -04:00
def extractgz(progressbar): # Linux
2021-06-22 12:14:19 -04:00
archive = tarfile.open("update.gz")
2021-06-21 22:57:55 -04:00
archive.extractall()
if os.path.exists("update." + ext[platform.system()]):
window = Tk()
window.title("AO2XP updater")
window.wm_resizable(0,0)
2021-06-22 19:55:15 -04:00
window.geometry("256x64")
lb = Label(window)
lb.pack()
2021-06-22 19:55:15 -04:00
pb = Progressbar(window, orient=HORIZONTAL, length=100, mode="indeterminate")
pb.pack(fill="x")
pb.start()
2021-06-22 19:55:15 -04:00
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()
2021-06-21 22:57:55 -04:00
else:
print "This program will be automatically run by AO2XP to apply updates.\nYou do not need to run this yourself."
raw_input("Press enter to exit.\n")