-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.py
434 lines (376 loc) · 17.9 KB
/
installer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
import os
import json
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
from datetime import datetime
import subprocess
from locale import getlocale
import webbrowser
import urllib.request
import io
from PIL import Image, ImageTk
# _______ _________ _____ ______ _
# / _____ \ |____ ____| / ___ \ | ____ \ | |
#/ / \_\ | | / / \ \ | | \ \ | |
#| | | | / / \ \ | | | | | |
#\ \______ | | | | | | | |___/ / | |
# \______ \ | | | | | | | ____/ | |
# \ \ | | | | | | | | | |
# _ | | | | \ \ / / | | |_|
#\ \_____/ / | | \ \___/ / | | _
# \_______/ |_| \_____/ |_| |_|
# Stop!
# If someone instructed you to edit this code with another, it is not advisable to do so.
# Please do not edit the code unless you are certain of what you are doing.
# If you need something in the code to be modified, please inform the creators.
# Función para obtener el idioma del sistema
def get_system_language():
try:
# Extraer el primer valor de la tupla
return getlocale()[0]
except:
return 'en_US'
# Función para verificar si se necesita el argumento "powershell"
def check_powershell_execution():
command = 'Get-ExecutionPolicy'
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=10)
return result.returncode == 0 and result.stdout.strip()
except subprocess.SubprocessError:
return False
# Diccionario de traducciones
translations = {
"en_US": {
"title": "Loader Screen Installer",
"welcome": "Welcome to Loader Screen Installer",
"choose": "What would you like to do?",
"install": "Install/Change",
"uninstall": "Uninstall",
"cancel": "Cancel",
"select_video": "Select video file",
"select_vlc": "Select VLC location",
"install_vlc": "VLC not found. Would you like to select the VLC location or install VLC?",
"select_or_install_vlc": "Select or Install VLC",
"select": "Select",
"install": "Install",
"no_video": "No video file selected.",
"invalid_format": "The selected video file is not in a valid format.",
"no_vlc": "VLC not found. Please select the VLC location.",
"installation_complete": "Installation/Change completed.",
"uninstallation_complete": "Uninstallation completed.",
"log_title": "Change Log",
"bloxstrap_not_found": "Bloxstrap not found. Please install Bloxstrap.",
"install_bloxstrap": "Install Bloxstrap"
},
"es_ES": {
"title": "Instalador de Loader Screen ",
"welcome": "Bienvenido al instalador de Loader Screen ",
"choose": "¿Qué deseas hacer?",
"install": "Instalar/Cambiar",
"uninstall": "Desinstalar",
"cancel": "Cancelar",
"select_video": "Seleccionar archivo de video",
"select_vlc": "Seleccionar ubicación de VLC",
"install_vlc": "No se encontró VLC. ¿Te gustaría seleccionar la ubicación de VLC o instalar VLC?",
"select_or_install_vlc": "Seleccionar o Instalar VLC",
"select": "Seleccionar",
"install": "Instalar",
"no_video": "No se seleccionó ningún archivo de video.",
"invalid_format": "El archivo de video seleccionado no está en un formato válido.",
"no_vlc": "No se encontró VLC. Por favor, selecciona la ubicación de VLC.",
"installation_complete": "Instalación/Cambio completado.",
"uninstallation_complete": "Desinstalación completada.",
"log_title": "Registro de Cambios",
"bloxstrap_not_found": "No se encontró Bloxstrap. Por favor, instala Bloxstrap.",
"install_bloxstrap": "Instalar Bloxstrap"
},
"de_DE": {
"title": "Ladebildschirm-Installer",
"welcome": "Wilkommen im Ladebildschirm-installer ",
"choose": "Was würdest du gerne tun?",
"install": "Installieren",
"uninstall": "Entfernen",
"cancel": "Abbrechen",
"select_video": "Bitte wähl dein Video aus",
"select_vlc": "Wähl VLC.exe aus",
"install_vlc": "Kein VLC gefunden, möchtest du VLC manuell auswählen oder installieren?",
"select_or_install_vlc": "Wähl VLC.exe aus oder installiere VLC",
"select": "Auswählen",
"install": "Installieren",
"no_video": "Kein Video ausgewählt",
"invalid_format": "Das ausgewählte Video hat ein invalides Format.",
"no_vlc": "VLC wurde nicht gefunden, bitte wähl VLC.exe aus.",
"installation_complete": "Installation abgeschlossen.",
"uninstallation_complete": "Erfolgreich deinstalliert.",
"log_title": "Änderungen",
"bloxstrap_not_found": "Bloxstrap wurde nicht gefunden. Installier Bloxstrap nochmal und versuche erneut.",
"install_bloxstrap": "Bloxstrap installieren"
}
}
# Obtener el idioma del sistema y seleccionar las traducciones
system_language = get_system_language()
if system_language.startswith("es"):
lang = translations["es_ES"]
elif system_language.startswith("de"):
lang = translations["de_DE"]
else:
lang = translations["en_US"]
# Función para verificar si Bloxstrap está instalado
def verificar_bloxstrap_instalado():
return os.path.exists(os.path.expanduser("~/AppData/Local/Bloxstrap"))
# Función para seleccionar un archivo de video
def seleccionar_video():
return filedialog.askopenfilename(title=lang["select_video"],
filetypes=[("Video files",
"*.mp4;*.avi;*.mkv;*.mov;*.wmv;*.flv;*.mpeg;*.mpg")])
# Función para encontrar la ubicación de VLC
def encontrar_vlc(log_file):
program_files = os.environ.get("ProgramFiles")
program_files_x86 = os.environ.get("ProgramFiles(x86)")
vlc_path = os.path.join(program_files_x86, "VideoLAN", "VLC", "vlc.exe")
if os.path.exists(vlc_path):
log_file.write(f"[{datetime.now()}] VLC found at {vlc_path}\n")
return vlc_path
vlc_path = os.path.join(program_files, "VideoLAN", "VLC", "vlc.exe")
if os.path.exists(vlc_path):
log_file.write(f"[{datetime.now()}] VLC found at {vlc_path}\n")
return vlc_path
log_file.write(f"[{datetime.now()}] VLC not found\n")
return None
# Función para seleccionar la ubicación de VLC
def seleccionar_vlc():
return filedialog.askopenfilename(title=lang["select_vlc"])
# Función para instalar VLC usando winget
def instalar_vlc():
command = 'winget install -e --id VideoLAN.VLC'
try:
subprocess.run(command, shell=True)
messagebox.showinfo("Information", "VLC installed successfully.")
except subprocess.SubprocessError:
messagebox.showerror("Error", "Failed to install VLC.")
# Función para crear el script PowerShell
def crear_script_ps(video_path, vlc_path):
video_path = video_path.replace("/", "\\")
vlc_path = vlc_path.replace("/", "\\")
script_content = f"""
# Path to the video you want to play
$videoPath = "{video_path}"
# Define the P/Invoke method to call user32.dll functions
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class User32 {{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}}
"@
# Get the handle of the current PowerShell window
$hwnd = [User32]::GetForegroundWindow()
# Minimize the window
[User32]::ShowWindow($hwnd, 6)
# Variable to control full-screen playback
$fullscreen = $true
# VLC arguments
if ($fullscreen) {{
$vlcArgs = "--fullscreen --play-and-exit --no-osd `"$videoPath`""
}} else {{
$vlcArgs = "--play-and-exit --no-osd `"$videoPath`""
}}
# Function to check if Roblox is running
function Is-RobloxRunning {{
$robloxProcesses = @("RobloxPlayerBeta", "RobloxStudioBeta")
foreach ($process in $robloxProcesses) {{
if (Get-Process -Name $process -ErrorAction SilentlyContinue) {{
return $true
}}
}}
return $false
}}
# Wait for Roblox to start
while (-not (Is-RobloxRunning)) {{
Start-Sleep -Seconds 1
}}
# Wait a bit more to allow the window to appear
Start-Sleep -Seconds 5
# Start VLC and play the video
$vlcProcess = Start-Process -FilePath "{vlc_path}" -ArgumentList $vlcArgs -PassThru
# Wait for VLC to exit on its own (due to --play-and-exit)
$vlcProcess.WaitForExit()
# If for some reason VLC is still running, force it to close
if (Get-Process -Id $vlcProcess.Id -ErrorAction SilentlyContinue) {{
Stop-Process -Id $vlcProcess.Id -Force
}}
"""
return script_content
# Función para modificar el archivo Settings.json
def modificar_settings_json(video_path, log_file):
settings_path = os.path.expanduser("~/AppData/Local/Bloxstrap/Settings.json")
if not os.path.exists(settings_path):
log_file.write(f"[{datetime.now()}] Settings.json not found at {settings_path}\n")
return False
powershell_arg = "powershell" if not check_powershell_execution() else ""
custom_integration = {
"Name": "Loading Screen",
"Location": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"LaunchArgs": f"{powershell_arg} -ExecutionPolicy Bypass -File \"C:\\Users\\{os.getlogin()}\\AppData\\Local\\Bloxstrap\\Modifications\\content\\launcher_roblox.ps1\"",
"AutoClose": True
}
with open(settings_path, 'r+') as f:
try:
settings_data = json.load(f)
log_file.write(f"[{datetime.now()}] Loaded Settings.json\n")
except json.JSONDecodeError:
settings_data = {}
log_file.write(f"[{datetime.now()}] Settings.json is empty or corrupted, creating new structure\n")
if "CustomIntegrations" in settings_data:
# Eliminar la integración existente si la hay
settings_data["CustomIntegrations"] = [intg for intg in settings_data["CustomIntegrations"] if intg["Name"] != "Loading Screen"]
# Añadir la nueva integración
settings_data["CustomIntegrations"].append(custom_integration)
else:
settings_data["CustomIntegrations"] = [custom_integration]
f.seek(0)
json.dump(settings_data, f, indent=4)
f.truncate()
log_file.write(f"[{datetime.now()}] Updated custom integration in Settings.json\n")
return True
# Función para desinstalar
def desinstalar(log_file):
script_ps_path = os.path.expanduser("~/AppData/Local/Bloxstrap/Modifications/content/launcher_roblox.ps1")
settings_path = os.path.expanduser("~/AppData/Local/Bloxstrap/Settings.json")
if os.path.exists(script_ps_path):
os.remove(script_ps_path)
log_file.write(f"[{datetime.now()}] Removed {script_ps_path}\n")
else:
log_file.write(f"[{datetime.now()}] {script_ps_path} not found\n")
if os.path.exists(settings_path):
with open(settings_path, 'r+') as f:
settings_data = json.load(f)
if "CustomIntegrations" in settings_data:
settings_data["CustomIntegrations"] = []
f.seek(0)
json.dump(settings_data, f, indent=4)
f.truncate()
log_file.write(f"[{datetime.now()}] Removed CustomIntegrations from {settings_path}\n")
else:
log_file.write(f"[{datetime.now()}] {settings_path} not found\n")
# Función para instalar/cambiar
def instalar_cambiar(video_path, vlc_path, log_file):
script_ps_path = os.path.expanduser("~/AppData/Local/Bloxstrap/Modifications/content/launcher_roblox.ps1")
script_ps_content = crear_script_ps(video_path, vlc_path)
with open(script_ps_path, 'w') as f:
f.write(script_ps_content)
log_file.write(f"[{datetime.now()}] Created {script_ps_path}\n")
if modificar_settings_json(video_path, log_file):
log_file.write(f"[{datetime.now()}] Modified Settings.json\n")
else:
log_file.write(f"[{datetime.now()}] Settings.json already contains the integration or couldn't be modified\n")
# Descargar y guardar el logo temporalmente usando io
def descargar_logo_temporal(url):
try:
with urllib.request.urlopen(url) as response:
return io.BytesIO(response.read())
except Exception as e:
print(f"Error downloading logo: {e}")
return None
# Clase para la interfaz gráfica
class InstallerGUI:
def __init__(self, master):
self.master = master
master.title(lang["title"])
master.geometry("400x300")
# Descargar el logo de Bloxstrap temporalmente
logo_url = "https://raw.githubusercontent.com/pizzaboxer/bloxstrap/main/Images/Bloxstrap.png"
logo_stream = descargar_logo_temporal(logo_url)
if logo_stream:
logo_image = Image.open(logo_stream)
self.logo_photo = ImageTk.PhotoImage(logo_image)
master.iconphoto(True, self.logo_photo)
style = ttk.Style()
style.theme_use('clam')
self.label = ttk.Label(master, text=lang["welcome"], font=("Helvetica", 14))
self.label.pack(pady=20)
self.choose_label = ttk.Label(master, text=lang["choose"])
self.choose_label.pack()
self.install_button = ttk.Button(master, text=lang["install"], command=self.install)
self.install_button.pack(pady=10)
self.uninstall_button = ttk.Button(master, text=lang["uninstall"], command=self.uninstall)
self.uninstall_button.pack(pady=10)
self.cancel_button = ttk.Button(master, text=lang["cancel"], command=self.cancel)
self.cancel_button.pack(pady=10)
self.log_file_path = os.path.expanduser("~/AppData/Local/Bloxstrap/install_log.txt")
# Limpiar el archivo de logs si ya existe
with open(self.log_file_path, 'w') as log_file:
log_file.write(f"[{datetime.now()}] Log file created/cleaned\n")
self.log_file = open(self.log_file_path, 'a')
if not verificar_bloxstrap_instalado():
messagebox.showinfo("Information", lang["bloxstrap_not_found"])
self.log_file.write(f"[{datetime.now()}] Bloxstrap not found\n")
webbrowser.open("https://github.com/pizzaboxer/bloxstrap")
return
def install(self):
self.log_file.write(f"[{datetime.now()}] Installation process started\n")
video_path = seleccionar_video()
if not video_path:
self.log_file.write(f"[{datetime.now()}] No video file selected\n")
messagebox.showerror("Error", lang["no_video"])
return
video_path = video_path.replace("/", "\\")
self.log_file.write(f"[{datetime.now()}] Video file selected: {video_path}\n")
allowed_formats = ["mp4", "avi", "mkv", "mov", "wmv", "flv", "mpeg", "mpg"]
if not any(video_path.lower().endswith(fmt) for fmt in allowed_formats):
self.log_file.write(f"[{datetime.now()}] Invalid video format\n")
messagebox.showerror("Error", lang["invalid_format"])
return
vlc_path = encontrar_vlc(self.log_file)
if not vlc_path:
self.log_file.write(f"[{datetime.now()}] VLC not found automatically\n")
if messagebox.askyesno(lang["select_or_install_vlc"], lang["install_vlc"]):
self.log_file.write(f"[{datetime.now()}] User chose to install VLC\n")
instalar_vlc()
vlc_path = encontrar_vlc(self.log_file)
if not vlc_path:
self.log_file.write(f"[{datetime.now()}] VLC installation failed\n")
messagebox.showerror("Error", lang["no_vlc"])
return
else:
vlc_path = seleccionar_vlc()
if not vlc_path:
self.log_file.write(f"[{datetime.now()}] VLC not selected manually\n")
messagebox.showerror("Error", lang["no_vlc"])
return
vlc_path = vlc_path.replace("/", "\\")
self.log_file.write(f"[{datetime.now()}] VLC path: {vlc_path}\n")
instalar_cambiar(video_path, vlc_path, self.log_file)
messagebox.showinfo("Information", lang["installation_complete"])
self.show_logs()
def uninstall(self):
self.log_file.write(f"[{datetime.now()}] Uninstallation process started\n")
desinstalar(self.log_file)
messagebox.showinfo("Information", lang["uninstallation_complete"])
self.show_logs()
def cancel(self):
self.log_file.write(f"[{datetime.now()}] Operation cancelled\n")
self.show_logs()
def show_logs(self):
self.log_file.close()
with open(self.log_file_path, 'r') as log_file:
log_content = log_file.read()
log_window = tk.Toplevel(self.master)
log_window.title(lang["log_title"])
log_text = tk.Text(log_window, wrap=tk.WORD)
log_text.insert(tk.END, log_content)
log_text.pack(expand=True, fill=tk.BOTH)
def on_closing():
log_window.destroy()
self.master.quit()
log_window.protocol("WM_DELETE_WINDOW", on_closing)
def main():
root = tk.Tk()
app = InstallerGUI(root)
root.mainloop()
if __name__ == "__main__":
main()