Merge branch 'main' of https://weforgecode.xyz/Spitfire/Launcher
This commit is contained in:
commit
90c068fe22
7 changed files with 1065 additions and 64 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -12,4 +12,5 @@ data/config.json
|
|||
downloaded_files/
|
||||
my_app_github/
|
||||
my_app_gitlab/
|
||||
data-backup/
|
||||
data-backup/
|
||||
.config.json
|
||||
|
|
34
dwnld.sh
34
dwnld.sh
|
@ -1,34 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
display_usage() {
|
||||
echo "Downloads all of a SourceForge project's files."
|
||||
echo -e "\nUsage: ./sourceforge-file-download.sh [project name]\n"
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
display_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
project=$1
|
||||
echo "Downloading $project's files"
|
||||
|
||||
# download all the pages on which direct download links are
|
||||
# be nice, sleep a second
|
||||
wget -w 1 -np -m -A download https://sourceforge.net/projects/$project/files/
|
||||
|
||||
# find the files (ignore "latest" link, that should be included as another URL already)
|
||||
find sourceforge.net/ | sed "s#.*${project}/files/##" | grep download$ | grep -v "latest/download" | sed -e "s#^#https://master.dl.sourceforge.net/project/${project}/#" -e "s#/download#?viasf=1#" > urllist
|
||||
|
||||
# download each of the extracted URLs, put into $projectname/
|
||||
while read url; do wget --content-disposition -x -nH --cut-dirs=1 "${url}"; done < urllist
|
||||
|
||||
# remove ?viasf=1 suffix
|
||||
find . -name '*?viasf=1' -print0 | xargs -0 rename --verbose "?viasf=1" ""
|
||||
|
||||
# remove temporary files, unless you want to keep them for some reason
|
||||
rm -ri sourceforge.net/
|
||||
rm -i urllist
|
||||
|
|
@ -5,21 +5,25 @@ import json
|
|||
import json_main
|
||||
import download_gitlab
|
||||
import download_github
|
||||
import install_main
|
||||
|
||||
data_location = "./data/"
|
||||
def sanity_check(download_folder,install_folder):
|
||||
# Ensure that the directory structure exists
|
||||
if not os.path.exists(download_folder):
|
||||
os.makedirs(download_folder)
|
||||
|
||||
# Ensure that the directory structure exists, once again
|
||||
if not os.path.exists(data_location):
|
||||
os.makedirs(data_location)
|
||||
# Ensure that the directory structure exists, once again
|
||||
if not os.path.exists(install_folder):
|
||||
os.makedirs(install_folder)
|
||||
|
||||
# Check if config.json exists and create it with default values if not
|
||||
if not os.path.isfile(data_location+"config.json"):
|
||||
default_data = {
|
||||
"first_run": "false",
|
||||
"packages": []
|
||||
}
|
||||
with open(data_location+"config.json", "w") as json_file:
|
||||
json.dump(default_data, json_file, indent=4)
|
||||
# Check if config.json exists and create it with default values if not
|
||||
if not os.path.isfile(download_folder+"config.json"):
|
||||
default_data = {
|
||||
"first_run": "false",
|
||||
"packages": []
|
||||
}
|
||||
with open(download_folder+"config.json", "w") as json_file:
|
||||
json.dump(default_data, json_file, indent=4)
|
||||
|
||||
# Placeholder functions for SourceForge and Gitea
|
||||
def download_from_sourceforge(url, destination, progress_bar, version):
|
||||
|
@ -31,13 +35,18 @@ def download_from_gitea(api_url, project_id, token, destination, progress_bar, v
|
|||
print("Gita not supported, yet")
|
||||
|
||||
# Function to install all packages
|
||||
def install_all_packages(progress_bar, progress_label):
|
||||
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}")
|
||||
sanity_check(download_folder,install_folder)
|
||||
try:
|
||||
with open(data_location+"config.json", 'r') as file:
|
||||
with open(download_folder+"config.json", 'r') as file:
|
||||
data = json.load(file)
|
||||
packages = data.get("packages", [])
|
||||
total_packages = len(packages)
|
||||
|
||||
|
||||
for index, package in enumerate(packages, start=1):
|
||||
app_name, app_data = package.popitem()
|
||||
source_info = app_data.get("source", {})
|
||||
|
@ -50,10 +59,10 @@ def install_all_packages(progress_bar, progress_label):
|
|||
progress_bar.set_fraction(progress_value)
|
||||
|
||||
if source_type == "github":
|
||||
download_github.download_from_github(source_info["github_url"], app_name, tqdm, version)
|
||||
download_github.download_from_github(source_info["github_url"], 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"], app_name, tqdm, version)
|
||||
source_info["private_token"], 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}")
|
||||
|
@ -61,11 +70,12 @@ def install_all_packages(progress_bar, progress_label):
|
|||
except Exception as e:
|
||||
progress_label.set_text(f"Error processing {app_name}: {e}")
|
||||
print(f"Error processing {app_name}: {e}")
|
||||
install_main.install_all_packages()
|
||||
except FileNotFoundError:
|
||||
progress_label.set_text(f"Config file not found.")
|
||||
print("Config file not found.")
|
||||
|
||||
|
||||
# Check if the script is executed directly
|
||||
if __name__ == "__main__":
|
||||
install_all_packages()
|
||||
# # Check if the script is executed directly
|
||||
# if __name__ == "__main__":
|
||||
# install_all_packages()
|
|
@ -6,6 +6,7 @@ import threading
|
|||
import download_main
|
||||
|
||||
number_of_tabs = 4
|
||||
download_folder = "."
|
||||
|
||||
class InstallerGUI:
|
||||
def __init__(self):
|
||||
|
@ -42,11 +43,12 @@ class UpdaterGUI(Gtk.Box):
|
|||
|
||||
def on_realize(self, widget):
|
||||
# Run the install_all_packages function in a separate thread when the widget becomes visible
|
||||
threading.Thread(target=self.run_installation).start()
|
||||
print(download_folder)
|
||||
threading.Thread(target=self.run_installation(download_folder)).start()
|
||||
|
||||
def run_installation(self):
|
||||
def run_installation(self,download_folder):
|
||||
# Pass the progress bar and label to the install_all_packages function
|
||||
download_main.install_all_packages(self.progress_bar, self.progress_label)
|
||||
download_main.download_all_packages(self.progress_bar, self.progress_label, download_folder,"./data/")
|
||||
# Glib.idle_add() ?
|
||||
|
||||
|
||||
|
@ -201,8 +203,9 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
self.logo_and_title_box.get_children()[0].set_from_pixbuf(logo_pixbuf)
|
||||
|
||||
# Make the MainWindow class callable as a function
|
||||
def run_installer():
|
||||
app = Gtk.Application(application_id="org.example.customizableapp",
|
||||
def run_installer(download_foler_tmp):
|
||||
download_folder = download_foler_tmp
|
||||
app = Gtk.Application(application_id="com.spitfire.launcher",
|
||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||
app.connect("activate", lambda app: MainWindow(application=app))
|
||||
app.run()
|
||||
|
|
4
src/install_main.py
Normal file
4
src/install_main.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
|
||||
def install_all_packages():
|
||||
print("installing!")
|
|
@ -16,7 +16,7 @@ def get_temp_folder():
|
|||
temp_dir = tempfile.gettempdir()
|
||||
|
||||
# Create a subdirectory inside the temporary directory
|
||||
user_temp_folder = os.path.join(temp_dir, 'my_temp_folder')
|
||||
user_temp_folder = os.path.join(temp_dir, 'SpitfireBrowserTmp')
|
||||
|
||||
# Create the directory if it doesn't exist
|
||||
if not os.path.exists(user_temp_folder):
|
||||
|
@ -83,7 +83,7 @@ def main():
|
|||
# Skips entier program if is a different system than windows
|
||||
if sys.platform != 'win32':
|
||||
from gui_main import run_installer
|
||||
run_installer()
|
||||
run_installer(".")
|
||||
return
|
||||
|
||||
# Replace this with the desired download path
|
||||
|
@ -127,7 +127,7 @@ def main():
|
|||
|
||||
# Run your main application function
|
||||
from gui_main import run_installer
|
||||
run_installer()
|
||||
run_installer(download_path)
|
||||
|
||||
# Schedule the start_download function to run after 100 milliseconds
|
||||
root.after(100, start_download)
|
||||
|
@ -137,7 +137,7 @@ def main():
|
|||
else:
|
||||
# Run installer directly if all files are present
|
||||
from gui_main import run_installer
|
||||
run_installer()
|
||||
run_installer(download_path)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Reference in a new issue