From b727633f74647dca7433af431b58153aade52a0a Mon Sep 17 00:00:00 2001 From: Obie Hinojosa Date: Wed, 28 May 2025 20:06:02 -0500 Subject: [PATCH] add custom exception and barebones error handling to launcher detection --- installer.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/installer.py b/installer.py index 3d4fe8f..10320ea 100644 --- a/installer.py +++ b/installer.py @@ -29,6 +29,11 @@ from pathlib import Path # as far as i can tell, i wanted to add an "option" to the function that toggled the warning m- # -essage, so i dont have to use all this space here defining functions i dont really need. +class customerror(Exception): + def __init__(self, message): + self.message = message + super().__init__(self.message) + def delete_directory_warn(directory_to_delete, warn=False): #this defines a function to delete a directory (no shit) try: @@ -115,13 +120,16 @@ def check_if_exists_and_delete_file(filepath): else: pass +global detectedlauncher +detectedlauncher = "null" + def check_for_launcher_files(filepath, launchername): #checks for evidence of 3rd party launchers and sets a variable flag if a launcher is installed if os.path.exists(filepath): - print("Alternative Minecraft launcher detected: " + str(launchername)) + print("[INFO]: Detected Minecraft launcher: " + str(launchername)) detectedlauncher = str(launchername) else: - pass + raise customerror("[ERR!]: File not detected.") # --------------------the real shit!------------------------ @@ -133,13 +141,16 @@ os.chdir(homedir) global mcfolder global modfolder - # `global` sets these variables to exist outside of the scope of these specific `if` statements. +# `global` sets these variables to exist outside of the scope of these specific `if` statements. if platform.system() == "Linux": print("Operating system detected: Linux") - check_for_launcher_files(str(Path.cwd()) + "/.var/app/org.prismlauncher.Prism.Launcher", "PrismLauncherFlatpak") - check_for_launcher_files(str(Path.cwd()) + "/.local/share/PrismLauncher/prismlauncher.cfg", "PrismLauncherPackage") + try: + check_for_launcher_files(str(Path.cwd()) + "/.local/share/PrismLauncher", "PrismLauncherPackage") + check_for_launcher_files(str(Path.cwd()) + "/.var/app/org.prismlauncher.Prism.Launcher", "PrismLauncherFlatpak") + except customerror as e: + pass os.chdir(".minecraft") mcfolder = str(Path.cwd()) @@ -160,7 +171,7 @@ elif platform.system() == "Windows": mcfolder = str(Path.cwd()) print("Changed current working directory to '" + str(mcfolder) + "'") - time.sleep(1) + time.sleep(1) print(); print("Backing up minecraft install...") print("Don't close the window! This'll take a moment...")