# -*- coding: utf-8 -*-
from setuphelpers import *
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
bin_contains = "7z"
ext_file_association = [
".7z",
".zip",
".rar",
".001",
".cab",
# ".iso",
".xz",
".txz",
".lzma",
".tar",
".cpio",
".bz2",
".bzip2",
".tbz2",
".tbz",
".gz",
".gzip",
".tgz",
".tpz",
".z",
".taz",
".lzh",
".lha",
".rpm",
".deb",
".arj",
# ".vhd",
# ".vhdx",
".wim",
".swm",
".esd",
".fat",
".ntfs",
".dmg",
".hfs",
".xar",
".squashfs",
]
def install():
# Initializing variables
package_version = control.version.split("-", 1)[0]
bin_name = glob.glob("*%s*.msi" % bin_contains)[0]
to_force = False
# Uninstalling other versions of the software
if len(installed_softwares(name="7-Zip")) >= 2:
to_force = True
for to_uninstall in installed_softwares(name="7-Zip"):
if Version(to_uninstall["version"], 2) < Version(package_version, 2) or to_uninstall["key"] == "7-Zip" or force or to_force:
print("Removing: %s (%s)" % (to_uninstall["name"], to_uninstall["version"]))
killalltasks(control.impacted_process.split(","))
try:
run(uninstall_cmd(to_uninstall["key"]))
except:
wait_uninstallkey_absent(to_uninstall["key"])
unregister_uninstall(to_uninstall["key"], win64app=to_uninstall["win64"])
# Installing the software
print("Installing: %s" % bin_name)
if to_force:
install_msi_if_needed(bin_name, min_version=package_version, force=to_force)
else:
install_msi_if_needed(bin_name, min_version=package_version)
# File association for 7-Zip
for ext in ext_file_association:
register_ext(
"7-zip",
ext,
'"%s" "%%1"' % (makepath(programfiles, "7-zip", "7zFM.exe")),
icon="%s,1" % (makepath(programfiles, "7-zip", "7z.dll")),
)