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

# Installation procedure: https://www.sumatrapdfreader.org/docs/Installer-cmd-line-arguments.html
# Defining variables
##silent_args = '-s -d "%s"' % makepath(programfiles,'SumatraPDF')
bin_name = "SumatraPDF"
app_uninstallkey = "SumatraPDF"

def install():
    # Initializing variables
    package_version = control.get_software_version()
    sumatrapdf_version = control.get_software_version().split(".")[0]
    bin_contains = f"SumatraPDF-{sumatrapdf_version}"

    if "x64" in control.architecture:
        bin_name_x64 = glob.glob(f"{bin_contains}*-64-install.exe")[0]
        install_exe_if_needed(
            bin_name_x64,
            silentflags="-s -all-users",
            key=app_uninstallkey,
            min_version=package_version,
        )

    if "arm" in control.architecture:
        bin_name_arm = glob.glob(f"{bin_contains}*-arm64-install.exe")[0]
        install_exe_if_needed(
            bin_name_arm,
            silentflags="-s -all-users",
            key=app_uninstallkey,
            min_version=package_version,
        )

    # Uninstalling older versions
def uninstall():
    uninstall_sumatra = makepath(programfiles32, bin_name, "SumatraPDF.exe", "-uninstall -all-users")