diff --git a/build-installer.bat b/build-installer.bat deleted file mode 100644 index 3ebf9cb..0000000 --- a/build-installer.bat +++ /dev/null @@ -1,4 +0,0 @@ -pip install -r requirements.txt -pyinstaller --noconfirm --icon "img/icon.ico" --windowed --onefile "horsy_installer.py" -rmdir /s /q __pycache__ -del horsy_installer.spec \ No newline at end of file diff --git a/build-gui.bat b/build_bats/build-gui.bat similarity index 96% rename from build-gui.bat rename to build_bats/build-gui.bat index 70e40b5..7be6658 100644 --- a/build-gui.bat +++ b/build_bats/build-gui.bat @@ -1,3 +1,4 @@ +cd .. pip install -r requirements.txt pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsygui.py" rmdir /s /q __pycache__ diff --git a/build-gui_clean.bat b/build_bats/build-gui_clean.bat similarity index 96% rename from build-gui_clean.bat rename to build_bats/build-gui_clean.bat index dc90c48..124fde6 100644 --- a/build-gui_clean.bat +++ b/build_bats/build-gui_clean.bat @@ -1,3 +1,4 @@ +cd .. pip install -r requirements.txt rmdir /s /q build pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsygui.py" diff --git a/build_bats/build-installer.bat b/build_bats/build-installer.bat new file mode 100644 index 0000000..5a8e93a --- /dev/null +++ b/build_bats/build-installer.bat @@ -0,0 +1,5 @@ +cd .. +pip install -r requirements.txt +pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsy_installer.py" +rmdir /s /q __pycache__ +del horsy_installer.spec \ No newline at end of file diff --git a/build-installer_clean.bat b/build_bats/build-installer_clean.bat similarity index 55% rename from build-installer_clean.bat rename to build_bats/build-installer_clean.bat index 53c9100..947f528 100644 --- a/build-installer_clean.bat +++ b/build_bats/build-installer_clean.bat @@ -1,6 +1,7 @@ +cd .. pip install -r requirements.txt rmdir /s /q build -pyinstaller --noconfirm --icon "img/icon.ico" --windowed --onefile "horsy_installer.py" +pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsy_installer.py" rmdir /s /q __pycache__ del horsy_installer.spec rmdir /s /q build \ No newline at end of file diff --git a/build.bat b/build_bats/build.bat similarity index 96% rename from build.bat rename to build_bats/build.bat index dcfa030..70a79f5 100644 --- a/build.bat +++ b/build_bats/build.bat @@ -1,3 +1,4 @@ +cd .. pip install -r requirements.txt pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsy.py" rmdir /s /q __pycache__ diff --git a/build_clean.bat b/build_bats/build_clean.bat similarity index 96% rename from build_clean.bat rename to build_bats/build_clean.bat index a81c3bb..9a47ca5 100644 --- a/build_clean.bat +++ b/build_bats/build_clean.bat @@ -1,3 +1,4 @@ +cd .. pip install -r requirements.txt rmdir /s /q build pyinstaller --noconfirm --icon "img/icon.ico" --console --onefile "horsy.py" diff --git a/horsy_installer.py b/horsy_installer.py index cc45eab..ecde3bf 100644 --- a/horsy_installer.py +++ b/horsy_installer.py @@ -4,8 +4,8 @@ from modules.path import add_to_path, add_var import modules.images import urllib.request import os -import ctypes import threading +import ctypes class Ui_MainWindow(object): @@ -159,6 +159,8 @@ class Ui_MainWindow(object): self.centralwidget, 'Installation folder')) + "\horsy").replace("/", "\\").replace('\\\\', '\\')) +ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0) + app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() @@ -175,26 +177,41 @@ def 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() + ui.logs_box.append("Adding task to download horsy") + threads.append(threading.Thread(target=urllib.request.urlretrieve, + args=("https://github.com/BarsTiger/horsy/raw/master/bin/horsy.exe", + os.path.join(path_to_install) + '/horsy.exe'), )) + if ui.install_gui_check.isChecked(): + ui.logs_box.append("Adding task to download horsygui") + threads.append(threading.Thread(target=urllib.request.urlretrieve, + args=("https://github.com/BarsTiger/horsy/raw/master/bin/horsygui.exe", + os.path.join(path_to_install) + '/horsy.exe'), )) try: - ui.logs_box.append("Downloading horsy") - threading.Thread(target=urllib.request.urlretrieve, - args=("https://github.com/BarsTiger/horsy/raw/master/bin/horsy.exe", - os.path.join(path_to_install) + '/horsy.exe'),).start() + ui.logs_box.append("Starting tasks") + for thread in threads: + thread.start() except: ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) sys.exit() - if ui.install_gui_check.isChecked(): - try: - ui.logs_box.append("Installing horsygui") - threading.Thread(target=urllib.request.urlretrieve, - args=("https://github.com/BarsTiger/horsy/raw/master/bin/horsygui.exe", - os.path.join(path_to_install) + '/horsy.exe'), ).start() - except: - ui.logs_box.append("Error while installing horsygui") + ui.logs_box.append("Adding to PATH") add_var(path_to_install) add_to_path(os.path.join(path_to_install)) - ui.logs_box.append("Installation complete") + ui.logs_box.append("Downloading version file") + urllib.request.urlretrieve("https://github.com/BarsTiger/horsy/raw/master/web_vars/version", + os.path.join(path_to_install) + '/apps/version') + ui.logs_box.append("Version specified") + + def wait_for_finish(): + for thread in threads: + thread.join() + ui.logs_box.append("Downloading finished") + ui.logs_box.append("Installation complete") + + threading.Thread(target=wait_for_finish).start() ui.choose_path_button.clicked.connect(ui.openFile) diff --git a/horsygui.py b/horsygui.py index 749a8ba..d321066 100644 --- a/horsygui.py +++ b/horsygui.py @@ -2,10 +2,14 @@ import sys import math import webbrowser import modules.vars as horsy_vars -from PyQt5 import QtCore, QtGui, QtWidgets - +from PyQt5 import QtWidgets +import ctypes import modules.gui as gui + +# Hide console window (does not work on custom terminals like Windows Terminal) +ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0) + # Initialize GUI if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) diff --git a/modules/path.py b/modules/path.py index f16d1f8..571aded 100644 --- a/modules/path.py +++ b/modules/path.py @@ -2,6 +2,7 @@ import os os.popen('cls') existing_path_value_l = os.popen('PATH').read()[5:].replace('\n', '') # Get the existing path value +print('Existing path value: ' + existing_path_value_l) existing_path_value_s = set() for i in existing_path_value_l.split(';'): existing_path_value_s.add(i + ';') @@ -11,8 +12,6 @@ existing_path_value = str() for i in existing_path_value_s: existing_path_value += i -print('Existing path value: ' + existing_path_value) - def add_to_path(program_path: str): import winreg @@ -20,13 +19,11 @@ def add_to_path(program_path: str): with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key: # Open the environment key new_path_value = existing_path_value + f'{";" if existing_path_value[-1] != ";" else ""}' + \ program_path + ';' + program_path + "\\apps;" # Create new - print(new_path_value) winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, new_path_value) # Update the path value def add_var(horsy_path: str): import winreg - with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root: # Get the current user's registry with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key: # Open the environment key winreg.SetValueEx(key, "HORSYPATH", 0, winreg.REG_EXPAND_SZ, horsy_path) # Update the path value diff --git a/requirements.txt b/requirements.txt index a93dafd..5f8a08a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ Cryptography Pyinstaller tqdm algoliasearch -PyQt5 \ No newline at end of file +PyQt5 +easygui \ No newline at end of file diff --git a/web_vars/version b/web_vars/version index c227083..56a6051 100644 --- a/web_vars/version +++ b/web_vars/version @@ -1 +1 @@ -0 \ No newline at end of file +1 \ No newline at end of file