Techpad

TechStore.tep

Mar 15th, 2021 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.33 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.     infofile = open(f"T:/ProgramData/Store/Apps/{name}/.info", "r")
  74.     appinfo = ast.literal_eval(infofile.read())
  75.     infofile.close()
  76.     if mb.askyesno("Install App", f"Are you sure you want to install {appinfo['NAME']}?"):
  77.         try:
  78.             codepage = requests.get(f"https://pastebin.com/raw/{appinfo['PROGRAMID']}")
  79.             rawcode = codepage.text
  80.             infopage = requests.get(f"https://pastebin.com/raw/{appinfo['INFOID']}")
  81.             rawinfo = infopage.text
  82.             fullinfo = ast.literal_eval(rawinfo)
  83.             programfile = sowb(appinfo["PROGRAMLOCATION"])
  84.             programfile.write(bytes(rawcode, "UTF-8"))
  85.             programfile.close()
  86.             infofile = sow(appinfo["INFOLOCATION"])
  87.             infofile.write(rawinfo)
  88.             infofile.close()
  89.             icon = open(f"T:/ProgramData/Store/Apps/{name}/Icon.png", "rb")
  90.             iconconts = icon.read()
  91.             icon.close()
  92.             newicon = sowb(fullinfo["ICONPATH"])
  93.             newicon.write(iconconts)
  94.             newicon.close()
  95.             ins_file = open("T:/ProgramData/Store/Installed.info", "r")
  96.             installed = ast.literal_eval(ins_file.read())
  97.             ins_file.close()
  98.             ins_file = open("T:/ProgramData/Store/Installed.info", "w")
  99.             installed.append(name)
  100.             ins_file.write(str(installed))
  101.             ins_file.close()
  102.             mb.showinfo("App Installed", f"{appinfo['NAME']} has been successfully installed.")
  103.         except:
  104.             mb.showinfo("Could not install", f"The installation process of {appinfo['NAME']} did not complete. Please try again or contact Techpad for help.")
  105.     else:
  106.         pass
  107.  
  108. def show_app(name, installed):
  109.     global __root
  110.     global ast
  111.     global homescreen
  112.     global uninstall_app
  113.     global install_app
  114.     infofile = open(f"T:/ProgramData/Store/Apps/{name}/.info", "r")
  115.     appinfo = ast.literal_eval(infofile.read())
  116.     infofile.close()
  117.     for child in __root.winfo_children():
  118.         child.destroy()
  119.     back = tk.Button(__root, bd=0, bg='white', activebackground='lightgray', font='TkDefaultFont 20', width=30,
  120.                      height=30, command=homescreen)
  121.     back.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/Back.png')
  122.     back.config(image=back.image)
  123.     back.pack(side='top', anchor='nw')
  124.     iconlabel = tk.Label(__root, text=" " + appinfo["NAME"], compound='left', bg='white', anchor='nw', justify='left', font="TkDefaultFont 20", fg=appinfo["ACCENTCOLOR"])
  125.     iconlabel.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{name}/Icon64.png")
  126.     iconlabel.config(image=iconlabel.image)
  127.     iconlabel.pack(anchor='nw', side='top', padx=5)
  128.     desclabel = tk.Label(__root, text=appinfo["DESCRIPTION"], bg='white', justify='left', wraplength=200)
  129.     desclabel.pack(side='top', anchor='nw', padx=5, pady=5)
  130.     if appinfo["UNINSTALL"] == True and installed == True:
  131.         uninstall_button = tk.Button(__root, bg='white', bd=1, relief='solid', text='Uninstall', font='TkDefaultFont 15', command=lambda name=name: uninstall_app(name))
  132.         uninstall_button.pack(padx=5, anchor='nw', side='top', pady=5)
  133.     elif installed == True:
  134.         runbutton = tk.Button(__root, text="Open", bg='white', bd=1, relief='solid', font='TkDefaultFont 15',
  135.                               command=lambda name=name: startprogram(name))
  136.         runbutton.pack(padx=5, anchor='nw', side='top', pady=5)
  137.     elif installed == False:
  138.         install_button = tk.Button(__root, bg='white', bd=1, relief='solid', text='Install', font='TkDefaultFont 15', command=lambda name=name: install_app(name))
  139.         install_button.pack(padx=5, anchor='nw', side='top', pady=5)
  140.  
  141. def homescreen():
  142.     global __root
  143.     global ast
  144.     global show_app
  145.     for child in __root.winfo_children():
  146.         child.destroy()
  147.     ins_file = open("T:/ProgramData/Store/Installed.info", "r")
  148.     ins_text = ins_file.read()
  149.     ins_file.close()
  150.     ins_list = ast.literal_eval(ins_text)
  151.     ins_frame = tk.Frame(__root, bd=0, bg='white')
  152.     ins_label = tk.Label(ins_frame, text='Installed', bg='white', font='TkDefaultFont 12 bold')
  153.     ins_label.pack(anchor='nw', side='top', padx=5)
  154.     for element in ins_list:
  155.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  156.         tempinfo = ast.literal_eval(tempfile.read())
  157.         tempfile.close()
  158.         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)
  159.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  160.         tempbutton.config(image=tempbutton.image)
  161.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  162.     ins_frame.pack(fill='x')
  163.     rec_file = open("T:/ProgramData/Store/Recommended.info", "r")
  164.     rec_text = rec_file.read()
  165.     rec_file.close()
  166.     rec_list = ast.literal_eval(rec_text)
  167.     rec_frame = tk.Frame(__root, bd=0, bg='white')
  168.     rec_label = tk.Label(rec_frame, text='Recommended', bg='white', font='TkDefaultFont 12 bold')
  169.     rec_label.pack(anchor='nw', side='top', padx=5)
  170.     for element in rec_list:
  171.         if element in ins_list:
  172.             ins = True
  173.         else:
  174.             ins = False
  175.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  176.         tempinfo = ast.literal_eval(tempfile.read())
  177.         tempfile.close()
  178.         tempbutton = tk.Button(rec_frame, bd=0, text=tempinfo["NAME"], bg='white', relief='solid', compound='top',
  179.                                command=lambda name=element, ins=ins: show_app(name, ins), activebackground='lightgray', width=70, wraplength=70)
  180.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  181.         tempbutton.config(image=tempbutton.image)
  182.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  183.     rec_frame.pack(fill='x')
  184.     aps_file = open("T:/ProgramData/Store/Apps.info", "r")
  185.     aps_text = aps_file.read()
  186.     aps_file.close()
  187.     aps_list = ast.literal_eval(aps_text)
  188.     aps_frame = tk.Frame(__root, bd=0, bg='white')
  189.     aps_label = tk.Label(aps_frame, text='Apps', bg='white', font='TkDefaultFont 12 bold')
  190.     aps_label.pack(anchor='nw', side='top', padx=5)
  191.     for element in aps_list:
  192.         if element in ins_list:
  193.             ins = True
  194.         else:
  195.             ins = False
  196.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  197.         tempinfo = ast.literal_eval(tempfile.read())
  198.         tempfile.close()
  199.         tempbutton = tk.Button(aps_frame, bd=0, text=tempinfo["NAME"], bg='white', relief='solid', compound='top',
  200.                                command=lambda name=element, ins=ins: show_app(name, ins), activebackground='lightgray', width=70, wraplength=70)
  201.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  202.         tempbutton.config(image=tempbutton.image)
  203.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  204.     aps_frame.pack(fill='x')
  205.     gms_file = open("T:/ProgramData/Store/Games.info", "r")
  206.     gms_text = gms_file.read()
  207.     gms_file.close()
  208.     gms_list = ast.literal_eval(gms_text)
  209.     gms_frame = tk.Frame(__root, bd=0, bg='white')
  210.     gms_label = tk.Label(gms_frame, text='Games', bg='white', font='TkDefaultFont 12 bold')
  211.     gms_label.pack(anchor='nw', side='top', padx=5)
  212.     for element in gms_list:
  213.         if element in ins_list:
  214.             ins = True
  215.         else:
  216.             ins = False
  217.         tempfile = open(f"T:/ProgramData/Store/Apps/{element}/.info", "r")
  218.         tempinfo = ast.literal_eval(tempfile.read())
  219.         tempfile.close()
  220.         tempbutton = tk.Button(gms_frame, bd=0, text=tempinfo["NAME"], bg='white', relief='solid', compound='top',
  221.                                command=lambda name=element, ins=ins: show_app(name, ins), activebackground='lightgray', width=70, wraplength=70)
  222.         tempbutton.image = tk.PhotoImage(file=f"T:/ProgramData/Store/Apps/{element}/Icon64.png")
  223.         tempbutton.config(image=tempbutton.image)
  224.         tempbutton.pack(side="left", padx=5, pady=5, anchor='nw')
  225.     gms_frame.pack(fill='x')
  226.  
  227. homescreen()
Add Comment
Please, Sign In to add comment