# -*- coding: utf-8 -*-
from setuphelpers import *
import time
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 = [
".001",
".7z",
".arj",
".bz2",
".bzip2",
".cab",
".cpio",
".deb",
".dmg",
".esd",
".fat",
".gz",
".gzip",
".hfs",
".lha",
".lzh",
".lzma",
".ntfs",
".rar",
".rpm",
".squashfs",
".swm",
".tar",
".taz",
".tbz",
".tbz2",
".tgz",
".tpz",
".txz",
".vhd",
".wim",
".xar",
".xz",
".z",
".zip",
".zipe",
]
# ".iso",
def install():
# Initializing variables
package_version = control.version.split("-", 1)[0]
bin_name = glob.glob("*%s*.msi" % bin_contains)[0]
# Uninstalling other versions of the software
for uninstall in installed_softwares("7-zip"):
if Version(uninstall["version"], 2) < Version(package_version, 2) or force:
print("Removing: %s (%s)" % (uninstall["name"], uninstall["version"]))
killalltasks(control.impacted_process.split(","))
try:
run(uninstall_cmd(uninstall["key"]))
except:
if not "uninstall.exe" in str(uninstall_cmd(uninstall["key"])).lower():
raise
if uninstall_key_exists(uninstall["key"]):
time.sleep(10)
if "uninstall.exe" in str(uninstall_cmd(uninstall["key"])).lower():
unregister_uninstall(uninstall["key"], win64app=iswin64())
# Installing the software
print("Installing: %s" % bin_name)
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")),
)