This commit is contained in:
faroukbmiled 2023-09-20 14:35:02 +01:00
parent c1df8cbcf9
commit cf86eb35f9
8 changed files with 72 additions and 123 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,12 +1,7 @@
import src.shared_vars as main_app
from src.imports import * from src.imports import *
# Start helper functions # Start helper functions
def cwd():
if getattr(sys, 'frozen', False):
return os.path.dirname(sys.executable)
else:
return os.path.dirname(os.path.abspath(__file__))
def check_config(name, fallback=None): def check_config(name, fallback=None):
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(CONFIG_FILE_PATH) config.read(CONFIG_FILE_PATH)
@ -23,8 +18,8 @@ def save_config(name, value):
config.write(config_file) config.write(config_file)
def check_custom_theme(theme_name): def check_custom_theme(theme_name):
if os.path.exists(os.path.join(cwd(), theme_name)): if os.path.exists(os.path.join(application_path, theme_name)):
return os.path.join(cwd(), theme_name) return os.path.join(application_path, theme_name)
else: else:
try: try:
return os.path.join(RESOURCES_DIR, theme_name) return os.path.join(RESOURCES_DIR, theme_name)
@ -191,7 +186,7 @@ def convert_speed(speed_bytes):
def create_default_config(): def create_default_config():
config = configparser.ConfigParser() config = configparser.ConfigParser()
config["Settings"] = { config["Settings"] = {
"SteamCMDPath": cwd(), "SteamCMDPath": application_path,
"DestinationFolder": "", "DestinationFolder": "",
"checkforupdtes": "on", "checkforupdtes": "on",
"console": "off" "console": "off"
@ -202,7 +197,7 @@ def create_default_config():
def get_steamcmd_path(): def get_steamcmd_path():
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(CONFIG_FILE_PATH) config.read(CONFIG_FILE_PATH)
return config.get("Settings", "SteamCMDPath", fallback=cwd()) return config.get("Settings", "SteamCMDPath", fallback=application_path)
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:
@ -254,8 +249,7 @@ def show_message(title, message, icon="warning", _return=False, option_1="No", o
else: else:
def callback(): def callback():
CTkMessagebox(title=title, message=message, icon=icon, sound=True) CTkMessagebox(title=title, message=message, icon=icon, sound=True)
from src.main import master_win main_app.app.after(0, callback)
master_win.after(0, callback)
def launch_boiii_func(path): def launch_boiii_func(path):
procname = "boiii.exe" procname = "boiii.exe"

View File

@ -207,7 +207,7 @@ class LibraryTab(ctk.CTkScrollableFrame):
folders_to_process = [mods_folder, maps_folder] folders_to_process = [mods_folder, maps_folder]
items_file = os.path.join(cwd(), LIBRARY_FILE) items_file = os.path.join(application_path, LIBRARY_FILE)
for folder_path in folders_to_process: for folder_path in folders_to_process:
for zone_path in folder_path.glob("**/zone"): for zone_path in folder_path.glob("**/zone"):
@ -331,7 +331,7 @@ class LibraryTab(ctk.CTkScrollableFrame):
text_to_add += f" | Mode: {mode_type}" text_to_add += f" | Mode: {mode_type}"
text_to_add += f" | ID: {workshop_id} | Size: {size}" text_to_add += f" | ID: {workshop_id} | Size: {size}"
date_added = datetime.now().strftime("%d %b, %Y @ %I:%M%p") date_added = datetime.now().strftime("%d %b, %Y @ %I:%M%p")
items_file = os.path.join(cwd(), LIBRARY_FILE) items_file = os.path.join(application_path, LIBRARY_FILE)
item_info = { item_info = {
"id": workshop_id, "id": workshop_id,
@ -347,7 +347,7 @@ class LibraryTab(ctk.CTkScrollableFrame):
show_message("Error updating json file", f"Error while updating library json file\n{e}") show_message("Error updating json file", f"Error while updating library json file\n{e}")
def remove_item(self, item, folder, id): def remove_item(self, item, folder, id):
items_file = os.path.join(cwd(), LIBRARY_FILE) items_file = os.path.join(application_path, LIBRARY_FILE)
for label, button, button_view_list in zip(self.label_list, self.button_list, self.button_view_list): for label, button, button_view_list in zip(self.label_list, self.button_list, self.button_view_list):
if item == label.cget("text"): if item == label.cget("text"):
self.added_folders.remove(os.path.basename(folder)) self.added_folders.remove(os.path.basename(folder))
@ -480,7 +480,7 @@ class LibraryTab(ctk.CTkScrollableFrame):
date_created ,date_updated, stars_image, stars_image_size, ratings_text, url, workshop_id, invalid_warn): date_created ,date_updated, stars_image, stars_image_size, ratings_text, url, workshop_id, invalid_warn):
def main_thread(): def main_thread():
try: try:
items_file = os.path.join(cwd(), LIBRARY_FILE) items_file = os.path.join(application_path, LIBRARY_FILE)
top = ctk.CTkToplevel(self) top = ctk.CTkToplevel(self)
if os.path.exists(os.path.join(RESOURCES_DIR, "ryuk.ico")): if os.path.exists(os.path.join(RESOURCES_DIR, "ryuk.ico")):
top.after(210, lambda: top.iconbitmap(os.path.join(RESOURCES_DIR, "ryuk.ico"))) top.after(210, lambda: top.iconbitmap(os.path.join(RESOURCES_DIR, "ryuk.ico")))
@ -655,7 +655,7 @@ class LibraryTab(ctk.CTkScrollableFrame):
def check_for_update(): def check_for_update():
lib_data = None lib_data = None
if not os.path.exists(os.path.join(cwd(), LIBRARY_FILE)): if not os.path.exists(os.path.join(application_path, LIBRARY_FILE)):
show_message("Error checking for item updates! -> Setting is on", "Please visit library tab at least once with the correct boiii path!, you also need to have at lease 1 item!") show_message("Error checking for item updates! -> Setting is on", "Please visit library tab at least once with the correct boiii path!, you also need to have at lease 1 item!")
return return

View File

@ -1,61 +1,20 @@
from src.update_window import check_for_updates_func
from src.helpers import * from src.helpers import *
from src.library_tab import LibraryTab from src.library_tab import LibraryTab
from src.settings_tab import SettingsTab from src.settings_tab import SettingsTab
from src.update_window import UpdateWindow
def check_for_updates_func(window, ignore_up_todate=False):
try:
latest_version = get_latest_release_version()
current_version = VERSION
int_latest_version = int(latest_version.replace("v", "").replace(".", ""))
int_current_version = int(current_version.replace("v", "").replace(".", ""))
if latest_version and int_latest_version > int_current_version:
msg_box = CTkMessagebox(title="Update Available", message=f"An update is available! Install now?\n\nCurrent Version: {current_version}\nLatest Version: {latest_version}", option_1="View", option_2="No", option_3="Yes", fade_in_duration=int(1), sound=True)
result = msg_box.get()
if result == "View":
webbrowser.open(f"https://github.com/{GITHUB_REPO}/releases/latest")
if result == "Yes":
update_window = UpdateWindow(window, LATEST_RELEASE_URL)
update_window.start_update()
if result == "No":
return
elif int_latest_version < int_current_version:
if ignore_up_todate:
return
msg_box = CTkMessagebox(title="Up to Date!", message=f"Unreleased version!\nCurrent Version: {current_version}\nLatest Version: {latest_version}", option_1="Ok", sound=True)
result = msg_box.get()
elif int_latest_version == int_current_version:
if ignore_up_todate:
return
msg_box = CTkMessagebox(title="Up to Date!", message="No Updates Available!", option_1="Ok", sound=True)
result = msg_box.get()
else:
show_message("Error!", "An error occured while checking for updates!\nCheck your internet and try again")
except Exception as e:
show_message("Error", f"Error while checking for updates: \n{e}", icon="cancel")
class BOIIIWD(ctk.CTk): class BOIIIWD(ctk.CTk):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
global master_win
master_win = self
# self.app_instance = BOIIIWD() # self.app_instance = BOIIIWD()
# configure window # configure window
self.title("boiii Workshop Downloader - Main") self.title("boiii Workshop Downloader - Main")
try: try:
geometry_file = os.path.join(cwd(), "boiiiwd_dont_touch.conf") geometry_file = os.path.join(application_path, "boiiiwd_dont_touch.conf")
if os.path.isfile(geometry_file): if os.path.isfile(geometry_file):
with open(geometry_file, "r") as conf: with open(geometry_file, "r") as conf:
self.geometry(conf.read()) self.geometry(conf.read())
@ -466,7 +425,7 @@ class BOIIIWD(ctk.CTk):
def load_configs(self): def load_configs(self):
if os.path.exists(CONFIG_FILE_PATH): if os.path.exists(CONFIG_FILE_PATH):
destination_folder = check_config("DestinationFolder", "") destination_folder = check_config("DestinationFolder", "")
steamcmd_path = check_config("SteamCMDPath", os.getcwd()) steamcmd_path = check_config("SteamCMDPath", application_path)
new_appearance_mode = check_config("appearance", "Dark") new_appearance_mode = check_config("appearance", "Dark")
new_scaling = check_config("scaling", 1.0) new_scaling = check_config("scaling", 1.0)
self.edit_destination_folder.delete(0, "end") self.edit_destination_folder.delete(0, "end")
@ -489,7 +448,7 @@ class BOIIIWD(ctk.CTk):
scaling_int = math.trunc(scaling_float) scaling_int = math.trunc(scaling_float)
self.settings_tab.scaling_optionemenu.set(f"{scaling_int}%") self.settings_tab.scaling_optionemenu.set(f"{scaling_int}%")
self.edit_steamcmd_path.delete(0, "end") self.edit_steamcmd_path.delete(0, "end")
self.edit_steamcmd_path.insert(0, cwd()) self.edit_steamcmd_path.insert(0, application_path)
create_default_config() create_default_config()
def help_queue_text_func(self, event=None): def help_queue_text_func(self, event=None):
@ -557,11 +516,11 @@ class BOIIIWD(ctk.CTk):
def download_steamcmd(self): def download_steamcmd(self):
self.edit_steamcmd_path.delete(0, "end") self.edit_steamcmd_path.delete(0, "end")
self.edit_steamcmd_path.insert(0, cwd()) self.edit_steamcmd_path.insert(0, application_path)
save_config("DestinationFolder" ,self.edit_destination_folder.get()) save_config("DestinationFolder" ,self.edit_destination_folder.get())
save_config("SteamCMDPath" ,self.edit_steamcmd_path.get()) save_config("SteamCMDPath" ,self.edit_steamcmd_path.get())
steamcmd_url = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip" steamcmd_url = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip"
steamcmd_zip_path = os.path.join(cwd(), "steamcmd.zip") steamcmd_zip_path = os.path.join(application_path, "steamcmd.zip")
try: try:
response = requests.get(steamcmd_url) response = requests.get(steamcmd_url)
@ -571,7 +530,7 @@ class BOIIIWD(ctk.CTk):
zip_file.write(response.content) zip_file.write(response.content)
with zipfile.ZipFile(steamcmd_zip_path, "r") as zip_ref: with zipfile.ZipFile(steamcmd_zip_path, "r") as zip_ref:
zip_ref.extractall(cwd()) zip_ref.extractall(application_path)
if check_steamcmd(): if check_steamcmd():
os.remove(fr"{steamcmd_zip_path}") os.remove(fr"{steamcmd_zip_path}")
@ -1229,7 +1188,7 @@ class BOIIIWD(ctk.CTk):
if os.path.exists(json_file_path): if os.path.exists(json_file_path):
self.label_speed.configure(text="Installing...") self.label_speed.configure(text="Installing...")
mod_type = extract_json_data(json_file_path, "Type") mod_type = extract_json_data(json_file_path, "Type")
items_file = os.path.join(cwd(), LIBRARY_FILE) items_file = os.path.join(application_path, LIBRARY_FILE)
if self.library_tab.item_exists_in_file(items_file, workshop_id): if self.library_tab.item_exists_in_file(items_file, workshop_id):
get_folder_name = self.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name") get_folder_name = self.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name")
if get_folder_name: if get_folder_name:
@ -1488,7 +1447,7 @@ class BOIIIWD(ctk.CTk):
if os.path.exists(json_file_path): if os.path.exists(json_file_path):
self.label_speed.configure(text="Installing...") self.label_speed.configure(text="Installing...")
mod_type = extract_json_data(json_file_path, "Type") mod_type = extract_json_data(json_file_path, "Type")
items_file = os.path.join(cwd(), LIBRARY_FILE) items_file = os.path.join(application_path, LIBRARY_FILE)
if self.library_tab.item_exists_in_file(items_file, workshop_id): if self.library_tab.item_exists_in_file(items_file, workshop_id):
get_folder_name = self.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name") get_folder_name = self.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name")
if get_folder_name: if get_folder_name:
@ -1593,7 +1552,3 @@ class BOIIIWD(ctk.CTk):
self.after(50, self.status_text.configure(text=f"Status: Standby!")) self.after(50, self.status_text.configure(text=f"Status: Standby!"))
self.after(1, self.label_speed.configure(text=f"Awaiting Download!")) self.after(1, self.label_speed.configure(text=f"Awaiting Download!"))
self.skip_boutton.grid_remove() self.skip_boutton.grid_remove()
# if __name__ == "__main__":
# app = BOIIIWD()
# app.mainloop()

View File

@ -1,47 +1,9 @@
from src.update_window import check_for_updates_func
from src.imports import * from src.imports import *
from src.helpers import * from src.helpers import *
import src.shared_vars as shared import src.shared_vars as shared
def check_for_updates_func(window, ignore_up_todate=False):
try:
latest_version = get_latest_release_version()
current_version = VERSION
int_latest_version = int(latest_version.replace("v", "").replace(".", ""))
int_current_version = int(current_version.replace("v", "").replace(".", ""))
if latest_version and int_latest_version > int_current_version:
msg_box = CTkMessagebox(title="Update Available", message=f"An update is available! Install now?\n\nCurrent Version: {current_version}\nLatest Version: {latest_version}", option_1="View", option_2="No", option_3="Yes", fade_in_duration=int(1), sound=True)
result = msg_box.get()
if result == "View":
webbrowser.open(f"https://github.com/{GITHUB_REPO}/releases/latest")
from src.update_window import UpdateWindow
if result == "Yes":
update_window = UpdateWindow(window, LATEST_RELEASE_URL)
update_window.start_update()
if result == "No":
return
elif int_latest_version < int_current_version:
if ignore_up_todate:
return
msg_box = CTkMessagebox(title="Up to Date!", message=f"Unreleased version!\nCurrent Version: {current_version}\nLatest Version: {latest_version}", option_1="Ok", sound=True)
result = msg_box.get()
elif int_latest_version == int_current_version:
if ignore_up_todate:
return
msg_box = CTkMessagebox(title="Up to Date!", message="No Updates Available!", option_1="Ok", sound=True)
result = msg_box.get()
else:
show_message("Error!", "An error occured while checking for updates!\nCheck your internet and try again")
except Exception as e:
show_message("Error", f"Error while checking for updates: \n{e}", icon="cancel")
class SettingsTab(ctk.CTkFrame): class SettingsTab(ctk.CTkFrame):
def __init__(self, master=None): def __init__(self, master=None):
@ -210,7 +172,7 @@ class SettingsTab(ctk.CTkFrame):
if response == "No": if response == "No":
return return
elif response == "Ok": elif response == "Ok":
os.system(f"notepad {os.path.join(cwd(), 'config.ini')}") os.system(f"notepad {os.path.join(application_path, 'config.ini')}")
else: else:
return return
self.after(0, callback) self.after(0, callback)
@ -398,7 +360,7 @@ class SettingsTab(ctk.CTkFrame):
return 0 return 0
if setting == "theme": if setting == "theme":
if os.path.exists(os.path.join(cwd(), "boiiiwd_theme.json")): if os.path.exists(os.path.join(application_path, "boiiiwd_theme.json")):
return "Custom" return "Custom"
if check_config("theme", "boiiiwd_theme.json") == "boiiiwd_theme.json": if check_config("theme", "boiiiwd_theme.json") == "boiiiwd_theme.json":
return "Default" return "Default"
@ -419,11 +381,11 @@ class SettingsTab(ctk.CTkFrame):
return 0 return 0
def boiiiwd_custom_theme(self, disable_only=None): def boiiiwd_custom_theme(self, disable_only=None):
file_to_rename = os.path.join(cwd(), "boiiiwd_theme.json") file_to_rename = os.path.join(application_path, "boiiiwd_theme.json")
if os.path.exists(file_to_rename): if os.path.exists(file_to_rename):
timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
new_name = f"boiiiwd_theme_{timestamp}.json" new_name = f"boiiiwd_theme_{timestamp}.json"
os.rename(file_to_rename, os.path.join(cwd(), new_name)) os.rename(file_to_rename, os.path.join(application_path, new_name))
if not disable_only: if not disable_only:
show_message("Preset file renamed", "Custom preset disabled, file has been renmaed\n* Restart the app to take effect", icon="info") show_message("Preset file renamed", "Custom preset disabled, file has been renmaed\n* Restart the app to take effect", icon="info")
@ -431,9 +393,9 @@ class SettingsTab(ctk.CTkFrame):
if disable_only: if disable_only:
return return
try: try:
shutil.copy(os.path.join(RESOURCES_DIR, check_config("theme", "boiiiwd_theme.json")), os.path.join(cwd(), "boiiiwd_theme.json")) shutil.copy(os.path.join(RESOURCES_DIR, check_config("theme", "boiiiwd_theme.json")), os.path.join(application_path, "boiiiwd_theme.json"))
except: except:
shutil.copy(os.path.join(RESOURCES_DIR, "boiiiwd_theme.json"), os.path.join(cwd(), "boiiiwd_theme.json")) shutil.copy(os.path.join(RESOURCES_DIR, "boiiiwd_theme.json"), os.path.join(application_path, "boiiiwd_theme.json"))
show_message("Preset file created", "You can now edit boiiiwd_theme.json in the current directory to your liking\n* Edits will apply next time you open boiiiwd\n* Program will always take boiiiwd_theme.json as the first theme option if found\n* Click on this button again to disable your custom theme or just rename boiiiwd_theme.json", icon="info") show_message("Preset file created", "You can now edit boiiiwd_theme.json in the current directory to your liking\n* Edits will apply next time you open boiiiwd\n* Program will always take boiiiwd_theme.json as the first theme option if found\n* Click on this button again to disable your custom theme or just rename boiiiwd_theme.json", icon="info")
def settings_check_for_updates(self): def settings_check_for_updates(self):
@ -587,7 +549,7 @@ class SettingsTab(ctk.CTkFrame):
if os.path.exists(json_file_path): if os.path.exists(json_file_path):
mod_type = extract_json_data(json_file_path, "Type") mod_type = extract_json_data(json_file_path, "Type")
items_file = os.path.join(cwd(), LIBRARY_FILE) items_file = os.path.join(application_path, LIBRARY_FILE)
if shared.app.library_tab.item_exists_in_file(items_file, workshop_id): if shared.app.library_tab.item_exists_in_file(items_file, workshop_id):
get_folder_name = shared.app.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name") get_folder_name = shared.app.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name")

