This commit is contained in:
faroukbmiled 2023-09-07 14:58:08 +01:00
parent 3eaa56c2ae
commit 2e8fd955ba
6 changed files with 45 additions and 39 deletions

View File

@ -180,7 +180,7 @@ def initialize_steam(master):
master.attributes('-alpha', 1.0) 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}" url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}"
response = requests.get(url) response = requests.get(url)
response.raise_for_status() response.raise_for_status()

View File

@ -155,9 +155,9 @@ def get_steamcmd_path():
return config.get("Settings", "SteamCMDPath", fallback=cwd()) return config.get("Settings", "SteamCMDPath", fallback=cwd())
def extract_json_data(json_path, key): 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) data = json.load(json_file)
return data[key] return data.get(key, '')
def convert_bytes_to_readable(size_in_bytes, no_symb=None): def convert_bytes_to_readable(size_in_bytes, no_symb=None):
for unit in ['B', 'KB', 'MB', 'GB', 'TB']: for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
@ -191,13 +191,13 @@ def get_workshop_file_size(workshop_id, raw=None):
except: except:
return None return None
def show_message(title, message, icon="warning", exit_on_close=False, option_1="No", option_2="Ok"): def show_message(title, message, icon="warning", _return=False, option_1="No", option_2="Ok"):
if exit_on_close: if _return:
msg = CTkMessagebox(title=title, message=message, icon=icon, option_1=option_1, option_2=option_2, sound=True) msg = CTkMessagebox(title=title, message=message, icon=icon, option_1=option_1, option_2=option_2, sound=True)
response = msg.get() response = msg.get()
if response == "No": if response == option_1:
return False return False
elif response == "Ok": elif response == option_2:
return True return True
else: else:
return False return False

View File

@ -3,6 +3,7 @@ from tkinter import Menu, END, Event
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import customtkinter as ctk import customtkinter as ctk
from CTkToolTip import * from CTkToolTip import *
from pathlib import Path
from PIL import Image from PIL import Image
import configparser import configparser
import webbrowser import webbrowser
@ -21,7 +22,7 @@ import io
import os import os
import re import re
VERSION = "v0.2.8" VERSION = "v0.2.9"
GITHUB_REPO = "faroukbmiled/BOIIIWD" GITHUB_REPO = "faroukbmiled/BOIIIWD"
LATEST_RELEASE_URL = "https://github.com/faroukbmiled/BOIIIWD/releases/latest/download/Release.zip" LATEST_RELEASE_URL = "https://github.com/faroukbmiled/BOIIIWD/releases/latest/download/Release.zip"
UPDATER_FOLDER = "update" UPDATER_FOLDER = "update"

View File

@ -89,26 +89,23 @@ class LibraryTab(ctk.CTkScrollableFrame):
button.grid_remove() button.grid_remove()
def load_items(self, boiiiFolder): def load_items(self, boiiiFolder):
# if you add this under init the whole app shrinks for some reason maps_folder = Path(boiiiFolder) / "mods"
global boiiiFolderGlobal mods_folder = Path(boiiiFolder) / "usermaps"
boiiiFolderGlobal = boiiiFolder mod_img = os.path.join(RESOURCES_DIR, "mod_image.png")
maps_folder = os.path.join(boiiiFolder, "mods") map_img = os.path.join(RESOURCES_DIR, "map_image.png")
mods_folder = os.path.join(boiiiFolder, "usermaps")
folders_to_process = [mods_folder, maps_folder] folders_to_process = [mods_folder, maps_folder]
for folder_path in folders_to_process: for folder_path in folders_to_process:
for root, _, _ in os.walk(folder_path): for zone_path in folder_path.glob("**/zone"):
zone_path = os.path.join(root, "zone") json_path = zone_path / "workshop.json"
if os.path.exists(zone_path): if json_path.exists():
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 = extract_json_data(json_path, "Title").replace(">", "").replace("^", "")
name = name[:45] + "..." if len(name) > 45 else name name = name[:45] + "..." if len(name) > 45 else name
item_type = extract_json_data(json_path, "Type") item_type = extract_json_data(json_path, "Type")
workshop_id = extract_json_data(json_path, "PublisherID") workshop_id = extract_json_data(json_path, "PublisherID")
folder_name = extract_json_data(json_path, "FolderName") folder_name = extract_json_data(json_path, "FolderName")
size = convert_bytes_to_readable(get_folder_size(root)) size = convert_bytes_to_readable(get_folder_size(zone_path.parent))
text_to_add = f"{name} | Type: {item_type.capitalize()}" 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 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: if mode_type:
@ -116,13 +113,10 @@ class LibraryTab(ctk.CTkScrollableFrame):
text_to_add += f" | ID: {workshop_id} | Size: {size}" text_to_add += f" | ID: {workshop_id} | Size: {size}"
if text_to_add not in self.added_items: if text_to_add not in self.added_items:
self.added_items.add(text_to_add) self.added_items.add(text_to_add)
image_path = mod_img if item_type == "mod" else map_img
if item_type == "mod": 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)
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=root)
if not self.added_items: if not self.added_items:
self.show_no_items_message() self.show_no_items_message()
else: else:
@ -153,7 +147,8 @@ class LibraryTab(ctk.CTkScrollableFrame):
self.button_list.clear() self.button_list.clear()
self.button_view_list.clear() self.button_view_list.clear()
self.added_items.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): def view_item(self, workshop_id):
url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}" url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={workshop_id}"

View File

@ -218,7 +218,17 @@ class SettingsTab(ctk.CTkFrame):
self.boiiiwd_custom_theme() self.boiiiwd_custom_theme()
save_config("theme", "boiiiwd_theme.json") save_config("theme", "boiiiwd_theme.json")
if not option == "Custom": 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): def enable_save_button(self, *args):
try: try:

BIN
dist/BOIIIWD.exe vendored

Binary file not shown.