Skip to content

Commit 3315e9c

Browse files
authored
Pre1.0_4
1 parent 6bf3610 commit 3315e9c

File tree

4 files changed

+376
-124
lines changed

4 files changed

+376
-124
lines changed

app_adder.py

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
"""
2+
App adder ; allows you to install/uninstall apps.
3+
"""
4+
import tkinter as tk
5+
from tkinter import filedialog
6+
from tkinter import messagebox
7+
import requests
8+
import os
9+
import json
10+
import zipfile
11+
import shutil
12+
13+
try:
14+
registry_file = open("../../registry.json", "r")
15+
except FileNotFoundError:
16+
registry_file = open("registry.json", "r")
17+
REGISTRY = json.load(registry_file)
18+
registry_file.close()
19+
20+
window = tk.Tk()
21+
window.geometry("400x200")
22+
window.title("App adder")
23+
window.iconbitmap("assets/ACOS_Logo.ico")
24+
25+
def get_zip_link(app:str):
26+
return f"https://raw.githubusercontent.com/megat69/ACOS_Apps/main/{app}/{app}.zip"
27+
28+
29+
# ------------------------- GUI ELEMENTS -------------------------
30+
def install_app():
31+
r = requests.get(get_zip_link(app_name_entry.get()))
32+
# If there has been a problem
33+
if r.status_code != 200:
34+
message.config(
35+
text=f"An error occurred with code {r.status_code}." +\
36+
("\nThe app doesn't seem to exist." if r.status_code == 404 else ""),
37+
fg = "red"
38+
)
39+
return
40+
41+
try:
42+
os.mkdir("temp")
43+
except FileExistsError:
44+
pass
45+
# ------- Writing the zip -------
46+
with open(f"temp/{app_name_entry.get()}.zip", "wb") as zip_contents:
47+
zip_contents.write(r.content)
48+
49+
# ------- Extracting the zip -------
50+
with zipfile.ZipFile(f"temp/{app_name_entry.get()}.zip", "r") as zip_ref:
51+
zip_ref.extractall(f"ROOT/{REGISTRY['SOFTWARES_FOLDER']}")
52+
53+
# ------- Deleting the temp folder -------
54+
shutil.rmtree("temp")
55+
56+
# ------- End message -------
57+
message.config(
58+
text=f"Correctly installed {app_name_entry.get()}",
59+
fg="green"
60+
)
61+
app_name_entry.delete(0, tk.END)
62+
63+
64+
install_app_button = tk.Button(
65+
window,
66+
text = "Install app",
67+
command = install_app
68+
)
69+
install_app_button.pack()
70+
71+
def uninstall_app():
72+
if app_name_entry.get() not in os.listdir(f"ROOT/{REGISTRY['SOFTWARES_FOLDER']}")\
73+
or app_name_entry.get() in ("ACOS_Console", "app_browser", "Ideaglue", "textrock", "Micr0n",
74+
"paintapp", "RegistryVisualizer", "settings", "SYSTEM_Filesystem"):
75+
message.config(
76+
text=f"The app {app_name_entry.get()} is not installed.",
77+
fg="red"
78+
)
79+
return
80+
81+
# ------- CONFIRM -------
82+
confirm_box = messagebox.askquestion(
83+
f"Uninstall {app_name_entry.get()}",
84+
f"Are you sure you want to uninstall {app_name_entry.get()} ?\n"
85+
"This action cannot be undone.",
86+
icon = "warning"
87+
)
88+
if confirm_box == "no":
89+
message.config(
90+
text="Uninstall cancelled.",
91+
fg="red"
92+
)
93+
return
94+
95+
# ------- App uninstall --------
96+
shutil.rmtree(f"ROOT/{REGISTRY['SOFTWARES_FOLDER']}/{app_name_entry.get()}")
97+
98+
# ------- End message -------
99+
message.config(
100+
text=f"App '{app_name_entry.get()}' uninstalled.",
101+
fg="black"
102+
)
103+
app_name_entry.delete(0, tk.END)
104+
105+
uninstall_app_button = tk.Button(
106+
window,
107+
text = "Uninstall app",
108+
command = uninstall_app
109+
)
110+
uninstall_app_button.pack()
111+
112+
def install_local_app():
113+
file = filedialog.askopenfilename(filetypes=(("ZIP", "*.zip"),), title="Install app from local file")
114+
if file == "" or file is None:
115+
message.config(
116+
text="Install cancelled.",
117+
fg="red"
118+
)
119+
return
120+
121+
# ------- App extracting -------
122+
with zipfile.ZipFile(file, "r") as zip_ref:
123+
zip_ref.extractall(f"ROOT/{REGISTRY['SOFTWARES_FOLDER']}")
124+
125+
# ------- End message -------
126+
file = file.split("/")[-1][:-4]
127+
message.config(
128+
text=f"App '{file}' installed.",
129+
fg="green"
130+
)
131+
132+
install_local_app_button = tk.Button(
133+
window,
134+
text = "Install local app",
135+
command = install_local_app
136+
)
137+
install_local_app_button.pack()
138+
139+
def update_app():
140+
app_name = app_name_entry.get()
141+
uninstall_app()
142+
app_name_entry.insert(0, app_name)
143+
install_app()
144+
145+
update_app_button = tk.Button(
146+
window,
147+
text = "Update app",
148+
command = update_app
149+
)
150+
update_app_button.pack()
151+
152+
app_name_entry = tk.Entry(
153+
window
154+
)
155+
app_name_entry.pack(pady=5)
156+
157+
message = tk.Label(window)
158+
message.pack()
159+
160+
window.mainloop()

general_data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"last_connected_user": "user",
3-
"version": "Pre1.0_3"
3+
"version": "Pre1.0_4"
44
}

0 commit comments

Comments
 (0)