Window instead of terminal
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (pythonProject)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (pythonProject)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
2
.idea/pythonProject.iml
generated
2
.idea/pythonProject.iml
generated
@@ -4,7 +4,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (pythonProject)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
15
build.bat
15
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
|
||||
python -m PyInstaller --clean --onefile --uac-admin --noconsole --icon=app.ico -n=chronos-installer main.py
|
||||
13
clean.bat
13
clean.bat
@@ -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
|
||||
)
|
||||
171
main.py
171
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,37 +65,44 @@ 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 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 clean_folder(path):
|
||||
def clean_folder(self, path):
|
||||
if os.path.exists(path):
|
||||
for filename in os.listdir(path):
|
||||
if filename != CACHE_FOLDER:
|
||||
@@ -77,44 +113,51 @@ def clean_folder(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))
|
||||
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():
|
||||
def clean(self):
|
||||
if '--clean' in sys.argv:
|
||||
clean_folder(INSTALL_FOLDER)
|
||||
clean_folder(CACHE_FOLDER_PATH)
|
||||
self.clean_folder(INSTALL_FOLDER)
|
||||
self.clean_folder(CACHE_FOLDER_PATH)
|
||||
if '--clean-cache' in sys.argv:
|
||||
clean_folder(CACHE_FOLDER_PATH)
|
||||
self.clean_folder(CACHE_FOLDER_PATH)
|
||||
if '--clean-installer' in sys.argv:
|
||||
clean_folder(INSTALL_FOLDER)
|
||||
self.clean_folder(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 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 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()
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
requests
|
||||
rich
|
||||
wxPython
|
||||
pyinstaller
|
||||
Reference in New Issue
Block a user