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


def install():
    bin_name = glob.glob("audacity-win-*x86_64.msi")[0]

    # Uninstalling older versions of the software that can remain
    for to_uninstall in installed_softwares("Audacity_is1"):
      if Version(to_uninstall["version"]) < Version(control.get_software_version()):
        print(f"Removing: {to_uninstall['name']} ({to_uninstall['version']})")
        killalltasks(ensure_list(control.impacted_process))
        run(uninstall_cmd(to_uninstall["key"]))
        wait_uninstallkey_absent(to_uninstall["key"])

    install_msi_if_needed(
        bin_name,
        name=f"Audacity {str(Version(control.get_software_version(), 2))}",
        min_version=control.get_software_version(),
    )

    remove_desktop_shortcut(f"Audacity {str(Version(control.get_software_version(), 2))}")
