2021-06-21 22:57:55 -04:00
|
|
|
import zipfile, tarfile, platform, os, time, shutil
|
2021-06-22 16:36:08 -04:00
|
|
|
from tkinter import Tk, HORIZONTAL
|
|
|
|
from tkinter.ttk import Progressbar, Label
|
2021-06-21 22:57:55 -04:00
|
|
|
|
|
|
|
ext = {
|
|
|
|
"Windows": "zip",
|
|
|
|
"Darwin": "zip",
|
|
|
|
"Linux": "gz"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def extractzip(): # 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
|
|
|
|
|
2021-06-22 16:36:08 -04:00
|
|
|
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
|
|
|
|
|
2021-06-21 22:57:55 -04:00
|
|
|
def extractgz(): # Linux
|
|
|
|
archive = tarfile.open("update.tar.gz")
|
|
|
|
archive.extractall()
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists("update." + ext[platform.system()]):
|
2021-06-22 16:36:08 -04:00
|
|
|
window = Tk()
|
|
|
|
window.title("AO2XP updater")
|
|
|
|
window.wm_resizable(0,0)
|
|
|
|
window.geometry("256x56")
|
|
|
|
lb = Label(window)
|
|
|
|
lb.pack()
|
|
|
|
pb = Progressbar(orient=HORIZONTAL, mode="indeterminate")
|
|
|
|
pb.pack()
|
|
|
|
pb.start()
|
|
|
|
|
|
|
|
lb["text"] = "Waiting 3 seconds for AO2XP to close..."
|
2021-06-21 22:57:55 -04:00
|
|
|
time.sleep(3)
|
2021-06-22 16:36:08 -04:00
|
|
|
lb["text"] = "Extracting update." + ext[platform.system()] + "..."
|
2021-06-21 22:57:55 -04:00
|
|
|
globals()["extract" + ext[platform.system()]]() # call the extract function according to OS
|
2021-06-22 16:36:08 -04:00
|
|
|
lb["text"] = "Done!\nYou can now start AO2XP."
|
2021-06-21 22:57:55 -04:00
|
|
|
os.remove("update." + ext[platform.system()])
|
2021-06-22 16:36:08 -04:00
|
|
|
time.sleep(4)
|
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")
|