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

def install():
    # Declaring local variables
    bin_name = glob.glob('DocFetcher-*Setup.exe')[0]

    # Uninstalling existing versions
    for to_uninstall in installed_softwares(name="DocFetcher"):
        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"])

    # Installing the software
    install_exe_if_needed(bin_name,
        silentflags='/S',
        key='DocFetcher',
        min_version= control.get_software_version(),
    )