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


def install():
    bin_name = glob.glob("video_editor_x*.exe")[0]

    # Uninstalling older versions of the software
    for to_uninstall in installed_softwares(uninstallkey="VSDC Free Video Editor_is1"):
        if Version(to_uninstall["version"]) < Version(control.get_software_version()) or force:
            print("Removing: %s (%s)" % (to_uninstall["name"], to_uninstall["version"]))
            killalltasks(control.get_impacted_process_list())
            run(uninstall_cmd(to_uninstall["key"]))
            wait_uninstallkey_absent(to_uninstall["key"])
            time.sleep(5)

    install_exe_if_needed(
        bin_name,
        silentflags="/VERYSILENT /SUPPRESSMSGBOXES /NORESTART",
        key="VSDC Free Video Editor_is1",
        min_version=control.get_software_version(),
        timeout=600,
    )


def session_setup():
    registry_setstring(HKEY_CURRENT_USER, r"Software\FlashIntegro\VideoEditor", "UpdatePeriod", 6, type=REG_DWORD)
