Techpad

Update 13

May 6th, 2021 (edited)
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.12 KB | None | 0 0
  1. import tkinter as tk
  2. import requests
  3. from threading import Thread
  4. from tkinter import messagebox as mb
  5. import time
  6. import sys
  7. import os
  8. import errno
  9. import base64
  10.  
  11. root = tk.Tk()
  12. root.title("TechOS Update")
  13. root.attributes("-fullscreen", True)
  14. root.config(bg="#00afff", cursor="none")
  15.  
  16. step = tk.StringVar()
  17. step.set("Starting Update...")
  18.  
  19. percentage = tk.StringVar()
  20. percentage.set("0%")
  21.  
  22. updating = tk.Label(root, bg="#00afff", text="\n\n\n\n\nUpdating...", fg="white", font="TkDefaultFont 50")
  23. updating.pack(side="top", anchor="center", pady=20)
  24.  
  25. steplabel = tk.Label(root, bg="#00afff", textvariable=step, fg="white", font="TkDefaultFont 30")
  26. steplabel.pack(side="top", anchor="center", pady=20)
  27.  
  28. percentlabel = tk.Label(root, bg="#00afff", textvariable=percentage, fg="white", font="TkDefaultFont 40")
  29. percentlabel.pack(side="top", anchor="center", pady=20)
  30.  
  31. def mkdir_p(path):
  32. global os
  33. global errno
  34. try:
  35. os.makedirs(path)
  36. except OSError as exc:
  37. if exc.errno == errno.EEXIST and os.path.isdir(path):
  38. pass
  39. else: raise
  40.  
  41. def sow(path):
  42. global mkdir_p
  43. mkdir_p(os.path.dirname(path))
  44. return open(path, 'w')
  45.  
  46. def sowb(path):
  47. global mkdir_p
  48. mkdir_p(os.path.dirname(path))
  49. return open(path, 'wb')
  50.  
  51. def processcmd(cmd):
  52. params = cmd.split("|")
  53. if params[0] == "update" or params[0] == "updatefile":
  54. try:
  55. rawcode = requests.get(params[2]).text
  56. programfile = sowb(params[1])
  57. programfile.write(bytes(rawcode, "UTF-8"))
  58. programfile.close()
  59. except:
  60. updating.config(text="\n\n\n\n\nUpdate failed")
  61. step.set("The update seems to have invalid format.\nPlease contact Techpad for help.")
  62. percentage.set("Closing in 5...")
  63. time.sleep(1)
  64. percentage.set("Closing in 4...")
  65. time.sleep(1)
  66. percentage.set("Closing in 3...")
  67. time.sleep(1)
  68. percentage.set("Closing in 2...")
  69. time.sleep(1)
  70. percentage.set("Closing in 1...")
  71. time.sleep(1)
  72. root.destroy()
  73. sys.exit()
  74. elif params[0] == "mkdir":
  75. try:
  76. mkdir_p(params[1])
  77. except:
  78. updating.config(text="\n\n\n\n\nUpdate failed")
  79. step.set("The update seems to have invalid format.\nPlease contact Techpad for help.")
  80. percentage.set("Closing in 5...")
  81. time.sleep(1)
  82. percentage.set("Closing in 4...")
  83. time.sleep(1)
  84. percentage.set("Closing in 3...")
  85. time.sleep(1)
  86. percentage.set("Closing in 2...")
  87. time.sleep(1)
  88. percentage.set("Closing in 1...")
  89. time.sleep(1)
  90. root.destroy()
  91. sys.exit()
  92. elif params[0] == "mkfile":
  93. try:
  94. rawtext = requests.get(params[2]).text
  95. file = sowb(params[1])
  96. file.write(bytes(rawtext, "UTF-8"))
  97. file.close()
  98. except:
  99. updating.config(text="\n\n\n\n\nUpdate failed")
  100. step.set("The update seems to have invalid format.\nPlease contact Techpad for help.")
  101. percentage.set("Closing in 5...")
  102. time.sleep(1)
  103. percentage.set("Closing in 4...")
  104. time.sleep(1)
  105. percentage.set("Closing in 3...")
  106. time.sleep(1)
  107. percentage.set("Closing in 2...")
  108. time.sleep(1)
  109. percentage.set("Closing in 1...")
  110. time.sleep(1)
  111. root.destroy()
  112. sys.exit()
  113. elif params[0] == "mkbin":
  114. try:
  115. rawbin = requests.get(params[2]).text
  116. binfile = sowb(params[1])
  117. binfile.write(base64.decodebytes(rawbin.encode('ascii')))
  118. binfile.close()
  119. except:
  120. updating.config(text="\n\n\n\n\nUpdate failed")
  121. step.set("The update seems to have invalid format.\nPlease contact Techpad for help.")
  122. percentage.set("Closing in 5...")
  123. time.sleep(1)
  124. percentage.set("Closing in 4...")
  125. time.sleep(1)
  126. percentage.set("Closing in 3...")
  127. time.sleep(1)
  128. percentage.set("Closing in 2...")
  129. time.sleep(1)
  130. percentage.set("Closing in 1...")
  131. time.sleep(1)
  132. root.destroy()
  133. sys.exit()
  134. elif params[0] == "rm":
  135. try:
  136. os.remove(params[1])
  137. except:
  138. pass
  139. elif params[0] == "rmdir":
  140. try:
  141. os.rmdir(params[1])
  142. except:
  143. pass
  144. else:
  145. updating.config(text="\n\n\n\n\nUpdate failed")
  146. step.set("The TechOS updater might be out of date.\nPlease contact Techpad for help.")
  147. percentage.set("Closing in 5...")
  148. time.sleep(1)
  149. percentage.set("Closing in 4...")
  150. time.sleep(1)
  151. percentage.set("Closing in 3...")
  152. time.sleep(1)
  153. percentage.set("Closing in 2...")
  154. time.sleep(1)
  155. percentage.set("Closing in 1...")
  156. time.sleep(1)
  157. root.destroy()
  158. sys.exit()
  159.  
  160. def startupdate():
  161. try:
  162. step.set("Checking latest update...")
  163.  
  164. cupfile = open("T:/TechOS/Virtual/Info/Version.info", "r")
  165. currentupdate = int(cupfile.read())
  166. cupfile.close()
  167. latestupdate = int(requests.get("https://ghostbin.co/paste/sra8/raw").text)
  168.  
  169. if currentupdate < latestupdate:
  170. percentage.set("1%")
  171. step.set("Getting update information...")
  172.  
  173. nextupdate = currentupdate + 1
  174. updateids = requests.get("https://ghostbin.co/paste/c4na2/raw").text.replace("\r\n", "\n").split("\n")
  175. thisupdate = [i for i in updateids if i.startswith(str(nextupdate) + "|")][0]
  176. thisupdateid = thisupdate.split("|")[1]
  177. updateinfo = requests.get("https://ghostbin.co/paste/" + thisupdateid + "/raw").text
  178. updatecmds = updateinfo.replace("\r\n", "\n").split("\n")
  179.  
  180. percentage.set("2%")
  181. step.set("Installing update...")
  182.  
  183. percentint = 2
  184. percentageincrease = 98 / len(updatecmds)
  185.  
  186. for cmd in updatecmds:
  187. processcmd(cmd)
  188. percentint += percentageincrease
  189. percentage.set(str(round(percentint)) + "%")
  190.  
  191. percentage.set("100%")
  192. step.set("Finishing update...")
  193.  
  194. cupfile = open("T:/TechOS/Virtual/Info/Version.info", "w")
  195. cupfile.write(str(nextupdate))
  196. cupfile.close()
  197.  
  198. time.sleep(2.5)
  199.  
  200. updating.config(text="\n\n\n\n\nUpdate complete")
  201. step.set("You may need to run the updater again if you are behind on updates.")
  202. percentage.set("Closing in 5...")
  203. time.sleep(1)
  204. percentage.set("Closing in 4...")
  205. time.sleep(1)
  206. percentage.set("Closing in 3...")
  207. time.sleep(1)
  208. percentage.set("Closing in 2...")
  209. time.sleep(1)
  210. percentage.set("Closing in 1...")
  211. time.sleep(1)
  212. root.destroy()
  213. sys.exit()
  214. elif currentupdate == latestupdate:
  215. mb.showinfo("Software up to date", "Your version of TechOS is already up to date.")
  216. root.destroy()
  217. sys.exit()
  218. else:
  219. print(currentupdate)
  220. print(latestupdate)
  221. except:
  222. updating.config(text="\n\n\n\n\nUpdate failed")
  223. step.set("The TechOS update failed for an unknown reason.\nPlease contact Techpad for help.")
  224. percentage.set("Closing in 5...")
  225. time.sleep(1)
  226. percentage.set("Closing in 4...")
  227. time.sleep(1)
  228. percentage.set("Closing in 3...")
  229. time.sleep(1)
  230. percentage.set("Closing in 2...")
  231. time.sleep(1)
  232. percentage.set("Closing in 1...")
  233. time.sleep(1)
  234. root.destroy()
  235. sys.exit()
  236.  
  237. Thread(target=startupdate, daemon=True).start()
  238.  
  239. root.mainloop()
Add Comment
Please, Sign In to add comment