View File

@ -1,10 +1,49 @@
import src.shared_vars as main_app
from src.imports import * from src.imports import *
from src.helpers import * from src.helpers import *
def check_for_updates_func(window, ignore_up_todate=False):
try:
latest_version = get_latest_release_version()
current_version = VERSION
int_latest_version = int(latest_version.replace("v", "").replace(".", ""))
int_current_version = int(current_version.replace("v", "").replace(".", ""))
if latest_version and int_latest_version > int_current_version:
msg_box = CTkMessagebox(title="Update Available", message=f"An update is available! Install now?\n\nCurrent Version: {current_version}\nLatest Version: {latest_version}", option_1="View", option_2="No", option_3="Yes", fade_in_duration=int(1), sound=True)
result = msg_box.get()
if result == "View":
webbrowser.open(f"https://github.com/{GITHUB_REPO}/releases/latest")
if result == "Yes":
update_window = UpdateWindow(window, LATEST_RELEASE_URL)
update_window.start_update()
if result == "No":
return
elif int_latest_version < int_current_version:
if ignore_up_todate:
return
msg_box = CTkMessagebox(title="Up to Date!", message=f"Unreleased version!\nCurrent Version: {current_version}\nLatest Version: {latest_version}", option_1="Ok", sound=True)
result = msg_box.get()
elif int_latest_version == int_current_version:
if ignore_up_todate:
return
msg_box = CTkMessagebox(title="Up to Date!", message="No Updates Available!", option_1="Ok", sound=True)
result = msg_box.get()
else:
show_message("Error!", "An error occured while checking for updates!\nCheck your internet and try again")
except Exception as e:
show_message("Error", f"Error while checking for updates: \n{e}", icon="cancel")
class UpdateWindow(ctk.CTkToplevel): class UpdateWindow(ctk.CTkToplevel):
def __init__(self, master, update_url): def __init__(self, master, update_url):
global master_win
master_win = master
super().__init__(master) super().__init__(master)
self.title("BOIIIWD Self-Updater") self.title("BOIIIWD Self-Updater")
self.geometry("400x150") self.geometry("400x150")
@ -41,7 +80,7 @@ class UpdateWindow(ctk.CTkToplevel):
def update_progress_bar(self): def update_progress_bar(self):
try: try:
update_dir = os.path.join(os.getcwd(), UPDATER_FOLDER) update_dir = os.path.join(application_path, UPDATER_FOLDER)
response = requests.get(LATEST_RELEASE_URL, stream=True) response = requests.get(LATEST_RELEASE_URL, stream=True)
response.raise_for_status() response.raise_for_status()
current_exe = sys.argv[0] current_exe = sys.argv[0]
@ -95,9 +134,8 @@ class UpdateWindow(ctk.CTkToplevel):
self.label_download.configure(text="Update cancelled.") self.label_download.configure(text="Update cancelled.")
self.progress_bar.set(0.0) self.progress_bar.set(0.0)
# there's a better solution ill implement it later # there's a better solution ill implement it later
global master_win
try: try:
master_win.attributes('-alpha', 1.0) main_app.app.attributes('-alpha', 1.0)
except: except:
pass pass
show_message("Cancelled!", "Update cancelled by user", icon="warning") show_message("Cancelled!", "Update cancelled by user", icon="warning")