# /*
#  * Copyright (C) 2020, KylinSoft Co., Ltd.
#  *
#  * This program is free software: you can redistribute it and/or modify
#  * it under the terms of the GNU General Public License as published by
#  * the Free Software Foundation, either version 3 of the License, or
#  * (at your option) any later version.
#  *
#  * This program is distributed in the hope that it will be useful,
#  * but WITHOUT ANY WARRANTY; without even the implied warranty of
#  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  * GNU General Public License for more details.
#  *
#  * You should have received a copy of the GNU General Public License
#  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
#  */
import os
import json
import logging
from gettext import gettext as _
from SystemUpdater.Core.enums import *
from SystemUpdater.checks.registry import register_check
from SystemUpdater.constants import CURRENT_PROGRESS,VERSION_MANIFEST_FILE

@register_check("check-update-versions", roles=[ROLE_UPDATE_CACHE])
def check_device_version(trans):
    """
    检查当前进度目录下的版本清单文件，输出每个包的新版本号。
    """
    try:
        version_manifest = os.path.join(CURRENT_PROGRESS, VERSION_MANIFEST_FILE)
        if not os.path.exists(version_manifest):
            return
        
        with open(version_manifest, "r", encoding="utf-8") as f:
            data = json.load(f)

        packages_info = data.get("packages", {})
        if not packages_info:
            logging.info("No package information found in version manifest.")
            return

        for pkg, manifest in packages_info.items():
            new_ver = manifest.get("new_version", "unknown")
            logging.info(f"Package: {pkg}:{new_ver}")
    except Exception as e:
        logging.error("Failed to load version manifest: %s", e)
        return