Skip to content

Commit

Permalink
User gets an error now when they try to add a file that is not an arc…
Browse files Browse the repository at this point in the history
…hive
  • Loading branch information
Ati1707 committed Dec 13, 2024
1 parent 80dd88a commit ad0252f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions helper/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions main.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ad0252f

Please sign in to comment.