PATH debug
This commit is contained in:
@@ -2,7 +2,10 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import sys
|
||||
from modules.path import add_to_path, add_var
|
||||
import modules.images
|
||||
import urllib.request
|
||||
import os
|
||||
import ctypes
|
||||
import threading
|
||||
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
@@ -72,12 +75,12 @@ class Ui_MainWindow(object):
|
||||
self.path_message.setAcceptRichText(False)
|
||||
self.path_message.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
|
||||
self.path_message.setObjectName("path_message")
|
||||
self.install_horsy_chech = QtWidgets.QCheckBox(self.centralwidget)
|
||||
self.install_horsy_chech.setEnabled(False)
|
||||
self.install_horsy_chech.setGeometry(QtCore.QRect(20, 130, 91, 17))
|
||||
self.install_horsy_chech.setStyleSheet("color: white;")
|
||||
self.install_horsy_chech.setChecked(True)
|
||||
self.install_horsy_chech.setObjectName("install_horsy_chech")
|
||||
self.install_horsy_check = QtWidgets.QCheckBox(self.centralwidget)
|
||||
self.install_horsy_check.setEnabled(False)
|
||||
self.install_horsy_check.setGeometry(QtCore.QRect(20, 130, 91, 17))
|
||||
self.install_horsy_check.setStyleSheet("color: white;")
|
||||
self.install_horsy_check.setChecked(True)
|
||||
self.install_horsy_check.setObjectName("install_horsy_chech")
|
||||
self.install_gui_check = QtWidgets.QCheckBox(self.centralwidget)
|
||||
self.install_gui_check.setEnabled(True)
|
||||
self.install_gui_check.setGeometry(QtCore.QRect(30, 150, 111, 17))
|
||||
@@ -139,7 +142,7 @@ class Ui_MainWindow(object):
|
||||
"p, li { white-space: pre-wrap; }\n"
|
||||
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Installation folder, apps will be stored here</p></body></html>"))
|
||||
self.install_horsy_chech.setText(_translate("MainWindow", "Install horsy"))
|
||||
self.install_horsy_check.setText(_translate("MainWindow", "Install horsy"))
|
||||
self.install_gui_check.setText(_translate("MainWindow", "Install horsy GUI"))
|
||||
self.install_button.setText(_translate("MainWindow", "Install"))
|
||||
self.logs_box.setHtml(_translate("MainWindow",
|
||||
@@ -152,8 +155,8 @@ class Ui_MainWindow(object):
|
||||
self.label.setText(_translate("MainWindow", "-"))
|
||||
|
||||
def openFile(self, MainWindow):
|
||||
self.path_box.setText(str(QtWidgets.QFileDialog.getExistingDirectory(
|
||||
self.centralwidget, 'Installation folder')[0]))
|
||||
self.path_box.setText(str(os.path.join(QtWidgets.QFileDialog.getExistingDirectory(
|
||||
self.centralwidget, 'Installation folder')) + "\horsy").replace("/", "\\").replace('\\\\', '\\'))
|
||||
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
@@ -165,9 +168,36 @@ MainWindow.show()
|
||||
|
||||
|
||||
def install():
|
||||
pass
|
||||
path_to_install = os.path.join(ui.path_box.text()).replace("/", "\\").replace('\\\\', '\\')
|
||||
ui.logs_box.clear()
|
||||
if path_to_install == "":
|
||||
ui.logs_box.append("Please choose path to install")
|
||||
return
|
||||
if not os.path.exists(path_to_install):
|
||||
os.makedirs(path_to_install)
|
||||
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()
|
||||
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")
|
||||
add_var(path_to_install)
|
||||
add_to_path(os.path.join(path_to_install))
|
||||
ui.logs_box.append("Installation complete")
|
||||
|
||||
|
||||
ui.choose_path_button.clicked.connect(ui.openFile)
|
||||
ui.install_button.clicked.connect(install)
|
||||
|
||||
sys.exit(app.exec_())
|
||||
|
||||
@@ -802,7 +802,6 @@ class Ui_DownloadWindow(object):
|
||||
self.logs_box.setPlaceholderText(_translate("MainWindow", "Logs"))
|
||||
|
||||
def popup(title, text):
|
||||
|
||||
QtWidgets.QMessageBox.information(None, title, text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
# Module for PATH actions
|
||||
import os
|
||||
os.popen('cls')
|
||||
existing_path_value_l = os.popen('PATH').read()[5:].replace('\n', '') # Get the existing path value
|
||||
existing_path_value_s = set()
|
||||
for i in existing_path_value_l.split(';'):
|
||||
existing_path_value_s.add(i + ';')
|
||||
existing_path_value_s = list(existing_path_value_s)
|
||||
existing_path_value_s.sort()
|
||||
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
|
||||
|
||||
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
|
||||
existing_path_value = os.popen('echo %PATH%').read() # Get the existing path value
|
||||
print(existing_path_value)
|
||||
new_path_value = existing_path_value + ";" + program_path # Connect the new path to the existing path
|
||||
winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, new_path_value) # Update the path value
|
||||
|
||||
|
||||
def delete_from_path(program_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
|
||||
existing_path_value = os.popen('echo %PATH%').read() # Get the existing path value
|
||||
new_path_value = existing_path_value.replace(program_path + ";", "") # Remove the program path from path
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user