From ad0252f7e5b70fa261c23bb63dbf2335c2d9d515 Mon Sep 17 00:00:00 2001 From: Ati1707 <152104750+Ati1707@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:31:43 +0100 Subject: [PATCH] User gets an error now when they try to add a file that is not an archive --- helper/file_operations.py | 4 ++++ installer.py | 4 ++-- main.pyw | 21 +++++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/helper/file_operations.py b/helper/file_operations.py index 7075572..6d4edfd 100644 --- a/helper/file_operations.py +++ b/helper/file_operations.py @@ -113,3 +113,7 @@ def create_logger() -> logging.Logger: datefmt='%m/%d/%Y %I:%M:%S' ) return logging.getLogger(__name__) + +def is_file_archive(file): + if file.lower().endswith(('.zip', '.rar', '.7z', '.tar')): + return True diff --git a/installer.py b/installer.py index 7a6420d..bdb660b 100644 --- a/installer.py +++ b/installer.py @@ -65,7 +65,7 @@ def extract_archive(item_path: pathlib.Path, is_debug_mode: bool) -> bool: Extract an archive into the temporary folder. """ base_item_name = item_path.name - if base_item_name.lower().endswith(('.zip', '.rar', '7z', '.tar')): + if base_item_name.lower().endswith(('.zip', '.rar', '.7z', '.tar')): logger.info(f"Extracting {base_item_name}") try: verbosity = 2 if is_debug_mode else -1 @@ -119,7 +119,7 @@ def handle_nested_archives(root_path, files, is_debug_mode): archive_extracted = False for file in files: file_path = root_path / file - if file.lower().endswith(('.zip', '.rar', '7z', '.tar')): + if file.lower().endswith(('.zip', '.rar', '.7z', '.tar')): logger.info(f"Extracting nested archive: {file}") try: verbosity = 2 if is_debug_mode else -1 diff --git a/main.pyw b/main.pyw index 861fdcc..4d241a1 100644 --- a/main.pyw +++ b/main.pyw @@ -7,6 +7,7 @@ from CTkToolTip import CTkToolTip from content_database import get_archives, delete_archive from customtkinter import CTk, filedialog, CTkLabel from helper import file_operations, updater +from helper.file_operations import is_file_archive from installer import start_installer_gui from tkinter import BooleanVar from tkinter.constants import DISABLED, NORMAL @@ -230,7 +231,13 @@ class MyTabView(ctk.CTkTabview): if file_path: file_name = file_operations.get_file_from_path(file_path) asset_name = file_operations.get_file_name_without_extension(file_name) - self.add_asset_widget(asset_name, file_path) + if is_file_archive(file_name): + self.add_asset_widget(asset_name, file_path) + else: + CTkMessagebox(title="Info", + message="The File is not an archive", + option_1="Okay", + width=500, height=250) def remove_selected(self): temp_install_list = install_asset_list.copy() @@ -265,9 +272,15 @@ class MyTabView(ctk.CTkTabview): def drop_files(self, files): """Handles file drop to create asset widgets.""" for file_path in files: - file_name = file_operations.get_file_from_path(file_path) - asset_name = file_operations.get_file_name_without_extension(file_name) - self.after(50, self.add_asset_widget, asset_name, file_path) + if is_file_archive(file_path): + file_name = file_operations.get_file_from_path(file_path) + asset_name = file_operations.get_file_name_without_extension(file_name) + self.after(50, self.add_asset_widget, asset_name, file_path) + else: + CTkMessagebox(title="Info", + message="The File is not an archive", + option_1="Okay", + width=500, height=250) def refresh_tab(self):