Techpad

TechStore 4

Mar 16th, 2021
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
E 10.76 KB | None | 0 0
  1. import tkinter as tk
  2. import requests
  3. import os
  4. import ast
  5. import errno
  6. from tkinter import messagebox as mb
  7. try:
  8.     import shutil
  9. except ModuleNotFoundError:
  10.     os.system("pip install shutil")
  11.     import shutil
  12.  
  13. __root = frame1
  14.  
  15. def mkdir_p(path):
  16.     global os
  17.     global errno
  18.     try:
  19.         os.makedirs(path)
  20.     except OSError as exc:
  21.         if exc.errno == errno.EEXIST and os.path.isdir(path):
  22.             pass
  23.         else: raise
  24.  
  25. def sow(path):
  26.     global mkdir_p
  27.     mkdir_p(os.path.dirname(path))
  28.     return open(path, 'w')
  29.  
  30. def sowb(path):
  31.     global mkdir_p
  32.     mkdir_p(os.path.dirname(path))
  33.     return open(path, 'wb')
  34.  
  35. def uninstall_app(name):
  36.     global mb
  37.     global ast
  38.     global homescreen
  39.     global os
  40.     global shutil
  41.     infofile = open(f"T:/ProgramData/Store/Apps/{name}/.info", "r")
  42.     appinfo = ast.literal_eval(infofile.read())
  43.     infofile.close()
  44.     if mb.askyesno("Uninstall App", "Are you sure you want to uninstall " + appinfo["NAME"] + "?"):
  45.         try:
  46.             try:
  47.                 shutil.rmtree(appinfo["LOCATION"])
  48.                 os.remove(appinfo["INFOLOCATION"])
  49.             except:
  50.                 mb.showinfo("App already uninstalled", f"{appinfo['NAME']} has already been uninstalled. Press OK to continue and remove app data.")
  51.             finally:
  52.                 ins_file = open("T:/ProgramData/Store/Installed.info", "r")
  53.                 installed = ast.literal_eval(ins_file.read())
  54.                 ins_file.close()
  55.                 ins_file = open("T:/ProgramData/Store/Installed.info", "w")
  56.                 installed.remove(name)
  57.                 ins_file.write(str(installed))
  58.                 ins_file.close()
  59.                 homescreen()
  60.                 mb.showinfo("App Uninstalled", f"{appinfo['NAME']} has successfully been uninstalled.")
  61.         except:
  62.             mb.showinfo("Could not uninstall", f"The uninstallation process of {appinfo['NAME']} did not complete. Please try again or contact Techpad for help.")
  63.     else:
  64.         pass
  65.  
  66. def install_app(name):
  67.     global mb
  68.     global ast
  69.     global os
  70.     global requests
  71.     global sow
  72.     global sowb
  73.     global show_app
  74.     infofile = open(f"T:/ProgramData/Store/Apps/{name}/.info", "r")
  75.     appinfo = ast.literal_eval(infofile.read())
  76.     infofile.close()
  77.     if mb.askyesno("Install App", f"Are you sure you want to install {appinfo['NAME']}?"):
  78.         try:
  79.             codepage = requests.get(f"https://pastebin.com/raw/{appinfo['PROGRAMID']}")
  80.             rawcode = codepage.text
  81.             infopage = requests.get(f"https://pastebin.com/raw/{appinfo['INFOID']}")
  82.             rawinfo = infopage.text
  83.             fullinfo = ast.literal_eval(rawinfo)
  84.             programfile = sowb(appinfo["PROGRAMLOCATION"])
  85.             programfile.write(bytes(rawcode, "UTF-8"))
  86.             programfile.close()
  87.             infofile = sow(appinfo["INFOLOCATION"])
  88.             infofile.write(rawinfo)
  89.             infofile.close()
  90.             icon = open(f"T:/ProgramData/Store/Apps/{name}/Icon.png", "rb")
  91.             iconconts = icon.read()
  92.             icon.close()
  93.             newicon = sowb(fullinfo["ICONPATH"])
  94.             newicon.write(iconconts)
  95.             newicon.close()
  96.             ins_file = open("T:/ProgramData/Store/Installed.info", "r")
  97.             installed = ast.literal_eval(ins_file.read())
  98.             ins_file.close()
  99.             ins_file = open("T:/ProgramData/Store/Installed.info", "w")
  100.             installed.append(name)
  101.             ins_file.write(str(installed))
  102.             ins_file.close()
  103.             mb.showinfo("App Installed", f"{appinfo['NAME']} has been successfully installed.")
  104.             show_app(name, True)
  105.         except:
  106.             mb.showinfo("Could not install", f"The installation process of {appinfo['NAME']} did not complete. Please try again or contact Techpad for help.")
  107.     else:
  108.         pass
  109.  
  110. def update_app(name):
  111.     uninstall_app(name)
  112.     install_app(name)
  113.  
  114. def show_app(name, installed):
  115.     global __root
  116.     global ast
  117.     global homescreen
  118.     global uninstall_app
  119.     global install_app
  120.     global update_app
  121.     infofile = open(f"T:/ProgramData/Store/Apps/{name}/.info", "r")
  122.     appinfo = ast.literal_eval(infofile.read())
  123.     infofile.close()
  124.     for child in __root.winfo_children():
  125.         child.destroy()
  126.     back = tk.Button(__root, bd=0, bg='white', activebackground='lightgray', font='TkDefaultFont 20', width=30,
  127.                      height=30, command=homescreen)
  128.     back.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/Back.png')
  129.     back.config(image=back.image)
  130.     back.pack(side='top', anchor='nw')
  131.     iconlabel = tk.Label(__root, text=" " + appinfo["NAME"], compound='left', bg='white', anchor='nw', justify='left', font="TkDefaultFont 20", fg=appinfo["ACCENTCOLOR"])
  132.     iconlabel.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{name}/Icon64.png")
  133.     iconlabel.config(image=iconlabel.image)
  134.     iconlabel.pack(anchor='nw', side='top', padx=5)
  135.     desclabel = tk.Label(__root, text=appinfo["DESCRIPTION"], bg='white', justify='left', wraplength=200)
  136.     desclabel.pack(side='top', anchor='nw', padx=5, pady=5)
  137.     if appinfo["UNINSTALL"] == True and installed == True:
  138.         uninstall_button = tk.Button(__root, bg='white', bd=1, relief='solid', text='Uninstall', font='TkDefaultFont 15', command=lambda name=name: uninstall_app(name))
  139.         uninstall_button.pack(padx=5, anchor='nw', side='top', pady=5)
  140.         update_button = tk.Button(__root, bg='white', bd=1, relief='solid', text='Update',
  141.                                      font='TkDefaultFont 15', command=lambda name=name: update_app(name))
  142.         update_button.pack(padx=5, anchor='nw', side='top', pady=5)
  143.     elif installed == True:
  144.         runbutton = tk.Button(__root, text="Open", bg='white', bd=1, relief='solid', font='TkDefaultFont 15',
  145.                               command=lambda name=name: startprogram(name))
  146.         runbutton.pack(padx=5, anchor='nw', side='top', pady=5)
  147.     elif installed == False:
  148.         install_button = tk.Button(__root, bg='white', bd=1, relief='solid', text='Install', font='TkDefaultFont 15', command=lambda name=name: install_app(name))
  149.         install_button.pack(padx=5, anchor='nw', side='top', pady=5)
  150.  
  151. def homescreen():
  152.     global __root
  153.     global ast
  154.     global show_app
  155.     global tk
  156.     for child in __root.winfo_children():
  157.         child.destroy()
  158.     ins_file = open("T:/ProgramData/Store/Installed.info", "r")
  159.     ins_text = ins_file.read()
  160.     ins_file.close()
  161.     ins_list = ast.literal_eval(ins_text)
  162.     ins_frame = tk.Frame(__root, bd=0, bg='white')
  163.     ins_label = tk.Label(ins_frame, text='Installed', bg='white', font='TkDefaultFont 12 bold')
  164.     ins_label.pack(anchor='nw', side='top', padx=5)
  165.     for element in ins_list:
  166.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  167.         tempinfo = ast.literal_eval(tempfile.read())
  168.         tempfile.close()
  169.         tempbutton = tk.Button(ins_frame, bd=0, text=tempinfo["NAME"], bg='white', relief='solid', compound='top', command=lambda name=element: show_app(name, True), activebackground='lightgray', width=70, wraplength=70)
  170.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  171.         tempbutton.config(image=tempbutton.image)
  172.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  173.     ins_frame.pack(fill='x')
  174.     rec_file = open("T:/ProgramData/Store/Recommended.info", "r")
  175.     rec_text = rec_file.read()
  176.     rec_file.close()
  177.     rec_list = ast.literal_eval(rec_text)
  178.     rec_frame = tk.Frame(__root, bd=0, bg='white')
  179.     rec_label = tk.Label(rec_frame, text='Recommended', bg='white', font='TkDefaultFont 12 bold')
  180.     rec_label.pack(anchor='nw', side='top', padx=5)
  181.     for element in rec_list:
  182.         if element in ins_list:
  183.             ins = True
  184.         else:
  185.             ins = False
  186.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  187.         tempinfo = ast.literal_eval(tempfile.read())
  188.         tempfile.close()
  189.         tempbutton = tk.Button(rec_frame, bd=0, text=tempinfo["NAME"], bg='white', relief='solid', compound='top',
  190.                                command=lambda name=element, ins=ins: show_app(name, ins), activebackground='lightgray', width=70, wraplength=70)
  191.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  192.         tempbutton.config(image=tempbutton.image)
  193.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  194.     rec_frame.pack(fill='x')
  195.     aps_file = open("T:/ProgramData/Store/Apps.info", "r")
  196.     aps_text = aps_file.read()
  197.     aps_file.close()
  198.     aps_list = ast.literal_eval(aps_text)
  199.     aps_frame = tk.Frame(__root, bd=0, bg='white')
  200.     aps_label = tk.Label(aps_frame, text='Apps', bg='white', font='TkDefaultFont 12 bold')
  201.     aps_label.pack(anchor='nw', side='top', padx=5)
  202.     for element in aps_list:
  203.         if element in ins_list:
  204.             ins = True
  205.         else:
  206.             ins = False
  207.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  208.         tempinfo = ast.literal_eval(tempfile.read())
  209.         tempfile.close()
  210.         tempbutton = tk.Button(aps_frame, bd=0, text=tempinfo["NAME"], bg='white', relief='solid', compound='top',
  211.                                command=lambda name=element, ins=ins: show_app(name, ins), activebackground='lightgray', width=70, wraplength=70)
  212.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  213.         tempbutton.config(image=tempbutton.image)
  214.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  215.     aps_frame.pack(fill='x')
  216.     gms_file = open("T:/ProgramData/Store/Games.info", "r")
  217.     gms_text = gms_file.read()
  218.     gms_file.close()
  219.     gms_list = ast.literal_eval(gms_text)
  220.     gms_frame = tk.Frame(__root, bd=0, bg='white')
  221.     gms_label = tk.Label(gms_frame, text='Games', bg='white', font='TkDefaultFont 12 bold')
  222.     gms_label.pack(anchor='nw', side='top', padx=5)
  223.     for element in gms_list:
  224.         if element in ins_list:
  225.             ins = True
  226.         else:
  227.             ins = False
  228.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  229.         tempinfo = ast.literal_eval(tempfile.read())
  230.         tempfile.close()
  231.         tempbutton = tk.Button(gms_frame, bd=0, text=tempinfo["NAME"], bg='white', relief='solid', compound='top',
  232.                                command=lambda name=element, ins=ins: show_app(name, ins), activebackground='lightgray', width=70, wraplength=70)
  233.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  234.         tempbutton.config(image=tempbutton.image)
  235.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  236.     gms_frame.pack(fill='x')
  237.  
  238. homescreen()
Add Comment
Please, Sign In to add comment