diff --git a/boiiiwd.py b/boiiiwd.py index 0aed047..b99c503 100644 --- a/boiiiwd.py +++ b/boiiiwd.py @@ -180,7 +180,7 @@ def initialize_steam(master): master.attributes('-alpha', 1.0) -def valid_id(workshop_id, yo=None): +def valid_id(workshop_id): url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}" response = requests.get(url) response.raise_for_status() diff --git a/boiiiwd_package/src/helpers.py b/boiiiwd_package/src/helpers.py index ac03f0b..694790d 100644 --- a/boiiiwd_package/src/helpers.py +++ b/boiiiwd_package/src/helpers.py @@ -155,9 +155,9 @@ def get_steamcmd_path(): return config.get("Settings", "SteamCMDPath", fallback=cwd()) def extract_json_data(json_path, key): - with open(json_path, "r") as json_file: + with open(json_path, 'r') as json_file: data = json.load(json_file) - return data[key] + return data.get(key, '') def convert_bytes_to_readable(size_in_bytes, no_symb=None): for unit in ['B', 'KB', 'MB', 'GB', 'TB']: @@ -191,13 +191,13 @@ def get_workshop_file_size(workshop_id, raw=None): except: return None -def show_message(title, message, icon="warning", exit_on_close=False, option_1="No", option_2="Ok"): - if exit_on_close: +def show_message(title, message, icon="warning", _return=False, option_1="No", option_2="Ok"): + if _return: msg = CTkMessagebox(title=title, message=message, icon=icon, option_1=option_1, option_2=option_2, sound=True) response = msg.get() - if response == "No": + if response == option_1: return False - elif response == "Ok": + elif response == option_2: return True else: return False diff --git a/boiiiwd_package/src/imports.py b/boiiiwd_package/src/imports.py index c56ba49..954a33c 100644 --- a/boiiiwd_package/src/imports.py +++ b/boiiiwd_package/src/imports.py @@ -3,6 +3,7 @@ from tkinter import Menu, END, Event from bs4 import BeautifulSoup import customtkinter as ctk from CTkToolTip import * +from pathlib import Path from PIL import Image import configparser import webbrowser @@ -21,7 +22,7 @@ import io import os import re -VERSION = "v0.2.8" +VERSION = "v0.2.9" GITHUB_REPO = "faroukbmiled/BOIIIWD" LATEST_RELEASE_URL = "https://github.com/faroukbmiled/BOIIIWD/releases/latest/download/Release.zip" UPDATER_FOLDER = "update" diff --git a/boiiiwd_package/src/library_tab.py b/boiiiwd_package/src/library_tab.py index 17d4114..2d73437 100644 --- a/boiiiwd_package/src/library_tab.py +++ b/boiiiwd_package/src/library_tab.py @@ -89,40 +89,34 @@ class LibraryTab(ctk.CTkScrollableFrame): button.grid_remove() def load_items(self, boiiiFolder): - # if you add this under init the whole app shrinks for some reason - global boiiiFolderGlobal - boiiiFolderGlobal = boiiiFolder - maps_folder = os.path.join(boiiiFolder, "mods") - mods_folder = os.path.join(boiiiFolder, "usermaps") + maps_folder = Path(boiiiFolder) / "mods" + mods_folder = Path(boiiiFolder) / "usermaps" + mod_img = os.path.join(RESOURCES_DIR, "mod_image.png") + map_img = os.path.join(RESOURCES_DIR, "map_image.png") folders_to_process = [mods_folder, maps_folder] for folder_path in folders_to_process: - for root, _, _ in os.walk(folder_path): - zone_path = os.path.join(root, "zone") - if os.path.exists(zone_path): - json_path = os.path.join(zone_path, "workshop.json") - if os.path.exists(json_path): - name = extract_json_data(json_path, "Title").replace(">", "").replace("^", "") - name = name[:45] + "..." if len(name) > 45 else name - item_type = extract_json_data(json_path, "Type") - workshop_id = extract_json_data(json_path, "PublisherID") - folder_name = extract_json_data(json_path, "FolderName") - size = convert_bytes_to_readable(get_folder_size(root)) - text_to_add = f"{name} | Type: {item_type.capitalize()}" - mode_type = "ZM" if item_type == "map" and folder_name.startswith("zm") else "MP" if folder_name.startswith("mp") and item_type == "map" else None - if mode_type: - text_to_add += f" | Mode: {mode_type}" - text_to_add += f" | ID: {workshop_id} | Size: {size}" - if text_to_add not in self.added_items: - self.added_items.add(text_to_add) + for zone_path in folder_path.glob("**/zone"): + json_path = zone_path / "workshop.json" + if json_path.exists(): + name = extract_json_data(json_path, "Title").replace(">", "").replace("^", "") + name = name[:45] + "..." if len(name) > 45 else name + item_type = extract_json_data(json_path, "Type") + workshop_id = extract_json_data(json_path, "PublisherID") + folder_name = extract_json_data(json_path, "FolderName") + size = convert_bytes_to_readable(get_folder_size(zone_path.parent)) + text_to_add = f"{name} | Type: {item_type.capitalize()}" + mode_type = "ZM" if item_type == "map" and folder_name.startswith("zm") else "MP" if folder_name.startswith("mp") and item_type == "map" else None + if mode_type: + text_to_add += f" | Mode: {mode_type}" + text_to_add += f" | ID: {workshop_id} | Size: {size}" + if text_to_add not in self.added_items: + self.added_items.add(text_to_add) + image_path = mod_img if item_type == "mod" else map_img - if item_type == "mod": - image_path = os.path.join(RESOURCES_DIR, "mod_image.png") - else: - image_path = os.path.join(RESOURCES_DIR, "map_image.png") + self.add_item(text_to_add, image=ctk.CTkImage(Image.open(image_path)), item_type=item_type, workshop_id=workshop_id, folder=zone_path.parent) - self.add_item(text_to_add, image=ctk.CTkImage(Image.open(image_path)), item_type=item_type, workshop_id=workshop_id, folder=root) if not self.added_items: self.show_no_items_message() else: @@ -153,7 +147,8 @@ class LibraryTab(ctk.CTkScrollableFrame): self.button_list.clear() self.button_view_list.clear() self.added_items.clear() - self.load_items(boiiiFolderGlobal) + from src.main import master_win + self.load_items(master_win.edit_destination_folder.get().strip()) def view_item(self, workshop_id): url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}" @@ -239,7 +234,7 @@ class LibraryTab(ctk.CTkScrollableFrame): image = Image.open(io.BytesIO(image_response.content)) image_size = image.size - self.toplevel_info_window(map_name, map_mod_type, map_size, image, image_size, date_created , + self.toplevel_info_window(map_name, map_mod_type, map_size, image, image_size, date_created, date_updated, stars_image, stars_image_size, ratings_text, url) except requests.exceptions.RequestException as e: diff --git a/boiiiwd_package/src/settings_tab.py b/boiiiwd_package/src/settings_tab.py index c077670..8c4edb8 100644 --- a/boiiiwd_package/src/settings_tab.py +++ b/boiiiwd_package/src/settings_tab.py @@ -218,7 +218,17 @@ class SettingsTab(ctk.CTkFrame): self.boiiiwd_custom_theme() save_config("theme", "boiiiwd_theme.json") if not option == "Custom": - show_message("Restart to take effect!", f"{option} theme has been set ,please restart to take effect", icon="info") + if show_message("Restart to take effect!", f"{option} theme has been set ,please restart to take effect", icon="info", _return=True, option_1="Ok", option_2="Restart"): + try: + p = psutil.Process(os.getpid()) + for handler in p.open_files() + p.connections(): + os.close(handler.fd) + except Exception: + pass + python = sys.executable + os.execl(python, python, *sys.argv) + else: + pass def enable_save_button(self, *args): try: diff --git a/dist/BOIIIWD.exe b/dist/BOIIIWD.exe index f622a79..7fd2eea 100644 Binary files a/dist/BOIIIWD.exe and b/dist/BOIIIWD.exe differ