auto_build_launcher/scripts/project_update_config.py

67 lines
2.3 KiB
Python
Raw Normal View History

2025-10-28 02:04:16 +00:00
import os
import shutil
import javaproperties
from scripts.task import Task
from utils import FileUtils
from utils.logger_utils import app_logger
class ProjectUpdateConfig(Task):
def update_config(self):
if not self.context.update_config:
app_logger().info("配置文件没有更新")
return
"""
更新配置文件
:return:
"""
target_path = self.context.config_path
dst = os.path.join(self.context.temp_project_path, os.path.basename(target_path).replace(".zip", ""))
if os.path.exists(dst):
shutil.rmtree(dst)
result = FileUtils.decompress(target_path, dst)
app_logger().debug(f"{target_path} -> {dst} , 解压结果: {result}")
2025-10-28 02:22:16 +00:00
with open(os.path.join(dst, "tkg_config_mainly.properties"), 'rb') as f:
self.context.config = javaproperties.load(f)
# 不打admob
if self.context.admob_app_id is None or self.context.admob_app_id == "":
self.context.admob_app_id = self.context.get_config("admob_id")
2025-10-28 02:04:16 +00:00
mainly_path = os.path.join(dst, "mainly")
if not os.path.exists(mainly_path):
mainly_path = os.path.join(dst, "appConfig")
google_services_json_path = os.path.join(dst, "google-services.json")
if not os.path.exists(google_services_json_path):
google_services_json_path = os.path.join(dst, "appConfig", "google-services.json")
FileUtils.copy(google_services_json_path,
os.path.join(self.context.temp_project_path, "google-services.json"),
True)
dst_path = os.path.join(self.context.temp_project_path, f"launcher-game{os.sep}assets")
for file in list(filter(lambda f: not (f == "google_fonts.json" or f == "pag_gl_slide.pag"),
os.listdir(dst_path))):
FileUtils.delete(os.path.join(dst_path, file), True)
pass
for file in list(filter(lambda f: f.find(".") <= 0, os.listdir(mainly_path))):
FileUtils.copy(os.path.join(mainly_path, file), os.path.join(dst_path, file), True)
pass
def execute(self):
self.update_config()
self.context.save_cache_config("config", self.context.config_config_md5)
pass