diff --git a/.idea/misc.xml b/.idea/misc.xml
index f56ad02..13fecf3 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/.idea/pythonProject.iml b/.idea/pythonProject.iml
index 74d515a..5befd7a 100644
--- a/.idea/pythonProject.iml
+++ b/.idea/pythonProject.iml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/build.bat b/build.bat
index 64c2472..0516476 100644
--- a/build.bat
+++ b/build.bat
@@ -1,16 +1,3 @@
@echo off
-call clean.bat
pip install -r requirements.txt
-IF EXIST "build" (
- RMDIR /S /Q build
-)
-IF EXIST "dist" (
- RMDIR /S /Q dist
-)
-IF EXIST "__pycache__" (
- RMDIR /S /Q __pycache__
-)
-IF EXIST "main.spec" (
- ERASE main.spec
-)
-pyinstaller --onefile --uac-admin --icon=app.ico main.py
\ No newline at end of file
+python -m PyInstaller --clean --onefile --uac-admin --noconsole --icon=app.ico -n=chronos-installer main.py
\ No newline at end of file
diff --git a/clean.bat b/clean.bat
deleted file mode 100644
index 9542e4e..0000000
--- a/clean.bat
+++ /dev/null
@@ -1,13 +0,0 @@
-@echo off
-IF EXIST "build" (
- RMDIR /S /Q build
-)
-IF EXIST "dist" (
- RMDIR /S /Q dist
-)
-IF EXIST "__pycache__" (
- RMDIR /S /Q __pycache__
-)
-IF EXIST "main.spec" (
- ERASE main.spec
-)
\ No newline at end of file
diff --git a/main.py b/main.py
index cccbdb4..917454b 100644
--- a/main.py
+++ b/main.py
@@ -1,11 +1,12 @@
-import requests
-import os
-import subprocess
-from rich.progress import Progress
-from rich import print
import ctypes
-import sys
+import os
import shutil
+import subprocess
+import sys
+
+import requests
+import wx
+from wx import Size, Point
REPO_URL = "https://alexisdelhaie.ovh/dlcenter/chronos-repo/installer/"
VERSION_FILE = "version"
@@ -20,6 +21,34 @@ EXECUTABLE_PATH = "{}\\{}".format(INSTALL_FOLDER, EXECUTABLE)
FILES = ["libeay32.dll", "ssleay32.dll", "7z.dll", EXECUTABLE]
+def create_install_folder():
+ company_directory = "{}\\{}".format(os.getenv('APPDATA'), COMPANY_NAME)
+ if not os.path.exists(company_directory):
+ os.mkdir(company_directory)
+ if not os.path.exists(INSTALL_FOLDER):
+ os.mkdir(INSTALL_FOLDER)
+
+
+def download_file_from_repo(filename, dlg):
+ url = "{}{}".format(REPO_URL, filename)
+ with open("{}\\{}".format(INSTALL_FOLDER, filename), 'wb') as f:
+ response = requests.get(url, stream=True)
+ total_length = response.headers.get('content-length')
+ dlg.set_total(filename, int(total_length))
+ if total_length is None: # no content length header
+ f.write(response.content)
+ else:
+ for data in response.iter_content(chunk_size=4096):
+ f.write(data)
+ dlg.update_progress(len(data))
+
+
+def get_version_from_repo():
+ url = "{}{}".format(REPO_URL, VERSION_FILE)
+ r = requests.get(url, allow_redirects=True)
+ return r.text
+
+
def get_installed_version():
if os.path.exists(INSTALLED_VERSION_PATH):
file = open(INSTALLED_VERSION_PATH, "r")
@@ -36,85 +65,99 @@ def is_admin():
return False
-def get_version_from_repo():
- url = "{}{}".format(REPO_URL, VERSION_FILE)
- r = requests.get(url, allow_redirects=True)
- return r.text
+class MyApplication(wx.App):
-
-def download_file_from_repo(filename):
- url = "{}{}".format(REPO_URL, filename)
- with open("{}\\{}".format(INSTALL_FOLDER, filename), 'wb') as f:
- response = requests.get(url, stream=True)
- total_length = response.headers.get('content-length')
-
- if total_length is None: # no content length header
- f.write(response.content)
+ def OnInit(self):
+ self.SetAppName("EndPoint installer")
+ if is_admin():
+ self.main()
else:
- with Progress() as progress:
- task = progress.add_task("Downloading {}".format(filename), total=int(total_length))
- for data in response.iter_content(chunk_size=4096):
- f.write(data)
- progress.update(task, advance=len(data))
+ dlg = wx.MessageDialog(None, "This application requires administrative privileges to run",
+ "EndPoint installer", style=wx.OK | wx.ICON_HAND)
+ dlg.ShowModal()
+ dlg.Destroy()
+ return True
+
+ def main(self):
+ version = get_version_from_repo()
+ create_install_folder()
+ self.clean()
+ if get_installed_version() != version:
+ dlg = MyDialog(None, -1, "EndPoint installer", Size(400, 120))
+ dlg.Show()
+ self.clean_folder(INSTALL_FOLDER)
+ for file in FILES:
+ download_file_from_repo(file, dlg)
+ if os.path.exists(INSTALLED_VERSION_PATH):
+ os.remove(INSTALLED_VERSION_PATH)
+ file = open(INSTALLED_VERSION_PATH, "w")
+ file.write(version)
+ file.close()
+ dlg.Destroy()
+ if os.path.exists(EXECUTABLE_PATH):
+ subprocess.Popen([EXECUTABLE_PATH], cwd=INSTALL_FOLDER)
+ else:
+ dlg = wx.MessageDialog(None, "Installer executable not found",
+ "EndPoint installer", style=wx.OK | wx.ICON_HAND)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+ def clean_folder(self, path):
+ if os.path.exists(path):
+ for filename in os.listdir(path):
+ if filename != CACHE_FOLDER:
+ file_path = os.path.join(path, filename)
+ try:
+ if os.path.isfile(file_path) or os.path.islink(file_path):
+ os.unlink(file_path)
+ elif os.path.isdir(file_path):
+ shutil.rmtree(file_path)
+ except Exception as e:
+ dlg = wx.MessageDialog(self, 'Failed to delete {}. Reason: {}'.format(file_path, e),
+ "EndPoint installer", style=wx.OK | wx.ICON_HAND)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+ def clean(self):
+ if '--clean' in sys.argv:
+ self.clean_folder(INSTALL_FOLDER)
+ self.clean_folder(CACHE_FOLDER_PATH)
+ if '--clean-cache' in sys.argv:
+ self.clean_folder(CACHE_FOLDER_PATH)
+ if '--clean-installer' in sys.argv:
+ self.clean_folder(INSTALL_FOLDER)
-def create_install_folder():
- company_directory = "{}\\{}".format(os.getenv('APPDATA'), COMPANY_NAME)
- if not os.path.exists(company_directory):
- os.mkdir(company_directory)
- if not os.path.exists(INSTALL_FOLDER):
- os.mkdir(INSTALL_FOLDER)
+class MyDialog(wx.Dialog):
+ def __init__(self, parent, i, title, size=wx.DefaultSize):
+ wx.Dialog.__init__(self)
+ self.Create(parent, i, title, wx.DefaultPosition, size, wx.DEFAULT_DIALOG_STYLE, 'EndPoint installer')
+ self.Centre()
+ self.panel = wx.Panel(self)
+ self.status = wx.StaticText(self.panel, label="-------------------------------------------", pos=Point(17, 10))
+ self.progress = wx.Gauge(self.panel, -1, size=Size(350, 25), pos=Point(17, 40))
+ self.pg = 0
+ self.total = 100
+ self.filename = "no_name_file"
-def clean_folder(path):
- if os.path.exists(path):
- for filename in os.listdir(path):
- if filename != CACHE_FOLDER:
- file_path = os.path.join(path, filename)
- try:
- if os.path.isfile(file_path) or os.path.islink(file_path):
- os.unlink(file_path)
- elif os.path.isdir(file_path):
- shutil.rmtree(file_path)
- except Exception as e:
- print('[bold red]ERROR[/] Failed to delete {}. Reason: {}'.format(file_path, e))
+ def update_progress(self, value):
+ self.pg += value
+ percentage = (self.pg / self.total) * 100
+ self.status.SetLabelText("Downloading {} ({}%)".format(self.filename, int(percentage)))
+ self.progress.SetValue(self.pg)
-
-def clean():
- if '--clean' in sys.argv:
- clean_folder(INSTALL_FOLDER)
- clean_folder(CACHE_FOLDER_PATH)
- if '--clean-cache' in sys.argv:
- clean_folder(CACHE_FOLDER_PATH)
- if '--clean-installer' in sys.argv:
- clean_folder(INSTALL_FOLDER)
+ def set_total(self, filename, total):
+ self.filename = filename
+ self.pg = 0
+ self.total = total
+ self.progress.SetValue(0)
+ self.progress.SetRange(total)
def main():
- if not is_admin():
- print('[bold red]ERROR[/] This app need to be launched eleveted')
- input('-- Press enter key to quit --')
- sys.exit(0)
- print('Chronos installer bootstrap\n\n@alexlegarnd -- https://alexisdelhaie.ovh/')
- print('Github: https://github.com/alexlegarnd/chronos-installer-bootstrap\n')
- version = get_version_from_repo()
- create_install_folder()
- clean()
- if get_installed_version() != version:
- print('[bold green]INFO[/] Downloading latest version of the software installer')
- clean_folder(INSTALL_FOLDER)
- for file in FILES:
- download_file_from_repo(file)
- if os.path.exists(INSTALLED_VERSION_PATH):
- os.remove(INSTALLED_VERSION_PATH)
- file = open(INSTALLED_VERSION_PATH, "w")
- file.write(version)
- file.close()
- if os.path.exists(EXECUTABLE_PATH):
- subprocess.Popen([EXECUTABLE_PATH], cwd=INSTALL_FOLDER)
- else:
- print('[bold red]ERROR[/] Executable not found')
- input('-- Press enter key to quit --')
+ app = MyApplication()
+ app.MainLoop()
main()
diff --git a/requirements.txt b/requirements.txt
index 850d442..2e24581 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
requests
-rich
+wxPython
pyinstaller
\ No newline at end of file