system path win fix

This commit is contained in:
admin 2024-01-11 22:12:06 +01:00
parent af88f68a86
commit d4d5b853dd
5 changed files with 50 additions and 30 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ my_app_github/
my_app_gitlab/
data-backup/
.config.json
nuitka-crash-report.xml

View file

@ -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
pause

View file

@ -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):
download_folder = download_location + "/"
install_folder = install_location + "/"
print(f"install location {install_folder}")
print(f"download location {download_folder}")
print(f"Install location: {install_folder}")
print(f"Download location: {download_folder}")
sanity_check(download_folder,install_folder)
try:
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)
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":
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
else:
progress_label.set_text(f"Unsupported source type for {app_name}: {source_type}")

View file

@ -10,7 +10,7 @@ download_folder = "."
class InstallerGUI:
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)
self.app.connect("activate", self.activate)
@ -204,6 +204,7 @@ class MainWindow(Gtk.ApplicationWindow):
# Make the MainWindow class callable as a function
def run_installer(download_foler_tmp):
global download_folder
download_folder = download_foler_tmp
app = Gtk.Application(application_id="com.spitfire.launcher",
flags=Gio.ApplicationFlags.FLAGS_NONE)

View file

@ -24,7 +24,8 @@ def get_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())
with urlopen(url, context=context) as response, open(destination, 'wb') as out_file:
@ -39,26 +40,35 @@ def download_file(url, destination, progress_callback=None):
current_size += len(buffer)
if progress_callback:
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:
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:
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)):
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
if dll_file.endswith('.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))
def set_path_variable(download_path):
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}")
def main():
# Skips entier program if is a different system than windows
if sys.platform != 'win32':
from gui_main import run_installer
run_installer(".")
return
# Replace this with the desired download path
download_path = get_temp_folder()
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
dll_files = [
'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:
# Create a simple GUI window if files are not present
# Check if all corresponding folders exist
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.title("Preparing for first start")
root.geometry("300x100")
root.geometry("240x120")
progress_var = tk.DoubleVar()
progress = ttk.Progressbar(root, variable=progress_var, length=200)
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):
progress_value = (current_size / total_size) * 100
progress_var.set(progress_value)
root.update_idletasks()
def start_download():
# Download GTK4 DLLs if they are not already present
download_gtk_dlls(download_path, dll_url, dll_files, update_progress_bar)
def update_label(new_label):
label_var.set(new_label)
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':
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()
# Run your main application function
# Run your main application function
from gui_main import run_installer
run_installer(download_path)
# Schedule the start_download function to run after 100 milliseconds
root.after(100, start_download)
# Start the Tkinter event loop
root.mainloop()
else:
# Run installer directly if all files are present
from gui_main import run_installer
run_installer(download_path)
if __name__ == "__main__":
main()