tis-itunes-uwp icon

iTunes UWP

Silent install package for iTunes UWP

12129.4.57066.0-48

  • package: tis-itunes-uwp
  • name: iTunes UWP
  • version: 12129.4.57066.0-48
  • categories: Media,Drivers
  • maintainer: WAPT Team,Tranquil IT,Jimmy PELÉ
  • editor: Apple Inc.
  • licence: proprietary_free,wapt_public
  • locale: all
  • target_os: windows
  • impacted_process: iTunesVisualizerHost,iTunesHelper,iTunes,AppleMobileDeviceService
  • architecture: all
  • signature_date:
  • size: 654.77 Mo
  • homepage : https://apple.com/itunes/

package           : tis-itunes-uwp
version           : 12129.4.57066.0-48
architecture      : all
section           : base
priority          : optional
name              : iTunes UWP
categories        : Media,Drivers
maintainer        : WAPT Team,Tranquil IT,Jimmy PELÉ
description       : iTunes is a media player, media library and mobile device management utility distributed by Apple (includes drivers for iPhone, etc.)
depends           : 
conflicts         : 
maturity          : PROD
locale            : all
target_os         : windows
min_wapt_version  : 2.3
sources           : https://apps.microsoft.com/store/detail/9PB2MZ1ZMB1S
installed_size    : 
impacted_process  : iTunesVisualizerHost,iTunesHelper,iTunes,AppleMobileDeviceService
description_fr    : iTunes est un logiciel de lecture et de gestion de bibliothèque multimédia et un utilitaire de gestion des appareils mobiles distribués par Apple (inclus les drivers pour iPhone, etc.)
description_pl    : iTunes to odtwarzacz multimedialny, biblioteka mediów i narzędzie do zarządzania urządzeniami mobilnymi dystrybuowane przez Apple (zawiera sterowniki do iPhone'a itp.)
description_de    : iTunes ist ein von Apple vertriebenes Dienstprogramm zur Verwaltung von Medien, Mediatheken und mobilen Geräten (einschließlich Treibern für das iPhone usw)
description_es    : iTunes es un reproductor multimedia, una biblioteca multimedia y una utilidad de gestión de dispositivos móviles distribuida por Apple (incluye controladores para el iPhone, etc)
description_pt    : O iTunes é um leitor multimédia, biblioteca multimédia e utilitário de gestão de dispositivos móveis distribuído pela Apple (inclui controladores para iPhone, etc)
description_it    : iTunes è un lettore multimediale, una libreria multimediale e un'utility di gestione dei dispositivi mobili distribuita da Apple (include i driver per iPhone, ecc.)
description_nl    : iTunes is een mediaspeler, mediabibliotheek en hulpprogramma voor het beheer van mobiele apparaten dat door Apple wordt gedistribueerd (bevat stuurprogramma's voor iPhone, enz)
description_ru    : iTunes - это медиаплеер, медиатека и утилита для управления мобильными устройствами, распространяемая компанией Apple (включает драйверы для iPhone и т.д.)
audit_schedule    : 
editor            : Apple Inc.
keywords          : apple,itunes,itune,iphone,ipod,touch,ipad
licence           : proprietary_free,wapt_public
homepage          : https://apple.com/itunes/
package_uuid      : 7c882e0a-acc3-42e3-8a3b-56534aa78ad9
valid_from        : 
valid_until       : 
forced_install_on : 
changelog         : https://support.apple.com/kb/index?q=About+the+security+content+of+iTunes&src=globalnav_support&locale=en_US&type=organic&page=search
min_os_version    : 10.0
max_os_version    : 
icon_sha256sum    : a03dcbfd04f59ae7ec1f8be6664f35c25d199a843618aaf69825dd8d9e09853c
signer            : Tranquil IT
signer_fingerprint: 8c5127a75392be9cc9afd0dbae1222a673072c308c14d88ab246e23832e8c6bb
signature         : iEWAQy4qyDTkFn4+EJWjIFVejgVHMwCTc8OoIt4jKPoEb8dKArXdXosL8g7gNG1d9JnWdik7uz5pN1X/Le3RaGChwZicItq3Fj82vgVCbLDy6kZCJccaO1tbyoMG0VHuPSLRu0IrsFTclNpoEHobncUnLiJSCUhfPC1vgKC1CW4qigRVmaStR3FcXVz5jRVidFO6yj0N/RrmmX+65eAjUvR44u/vZd8l+3ElKy8atzKSM8/qAOSE25dLTZJqT15mMCO+fJGdi22FNiU4AaxFE1V8ONm7/4aRD5b+UbtB7obrxqszSk5KdwmRxPDhyJ3LWfIDTBN4UJ8Ype6ArGoxqg==
signature_date    : 2023-07-26T19:02:53.446551
signed_attributes : package,version,architecture,section,priority,name,categories,maintainer,description,depends,conflicts,maturity,locale,target_os,min_wapt_version,sources,installed_size,impacted_process,description_fr,description_pl,description_de,description_es,description_pt,description_it,description_nl,description_ru,audit_schedule,editor,keywords,licence,homepage,package_uuid,valid_from,valid_until,forced_install_on,changelog,min_os_version,max_os_version,icon_sha256sum,signer,signer_fingerprint,signature_date,signed_attributes

# -*- coding: utf-8 -*-
from setuphelpers import *


appx_package_name = "AppleInc.iTunes"
appx_dir = makepath(programfiles, "WindowsAppsInstallers")
allow_remove = True
remove_sources = False  # remove_sources = True may prevent multi-user installations.


def install():
    # Declare local variables
    bins_dir = control.package.split("-", 1)[1]
    appx_bins_dir = makepath(appx_dir, bins_dir)

    # Remove from old path
    for appx_file in glob.glob(makepath(appx_dir, "%s_*" % appx_package_name)):
        remove_file(appx_file)

    # Placing bins for session-setup installs
    if isdir(appx_bins_dir):
        remove_tree(appx_bins_dir)
    mkdirs(appx_bins_dir)
    print(f"Creating: {appx_bins_dir}")
    for f in glob.glob(bins_dir + "/*"):
        filecopyto(f, appx_bins_dir)
    for f in glob.glob(appx_bins_dir + "/*"):
        fname = f.split(os.sep)[-1]
        if control.architecture == "all":
            if "x86" in glob.glob(makepath(appx_bins_dir, f"{appx_package_name}_*"))[0].split(os.sep)[-1]:
                if not "x86" in fname and not "neutral" in fname:
                    remove_file(f)
            else:
                if not get_host_architecture() in fname and not "neutral" in fname:
                    remove_file(f)
        else:
            if not get_host_architecture() in fname and not "neutral" in fname:
                remove_file(f)


def session_setup():
    # Declare local variables
    bins_dir = control.package.split("-", 1)[1]
    appx_bins_dir = makepath(appx_dir, bins_dir)
    try:
        bin_path = glob.glob(makepath(appx_bins_dir, f"{appx_package_name}_*"))[0]
    except:
        error("Unable to find sources, please reinstall this package (change remove_sources to False if necessary)")
    dependencies_pathes = ",".join([f'"{a}"' for a in glob.glob(makepath(appx_bins_dir, "*")) if not appx_package_name in a])

    # Installing the UWP application in the user environment
    try:
        appx_version = get_powershell_str(f'Get-AppxPackage -Name "{appx_package_name}"', "Version")
    except:
        appx_version = "0"
    if not appx_version or Version(appx_version) < Version(control.get_software_version()) or force:
        print("Installing: %s" % bin_path.split("\\")[-1])
        killalltasks(control.get_impacted_process_list())
        add_appx_cmd = f'Add-AppxPackage -Path "{bin_path}"'
        if dependencies_pathes:
            add_appx_cmd += f" -DependencyPath {dependencies_pathes}"
        run_powershell(add_appx_cmd)
    else:
        print(f"{appx_package_name} ({appx_version}) is installed and up-to-date")


def audit():
    bins_dir = control.package.split("-", 1)[1]
    appx_bins_dir = makepath(appx_dir, bins_dir)
    try:
        appx_version = get_powershell_str(f'Get-AppxPackage -Name "{appx_package_name}"', "Version")
        appx_installlocation = get_powershell_str(f'Get-AppxPackage -Name "{appx_package_name}"', "InstallLocation")
    except:
        appx_version = "0"
        appx_installlocation = "notfound"
    if dir_is_empty(appx_installlocation):
        print(f"Removing: {appx_bins_dir} since dir is empty")
    if isdir(appx_installlocation):
        if Version(appx_version) >= Version(control.get_software_version()):
            if remove_sources:
                print(f"Removing: {appx_bins_dir} since App is installed and up-to-date")
                remove_tree(appx_bins_dir)
            else:
                print(f"{appx_installlocation} is installed and up-to-date")
        else:
            print(f"{appx_installlocation} is installed but outdated")
    else:
        print(f"No user seems to have installed {appx_package_name} on this PC at the moment")

    return "OK"


def uninstall():
    # Declare local variables
    bins_dir = control.package.split("-", 1)[1]
    appx_bins_dir = makepath(appx_dir, bins_dir)

    if allow_remove:
        remove_appx(appx_package_name)
    if isdir(appx_bins_dir):
        print("Removing: %s" % (appx_bins_dir))
        remove_tree(appx_bins_dir)
    if dir_is_empty(appx_dir):
        print("Removing: %s since it is empty" % (appx_dir))
        remove_tree(appx_dir)

# -*- coding: utf-8 -*-
from setuphelpers import *
import requests
import re
import json
import os
import sys

if "__file__" in locals():
    sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
from setupdevhelpers import *


def update_package():
    # Declaring local variables
    package_updated = False
    proxies = get_proxies()
    if not proxies:
        proxies = get_proxies_from_wapt_console()
    microsoft_store_url = control.sources
    if not microsoft_store_url:
        store_id = ask_input(
            control.package,
            "Enter the application ProductId or the link from the Microsoft Store (web address: https://apps.microsoft.com/store/apps)",
            microsoft_store_url,
        ).split("/")[-1]
    else:
        store_id = microsoft_store_url.split("/")[-1]
    store_id = store_id.split("?")[0].split("#")[0]
    if store_id:
        microsoft_store_url = "https://apps.microsoft.com/store/detail/%s" % store_id
        control.sources = microsoft_store_url
        control.save_control_to_wapt()
    package_prefix = control.package.split("-")[0]
    selected = None

    # check setup.py incase the package name does not match the installer file
    appx_package_name = ""
    with open("setup.py", "r", encoding="utf8") as f:
        for line in f.readlines():
            if line.startswith("appx_package_name"):
                appx_package_name = line.split("=")[1].split('"')[1]
                break
    old_appx_package_name = appx_package_name

    # Getting info from adguard api
    res = requests.post(
        "https://store.rg-adguard.net/api/GetFiles",
        "type=ProductId&url=%s&ring=RP&lang=fr-FR" % store_id,
        headers={"content-type": "application/x-www-form-urlencoded"},
        proxies=proxies,
    )
    all_files = []
    for bs_search in bs_find_all(res.text, "a"):
        if not "BlockMap" in bs_search.text and not "eappxbundle" in bs_search.text and not "emsixbundle" in bs_search.text:
            # bin_name = bs_search.text.replace("~", "_")
            bin_name = str(bs_search.text)
            if not get_file_extension(bin_name):
                continue
            version = bin_name.split("_")[1]
            download_url = bs_search["href"]
            pkg_splitted = re.split(r"_\d+\.", bin_name)[0]
            package_name = package_prefix + "-" + pkg_splitted.split("_")[0].replace(".", "-").lower()
            software_name = bin_name.split("_")[0].replace("-", " ").replace(".", " ")
            package_arch = get_uwp_filename_arch(bin_name, appx_package_name)
            file_dict = {
                "version": version,
                "bin_name": bin_name,
                "package_name": package_name,
                "software_name": software_name,
                "package_arch": package_arch,
                "download_url": download_url,
            }
            all_files.append(file_dict)
    if (
        "template-microsoft-store" in control.package
        or not appx_package_name
        or not len([a for a in all_files if appx_package_name in a["bin_name"]]) != 0
    ):
        if not all_files:
            error(f"API returned an empty list for URL: {microsoft_store_url}, please try again")
        selected = ask_grid(
            "Please select the App version that you want to package",
            all_files,
            "GRT_SELECTED",
            '{"columns":[{"propertyname":"version","datatype":"String","required":false,"readonly":false,"width":130},{"propertyname":"bin_name","datatype":"String","required":false,"readonly":false,"width":420},{"propertyname":"package_name","datatype":"String","required":false,"readonly":false,"width":190},{"propertyname":"software_name","datatype":"String","required":false,"readonly":false,"width":172},{"propertyname":"package_arch","datatype":"String","required":false,"readonly":false,"width":88},{"propertyname":"download_url","datatype":"String","required":false,"readonly":false,"width":1472}]}',
        )
        appx_package_name = selected[0]["bin_name"].split("_")[0]

    # Updating package.json ignored_versions list
    if isfile("package.json"):
        package_json = json_load_file("package.json")
    else:
        package_json = {"ignored_versions": []}
    if selected:
        ignored_versions = list(
            set(
                package_json["ignored_versions"]
                + [v["version"] for v in all_files if appx_package_name in v["bin_name"] and v["version"] != selected[0]["version"]]
            )
        )
        ignored_versions.sort()
        package_json["ignored_versions"] = ignored_versions
        json_write_file("package.json", package_json)
    else:
        ignored_versions = package_json["ignored_versions"]

    # Updating setup.py appx_package_name variable
    new_lines = []
    with open("setup.py", "r", encoding="utf8") as f:
        for line in f.readlines():
            if line.startswith("appx_package_name"):
                line = 'appx_package_name = "%s"\n' % appx_package_name
            new_lines.append(line)
    with open("setup.py", "w", encoding="utf8", newline="\n") as f:
        f.writelines(new_lines)

    # Downloading app files
    download_app_files(all_files, appx_package_name, proxies=proxies, ignored_versions=ignored_versions)

    # # Import xmltodict for make_uwp_app_dict()
    # if not isfile("xmltodict.py"):
    #     pip_download_xmltodict = "waptpython -m pip download xmltodict -d %s" % basedir
    #     if proxies:
    #         pip_download_xmltodict += " --proxy %s" % proxies["http"]
    #     run(pip_download_xmltodict)
    #     unzip(glob.glob("*.whl")[0], ".", "xmltodict.py")
    #     remove_file(glob.glob("*.whl")[0])

    # Keep app files
    uwp_app_dict = make_uwp_app_dict(appx_package_name)
    newer_uwp_app = get_newer_uwp_app(uwp_app_dict, tdf_list=None)
    version = newer_uwp_app["Version"]

    # Downloading dependency files
    dependencies_to_download = []
    if newer_uwp_app["Dependencies"]:
        for dependency in newer_uwp_app["Dependencies"]:
            dependencies_to_download.append(get_newer_uwp_depency(dependency, all_files, min_version=dependency["MinVersion"]))
    if dependencies_to_download:
        for dependency_file in all_files:
            latest_bin = dependency_file["bin_name"]
            if not True in [d in latest_bin for d in dependencies_to_download]:  # ignore unecessary dependencies
                continue
            if control.architecture != "all" and type(control_get_architecture_list(control)) != list:
                if not control.architecture in latest_bin and not "neutral" in latest_bin:
                    continue
            if latest_bin.split(".")[-1].lower().startswith("e"):  # ignore encrypted uwp apps
                continue
            download_url = dependency_file["download_url"]
            if download_url.split("/")[2].endswith("microsoft.com"):
                if not isfile(latest_bin):
                    print("Downloading: %s" % latest_bin)
                    wget(download_url, latest_bin, proxies=proxies)
                else:
                    print("Binary is present: %s" % latest_bin)
            else:
                error("ERROR: The retrieved URL will not download from microsoft's servers")

    # No dependencies since it will be contained
    control.depends = ""
    control.save_control_to_wapt()

    # Applying or asking control information if needed
    if len(control_get_architecture_list(control)) <= 1:
        control.architecture = get_uwp_filename_arch(newer_uwp_app["FileName"], newer_uwp_app["Name"])

    # Only asking once
    if not old_appx_package_name or old_appx_package_name != appx_package_name:
        # control.min_os_version and control.max_os_version
        set_control_os_version_uwp_app(newer_uwp_app)

        # control.name
        bs_name = bs_find(str(bs_find(microsoft_store_url, "head").contents), "meta", "property", "og:title")["content"]
        control_name = bs_name.split("Get ")[-1].split(" from the Microsoft Store")[0]
        control_name = complete_control_name(control, control_name)

        # control.package
        control_package = package_prefix + "-" + control_name.lower()
        complete_control_package(control, control_package, params.get("running_as_luti"))

        # control.description
        control_description = bs_find(str(bs_find(microsoft_store_url + "?hl=en-us&gl=us", "head").contents), "meta", "property", "og:description")[
            "content"
        ]

        complete_control_description(control, control_description, params.get("running_as_luti"), "update_package", 250)

        # control.description_fr = (
        #     bs_find(str(bs_find(microsoft_store_url + "?hl=fr-fr&gl=fr", "head").contents), "meta", "property", "og:description")["content"]
        #     .split(". ")[0]
        #     .replace("’", "'")
        # )

        # control.categories
        complete_control_categories(control)

    # Get icon.png
    icon_png = []
    if "b4:Dependencies" in newer_uwp_app:
        if newer_uwp_app["b4:Dependencies"]:
            unzip(newer_uwp_app["FileName"], ".", newer_uwp_app["b4:Dependencies"][0]["FileName"], False)
            icon_png = unzip(newer_uwp_app["b4:Dependencies"][0]["FileName"], ".", "*.targetsize-48_altform-unplated.png", False)
            if not icon_png:
                icon_png = unzip(newer_uwp_app["b4:Dependencies"][0]["FileName"], ".", "*.targetsize-48.png", False)
            if not icon_png:
                icon_png = unzip(newer_uwp_app["b4:Dependencies"][0]["FileName"], ".", "**/PkgSmallLogo.png", False)
            if icon_png:
                shutil.move(icon_png[0], "WAPT\\icon.png")
    if not icon_png:
        icon_png = unzip(newer_uwp_app["FileName"], ".", "*.targetsize-48_altform-unplated.png", False)
        if not icon_png:
            icon_png = unzip(newer_uwp_app["FileName"], ".", "*.targetsize-48.png", False)
        if icon_png:
            shutil.move(icon_png[0], "WAPT\\icon.png")
    [remove_file(a) for a in glob.glob("*.png")]

    # Placing binaries in a dir ["appxbundle", "msixbundle", "appx", "msix]
    for f in glob.glob("*.part"):
        remove_file(f)
    bins_dir = control.package.split("-", 1)[1]
    if isdir(bins_dir):
        remove_tree(bins_dir)
    mkdirs(bins_dir)
    for uwp_file in glob.glob(f'{newer_uwp_app["Name"]}*{newer_uwp_app["Version"]}*.*'):
        if not isfile(makepath(bins_dir, uwp_file)):
            shutil.move(uwp_file, bins_dir)
    if uwp_app_dict[newer_uwp_app["FileName"]]["Dependencies"] is not None:
        for l in [glob.glob(a["Name"] + "_*") for a in uwp_app_dict[newer_uwp_app["FileName"]]["Dependencies"]]:
            for f in l:
                if not isfile(makepath(bins_dir, f)):
                    shutil.move(f, bins_dir)

    # Removing remaining files ["appxbundle", "msixbundle", "appx", "msix]
    for f in glob.glob("*.appxbundle") + glob.glob("*.msixbundle") + glob.glob("*.appx") + glob.glob("*.msix"):
        remove_file(f)

    # Changing version of the package and validating update-package-sources
    return complete_control_version(control, version)


def control_get_architecture_list(control=None):
    """Return the list of the package compatible architectures

    Returns:
        List[str] architecture list
    """
    return [a.strip() for a in control.architecture.split(",")]


def json_write_file(json_file, data, indent=4, sort_keys=False, encoding="utf-8", newline="\n"):
    """
    Write dictionary to a JSON file.

    Args:
        json_file (str): Path to the JSON file.
        data (dict): Dictionary content.
        indent (int or str): Tabulation size for indentation; default: 4 spaces.
        sort_keys (bool): Sort the keys alphabetically or not; default: False.
        encoding (str): File encoding; default: 'utf-8'.
        newline (str): Newline character(s) to use; default: 'LF'.
    """
    with open(json_file, "w", encoding=encoding, newline=newline) as write_file:
        json.dump(data, write_file, sort_keys=sort_keys, indent=indent)


def download_app_files(all_files, appx_package_name, proxies=None, ignored_versions=[]):
    for app_file in all_files:
        latest_bin = app_file["bin_name"]
        if not latest_bin.startswith(f"{appx_package_name}_"):  # ignore other files
            continue
        if latest_bin.split(".")[-1].lower().startswith("e"):  # ignore encrypted UWP apps
            continue
        if any(
            Version(app_file["version"], len(ignored_version.split("."))) == Version(ignored_version, len(ignored_version.split(".")))
            for ignored_version in ignored_versions
        ):
            continue
        download_url = app_file["download_url"]
        if download_url.split("/")[2].endswith("microsoft.com"):
            if not isfile(latest_bin):
                print("Downloading: %s" % latest_bin)
                wget(download_url, latest_bin, proxies=proxies)
            else:
                print("Binary is present: %s" % latest_bin)
        else:
            error("ERROR: The retrieved URL will not download from Microsoft's servers")


def get_uwp_filename_arch(appx_filename, appx_package_name=None):
    if not appx_package_name:
        appx_package_name = None
    if len(glob.glob(f'{appx_package_name}*{appx_filename.split("_")[1]}*')) > 1:
        pass
    elif "arm64" in appx_filename:
        return "arm64"
    elif "arm" in appx_filename:
        return "arm"
    elif "x64" in appx_filename:
        return "x64"
    if appx_filename is not None and "x86" in appx_filename and (appx_package_name is None or not appx_package_name in appx_filename):
        return "x86"

    return "all"


def get_newer_uwp_app(uwp_app_dict, version_prefix=None, min_version=None, max_version=None, tdf_list=["Windows.Universal", "Windows.Desktop"]):
    """Get the newer Universal Windows Platform (UWP) app from a dictionary of UWP apps based on specified criteria.

    Args:
        uwp_app_dict (dict): A dictionary containing UWP app information with app IDs as keys and app details as values.
        version_prefix (str, optional): The prefix of the version number to filter the apps. Defaults to None.
        min_version (str, optional): The minimum version of the UWP app. Defaults to None.
        max_version (str, optional): The maximum version of the UWP app. Defaults to None.
        tdf_list (list, optional): A list of target device families to filter the apps. Defaults to ["Windows.Universal", "Windows.Desktop"].

    Returns:
        dict or None: The dictionary containing the details of the newer UWP app that matches the specified criteria, or None if no app is found.

    """
    newer_version = "0"

    for uwp_app in uwp_app_dict.values():
        to_skip = True
        if version_prefix is not None and Version(uwp_app["Version"], len(version_prefix.split("."))) != Version(
            version_prefix, len(version_prefix.split("."))
        ):
            continue
        if tdf_list is not None and uwp_app["TargetDeviceFamily"] is not None:
            if not uwp_app["TargetDeviceFamily"]:
                continue
            for tdf in tdf_list:
                for uwp_app_tdf in uwp_app["TargetDeviceFamily"]:
                    if (
                        tdf == uwp_app_tdf["Name"]
                        and (min_version is None or Version(min_version, 3) == Version(uwp_app_tdf["MinVersion"], 3))
                        and (max_version is None or Version(max_version, 3) == Version(uwp_app_tdf["MaxVersionTested"], 3))
                    ):
                        to_skip = False
        else:
            to_skip = False

        if to_skip:
            continue

        if control.max_os_version:
            if not Version(uwp_app["MinVersion"], 3) < Version(control.max_os_version, 3):
                continue
        if Version(newer_version) < Version(uwp_app["Version"]):
            newer_uwp_app = uwp_app
            newer_version = newer_uwp_app["Version"]
    return newer_uwp_app


def get_newer_uwp_depency(dependency_dict, all_files_dict, version_prefix=None, min_version=None):
    """Returns a list of the bin_name of the latest required dependencies"""
    newer_version = "0"

    for uwp_app in all_files_dict:
        if not uwp_app["bin_name"].startswith(f'{dependency_dict["Name"]}_'):
            continue
        if version_prefix is not None and Version(uwp_app["version"], len(version_prefix.split("."))) != Version(
            version_prefix, len(version_prefix.split("."))
        ):
            continue

        if Version(newer_version) < Version(uwp_app["version"]):
            newer_uwp_depency = uwp_app
            newer_version = uwp_app["version"]

    return newer_uwp_depency["bin_name"].split(newer_version + "_")[0] + newer_version + "_"


def make_uwp_app_dict(appx_package_name):
    import xmltodict

    ms_app_db = {}
    # for ms_app_file in (
    #     glob.glob("*.appxbundle")
    #     + glob.glob("*.msixbundle")
    #     + glob.glob("*.appx")
    #     + glob.glob("*.msix")
    # ):
    for ms_app_file in (
        glob.glob(f"{appx_package_name}*.appxbundle")
        + glob.glob(f"{appx_package_name}*.msixbundle")
        + glob.glob(f"{appx_package_name}*.appx")
        + glob.glob(f"{appx_package_name}*.msix")
    ):
        data_dict = {}
        before_dependencies = []
        sub_dependencies = []
        dependency_data_dict = None

        manifest = unzip(ms_app_file, ".", "AppxManifest.xml", False)
        bundle_manifest = unzip(ms_app_file, ".", "AppxMetadata\\AppxBundleManifest.xml", False)
        ms_app_info = {
            "FileName": ms_app_file,
        }

        if not manifest:
            if bundle_manifest:
                with open(bundle_manifest[0], encoding="utf8") as xml_file:
                    data_dict = xmltodict.parse(xml_file.read(), attr_prefix="")

                if type(data_dict["Bundle"]["Packages"]["Package"]) == dict:
                    data_dict["Bundle"]["Packages"]["Package"] = [dict(data_dict["Bundle"]["Packages"]["Package"])]

                for app_pkg in list(data_dict["Bundle"]["Packages"]["Package"]):
                    if app_pkg["Type"] == "application":
                        before_dependency_info = {
                            "FileName": app_pkg["FileName"],
                            "Version": app_pkg["Version"],
                            "Architecture": app_pkg["Architecture"],
                        }
                        before_dependencies.append(before_dependency_info)

                if before_dependencies:
                    for dependency in before_dependencies:
                        unzip(
                            ms_app_file,
                            ".",
                            makepath(
                                dependency["FileName"],
                            ),
                            False,
                        )
                        manifest = unzip(dependency["FileName"], ".", makepath("AppxManifest.xml"), False)
                        if isfile(dependency["FileName"]):
                            remove_file(dependency["FileName"])
                        with open(manifest[0], encoding="utf8") as xml_file:
                            dependency_data_dict = xmltodict.parse(xml_file.read(), attr_prefix="")

                    if dependency_data_dict["Package"].get("Dependencies"):
                        if dependency_data_dict["Package"]["Dependencies"].get("PackageDependency"):
                            sub_dependencies = list(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"])
                            if type(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"]) == dict:
                                sub_dependencies = [dict(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"])]
                            if type(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"]) == list:
                                sub_dependencies = dependency_data_dict["Package"]["Dependencies"]["PackageDependency"]
                        if dependency_data_dict["Package"]["Dependencies"].get("TargetDeviceFamily"):
                            if not "TargetDeviceFamily" in ms_app_info:
                                if type(dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"]) == dict:
                                    ms_app_info["TargetDeviceFamily"] = [dict(dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"])]
                                if type(dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"]) == list:
                                    ms_app_info["TargetDeviceFamily"] = dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"]
            else:
                error("nothing to parse")
        else:
            manifest = unzip(ms_app_file, ".", makepath("AppxManifest.xml"), False)
            with open(manifest[0], encoding="utf8") as xml_file:
                dependency_data_dict = xmltodict.parse(xml_file.read(), attr_prefix="")

        if dependency_data_dict["Package"].get("Dependencies"):
            if "PackageDependency" in dependency_data_dict["Package"]["Dependencies"]:
                sub_dependencies = list(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"])
                if type(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"]) == dict:
                    sub_dependencies = [dict(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"])]
                if type(dependency_data_dict["Package"]["Dependencies"]["PackageDependency"]) == list:
                    sub_dependencies = dependency_data_dict["Package"]["Dependencies"]["PackageDependency"]
            if "TargetDeviceFamily" in dependency_data_dict["Package"]["Dependencies"]:
                if not "TargetDeviceFamily" in ms_app_info:
                    if type(dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"]) == dict:
                        ms_app_info["TargetDeviceFamily"] = [dict(dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"])]
                    if type(dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"]) == list:
                        ms_app_info["TargetDeviceFamily"] = dependency_data_dict["Package"]["Dependencies"]["TargetDeviceFamily"]
        else:
            ms_app_info.update({"Dependencies": None})

        if ms_app_info.get("TargetDeviceFamily"):
            ms_app_info.update(
                {
                    "MinVersion": ms_app_info["TargetDeviceFamily"][0]["MinVersion"],
                    "MaxVersionTested": ms_app_info["TargetDeviceFamily"][0]["MaxVersionTested"],
                }
            )
        elif dependency_data_dict is not None and dependency_data_dict["Package"].get("Prerequisites"):
            ms_app_info.update(
                {
                    "MinVersion": dependency_data_dict["Package"]["Prerequisites"]["OSMinVersion"],
                    "MaxVersionTested": dependency_data_dict["Package"]["Prerequisites"]["OSMaxVersionTested"],
                }
            )
        else:
            ms_app_info.update({"TargetDeviceFamily": None})

        if data_dict:
            ms_app_info.update(data_dict["Bundle"]["Identity"])
        else:
            ms_app_info.update(dependency_data_dict["Package"]["Identity"])
        if "ProcessorArchitecture" in ms_app_info:
            ms_app_info.update({"Architecture": ms_app_info["ProcessorArchitecture"]})
        if before_dependencies:
            ms_app_info["b4:Dependencies"] = before_dependencies
        else:
            ms_app_info.update({"b4:Dependencies": None})

        if sub_dependencies:
            ms_app_info["Dependencies"] = sub_dependencies
        else:
            ms_app_info.update({"Dependencies": None})

        ms_app_db[ms_app_file] = ms_app_info

        for xml_file in glob.glob("AppxManifest.xml") + glob.glob("AppxBundleManifest.xml"):
            remove_file(xml_file)

    return ms_app_db


def set_control_os_version_uwp_app(
    newer_uwp_app,
    force_values=False,
    priority_windows=WindowsVersions.Windows11,
    eol_windows=WindowsVersions.Windows10v2004,
    silent=False,
):
    if newer_uwp_app.get("MinVersion") and newer_uwp_app.get("MaxVersionTested"):
        control.min_os_version = ".".join(newer_uwp_app["MinVersion"].split(".")[: 2 if newer_uwp_app["MinVersion"].endswith("0") else 3])
        # MaxVersionTested value seems not reliable, now asking to change control.max_os_version
        if not Version(newer_uwp_app["MaxVersionTested"], 3) <= eol_windows:  # Ignore end-of-life Windows versions
            if control.max_os_version != ".".join(newer_uwp_app["MaxVersionTested"].split(".")[:3]):
                if force_values:
                    control.max_os_version = ".".join(newer_uwp_app["MaxVersionTested"].split(".")[:3])
                else:
                    if not silent:
                        control_max_os_version = ask_input(
                            control.package,
                            f'INFO: You may wanna change "control.max_os_version" by "{".".join(newer_uwp_app["MaxVersionTested"].split(".")[:3])}" or "{newer_uwp_app["MaxVersionTested"]}"',
                            "",
                            raise_error=False,
                        )
                    if control_max_os_version or control_max_os_version == "":
                        control.max_os_version = control_max_os_version
                    else:
                        print(
                            f'INFO: You may wanna change "control.max_os_version" by "{".".join(newer_uwp_app["MaxVersionTested"].split(".")[:3])}"'
                        )
        else:
            if control.max_os_version != "":
                if force_values:
                    control.max_os_version = ""
                else:
                    if not silent:
                        control_max_os_version = ask_message(
                            control.package,
                            f'INFO: You may wanna erase "control.max_os_version    : {control.max_os_version}"',
                            3 + 32,
                            raise_error=False,
                        )
                    if control_max_os_version == 6:
                        control.max_os_version = ""
    control.save_control_to_wapt()

689417d9edc1db02aa22765e74020e839cd58c7e5dd4172e29be2fe7e0307036 : setup.py
e8dd4ba88bb065e6c47a7aa490119eaaca1eaac13d5a2428c86ab7a1e200932d : itunes-uwp/Microsoft.VCLibs.140.00.UWPDesktop_14.0.32530.0_x64__8wekyb3d8bbwe.appx
4a6e78afa9f9dc80959e32c452f7c37f9bbe03de8a649d378528abf8e7772bed : itunes-uwp/AppleInc.iTunes_12129.4.57066.0_x86.appx
e5a3f50abe704ff748e89fe3eee9d3f1dde0e524c9a3ecd28c03ed0d537707e6 : itunes-uwp/Microsoft.VCLibs.140.00.UWPDesktop_14.0.32530.0_arm__8wekyb3d8bbwe.appx
6d161a38669cbabf100fb559663a9368a48126af29e62f6804cb09246ea490ab : itunes-uwp/AppleInc.iTunes_12129.4.57066.0_neutral_~_nzyj5cx40ttqa.appxbundle
d0d184f3e05c2c989d573ccabc2f7a65d0f1ac5aa1d91e5f82aee2342c970280 : itunes-uwp/Microsoft.VCLibs.140.00.UWPDesktop_14.0.32530.0_x86__8wekyb3d8bbwe.appx
2b56a3c3c2b4642fc11a78fc893bffd5dd7cf6d7b12f39b9d16b0c6197434ae6 : itunes-uwp/Microsoft.VCLibs.140.00.UWPDesktop_14.0.32530.0_arm64__8wekyb3d8bbwe.appx
ce19628cea6e726febb4693aeb12626d88393df0c23dfa12c9e3147cfa408f71 : __pycache__/setupdevhelpers.cpython-38.pyc
757061d127f8f3521693974b39b7aaf4533d867ae83416439ceac628d59305a3 : __pycache__/xmltodict.cpython-38.pyc
a085d7ea924575408aee680bf1b761f4c164c15499f86b0b3382da0782b074d6 : update_package.py
a03dcbfd04f59ae7ec1f8be6664f35c25d199a843618aaf69825dd8d9e09853c : WAPT/icon.png
a5a97261381e1d0ad46ee15916abec9c2631d0201f5cc50ceb0197a165a0bbbf : WAPT/certificate.crt
b453ba4752cad761099d08a3a295e06e07c2a305ceb6792e34fb1eadcb9f6d07 : WAPT/changelog.txt
578a76d3737a2c01d93156df140189e8e3dab03ba5e8c02746bc515a7200fd0a : xmltodict.py
e696b56751b8f4912f746d31a2b5d5c17ce6261ab88006443df769c6a36d7fd8 : setupdevhelpers.py
38aa3f9c82f175409977a57722752373d10c6bfdb5e592c2170b727018ff3ef6 : luti.json
b9ee6faaa77473cc7ac003f55252cbf61dba66c08203301b8000fdf1817020c1 : WAPT/control