Merge pull request #29 from faroukbmiled/refactored

Invalid items improvements
This commit is contained in:
Ryuk 2023-10-06 06:15:12 -07:00 committed by GitHub
commit a53a3cdfc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 15 deletions

View File

@ -635,6 +635,16 @@ class LibraryTab(ctk.CTkScrollableFrame):
if offline_date: if offline_date:
down_date = offline_date down_date = offline_date
elif invalid_warn:
try:
zone_path = Path(folder) / "zone"
for ff_file in zone_path.glob("*.ff"):
if ff_file.exists():
creation_timestamp = ff_file.stat().st_mtime
break
down_date = datetime.fromtimestamp(creation_timestamp).strftime("%d %b, %Y @ %I:%M%p")
except:
down_date = "Failed to get download date"
else: else:
down_date = self.get_item_by_id(items_file, workshop_id, 'date') down_date = self.get_item_by_id(items_file, workshop_id, 'date')
@ -683,7 +693,10 @@ class LibraryTab(ctk.CTkScrollableFrame):
main_app.app.edit_workshop_id.delete(0, "end") main_app.app.edit_workshop_id.delete(0, "end")
main_app.app.edit_workshop_id.insert(0, workshop_id) main_app.app.edit_workshop_id.insert(0, workshop_id)
main_app.app.main_button_event() main_app.app.main_button_event()
main_app.app.download_map(update=True) if invalid_warn and check_config("update_invalid", "no") == "yes":
main_app.app.download_map(update=True, invalid_item_folder=os.path.basename(folder))
else:
main_app.app.download_map(update=True)
top.destroy() top.destroy()
return return
else: else:
@ -797,7 +810,9 @@ class LibraryTab(ctk.CTkScrollableFrame):
update_btn.configure(state="disabled") update_btn.configure(state="disabled")
update_btn_tooltip.configure(message="Currently offline") update_btn_tooltip.configure(message="Currently offline")
view_button_tooltip.configure(message="Currently offline") view_button_tooltip.configure(message="Currently offline")
if invalid_warn: if check_config("update_invalid", "no") == "yes":
update_btn_tooltip.configure(message="update_invalid is set to 'yes' in config.ini")
elif invalid_warn:
update_btn.configure(text="Update", state="disabled") update_btn.configure(text="Update", state="disabled")
update_btn_tooltip.configure(message="Disabled due to item being blocked or duplicated") update_btn_tooltip.configure(message="Disabled due to item being blocked or duplicated")

View File

@ -1017,7 +1017,7 @@ class BOIIIWD(ctk.CTk):
self.after(0, callback) self.after(0, callback)
@if_internet_available @if_internet_available
def download_map(self, update=False): def download_map(self, update=False, invalid_item_folder=None):
self.is_downloading = False self.is_downloading = False
self.fail_threshold = 0 self.fail_threshold = 0
if not self.is_pressed: if not self.is_pressed:
@ -1029,7 +1029,7 @@ class BOIIIWD(ctk.CTk):
start_down_thread = threading.Thread(target=self.queue_download_thread, args=(update,)) start_down_thread = threading.Thread(target=self.queue_download_thread, args=(update,))
start_down_thread.start() start_down_thread.start()
else: else:
start_down_thread = threading.Thread(target=self.download_thread, args=(update,)) start_down_thread = threading.Thread(target=self.download_thread, args=(update, invalid_item_folder,))
start_down_thread.start() start_down_thread.start()
else: else:
show_message("Warning", "Already pressed, Please wait.") show_message("Warning", "Already pressed, Please wait.")
@ -1389,7 +1389,7 @@ class BOIIIWD(ctk.CTk):
self.stop_download() self.stop_download()
self.is_pressed = False self.is_pressed = False
def download_thread(self, update=None): def download_thread(self, update=None, invalid_item_folder=None):
try: try:
self.settings_tab.stopped = False self.settings_tab.stopped = False
@ -1580,20 +1580,23 @@ class BOIIIWD(ctk.CTk):
items_file = os.path.join(APPLICATION_PATH, LIBRARY_FILE) items_file = os.path.join(APPLICATION_PATH, LIBRARY_FILE)
item_exists,_ = self.library_tab.item_exists_in_file(items_file, workshop_id) item_exists,_ = self.library_tab.item_exists_in_file(items_file, workshop_id)
if item_exists: if invalid_item_folder:
get_folder_name = self.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name") folder_name = invalid_item_folder
if get_folder_name: else:
folder_name = get_folder_name if item_exists:
get_folder_name = self.library_tab.get_item_by_id(items_file, workshop_id, return_option="folder_name")
if get_folder_name:
folder_name = get_folder_name
else:
try:
folder_name = extract_json_data(json_file_path, self.settings_tab.folder_options.get())
except:
folder_name = extract_json_data(json_file_path, "publisherID")
else: else:
try: try:
folder_name = extract_json_data(json_file_path, self.settings_tab.folder_options.get()) folder_name = extract_json_data(json_file_path, self.settings_tab.folder_options.get())
except: except:
folder_name = extract_json_data(json_file_path, "publisherID") folder_name = extract_json_data(json_file_path, "publisherID")
else:
try:
folder_name = extract_json_data(json_file_path, self.settings_tab.folder_options.get())
except:
folder_name = extract_json_data(json_file_path, "publisherID")
if mod_type == "mod": if mod_type == "mod":
path_folder = os.path.join(destination_folder, "mods") path_folder = os.path.join(destination_folder, "mods")
@ -1622,7 +1625,8 @@ class BOIIIWD(ctk.CTk):
remove_tree(map_folder) remove_tree(map_folder)
remove_tree(download_folder) remove_tree(download_folder)
self.library_tab.update_item(self.edit_destination_folder.get(), workshop_id, mod_type, folder_name) if not invalid_item_folder:
self.library_tab.update_item(self.edit_destination_folder.get(), workshop_id, mod_type, folder_name)
self.show_complete_message(message=f"{mod_type.capitalize()} files were downloaded\nYou can run the game now!\nPS: You have to restart the game \n(pressing launch will launch/restarts)") self.show_complete_message(message=f"{mod_type.capitalize()} files were downloaded\nYou can run the game now!\nPS: You have to restart the game \n(pressing launch will launch/restarts)")
self.button_download.configure(state="normal") self.button_download.configure(state="normal")
self.button_stop.configure(state="disabled") self.button_stop.configure(state="disabled")