# -*- coding: utf-8 -*-
from setuphelpers import *
from setupdevhelpers import unzip_with_7zip
import os

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
app_path = makepath(programfiles, 'SwitchHosts')
app_exe = makepath(app_path,'SwitchHosts.exe')
nameshortcut = "SwitchHosts"

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

    # Installing the software
    killalltasks(ensure_list(control.impacted_process))
    if isdir(app_path) and force:
        remove_tree(app_path)
    mkdirs(app_path)
    print("Extracting: %s to: %s" % (bin_name, app_path))
    unzip_with_7zip(bin_name, app_path)

    # Creating custom shortcuts
    create_programs_menu_shortcut(nameshortcut, target=app_exe, wDir=os.path.dirname(app_exe))

def uninstall():
    # Force uninstalling the software
    killalltasks(['switchhosts', 'SwitchHosts'])

    if isdir(app_path):
        remove_tree(app_path)

    # Removing shortcuts
    remove_programs_menu_shortcut(nameshortcut)