# -*- coding: utf-8 -*-
from setuphelpers import *
r"""
To Delete implementations in C:\ProgramData\0install.net\implementations :
Go see C:\ProgramData\0install.net\implementations\_How to delete
"""
url = "https://appdownload.deepl.com/windows/0install/deepl.xml"
app_name = "DeepL"
zip_name = "deepl.zip"
unzipped_dir = zip_name.split(".zip")[0]
_0install_dir = makepath(programdata, "0install.net")
icons_package_dir = makepath(os.getcwd(), "icons")
interfaces_package_dir = makepath(os.getcwd(), "interfaces")
def install():
# Integrating the package to zero install
dest_dir = r"C:\ProgramData\0install.net\implementations"
print(f"Extracting {app_name} archive ({zip_name})...")
if isdir(makepath(os.getcwd(), unzipped_dir)):
remove_tree(makepath(os.getcwd(), unzipped_dir))
mkdirs(makepath(os.getcwd(), unzipped_dir))
unzip(makepath(os.getcwd(), zip_name), target=makepath(os.getcwd(), unzipped_dir))
if isdir(icons_package_dir):
remove_tree(icons_package_dir)
if isdir(interfaces_package_dir):
remove_tree(interfaces_package_dir)
mkdirs(icons_package_dir)
mkdirs(interfaces_package_dir)
move_directory(makepath(os.getcwd(), unzipped_dir, "icons"), icons_package_dir)
move_directory(makepath(os.getcwd(), unzipped_dir, "interfaces"), interfaces_package_dir)
print(f"Copying content to: {dest_dir}")
sha_tab = []
for path in glob.glob(makepath(os.getcwd(), unzipped_dir, "sha256*")):
sha_tab.append(path.split("\\")[-1])
for path in glob.glob(makepath(dest_dir, "sha256*")):
if path.split("\\")[-1] in sha_tab:
run([get_0install_path(), "store", "remove", path.split("\\")[-1]])
copytree2(makepath(os.getcwd(), unzipped_dir), dest_dir)
print(f"Copying Users files to: {dest_dir}")
copytree2(makepath(os.getcwd(), "icons"), makepath(_0install_dir, unzipped_dir, "icons"))
copytree2(makepath(os.getcwd(), "interfaces"), makepath(_0install_dir, unzipped_dir, "interfaces"))
def session_setup():
# Setting up the app in User environment
copytree2(makepath(_0install_dir, unzipped_dir, "icons"), makepath(user_appdata(), "0install.net", "desktop-integration", "icons"))
copytree2(makepath(_0install_dir, unzipped_dir, "interfaces"), makepath(user_local_appdata(), "0install.net", "interfaces"))
# --add-standard will make a silenced integrate, if no --add, 0install will open graphically
print(run([get_0install_path(), "integrate", url, "--add-standard", "--add=desktop-icon", "--offline", "--no-download"]))
# If you need to setup a proxy, here is an example of how to do it :
# if isrunning("Deepl"): # settings must be set before launching Deepl because it will
# error("Deepl is currently running") # override them when you close the application
# if isrunning("Deepl"):
# killalltasks("Deepl") # More extreme option but works too, be careful with it
#
# settings_file = makepath(user_appdata(), "DeepL_SE", "settings.json")
# if isfile(settings_file):
# settings_file_data = json_load_file(settings_file)
# settings_file_data["UserPreferences"]["ProxyPreferences"]["UseProxyCredentials"] = True
# settings_file_data["UserPreferences"]["ProxyPreferences"]["IpAddress"] = "example.ip.adress"
# settings_file_data["UserPreferences"]["ProxyPreferences"]["UseProxy"] = True
# settings_file_data["UserPreferences"]["ProxyPreferences"]["Username"] = "a_username"
# settings_file_data["UserPreferences"]["ProxyPreferences"]["Port"] = "80"
# json_write_file(settings_file, settings_file_data)
# else:
# print("%s does not exists" % settings_file)
def uninstall():
# Uninstalling the package
run([get_0install_path(), "remove", url], accept_returncodes=[0, 1])
remove_tree(makepath(_0install_dir, unzipped_dir))
def get_0install_path():
if get_os_name() == "Windows":
return makepath(programfiles, "Zero Install", "0install.exe")
else:
# To change for linux !!!
return makepath(programfiles, "Zero Install", "0install.exe")
def move_directory(source, destination):
"""
Moves a directory safely, avoiding unnecessary subfolders.
Args:
source (str): The path of the directory to move.
destination (str): The destination path where the directory will be moved to.
Returns:
bool: True if the directory was successfully moved, False otherwise.
"""
try:
if not os.path.exists(destination):
os.makedirs(destination)
for item in os.listdir(source):
item_path = os.path.join(source, item)
if os.path.isfile(item_path):
shutil.move(item_path, destination)
elif os.path.isdir(item_path):
new_destination = os.path.join(destination, item)
move_directory(item_path, new_destination)
os.rmdir(source)
return True
except Exception as e:
print(f"ERROR: {e}")
return False