def download_missing(self, asset_id, progress_function=None): ''' Downloads assets specified in 'asset_id' that are not already downloaded ''' asset_info = FileTools.read_json(str(self.get_paths(asset_id)["index"])) asset_list = asset_info["objects"] if not (progress_function == None): progress_function("Finding missing assets", 0) asset_dict = dict() if (self._is_virtual(asset_info)): assets_base_path = self.BASE_PATH.joinpath("virtual/" + asset_id) if not assets_base_path.exists(): for asset_name in asset_list.keys(): asset_url = URL([asset_list[asset_name]["hash"][:2], asset_list[asset_name]["hash"]], URL.RESOURCES) asset_dict[asset_url] = str(assets_base_path.joinpath(asset_name)) else: for asset in asset_list.values(): asset_relative_path = [asset["hash"][:2], asset["hash"]] asset_url = URL(asset_relative_path, URL.RESOURCES) asset_path = self.BASE_PATH.joinpath(*(["objects"] + asset_relative_path)) if not asset_path.exists(): asset_dict[asset_url] = str(asset_path) asset_count = 0 asset_total_count = len(asset_dict) for asset_url in asset_dict.keys(): asset_url_object = asset_url.url_object() FileTools.write_object(asset_dict[asset_url], asset_url_object) asset_count += 1 if not (progress_function == None): progress_function("Downloading assets", asset_count/asset_total_count)
def __init__(self, launcher_obj, name, profile_path): self.Launcher = launcher_obj self.profile_name = name self.data_path = profile_path self.metadata = FileTools.read_json(str(self.data_path.joinpath("yamcl_metadata.json"))) self.game_process = None
def __init__(self, launcher_obj): self.Launcher = launcher_obj self.download_exclusive = True self.BASE_PATH = self.Launcher.ROOT_PATH.joinpath("lib") self.index_path = str(self.BASE_PATH.joinpath("index.json")) self.index = FileTools.read_json(self.index_path)
def delete(self, asset_id): ''' Deletes assets 'asset_id' ''' asset_paths = self.get_paths(asset_id) if self._is_virtual(FileTools.read_json(str(asset_paths["index"]))): FileTools.delete_and_clean(str(asset_paths["directory"])) FileTools.delete_and_clean(str(asset_paths["index"])) else: FileTools.delete_and_clean(str(asset_paths["index"])) self._remove_unused_objects(self._get_indexes())
def get_paths(self, asset_id): ''' Returns a dictionary containing the path to the index and directory for assets ID 'asset_id' ''' asset_index_path = self.BASE_PATH.joinpath("indexes/" + asset_id + ".json") if not asset_index_path.exists(): raise Exception("Assets ID " + asset_id + " does not exist") asset_paths = dict() asset_paths["index"] = asset_index_path if self._is_virtual(FileTools.read_json(str(asset_index_path))): asset_paths["directory"] = str(self.BASE_PATH.joinpath("virtual/" + asset_id)) return asset_paths asset_paths["directory"] = self.BASE_PATH.joinpath("objects") return asset_paths
def _remove_unused_objects(self, asset_id_list): ''' Removes assets from the 'objects' folder that are not present in the indexes 'asset_id_list' This does not include virtual assets ''' used_hash_list = list() for asset_id in asset_id_list: current_assets = FileTools.read_json(str(self.get_paths(asset_id)["index"]))["objects"] for resource in current_assets.keys(): current_hash = current_assets[resource]["hash"] if not current_hash in used_hash_list: used_hash_list.append(current_hash) for prefix_hash_dir in self.BASE_PATH.joinpath("objects").iterdir(): for hash_file in prefix_hash_dir.iterdir(): if not hash_file.name in used_hash_list: FileTools.delete_and_clean(str(hash_file))
def __init__(self, launcher_obj): self.Launcher = launcher_obj self.BASE_PATH = self.Launcher.ROOT_PATH.joinpath("bin") self.index_path = str(self.BASE_PATH.joinpath("index.json")) self.index = FileTools.read_json(self.index_path)
def __init__(self, launcher_obj, json_path, custom_bool): self.Launcher = launcher_obj self.is_custom = custom_bool self.info_path = json_path self.json_info = FileTools.read_json(json_path)
def __init__(self, launcher_obj): self.Launcher = launcher_obj self.BASE_PATH = self.Launcher.ROOT_PATH.joinpath("profile") self.index = FileTools.read_json(str(self.BASE_PATH.joinpath("index.json"))) self.profile_instances = dict()