|
| 1 | +import os |
| 2 | +import pathlib |
| 3 | + |
| 4 | +from ue4ss_installer_gui.screens import main |
| 5 | + |
| 6 | +import dearpygui.dearpygui as dpg |
| 7 | + |
| 8 | +from ue4ss_installer_gui import data_structures, settings, constants, ue4ss, file_io |
| 9 | + |
| 10 | + |
| 11 | +# make sure it allows multiple game installs of the same game, show some _1 _2 or something |
| 12 | +# have it check the game dir not the game title for if it already exists later |
| 13 | +# if it's not an unreal game make it show a different popup, right now it says it's already in the list |
| 14 | + |
| 15 | + |
| 16 | +def game_dir_actually_has_unreal_game_check(game_dir_path: pathlib.Path): |
| 17 | + acceptable_dirs = [ |
| 18 | + f"{file_io.SCRIPT_DIR}/Engine/Binaries", |
| 19 | + f"{file_io.SCRIPT_DIR}/Engine/Shared", |
| 20 | + f"{file_io.SCRIPT_DIR}/Engine/Shared", |
| 21 | + ] |
| 22 | + acceptable_files = [f"{file_io.SCRIPT_DIR}/Manifest_NonUFSFiles_Win64.txt"] |
| 23 | + for acceptable_dir in acceptable_dirs: |
| 24 | + if os.path.isdir(os.path.normpath(acceptable_dir)): |
| 25 | + return True |
| 26 | + for acceptable_file in acceptable_files: |
| 27 | + if os.path.isfile(os.path.normpath(acceptable_file)): |
| 28 | + return True |
| 29 | + init_not_an_unreal_game_popup(game_dir_path) |
| 30 | + from time import sleep |
| 31 | + |
| 32 | + sleep(0.1) |
| 33 | + dpg.configure_item("not_an_unreal_game_pop_up", show=True) |
| 34 | + return False |
| 35 | + |
| 36 | + |
| 37 | +def call_dismiss_pop_up_game_already_in_list(): |
| 38 | + dpg.delete_item("game_already_exists_popup") |
| 39 | + |
| 40 | + |
| 41 | +def call_dismiss_pop_up_not_unreal_game(): |
| 42 | + dpg.delete_item("not_an_unreal_game_pop_up") |
| 43 | + |
| 44 | + |
| 45 | +def init_not_an_unreal_game_popup(game_directory: pathlib.Path): |
| 46 | + if dpg.does_item_exist("not_an_unreal_game_pop_up"): |
| 47 | + dpg.delete_item("not_an_unreal_game_pop_up") |
| 48 | + dpg.add_window( |
| 49 | + modal=True, |
| 50 | + tag="not_an_unreal_game_pop_up", |
| 51 | + no_title_bar=True, |
| 52 | + min_size=[100, 140], |
| 53 | + ) |
| 54 | + message = " The following game directory does not contain an unreal game:" |
| 55 | + message_two = os.path.normpath(str(game_directory)) |
| 56 | + dpg.add_text(message, parent="not_an_unreal_game_pop_up", wrap=384) |
| 57 | + dpg.add_text(message_two, parent="not_an_unreal_game_pop_up", wrap=384) |
| 58 | + dpg.add_separator(parent="not_an_unreal_game_pop_up") |
| 59 | + dpg.add_button( |
| 60 | + label="Close", |
| 61 | + parent="not_an_unreal_game_pop_up", |
| 62 | + width=-1, |
| 63 | + height=-1, |
| 64 | + callback=call_dismiss_pop_up_not_unreal_game, |
| 65 | + ) |
| 66 | + |
| 67 | + |
| 68 | +def init_game_already_in_list_pop_up(game_directory: pathlib.Path): |
| 69 | + dpg.add_window( |
| 70 | + modal=True, # this is randomly breaking it right now |
| 71 | + tag="game_already_exists_popup", |
| 72 | + no_title_bar=True, |
| 73 | + width=constants.window_width - 200, |
| 74 | + height=constants.window_height - 700, |
| 75 | + pos=(100, constants.y + 100), |
| 76 | + ) |
| 77 | + message = " The following game already exists in the games list:" |
| 78 | + message_two = os.path.normpath(str(game_directory)) |
| 79 | + dpg.add_text(message, parent="game_already_exists_popup", wrap=384) |
| 80 | + dpg.add_text(message_two, parent="game_already_exists_popup", wrap=384) |
| 81 | + dpg.add_separator(parent="game_already_exists_popup") |
| 82 | + dpg.add_button( |
| 83 | + label="Close", |
| 84 | + parent="game_already_exists_popup", |
| 85 | + width=-1, |
| 86 | + height=-1, |
| 87 | + callback=call_dismiss_pop_up_game_already_in_list, |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +def game_already_in_list_check(game_directory: pathlib.Path) -> bool: |
| 92 | + # this checks currently only the games in settings, it needs to also check the autopopulated list |
| 93 | + game_entries = settings.get_settings().get("games", {}) |
| 94 | + is_game_already_in_list = False |
| 95 | + for game_entry in game_entries: |
| 96 | + if os.path.normpath(game_entry["install_dir"]) == os.path.normpath( |
| 97 | + str(game_directory) |
| 98 | + ): |
| 99 | + is_game_already_in_list = True |
| 100 | + break |
| 101 | + if is_game_already_in_list: |
| 102 | + init_game_already_in_list_pop_up(game_directory) |
| 103 | + from time import sleep |
| 104 | + |
| 105 | + sleep(0.1) |
| 106 | + dpg.configure_item("game_already_exists_popup", show=True) |
| 107 | + return True |
| 108 | + return False |
| 109 | + |
| 110 | + |
| 111 | +def add_manual_game_to_settings_file(game_dir_path: pathlib.Path) -> bool: |
| 112 | + was_valid = True |
| 113 | + if game_already_in_list_check(game_dir_path) == True: |
| 114 | + was_valid = False |
| 115 | + if game_dir_actually_has_unreal_game_check(game_dir_path) == False: |
| 116 | + was_valid = False |
| 117 | + if was_valid == False: |
| 118 | + return was_valid |
| 119 | + loaded_settings = settings.get_settings() |
| 120 | + game_entry = data_structures.GameInfo( |
| 121 | + install_dir=game_dir_path, |
| 122 | + game_title=os.path.basename(str(game_dir_path)), |
| 123 | + ue4ss_version=ue4ss.get_default_ue4ss_version_tag(), |
| 124 | + installed_files=[], |
| 125 | + platform=data_structures.GamePlatforms.OTHER, |
| 126 | + ) |
| 127 | + |
| 128 | + new_installed_files = [] |
| 129 | + for file in game_entry.installed_files: |
| 130 | + new_installed_files.append(file) |
| 131 | + |
| 132 | + game_entry_dict = { |
| 133 | + "game_title": game_entry.game_title, |
| 134 | + "install_dir": str(game_entry.install_dir), |
| 135 | + "ue4ss_version": game_entry.ue4ss_version, |
| 136 | + "installed_files": new_installed_files, |
| 137 | + "platform": game_entry.platform.name, |
| 138 | + } |
| 139 | + |
| 140 | + games_list = loaded_settings.get("games", []) |
| 141 | + games_list.append(game_entry_dict) |
| 142 | + loaded_settings["games"] = games_list |
| 143 | + |
| 144 | + settings.save_settings(loaded_settings) |
| 145 | + return was_valid |
| 146 | + |
| 147 | + |
| 148 | +def callback_directory_selected(sender, app_data): |
| 149 | + if add_manual_game_to_settings_file(pathlib.Path(app_data["file_path_name"])): |
| 150 | + dpg.delete_item("directory_picker") |
| 151 | + main.add_new_game_to_games_list(os.path.basename(app_data["file_path_name"])) |
| 152 | + |
| 153 | + |
| 154 | +def choose_directory(): |
| 155 | + if dpg.does_item_exist("directory_picker"): |
| 156 | + dpg.delete_item("directory_picker") |
| 157 | + |
| 158 | + dpg.add_file_dialog( |
| 159 | + directory_selector=True, |
| 160 | + show=True, |
| 161 | + callback=callback_directory_selected, |
| 162 | + tag="directory_picker", |
| 163 | + width=constants.window_width - 80, |
| 164 | + height=constants.window_height - 80, |
| 165 | + modal=True, |
| 166 | + ) |
0 commit comments