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

uninstallkey = []

def install():
    print("installing tis-innosetup")

    # Variables
    version = control["version"].split("-", 1)[0]
    bin_name = glob.glob("innosetup*.exe")[0]

    # Uninstall Inno Setup 6 if installing Inno Setup 7
    if version.startswith("7"):
        for software in installed_softwares():
            if software["name"].startswith("Inno Setup version 6"):
                print("Uninstalling old version: %s" % software["name"])
                run(uninstall_cmd(software["key"]))

    install_exe_if_needed(
        bin_name,
        name = f"Inno Setup {version}",
        silentflags = "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART",
        min_version=control.get_software_version()
    )

    # Kill at end of installation
    killalltasks("innosetup.exe")