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


def install():
    # Declaring local variables
    bin_name = glob.glob('WinDirStat*.msi')[0]

    uninstall_older_version()

    # Installing the software
    install_msi_if_needed(
        bin_name,
        name="WinDirStat",
        min_version=control.get_software_version()
    )


def uninstall_older_version():

    killalltasks(ensure_list(control.impacted_process))

    for soft in installed_softwares(name=control.name):
        uninstall_key = soft['key']
        if Version(soft['version']) < Version(control.get_software_version()):
            run(uninstall_cmd(uninstall_key))
            wait_uninstallkey_absent(uninstall_key)