Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import requests
- from threading import Thread
- from tkinter import messagebox as mb
- import time
- import sys
- import os
- import errno
- root = tk.Tk()
- root.title("TechOS Update")
- root.attributes("-fullscreen", True)
- root.config(bg="#00afff", cursor="none")
- step = tk.StringVar()
- step.set("Starting Update...")
- percentage = tk.StringVar()
- percentage.set("0%")
- updating = tk.Label(root, bg="#00afff", text="\n\n\n\n\nUpdating...", fg="white", font="TkDefaultFont 50")
- updating.pack(side="top", anchor="center", pady=20)
- steplabel = tk.Label(root, bg="#00afff", textvariable=step, fg="white", font="TkDefaultFont 30")
- steplabel.pack(side="top", anchor="center", pady=20)
- percentlabel = tk.Label(root, bg="#00afff", textvariable=percentage, fg="white", font="TkDefaultFont 40")
- percentlabel.pack(side="top", anchor="center", pady=20)
- def mkdir_p(path):
- global os
- global errno
- try:
- os.makedirs(path)
- except OSError as exc:
- if exc.errno == errno.EEXIST and os.path.isdir(path):
- pass
- else: raise
- def sow(path):
- global mkdir_p
- mkdir_p(os.path.dirname(path))
- return open(path, 'w')
- def sowb(path):
- global mkdir_p
- mkdir_p(os.path.dirname(path))
- return open(path, 'wb')
- def processcmd(cmd):
- params = cmd.split("|")
- if params[0] == "update" or params[0] == "updatefile":
- try:
- rawcode = requests.get(params[2]).text
- programfile = sowb(params[1])
- programfile.write(bytes(rawcode, "UTF-8"))
- programfile.close()
- except:
- updating.config(text="\n\n\n\n\nUpdate failed")
- step.set("The update seems to have invalid format.\nPlease contact Techpad for help.")
- percentage.set("Closing in 5...")
- time.sleep(1)
- percentage.set("Closing in 4...")
- time.sleep(1)
- percentage.set("Closing in 3...")
- time.sleep(1)
- percentage.set("Closing in 2...")
- time.sleep(1)
- percentage.set("Closing in 1...")
- time.sleep(1)
- root.destroy()
- sys.exit()
- else:
- updating.config(text="\n\n\n\n\nUpdate failed")
- step.set("The TechOS updater might be out of date.\nPlease contact Techpad for help.")
- percentage.set("Closing in 5...")
- time.sleep(1)
- percentage.set("Closing in 4...")
- time.sleep(1)
- percentage.set("Closing in 3...")
- time.sleep(1)
- percentage.set("Closing in 2...")
- time.sleep(1)
- percentage.set("Closing in 1...")
- time.sleep(1)
- root.destroy()
- sys.exit()
- def startupdate():
- try:
- step.set("Checking latest update...")
- cupfile = open("T:/TechOS/Virtual/Info/Version.info", "r")
- currentupdate = int(cupfile.read())
- cupfile.close()
- latestupdate = int(requests.get("https://pastebin.com/raw/BLuxc2Lm").text)
- if currentupdate < latestupdate:
- percentage.set("1%")
- step.set("Getting update information...")
- nextupdate = currentupdate + 1
- updateids = requests.get("https://pastebin.com/raw/M0r6cGSZ").text.replace("\r\n", "\n").split("\n")
- thisupdate = [i for i in updateids if i.startswith(str(nextupdate) + "|")][0]
- thisupdateid = thisupdate.split("|")[1]
- updateinfo = requests.get("https://pastebin.com/raw/" + thisupdateid).text
- updatecmds = updateinfo.replace("\r\n", "\n").split("\n")
- percentage.set("2%")
- step.set("Installing update...")
- percentint = 2
- percentageincrease = 98 / len(updatecmds)
- for cmd in updatecmds:
- processcmd(cmd)
- percentint += percentageincrease
- percentage.set(str(round(percentint)) + "%")
- percentage.set("100%")
- step.set("Finishing update...")
- cupfile = open("T:/TechOS/Virtual/Info/Version.info", "w")
- cupfile.write(str(nextupdate))
- cupfile.close()
- time.sleep(10)
- updating.config(text="\n\n\n\n\nUpdate complete")
- step.set("You may need to run the updater again if you are behind on updates.")
- percentage.set("Closing in 5...")
- time.sleep(1)
- percentage.set("Closing in 4...")
- time.sleep(1)
- percentage.set("Closing in 3...")
- time.sleep(1)
- percentage.set("Closing in 2...")
- time.sleep(1)
- percentage.set("Closing in 1...")
- time.sleep(1)
- root.destroy()
- sys.exit()
- elif currentupdate == latestupdate:
- mb.showinfo("Software up to date", "Your version of TechOS is already up to date.")
- root.destroy()
- sys.exit()
- else:
- print(currentupdate)
- print(latestupdate)
- except:
- updating.config(text="\n\n\n\n\nUpdate failed")
- step.set("The TechOS update failed for an unknown reason.\nPlease contact Techpad for help.")
- percentage.set("Closing in 5...")
- time.sleep(1)
- percentage.set("Closing in 4...")
- time.sleep(1)
- percentage.set("Closing in 3...")
- time.sleep(1)
- percentage.set("Closing in 2...")
- time.sleep(1)
- percentage.set("Closing in 1...")
- time.sleep(1)
- root.destroy()
- sys.exit()
- Thread(target=startupdate, daemon=True).start()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement