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

r"""
 {
   "key":"82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC_is1",
   "name":"ShareX",
   "version":"16.0.1",
   "install_date":"2024-04-23 00:00:00",
   "install_location":"C:\\Program Files\\ShareX\\",
   "uninstall_string":"\"C:\\Program Files\\ShareX\\unins000.exe\"",
   "publisher":"ShareX Team",
   "system_component":0,
   "win64":true
  }

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


def install():
    # Declaring local variables
    bin_name = glob.glob("ShareX-*.exe")[0]
    # Installing the software

      # Uninstalling the software
    for to_uninstall in installed_softwares("ShareX"):
        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"])

    install_exe_if_needed(
        bin_name,
        silentflags="/sp /silent /norestart /norun /VERYSILENT",
        key="82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC_is1",
        min_version=control.get_software_version(),
    )
