From d9b71bec6c6551ce2474c696ffcf9d1e34727ff8 Mon Sep 17 00:00:00 2001 From: BarsTiger Date: Sat, 12 Mar 2022 13:24:11 +0200 Subject: [PATCH] Added silent installer --- build_bats/build-installer-silent.bat | 5 ++ build_bats/build-installer-silent_clean.bat | 7 ++ dist.py | 1 + horsy_installer_silent.py | 76 +++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 build_bats/build-installer-silent.bat create mode 100644 build_bats/build-installer-silent_clean.bat create mode 100644 horsy_installer_silent.py diff --git a/build_bats/build-installer-silent.bat b/build_bats/build-installer-silent.bat new file mode 100644 index 0000000..1e7e51a --- /dev/null +++ b/build_bats/build-installer-silent.bat @@ -0,0 +1,5 @@ +cd .. +pip install -r requirements.txt +pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsy_installer_silent.py" +rmdir /s /q __pycache__ +del horsy_installer_silent.spec \ No newline at end of file diff --git a/build_bats/build-installer-silent_clean.bat b/build_bats/build-installer-silent_clean.bat new file mode 100644 index 0000000..24adc2d --- /dev/null +++ b/build_bats/build-installer-silent_clean.bat @@ -0,0 +1,7 @@ +cd .. +pip install -r requirements.txt +rmdir /s /q build +pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsy_installer_silent.py" +rmdir /s /q __pycache__ +del horsy_installer_silent.spec +rmdir /s /q build \ No newline at end of file diff --git a/dist.py b/dist.py index a56a781..02c72af 100644 --- a/dist.py +++ b/dist.py @@ -3,6 +3,7 @@ import os os.system("xcopy /s /Y dist\horsy.exe bin\horsy.exe*") os.system("xcopy /s /Y dist\horsygui.exe bin\horsygui.exe*") os.system("xcopy /s /Y dist\horsy_installer.exe bin\installer-horsy-win.exe*") +os.system("xcopy /s /Y dist\horsy_installer_silent.exe bin\installer-horsy-win-silent.exe*") os.system("xcopy /s /Y dist\horsy_updater.exe bin\horsy_updater.exe*") with open("web_vars/version", "r") as f_r: diff --git a/horsy_installer_silent.py b/horsy_installer_silent.py new file mode 100644 index 0000000..97f9a77 --- /dev/null +++ b/horsy_installer_silent.py @@ -0,0 +1,76 @@ +import sys +from modules.path import add_to_path, add_var +import urllib.request +import os +import threading +import ctypes +import winshell +from win32com.client import Dispatch +import pythoncom +import argparse + +parser = argparse.ArgumentParser(description='horsy - the best package manager') +parser.add_argument('-p', '--path', action='store_true', help='path to install app', required=False, + default=os.path.expanduser("~") + "\horsy") +args = parser.parse_args() + + +def install(): + global args + path_to_install = args.path + if path_to_install == "": + print("Please choose path to install") + return + if not os.path.exists(path_to_install): + os.makedirs(path_to_install) + if not os.path.exists(path_to_install + "\\apps"): + os.makedirs(path_to_install + "\\apps") + threads = list() + print("Adding task to download horsy") + threads.append(threading.Thread(target=urllib.request.urlretrieve, + args=("https://github.com/horsy-ml/horsy/raw/master/bin/horsy.exe", + os.path.join(path_to_install) + '/horsy.exe'), )) + print("Adding task to download horsygui") + threads.append(threading.Thread(target=urllib.request.urlretrieve, + args=("https://github.com/horsy-ml/horsy/raw/master/bin/horsygui.exe", + os.path.join(path_to_install) + '/horsygui.exe'), )) + try: + print("Starting tasks") + for thread in threads: + thread.start() + except: + ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) + sys.exit() + + print("Adding to PATH") + add_var(path_to_install) + add_to_path(os.path.join(path_to_install)) + print("Downloading version file") + urllib.request.urlretrieve("https://github.com/horsy-ml/horsy/raw/master/web_vars/version", + os.path.join(path_to_install) + '/apps/version') + print("Version specified") + + def wait_for_finish(): + for thread in threads: + thread.join() + print("Downloading finished") + print("Creating shortcuts") + desktop = winshell.desktop() + path = os.path.join(desktop, "horsy GUI.lnk") + target = os.path.join(path_to_install) + '/horsygui.exe' + wDir = os.path.join(path_to_install) + icon = os.path.join(path_to_install) + '/horsygui.exe' + pythoncom.CoInitializeEx(0) + shell = Dispatch('WScript.Shell') + shortcut = shell.CreateShortCut(path) + shortcut.Targetpath = target + shortcut.WorkingDirectory = wDir + shortcut.IconLocation = icon + shortcut.save() + print("Installation complete") + + threading.Thread(target=wait_for_finish).start() + + +if __name__ == '__main__': + install()