system path win fix
This commit is contained in:
parent
af88f68a86
commit
d4d5b853dd
5 changed files with 50 additions and 30 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ my_app_github/
|
||||||
my_app_gitlab/
|
my_app_gitlab/
|
||||||
data-backup/
|
data-backup/
|
||||||
.config.json
|
.config.json
|
||||||
|
nuitka-crash-report.xml
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
nuitka3 ./src/main.py --clean-cache=all --onefile --run --output-dir=./build --enable-plugin=tk-inter
|
nuitka3 ./src/main.py --clean-cache=all --onefile --run --output-dir=./build --enable-plugin=tk-inter --deployment
|
||||||
:: --clean-cache=all --disable-console --windows-icon-from-ico=./data/icon.ico
|
:: --clean-cache=all --disable-console --windows-icon-from-ico=./data/icon.ico
|
||||||
pause
|
pause
|
|
@ -38,8 +38,8 @@ def download_from_gitea(api_url, project_id, token, destination, progress_bar, v
|
||||||
def download_all_packages(progress_bar, progress_label, download_location, install_location):
|
def download_all_packages(progress_bar, progress_label, download_location, install_location):
|
||||||
download_folder = download_location + "/"
|
download_folder = download_location + "/"
|
||||||
install_folder = install_location + "/"
|
install_folder = install_location + "/"
|
||||||
print(f"install location {install_folder}")
|
print(f"Install location: {install_folder}")
|
||||||
print(f"download location {download_folder}")
|
print(f"Download location: {download_folder}")
|
||||||
sanity_check(download_folder,install_folder)
|
sanity_check(download_folder,install_folder)
|
||||||
try:
|
try:
|
||||||
with open(download_folder+"config.json", 'r') as file:
|
with open(download_folder+"config.json", 'r') as file:
|
||||||
|
@ -59,10 +59,10 @@ def download_all_packages(progress_bar, progress_label, download_location, insta
|
||||||
progress_bar.set_fraction(progress_value)
|
progress_bar.set_fraction(progress_value)
|
||||||
|
|
||||||
if source_type == "github":
|
if source_type == "github":
|
||||||
download_github.download_from_github(source_info["github_url"], download_folder+app_name, tqdm, version) #(api_url, project_id, token, destination, progress_bar)
|
download_github.download_from_github(source_info["github_url"], os.path.join(download_folder,app_name), tqdm, version) #(api_url, project_id, token, destination, progress_bar)
|
||||||
elif source_type == "gitlab":
|
elif source_type == "gitlab":
|
||||||
download_gitlab.download_and_update(source_info["gitlab_api_url"], source_info["project_id"],
|
download_gitlab.download_and_update(source_info["gitlab_api_url"], source_info["project_id"],
|
||||||
source_info["private_token"], download_folder+app_name, tqdm, version)
|
source_info["private_token"], os.path.join(download_folder,app_name), tqdm, version)
|
||||||
# Add other source types as needed
|
# Add other source types as needed
|
||||||
else:
|
else:
|
||||||
progress_label.set_text(f"Unsupported source type for {app_name}: {source_type}")
|
progress_label.set_text(f"Unsupported source type for {app_name}: {source_type}")
|
||||||
|
|
|
@ -10,7 +10,7 @@ download_folder = "."
|
||||||
|
|
||||||
class InstallerGUI:
|
class InstallerGUI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.app = Gtk.Application(application_id="org.example.customizableapp",
|
self.app = Gtk.Application(application_id="com.spitfire.launcher",
|
||||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||||
self.app.connect("activate", self.activate)
|
self.app.connect("activate", self.activate)
|
||||||
|
|
||||||
|
@ -204,6 +204,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
|
|
||||||
# Make the MainWindow class callable as a function
|
# Make the MainWindow class callable as a function
|
||||||
def run_installer(download_foler_tmp):
|
def run_installer(download_foler_tmp):
|
||||||
|
global download_folder
|
||||||
download_folder = download_foler_tmp
|
download_folder = download_foler_tmp
|
||||||
app = Gtk.Application(application_id="com.spitfire.launcher",
|
app = Gtk.Application(application_id="com.spitfire.launcher",
|
||||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||||
|
|
66
src/main.py
66
src/main.py
|
@ -24,9 +24,10 @@ def get_temp_folder():
|
||||||
|
|
||||||
return user_temp_folder
|
return user_temp_folder
|
||||||
|
|
||||||
def download_file(url, destination, progress_callback=None):
|
|
||||||
|
def download_file(url, destination, progress_callback=None, label_callback=None):
|
||||||
context = ssl.create_default_context(cafile=certifi.where())
|
context = ssl.create_default_context(cafile=certifi.where())
|
||||||
|
|
||||||
with urlopen(url, context=context) as response, open(destination, 'wb') as out_file:
|
with urlopen(url, context=context) as response, open(destination, 'wb') as out_file:
|
||||||
total_size = int(response.headers.get('content-length', 0))
|
total_size = int(response.headers.get('content-length', 0))
|
||||||
block_size = 1024
|
block_size = 1024
|
||||||
|
@ -39,26 +40,35 @@ def download_file(url, destination, progress_callback=None):
|
||||||
current_size += len(buffer)
|
current_size += len(buffer)
|
||||||
if progress_callback:
|
if progress_callback:
|
||||||
progress_callback(current_size, total_size)
|
progress_callback(current_size, total_size)
|
||||||
|
if label_callback:
|
||||||
|
label_callback("Downloading")
|
||||||
|
|
||||||
def extract_zip(zip_file, extract_path):
|
if label_callback:
|
||||||
|
label_callback("Download Complete")
|
||||||
|
|
||||||
|
|
||||||
|
def extract_zip(zip_file, extract_path, label_callback=None):
|
||||||
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
|
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
|
||||||
zip_ref.extractall(extract_path)
|
zip_ref.extractall(extract_path)
|
||||||
|
|
||||||
def download_gtk_dlls(download_path, dll_url, dll_files, progress_callback=None):
|
if label_callback:
|
||||||
|
label_callback("Extracting")
|
||||||
|
|
||||||
|
|
||||||
|
def download_gtk_dlls(download_path, dll_url, dll_files, progress_callback=None, label_callback=None):
|
||||||
for dll_file in dll_files:
|
for dll_file in dll_files:
|
||||||
file_url = dll_url + dll_file
|
file_url = dll_url + dll_file
|
||||||
|
|
||||||
# Check if the file already exists, if not, download it
|
|
||||||
if not os.path.exists(os.path.join(download_path, dll_file)):
|
if not os.path.exists(os.path.join(download_path, dll_file)):
|
||||||
download_file(file_url, os.path.join(download_path, dll_file), progress_callback)
|
download_file(file_url, os.path.join(download_path, dll_file), progress_callback, label_callback)
|
||||||
|
|
||||||
# Check if the downloaded file is a zip file, extract it, and remove the zip file
|
# Check if the downloaded file is a zip file, extract it, and remove the zip file
|
||||||
if dll_file.endswith('.zip'):
|
if dll_file.endswith('.zip'):
|
||||||
extract_path = os.path.join(download_path, dll_file.replace('.zip', ''))
|
extract_path = os.path.join(download_path, dll_file.replace('.zip', ''))
|
||||||
extract_zip(os.path.join(download_path, dll_file), extract_path)
|
extract_zip(os.path.join(download_path, dll_file), extract_path, label_callback)
|
||||||
os.remove(os.path.join(download_path, dll_file))
|
os.remove(os.path.join(download_path, dll_file))
|
||||||
|
|
||||||
|
|
||||||
def set_path_variable(download_path):
|
def set_path_variable(download_path):
|
||||||
|
|
||||||
current = subprocess.run("echo %Path%", stdout=subprocess.PIPE, shell=True, text=True)
|
current = subprocess.run("echo %Path%", stdout=subprocess.PIPE, shell=True, text=True)
|
||||||
|
@ -79,14 +89,13 @@ def set_path_variable(download_path):
|
||||||
|
|
||||||
print(f"Added PATH: {output_string_unique}")
|
print(f"Added PATH: {output_string_unique}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Skips entier program if is a different system than windows
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
from gui_main import run_installer
|
from gui_main import run_installer
|
||||||
run_installer(".")
|
run_installer(".")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Replace this with the desired download path
|
|
||||||
download_path = get_temp_folder()
|
download_path = get_temp_folder()
|
||||||
|
|
||||||
dll_url = 'https://downloads.sourceforge.net/project/spitfire-browser/nightly/components/GTK4/'
|
dll_url = 'https://downloads.sourceforge.net/project/spitfire-browser/nightly/components/GTK4/'
|
||||||
|
@ -94,50 +103,59 @@ def main():
|
||||||
# Check if all required files are already present
|
# Check if all required files are already present
|
||||||
dll_files = [
|
dll_files = [
|
||||||
'libs.zip'
|
'libs.zip'
|
||||||
# Add more files as needed
|
|
||||||
]
|
]
|
||||||
|
|
||||||
all_files_exist = all(os.path.exists(os.path.join(download_path, filename)) for filename in dll_files)
|
# Get the names of the folders corresponding to ".zip" files
|
||||||
|
zip_folders = [filename.replace('.zip', '') for filename in dll_files if filename.endswith('.zip')]
|
||||||
|
|
||||||
if not all_files_exist:
|
# Check if all corresponding folders exist
|
||||||
# Create a simple GUI window if files are not present
|
all_folders_exist = all(os.path.exists(os.path.join(download_path, folder)) for folder in zip_folders)
|
||||||
|
|
||||||
|
if not all_folders_exist:
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.title("Preparing for first start")
|
root.title("Preparing for first start")
|
||||||
root.geometry("300x100")
|
root.geometry("240x120")
|
||||||
|
|
||||||
progress_var = tk.DoubleVar()
|
progress_var = tk.DoubleVar()
|
||||||
progress = ttk.Progressbar(root, variable=progress_var, length=200)
|
progress = ttk.Progressbar(root, variable=progress_var, length=200)
|
||||||
progress.grid(row=0, column=0, padx=20, pady=20)
|
progress.grid(row=0, column=0, padx=20, pady=20)
|
||||||
|
|
||||||
|
label_var = tk.StringVar()
|
||||||
|
label = tk.Label(root, textvariable=label_var)
|
||||||
|
label.grid(row=1, column=0, padx=20, pady=10)
|
||||||
|
|
||||||
def update_progress_bar(current_size, total_size):
|
def update_progress_bar(current_size, total_size):
|
||||||
progress_value = (current_size / total_size) * 100
|
progress_value = (current_size / total_size) * 100
|
||||||
progress_var.set(progress_value)
|
progress_var.set(progress_value)
|
||||||
root.update_idletasks()
|
root.update_idletasks()
|
||||||
|
|
||||||
def start_download():
|
def update_label(new_label):
|
||||||
# Download GTK4 DLLs if they are not already present
|
label_var.set(new_label)
|
||||||
download_gtk_dlls(download_path, dll_url, dll_files, update_progress_bar)
|
root.update_idletasks()
|
||||||
|
|
||||||
# Set PATH variable and refresh environment variables
|
def start_download():
|
||||||
|
download_gtk_dlls(download_path, dll_url, dll_files, update_progress_bar, update_label)
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
set_path_variable(download_path)
|
set_path_variable(download_path)
|
||||||
|
|
||||||
# Destroy the GUI window
|
for zip_folder in zip_folders:
|
||||||
|
set_path_variable(os.path.join(download_path, zip_folder))
|
||||||
|
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
|
|
||||||
|
# Run your main application function
|
||||||
|
|
||||||
# Run your main application function
|
# Run your main application function
|
||||||
from gui_main import run_installer
|
from gui_main import run_installer
|
||||||
run_installer(download_path)
|
run_installer(download_path)
|
||||||
|
|
||||||
# Schedule the start_download function to run after 100 milliseconds
|
|
||||||
root.after(100, start_download)
|
root.after(100, start_download)
|
||||||
|
|
||||||
# Start the Tkinter event loop
|
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
else:
|
else:
|
||||||
# Run installer directly if all files are present
|
|
||||||
from gui_main import run_installer
|
from gui_main import run_installer
|
||||||
run_installer(download_path)
|
run_installer(download_path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Reference in a new issue