def delete_overrides(): remote_files_data = _load_remote_files_data() for file_name, remote_file_entry in remote_files_data.items(): if isinstance(remote_file_entry, str): continue if remote_file_entry["target_dir"] == "override": try: os.remove(os.path.join(path_finder.get_nwn_path(), "override", file_name)) except: print("Couldn't find for removal: ", os.path.join(path_finder.get_nwn_path(), "override", file_name))
def _trigger_launch(e): config.set_player_name(player_var.get()) utilities.backup_logs() if dm_var.get(): subprocess.Popen(path_finder.get_executable_path() + " -dmc +connect " + config.nwn_server_address + " +password " + dm_pass_var.get(), cwd=path_finder.get_nwn_path()) else: subprocess.Popen(path_finder.get_executable_path() + " +connect " + config.nwn_server_address, cwd=path_finder.get_nwn_path())
def _move_entry(entry): target_dir = entry["target_dir"] src_path = os.path.join("tmp", entry["src_file"]) dst_path = os.path.join(path_finder.get_nwn_path(), target_dir) dst_path = os.path.join(dst_path, entry["target_file"]) filename, file_extension = os.path.splitext(src_path) # If not .gz file, move directly if file_extension != ".gz": if os.path.isfile(dst_path): os.remove(dst_path) shutil.move(src_path,dst_path) # Assume it's gzipped tarball else: print("Unballing ", src_path, "...") tar = tarfile.open(src_path) tar.extractall(os.path.join(path_finder.get_nwn_path(), target_dir)) tar.close() os.remove(src_path)
def _check_update_status(repeat = True): if dependency_manager.do_quit == True: return global gui_update_cycles if repeat: root.after(250, _check_update_status) if dependency_manager.status is dependency_manager.STATUS_DOWNLOADING: current_progress = dependency_manager.current_file_progress current_progress_str = '{0:0.1f}'.format(current_progress*100.0) total_progress = dependency_manager.total_progress total_progress_str = '{0:0.1f}'.format(total_progress*100.0) update_text = ("Downloading " + dependency_manager.file_being_downloaded + '.' * (1 + gui_update_cycles%3) + "\nCurrent progress: " + current_progress_str + " %" + "\nTotal progress: " + total_progress_str) + " %" update_status.set(update_text) elif dependency_manager.status is dependency_manager.STATUS_CHECKING: update_text = ("Checking for updates" + '.' * (1 + gui_update_cycles%3)) update_status.set(update_text) else: update_status.set(dependency_manager.status) if dependency_manager.status is dependency_manager.STATUS_UPDATES_AVAILABLE: update_text = ("Updates are available for " + str(dependency_manager.total_amount_of_updates) + " files,\ntotaling at: " + '{0:0.1f}'.format(dependency_manager.total_size_of_updates/1024.0/1024.0) + " MB\n") update_status.set(update_text) _image_to_enabled(update_button, "update") global update_check_queued if (update_check_queued and dependency_manager.status is not dependency_manager.STATUS_DOWNLOADING and dependency_manager.status is not dependency_manager.STATUS_CHECKING): if path_finder.get_nwn_path() is not path_finder.NO_PATH: t = Thread(target=dependency_manager.start_check, args=()) t.start() update_check_queued = False gui_update_cycles += 1
def _update_checksum_entry(entry, local_checksum_data): file_path = os.path.join(path_finder.get_nwn_path(), entry["target_dir"]) file_path = os.path.join(file_path, entry["name"]) print("Doing checksum for: ", entry["name"]) # Skip generating a checksum for portraits, since there's so bloody many of them! checksum = "portrait" if entry["target_dir"] != "portraits": checksum = _generate_file_md5(file_path) else: return print ("Checksum: ", checksum) modified_at = time.ctime(os.path.getmtime(file_path)) print ("Modified at: ", modified_at) checksum_entry = {} checksum_entry["name"] = entry["name"] checksum_entry["checksum"] = checksum checksum_entry["modified"] = modified_at found_entry = False if checksum_entry["name"] in local_checksum_data: found_entry = True local_checksum_data[checksum_entry["name"]]["checksum"] = checksum_entry["checksum"] if found_entry == False: local_checksum_data[checksum_entry["name"]] = checksum_entry f = open(path_finder.get_local_checksums_path(),'w') f.write(toml.dumps(local_checksum_data)) f.flush() f.close() return checksum_entry
def _find_entry_checksum_match(entry, local_checksum_data) -> bool: file_path = os.path.join(path_finder.get_nwn_path(), entry["target_dir"]) file_path = os.path.join(file_path, entry["name"]) # Bail out early if the file doesn't even exist! if os.path.isfile(file_path) != True: return False # Now it should be safe to bail out if overwriting isn't allowed.. if config.main_conf_values["allow_overwrite"] == 0: return True # And if the file exists and is a portrait, return right away without checksum checking if entry["target_dir"] == "portraits": return True local_entry = None # Check if the entry exists in the local checksum data if entry["name"] in local_checksum_data: local_entry = local_checksum_data[entry["name"]] modified_at = time.ctime(os.path.getmtime(file_path)) # If local entry doesn't exist, create it now if local_entry is None: local_entry = _update_checksum_entry(entry, local_checksum_data) # If time of modification mismatches, recreate the entry. elif local_entry["modified"] != modified_at: local_entry = _update_checksum_entry(entry, local_checksum_data) # Finally check for a matching checksum if local_entry["checksum"] == entry["checksum"]: return True return False
config.main_conf_values["player_names"].append(player_var.get()) config.serialize_to_main_conf(["player_names"], [config.main_conf_values["player_names"]]) player_save_button = Label(text = "Save Name", borderwidth = 0, width=0, padx=2, pady=2, font=config.get_gui_conf("save_button_font", "button_font"), foreground=config.get_gui_conf("save_button_fg_color", "button_enabled_fg_color"), background=config.get_gui_conf("save_button_bg_color", "button_bg_color")) player_save_button.place(in_=mainframe, anchor=config.get_gui_conf("save_button_anchor"), relx=config.get_gui_conf("save_button_pos")[0], rely=config.get_gui_conf("save_button_pos")[1]) player_save_button.bind("<Button-1>",lambda e:_save_player()) nwn_path = StringVar() nwn_path.set(path_finder.get_nwn_path()) nwn_path_label = _create_label(nwn_path) nwn_path_label.place(in_=mainframe, anchor=config.get_gui_conf("nwn_path_label_anchor"), relx=config.get_gui_conf("nwn_path_label_pos")[0], rely=config.get_gui_conf("nwn_path_label_pos")[1]) nwn_path_name_label = Label(text = "NWN Path:", borderwidth = 0, width=0, padx=2, pady=2, font=config.get_gui_conf("nwn_path_name_label_font", "label_font"), foreground=config.get_gui_conf("nwn_path_name_label_fg_color", "label_fg_color"), background=config.get_gui_conf("nwn_path_name_label_bg_color", "label_bg_color")) nwn_path_name_label.place(in_=mainframe, anchor=config.get_gui_conf("nwn_path_name_label_anchor"), relx=config.get_gui_conf("nwn_path_name_label_pos")[0], rely=config.get_gui_conf("nwn_path_name_label_pos")[1])
def _validate_target_dir(entry): target_dir = os.path.join(path_finder.get_nwn_path(), entry["target_dir"]) if not os.path.exists(target_dir): os.makedirs(target_dir)