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

r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()

"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls


def install():

    # Uninstalling the software
    for to_uninstall in installed_softwares("CherryTree"):
        print("Removing: %s (%s)" % (to_uninstall["name"], to_uninstall["version"]))
        killalltasks(ensure_list(control.impacted_process))
        run(uninstall_cmd(to_uninstall["key"]))
        wait_uninstallkey_absent(to_uninstall["key"])

    # Declaring local variables
    bin_name = glob.glob('cherrytree_*_win64_setup.exe')[0]
    # Installing the software

    install_exe_if_needed(bin_name,
        silentflags='/s /S /q /Q /quiet /silent /SILENT /VERYSILENT',
        key='{DBA7384C-E1C6-44B5-A3B4-C94F2F0B8C0C}_is1',
        min_version=control.get_software_version(),
    )



