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


def install():
    # Declaring local variables
    package_version = control.get_software_version()
    bin_name = glob.glob("*Opera_*.exe")[0]
    app_uninstallkey = "Opera %s" % package_version

    # Installing the software
    print("Installing: %s" % bin_name)
    install_exe_if_needed(
        bin_name,
        silentflags="/install /silent /launchopera=0 /setdefaultbrowser=0 /allusers=1 /pintotaskbar=0 /desktopshortcut=0",
        key=app_uninstallkey,
        min_version=package_version,
    )

    # Avoiding the usage by WAPT of the app built-in Uninstallstring
    uninstallkey.remove(app_uninstallkey)


def uninstall():
    # Declaring local variables
    package_version = control.get_software_version()
    app_uninstallkey = "Opera %s" % package_version

    # Uninstalling the software
    for uninstall in installed_softwares(uninstallkey=app_uninstallkey):
        print("Removing: %s (%s)" % (uninstall["name"], uninstall["version"]))
        killalltasks(control.get_impacted_process_list())
        app_uninstall_cmd = uninstall_cmd(uninstall["key"])
        app_uninstall_cmd[2] = "/silent"
        run(app_uninstall_cmd)
