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


def update_package():
    # Declaring local variables
    result = False
    proxies = get_proxies()
    if not proxies:
        proxies = get_proxies_from_wapt_console()
    download_url = "https://downloads.malwarebytes.com/file/adwcleaner"

    bin_name = "adwcleaner.exe"
    print("Download url is: %s" % download_url)

    print("Downloading: %s" % bin_name)
    wget(download_url, bin_name, proxies=proxies)

    # Checking version from file
    version = get_version_from_binary(bin_name, property_name="FileVersion")

    # Changing version of the package
    if Version(version) > Version(control.get_software_version()):
        print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version)))
        result = True
    else:
        print("Software version up-to-date (%s)" % Version(version))

    control.version = "%s-%s" % (Version(version), control.version.split("-", 1)[-1])
    control.save_control_to_wapt()

    # Validating update-package-sources
    return result
