import os import shutil from pathlib import Path from scripts.task import Task from utils import FileUtils from utils.logger_utils import app_logger class ProjectUpdateImage(Task): def update_image(self): """ 更新游戏的资源 :return: """ if not self.context.update_res_img: app_logger().info("No update image found") return dst = os.path.join(self.context.temp_project_path, "drawable_res") if os.path.exists(dst): shutil.rmtree(dst) FileUtils.decompress(self.context.res_img_path, dst) if os.path.join(dst, "drawable-xxhdpi"): dst = os.path.join(dst, "drawable-xxhdpi") target_root_path = os.path.join(self.context.temp_project_path, f"launcher-game{os.sep}res{os.sep}drawable-xxhdpi") image_list = list(map(lambda f: Path(f).stem, os.listdir(target_root_path))) for file in os.listdir(dst): if file == ".DS_Store": continue res_name = Path(file).stem file_name = self.context.get_map_from_key(res_name) temp_tar = os.path.join(dst, file) temp_dst = os.path.join(target_root_path, file).replace(file_name, self.context.get_map_from_key(res_name)) if file_name in image_list: FileUtils.delete(os.path.join(target_root_path, file_name + ".png")) FileUtils.delete(os.path.join(target_root_path, file_name + ".jpg")) pass app_logger().info(f"copy {temp_tar} => {temp_dst}") FileUtils.copy(temp_tar, temp_dst, True) pass def execute(self): self.update_image() self.context.save_cache_config("res_img", self.context.config_res_img_md5)