mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 06:51:36 +01:00
Compare commits
26 Commits
3912c66bb3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2b2dd3589 | ||
|
|
2b701825b3 | ||
|
|
d2fdc44eef | ||
|
|
010e19e6b4 | ||
|
|
366080afa2 | ||
|
|
3a99e0195b | ||
|
|
1b11b46723 | ||
| 472d9cfca2 | |||
| cf55f6f387 | |||
|
|
2e8a5facfd | ||
| 0dea7a55f4 | |||
|
|
94aaf97a4d | ||
|
|
3579948407 | ||
|
|
597a471949 | ||
|
|
27d32e147b | ||
|
|
ac8e8ad495 | ||
|
|
3368048dd7 | ||
|
|
7f608019ed | ||
|
|
839efae1a3 | ||
|
|
36e5cc3842 | ||
|
|
5ab17e6f4c | ||
|
|
2e5676d5a6 | ||
|
|
a2702d7f70 | ||
|
|
344d32901e | ||
|
|
aefab57bb0 | ||
|
|
d3840c216c |
43
.github/workflows/release.yaml
vendored
Normal file
43
.github/workflows/release.yaml
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
name: Build and Release EXE
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pyinstaller
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Build EXE
|
||||
run: pyinstaller client.py
|
||||
|
||||
- name: Copy helper scripts
|
||||
run: |
|
||||
cp .\dist\run.bat .\dist\client\
|
||||
cp .\dist\run.ps1 .\dist\client\
|
||||
cp .\windows_run_as_admin.ps1 .\dist\client\
|
||||
|
||||
- name: Archive EXE
|
||||
run: Compress-Archive -Path dist\ -DestinationPath release.zip
|
||||
|
||||
- name: Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh release create ${{ github.ref_name }} "release.zip" --generate-notes --title "release-${{ github.ref_name }}"
|
||||
|
||||
37
.github/workflows/server.yaml
vendored
Normal file
37
.github/workflows/server.yaml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: prod
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Login to Docker Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASS }}
|
||||
-
|
||||
name: Build and push gamevault server
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: server
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: "${{ secrets.REGISTRY }}/atlantishq/gamevault-server:latest"
|
||||
31
check_release.py
Normal file
31
check_release.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import requests
|
||||
import os
|
||||
|
||||
REPO = "FAUSheppy/homelab_gamevault"
|
||||
API_URL = f"https://api.github.com/repos/{REPO}/releases/latest"
|
||||
VERSION_FILE = ".gamevault_version"
|
||||
|
||||
def get_latest_release():
|
||||
response = requests.get(API_URL)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
version = data['tag_name']
|
||||
zip_url = data['zipball_url']
|
||||
return version, zip_url
|
||||
|
||||
|
||||
def read_local_version():
|
||||
if not os.path.exists(VERSION_FILE):
|
||||
return None
|
||||
with open(VERSION_FILE, 'r') as f:
|
||||
return f.read().strip()
|
||||
|
||||
def update_updater():
|
||||
pass # TODO
|
||||
# download updater
|
||||
# replace updater
|
||||
|
||||
def execute_updater(new_version):
|
||||
# TODO
|
||||
# os.system(["updater.exe", new_version])
|
||||
pass
|
||||
33
client.py
33
client.py
@@ -11,6 +11,8 @@ import imagetools
|
||||
import webbrowser
|
||||
import statekeeper
|
||||
import infowidget
|
||||
import requests
|
||||
import tkinter
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
customtkinter.set_default_color_theme("blue")
|
||||
@@ -191,13 +193,15 @@ def load_main():
|
||||
if not infowidget_window:
|
||||
infowidget_window = infowidget.ProgressBarApp(app, data_backend=db)
|
||||
|
||||
infowidget_window.root.grid(row=1, column=0, sticky="n")
|
||||
|
||||
# navbar should not expand when window is resized
|
||||
app.grid_rowconfigure(0, weight=0)
|
||||
# buttongrid (scrollable frame) should expand when window is resized
|
||||
app.grid_rowconfigure(1, weight=1)
|
||||
app.grid_columnconfigure(0, weight=1)
|
||||
app.grid_columnconfigure(1, weight=1)
|
||||
# place scrollable frame
|
||||
scrollable_frame.grid(row=1, column=0, sticky="nsew", columnspan=2)
|
||||
scrollable_frame.grid(row=1, column=1, sticky="nsew", columnspan=2)
|
||||
|
||||
|
||||
# create tiles from meta files #
|
||||
@@ -242,7 +246,7 @@ def load_details(app, software):
|
||||
global details_elements
|
||||
|
||||
app.title("Lan Vault: {}".format(software.title))
|
||||
details_elements = client_details.create_details_page(app, software, switch_to_main)
|
||||
details_elements = client_details.create_details_page(app, software, switch_to_main, infowidget_window)
|
||||
|
||||
def create_main_window_tile(software, parent):
|
||||
'''Create the main window tile'''
|
||||
@@ -294,7 +298,7 @@ def update_button_positions(event=None):
|
||||
scrollable_frame.configure(width=app.winfo_width(), height=app.winfo_height())
|
||||
|
||||
# Calculate the number of columns based on the current width of the window #
|
||||
num_columns = app.winfo_width() // 201 # Adjust 100 as needed for button width
|
||||
num_columns = app.winfo_width() // 301 # Adjust 100 as needed for button width
|
||||
|
||||
# window became too small #
|
||||
if num_columns == 0:
|
||||
@@ -312,11 +316,14 @@ def update_button_positions(event=None):
|
||||
continue
|
||||
else:
|
||||
DOWNSHIFT = 1 # FIXME make real navbar
|
||||
button.grid(row=(i // num_columns)+ DOWNSHIFT, column=i % num_columns, sticky="we")
|
||||
RIGHTSHIFT = 1 # first column for loading stuff
|
||||
button.grid(row=(i // num_columns)+ DOWNSHIFT, column=i % num_columns + RIGHTSHIFT, sticky="we")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# run updater #
|
||||
|
||||
pgw = pgwrapper.ProgressBarWrapper()
|
||||
pgw.new(app)
|
||||
|
||||
@@ -352,10 +359,11 @@ if __name__ == "__main__":
|
||||
elif backend_type == "HTTP/HTTPS":
|
||||
server = config_loaded["Server/Path:"]
|
||||
remote_root_dir = None
|
||||
if not server.startswith("http://") or "https://":
|
||||
if not any(server.startswith(s) for s in ["http://", "https://"]):
|
||||
server = "http://" + server
|
||||
if not ":" in server.split("://")[1]:
|
||||
server = server + ":5000"
|
||||
#if not ":" in server.split("://")[1]:
|
||||
# server = server + ":5000"
|
||||
print(server)
|
||||
elif backend_type == "Local Filesystem":
|
||||
remote_root_dir = config_loaded["Server/Path:"]
|
||||
server = None
|
||||
@@ -367,7 +375,8 @@ if __name__ == "__main__":
|
||||
|
||||
# add db backend #
|
||||
if backend_type == "HTTP/HTTPS":
|
||||
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server=server, progress_bar_wrapper=pgw,
|
||||
db = data_backend.HTTP(user, password, install_dir,
|
||||
remote_root_dir="./", server=server, progress_bar_wrapper=pgw,
|
||||
tkinter_root=app, hide_above_age=hide_above_age)
|
||||
elif backend_type == "FTP/FTPS":
|
||||
db = data_backend.FTP(user, password, install_dir, server=server,
|
||||
@@ -382,5 +391,9 @@ if __name__ == "__main__":
|
||||
app.update()
|
||||
|
||||
# fill and run app #
|
||||
load_main() # TODO add button to reopen config # TODO add button to purge cache/purge cache window # TODO show game size on remote
|
||||
try:
|
||||
load_main() # TODO add button to reopen config # TODO add button to purge cache/purge cache window # TODO show game size on remote
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
app.withdraw()
|
||||
tkinter.messagebox.showerror("There was a connection problem", str(e))
|
||||
app.mainloop()
|
||||
|
||||
@@ -4,6 +4,7 @@ import customtkinter
|
||||
import imagetools
|
||||
import os
|
||||
import statekeeper
|
||||
import localaction
|
||||
|
||||
def show_large_picture(app, path):
|
||||
'''Show a full-window version of the clicked picture'''
|
||||
@@ -25,9 +26,11 @@ def show_large_picture(app, path):
|
||||
|
||||
large_image.place(x=30, y=30)
|
||||
|
||||
def create_details_page(app, software, backswitch_function):
|
||||
def create_details_page(app, software, backswitch_function, infowidget_window):
|
||||
'''Create the details page for a software and return its elements for later destruction'''
|
||||
|
||||
infowidget_window.root.grid(row=1, column=0, sticky="n")
|
||||
|
||||
elements = []
|
||||
|
||||
if software.get_thumbnail():
|
||||
@@ -42,7 +45,7 @@ def create_details_page(app, software, backswitch_function):
|
||||
|
||||
# navbar #
|
||||
navbar = customtkinter.CTkFrame(app, fg_color="transparent")
|
||||
navbar.grid(column=0, row=0, padx=10, pady=5, sticky="ew")
|
||||
navbar.grid(column=1, row=0, padx=10, pady=5, sticky="ew")
|
||||
|
||||
# back button
|
||||
back_button = customtkinter.CTkButton(navbar, text="Back", command=backswitch_function)
|
||||
@@ -65,7 +68,7 @@ def create_details_page(app, software, backswitch_function):
|
||||
thumbnail_image = customtkinter.CTkButton(app, text="", image=img, width=500, height=700,
|
||||
fg_color="transparent", hover_color="black", corner_radius=0,
|
||||
command=lambda path=path: show_large_picture(app, path))
|
||||
thumbnail_image.grid(column=0, row=1, padx=10)
|
||||
thumbnail_image.grid(column=1, row=1, padx=10)
|
||||
elements.append(thumbnail_image)
|
||||
|
||||
# fonts #
|
||||
@@ -74,7 +77,7 @@ def create_details_page(app, software, backswitch_function):
|
||||
|
||||
# info box #
|
||||
info_frame = customtkinter.CTkFrame(app, width=500)
|
||||
info_frame.grid(column=1, row=1, sticky="nswe", padx=10)
|
||||
info_frame.grid(column=2, row=1, sticky="nswe", padx=10)
|
||||
elements.append(info_frame)
|
||||
|
||||
# title #
|
||||
@@ -157,7 +160,8 @@ def create_details_page(app, software, backswitch_function):
|
||||
# install button #
|
||||
print(software.run_exe)
|
||||
print(os.path.join(software.backend.install_dir, software.run_exe or ""))
|
||||
if not software.run_exe or not (os.path.isfile(software.run_exe)
|
||||
if not software.run_exe or not (os.path.isfile(software.run_exe)
|
||||
or localaction.check_substitute_path_exists(software.run_exe)
|
||||
or os.path.isfile(os.path.join(software.backend.install_dir, software.title, software.run_exe))):
|
||||
run_button.configure(state=tkinter.DISABLED)
|
||||
run_button.configure(fg_color="gray")
|
||||
|
||||
@@ -20,6 +20,7 @@ class DataBackend:
|
||||
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.auth = (self.user, self.password)
|
||||
self.remote_root_dir = remote_root_dir
|
||||
self.server = server
|
||||
self.install_dir = install_dir
|
||||
@@ -92,6 +93,7 @@ class LocalFS(DataBackend):
|
||||
meta_info_list.append(software.Software(meta_file, self, self.progress_bar_wrapper))
|
||||
|
||||
return list(filter(lambda x: not x.invalid, meta_info_list))
|
||||
|
||||
class HTTP(DataBackend):
|
||||
|
||||
paths_listed = {}
|
||||
@@ -165,10 +167,10 @@ class HTTP(DataBackend):
|
||||
|
||||
# this is with streaming
|
||||
chunk_size = 1024 * 1024 * 5 # 5MB
|
||||
r = requests.get(self._get_url(), params={"path": path, "as_string": True}, stream=True)
|
||||
r = requests.get(self._get_url(), params={"path": path, "as_string": True}, stream=True, auth=(self.user, self.password))
|
||||
r.raise_for_status()
|
||||
|
||||
if path.endswith(".reg") or path.endswith(".txt"):
|
||||
if path.endswith(".txt"):
|
||||
TYPE = "w"
|
||||
else:
|
||||
TYPE = "wb"
|
||||
@@ -197,7 +199,7 @@ class HTTP(DataBackend):
|
||||
|
||||
else:
|
||||
print("Async Requested for:", local_file)
|
||||
statekeeper.add_to_download_queue(self._get_url(), path)
|
||||
statekeeper.add_to_download_queue(self._get_url(), path, auth=(self.user, self.password))
|
||||
return local_file
|
||||
|
||||
elif return_content:
|
||||
@@ -220,7 +222,7 @@ class HTTP(DataBackend):
|
||||
paths = self.paths_listed[fullpath]
|
||||
else:
|
||||
|
||||
r = requests.get(self._get_url(), params={ "path" : path })
|
||||
r = requests.get(self._get_url(), params={ "path" : path }, auth=(self.user, self.password))
|
||||
r.raise_for_status()
|
||||
#print(r, r.status_code, r.content)
|
||||
paths = r.json()["contents"]
|
||||
@@ -273,4 +275,4 @@ class HTTP(DataBackend):
|
||||
print("Age limit set to", self.hide_above_age, "games have", [x.age_limit for x in software_list])
|
||||
results_with_age = list(filter(lambda x: x.age_limit <= self.hide_above_age, results_valid))
|
||||
|
||||
return results_with_age
|
||||
return results_with_age
|
||||
|
||||
1
db.py
1
db.py
@@ -15,6 +15,7 @@ class Download(Base):
|
||||
local_path = Column(String)
|
||||
url = Column(String)
|
||||
size = Column(Integer)
|
||||
count = Column(Integer) # extraction only
|
||||
type = Column(String)
|
||||
finished = Column(Boolean)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# update list and widget
|
||||
|
||||
# update list and widget
|
||||
import tkinter as tk
|
||||
import customtkinter as ctk
|
||||
from tkinter import ttk
|
||||
import threading
|
||||
import random
|
||||
@@ -22,13 +22,16 @@ class ProgressBarApp:
|
||||
|
||||
self.data_backend = data_backend
|
||||
self.parent = parent
|
||||
self.root = tk.Toplevel(parent)
|
||||
self.root.title("Dynamic Progress Bars")
|
||||
self.root = ctk.CTkFrame(parent)
|
||||
#self.root.title("Dynamic Progress Bars")
|
||||
|
||||
self.delete_all_button = tk.Button(self.root, text="Delete All Finished", command=self.delete_all_finished, state=tk.DISABLED)
|
||||
self.delete_all_button = ctk.CTkLabel(self.root, text="Downloads")
|
||||
self.delete_all_button.pack(pady=5)
|
||||
|
||||
self.frame = tk.Frame(self.root)
|
||||
self.delete_all_button = ctk.CTkButton(self.root, text="Delete All Finished", command=self.delete_all_finished, state=ctk.DISABLED)
|
||||
self.delete_all_button.pack(pady=5)
|
||||
|
||||
self.frame = ctk.CTkFrame(self.root)
|
||||
self.frame.pack(pady=10)
|
||||
|
||||
self.progress_bars = [] # Store tuples of (progressbar, frame, duration, delete_button)
|
||||
@@ -48,20 +51,20 @@ class ProgressBarApp:
|
||||
self.already_tracked |= downloads
|
||||
|
||||
for element in new:
|
||||
frame = tk.Frame(self.frame)
|
||||
frame.pack(fill=tk.X, pady=2)
|
||||
frame = ctk.CTkFrame(self.frame)
|
||||
frame.pack(fill=ctk.X, pady=2)
|
||||
|
||||
progress = ttk.Progressbar(frame, length=200, mode='determinate')
|
||||
progress.pack(side=tk.LEFT, padx=5)
|
||||
progress.pack(side=ctk.LEFT, padx=5)
|
||||
|
||||
delete_button = tk.Button(frame, text="Delete", command=lambda f=frame: self.delete_progress(f), state=tk.DISABLED)
|
||||
delete_button.pack(side=tk.LEFT, padx=5)
|
||||
delete_button = ctk.CTkButton(frame, text="Delete", command=lambda f=frame: self.delete_progress(f), state=ctk.DISABLED)
|
||||
delete_button.pack(side=ctk.LEFT, padx=5)
|
||||
|
||||
label = tk.Label(frame, text=os.path.basename(element.path))
|
||||
label.pack(side=tk.LEFT, padx=5)
|
||||
label = ctk.CTkLabel(frame, text=os.path.basename(element.path))
|
||||
label.pack(side=ctk.LEFT, padx=5)
|
||||
|
||||
self.progress_bars.insert(0, (progress, frame, delete_button)) # Insert at the top
|
||||
frame.pack(fill=tk.X, pady=2, before=self.frame.winfo_children()[-1] if self.frame.winfo_children() else None)
|
||||
frame.pack(fill=ctk.X, pady=2, before=self.frame.winfo_children()[-1] if self.frame.winfo_children() else None)
|
||||
|
||||
print("Starting tracker for", element.path)
|
||||
threading.Thread(target=self.fill_progress, args=(progress, element.path, frame, delete_button), daemon=True).start()
|
||||
@@ -83,7 +86,7 @@ class ProgressBarApp:
|
||||
return
|
||||
|
||||
try:
|
||||
percent_filled = statekeeper.get_percent_filled(path)
|
||||
percent_filled = statekeeper.get_percent_filled(path, self.data_backend.auth)
|
||||
except OSError as e:
|
||||
fail_count += 1
|
||||
if fail_count > 6:
|
||||
@@ -94,11 +97,11 @@ class ProgressBarApp:
|
||||
|
||||
print("Percent filled:", percent_filled, path)
|
||||
if percent_filled >= 99.9:
|
||||
self.root.after(0, progress.config, { "value" : 100 })
|
||||
self.root.after(0, progress.configure, { "value" : 100 })
|
||||
print("Finished", path)
|
||||
break
|
||||
else:
|
||||
self.root.after(0, progress.config, { "value" : percent_filled })
|
||||
self.root.after(0, progress.configure, { "value" : percent_filled })
|
||||
time.sleep(0.5)
|
||||
|
||||
# check for stuck downloads #
|
||||
@@ -108,7 +111,7 @@ class ProgressBarApp:
|
||||
else:
|
||||
same_size_count = 0
|
||||
if same_size_count > 100:
|
||||
self.root.after(0, delete_button.config, {"state": tk.NORMAL, "text": "Failed - Delete file manually!"})
|
||||
self.root.after(0, delete_button.configure, {"state": ctk.NORMAL, "text": "Failed - Delete file manually!"})
|
||||
self.progress_bars.append((progress, frame, path, delete_button))
|
||||
self.update_delete_all_button()
|
||||
statekeeper.log_end_download(path)
|
||||
@@ -117,7 +120,7 @@ class ProgressBarApp:
|
||||
prev_precent = percent_filled
|
||||
|
||||
# handle finished download #
|
||||
self.root.after(0, delete_button.config, {"state": tk.NORMAL})
|
||||
self.root.after(0, delete_button.configure, {"state": ctk.NORMAL})
|
||||
self.progress_bars.append((progress, frame, path, delete_button))
|
||||
self.update_delete_all_button()
|
||||
|
||||
@@ -134,10 +137,10 @@ class ProgressBarApp:
|
||||
|
||||
def update_delete_all_button(self):
|
||||
if self.progress_bars:
|
||||
self.delete_all_button.config(state=tk.NORMAL)
|
||||
self.delete_all_button.configure(state=ctk.NORMAL)
|
||||
else:
|
||||
self.delete_all_button.config(state=tk.DISABLED)
|
||||
self.delete_all_button.configure(state=ctk.DISABLED)
|
||||
|
||||
def on_close(self):
|
||||
self.running = False
|
||||
self.root.destroy()
|
||||
self.root.destroy()
|
||||
|
||||
@@ -11,6 +11,7 @@ def render_path(path, install_location, game_directory,):
|
||||
result_path = path[:-len(".j2")]
|
||||
|
||||
# prepare template #
|
||||
print("JINJA-> cwd: ", os.getcwd(), "path:", path)
|
||||
input_content = ""
|
||||
with open(path, encoding="utf-16") as f:
|
||||
input_content = f.read()
|
||||
|
||||
@@ -2,6 +2,8 @@ import subprocess
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import win32com.client
|
||||
import pythoncom
|
||||
|
||||
# windows imports #
|
||||
if os.name == "nt":
|
||||
@@ -43,6 +45,19 @@ def resolve_lnk(lnk_file_path):
|
||||
else:
|
||||
return lnk_file_path # not required on linux
|
||||
|
||||
def substitute_win_paths(path):
|
||||
|
||||
pythoncom.CoInitialize()
|
||||
shell = win32com.client.Dispatch("WScript.Shell")
|
||||
common_programs = shell.SpecialFolders("AllUsersPrograms")
|
||||
path = path.replace("%ProgramData%", common_programs)
|
||||
return path
|
||||
|
||||
def check_substitute_path_exists(path):
|
||||
|
||||
if "%" in path:
|
||||
return os.path.isfile(substitute_win_paths(path))
|
||||
|
||||
def run_exe(path, synchronous=False):
|
||||
'''Launches a given software'''
|
||||
|
||||
@@ -65,13 +80,23 @@ def run_exe(path, synchronous=False):
|
||||
if synchronous:
|
||||
raise NotImplementedError("SYNC not yet implemented")
|
||||
|
||||
print("Raw paths:", paths)
|
||||
|
||||
# substitute program data #
|
||||
paths = [ substitute_win_paths(p) for p in paths ]
|
||||
|
||||
# substituted paths #
|
||||
print("Subs paths:", paths)
|
||||
|
||||
# resolve links #
|
||||
paths = [resolve_lnk(p) if p.endswith(".lnk") else p for p in paths]
|
||||
|
||||
print("Executing:", paths)
|
||||
print("Executing prepared:", paths)
|
||||
|
||||
try:
|
||||
if paths[0].endswith(".reg"):
|
||||
raise OSError("WinError 740")
|
||||
path = paths[0].replace("\\\\", "\\")
|
||||
subprocess.Popen(path, cwd=os.path.dirname(paths[0])) # TODO fix this BS
|
||||
except OSError as e:
|
||||
if "WinError 740" in str(e):
|
||||
|
||||
@@ -4,4 +4,6 @@ customtkinter
|
||||
tqdm
|
||||
Jinja2
|
||||
pyyaml
|
||||
pywin32==<version>; platform_system=="Windows"
|
||||
pywin32==306; platform_system=="Windows"
|
||||
requests
|
||||
sqlalchemy
|
||||
25
software.py
25
software.py
@@ -96,25 +96,27 @@ class Software:
|
||||
|
||||
os.makedirs(software_path, exist_ok=True)
|
||||
|
||||
# beginn progress tracking #
|
||||
with zipfile.ZipFile(cache_src, 'r') as zip_ref:
|
||||
|
||||
statekeeper.log_begin_download(local_path=cache_src, path=cache_src, url=None, type="extraction", start_size=len(zip_ref.infolist()))
|
||||
total_count = zip_ref.infolist()
|
||||
count = 0
|
||||
for member in tqdm.tqdm(total_count, desc='Extracting '):
|
||||
try:
|
||||
zip_ref.extract(member, software_path)
|
||||
count += 1
|
||||
#self.progress_bar_wrapper.get_pb().set(count/len(total_count))
|
||||
#self.progress_bar_wrapper.get_pb().update_idletasks()
|
||||
#self.progress_bar_wrapper.set_text(
|
||||
# text="Extracting: {:.2f}%".format(count/len(total_count)*100))
|
||||
|
||||
# update progress #
|
||||
statekeeper.set_extraction_status(cache_src, count)
|
||||
|
||||
|
||||
except zipfile.error as e:
|
||||
print(e)
|
||||
pass # TODO ???
|
||||
#zip_ref.extractall(software_path)
|
||||
|
||||
#self.progress_bar_wrapper.set_text(text="Loading..")
|
||||
#self.progress_bar_wrapper.update()
|
||||
|
||||
# finish extraction tracking #
|
||||
statekeeper.log_end_download(cache_src, type="extraction")
|
||||
|
||||
def install_async(self):
|
||||
|
||||
@@ -182,8 +184,10 @@ class Software:
|
||||
s.install()
|
||||
|
||||
# run installer if set #
|
||||
print("self.installer", self.installer)
|
||||
if self.installer:
|
||||
installer_path = os.path.join(self.backend.install_dir, self.title, self.installer)
|
||||
print("installer path in if", installer_path)
|
||||
if os.name != "nt" and not os.path.isabs(installer_path):
|
||||
# need abs path for wine #
|
||||
installer_path = os.path.join(os.getcwd(), installer_path)
|
||||
@@ -226,6 +230,9 @@ class Software:
|
||||
|
||||
if self.run_exe:
|
||||
if os.name == "nt" or not ".lnk" in self.run_exe:
|
||||
localaction.run_exe(os.path.join(self.backend.install_dir, self.title, self.run_exe))
|
||||
if self.run_exe.startswith("%") or self.run_exe[1] == ":":
|
||||
localaction.run_exe(self.run_exe)
|
||||
else:
|
||||
localaction.run_exe(os.path.join(self.backend.install_dir, self.title, self.run_exe))
|
||||
else:
|
||||
localaction.run_exe(self.run_exe)
|
||||
|
||||
@@ -8,10 +8,10 @@ from sqlalchemy import or_, and_
|
||||
def _bytes_to_mb(size):
|
||||
return size / (1024*1024)
|
||||
|
||||
def add_to_download_queue(url, path):
|
||||
def add_to_download_queue(url, path, auth):
|
||||
'''The download is added to the global queue and downloaded eventually'''
|
||||
#_download(url, path)
|
||||
thread = threading.Thread(target=_download, args=(url, path))
|
||||
thread = threading.Thread(target=_download, args=(url, path, auth))
|
||||
thread.start()
|
||||
|
||||
def add_to_task_queue(task):
|
||||
@@ -21,9 +21,9 @@ def add_to_task_queue(task):
|
||||
thread.start()
|
||||
#task()
|
||||
|
||||
def _download(url, path):
|
||||
def _download(url, path, auth):
|
||||
|
||||
response = requests.get(url + "?path=" + path, stream=True)
|
||||
response = requests.get(url + "?path=" + path, stream=True, auth=auth)
|
||||
|
||||
# Check if the request was successful
|
||||
if response.status_code == 200:
|
||||
@@ -41,27 +41,45 @@ def _download(url, path):
|
||||
|
||||
raise AssertionError("Non-200 Response for:", url, path, response.status_code, response.text)
|
||||
|
||||
def log_begin_download(path, local_path, url):
|
||||
def log_begin_download(path, local_path, url, type="download", start_size=-1):
|
||||
|
||||
if type == "extraction":
|
||||
print("Extraction path:", path)
|
||||
else:
|
||||
print("Download path", path)
|
||||
|
||||
session = db.session()
|
||||
print("Download path", path)
|
||||
path_exists = session.query(Download).filter(and_(Download.path==path, Download.finished==False)).first()
|
||||
path_exists = session.query(Download).filter(and_(Download.path==path, Download.finished==False, Download.type==type)).first()
|
||||
|
||||
if path_exists and False: # TODO FIX THIS
|
||||
print("DAFUG", path_exists)
|
||||
print("WTF", path_exists.path)
|
||||
raise AssertionError("ERROR: {} is already downloading.".format(path))
|
||||
else:
|
||||
print("Adding to download log:", path)
|
||||
session.merge(Download(path=path, size=-1, type="download", local_path=local_path, url=url, finished=False))
|
||||
session.merge(Download(path=path, size=start_size, type=type, local_path=local_path, url=url, finished=False, count=1))
|
||||
session.commit()
|
||||
|
||||
db.close_session()
|
||||
|
||||
def log_end_download(path):
|
||||
def set_extraction_status(path, count):
|
||||
|
||||
session = db.session()
|
||||
obj = session.query(Download).filter(and_(Download.path==path, Download.type=="extraction")).first()
|
||||
if not obj:
|
||||
print("ERROR: {} is not currently extraction, cannot set status.".format(path))
|
||||
else:
|
||||
obj.count = count
|
||||
session.merge(obj)
|
||||
session.commit()
|
||||
|
||||
db.close_session()
|
||||
|
||||
def log_end_download(path, type="download"):
|
||||
|
||||
print("Downlod end logged", path)
|
||||
session = db.session()
|
||||
obj = session.query(Download).filter(Download.path==path).first()
|
||||
obj = session.query(Download).filter(and_(Download.path==path, Download.type==type)).first()
|
||||
if not obj:
|
||||
raise AssertionError("ERROR: {} is not downloading/cannot remove.".format(path))
|
||||
else:
|
||||
@@ -72,7 +90,7 @@ def log_end_download(path):
|
||||
|
||||
db.close_session()
|
||||
|
||||
def get_download_size(path):
|
||||
def get_download_size(path, auth):
|
||||
|
||||
session = db.session()
|
||||
obj = session.query(Download).filter(Download.path==path).first()
|
||||
@@ -85,7 +103,7 @@ def get_download_size(path):
|
||||
return obj.size
|
||||
|
||||
# query size #
|
||||
r = requests.get(obj.url, params={"path": path, "info": 1})
|
||||
r = requests.get(obj.url, params={"path": path, "info": 1}, auth=auth)
|
||||
r.raise_for_status()
|
||||
|
||||
size = r.json()["size"]
|
||||
@@ -96,14 +114,22 @@ def get_download_size(path):
|
||||
|
||||
return size
|
||||
|
||||
def get_percent_filled(path):
|
||||
def get_percent_filled(path, auth):
|
||||
|
||||
session = db.session()
|
||||
obj = session.query(Download).filter(Download.path==path, Download.finished==False).first()
|
||||
|
||||
if not obj:
|
||||
return 100
|
||||
|
||||
if obj.type == "extraction":
|
||||
return obj.count / obj.size * 100
|
||||
|
||||
if not obj:
|
||||
return 100 # means its finished
|
||||
|
||||
size = _bytes_to_mb(os.stat(obj.local_path).st_size)
|
||||
total_size = get_download_size(obj.path)
|
||||
total_size = get_download_size(obj.path, auth)
|
||||
session.close()
|
||||
|
||||
if total_size == 0:
|
||||
@@ -122,4 +148,4 @@ def get_download(path=None):
|
||||
downloads = session.query(Download).filter(Download.finished==False).all()
|
||||
|
||||
session.close()
|
||||
return downloads
|
||||
return downloads
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -1,7 +1,5 @@
|
||||
# important
|
||||
## downloaded file hash sum check
|
||||
## apply custom tkinter look to pg window & move pg window to better relativ start location so it's no longer blocking the back button by default
|
||||
## zip extraction progress
|
||||
## fix initial startup pictures not loading
|
||||
## implement flush download cache button
|
||||
## fix Call of duty installation chain
|
||||
|
||||
2
updater/requirements.txt
Normal file
2
updater/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
tkinter
|
||||
requests
|
||||
51
updater/updater.py
Normal file
51
updater/updater.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
import requests
|
||||
import zipfile
|
||||
import io
|
||||
import shutil
|
||||
import tkinter as tk
|
||||
|
||||
|
||||
CLIENT_DIR = os.path.join("client")
|
||||
INTERNAL_DIR = os.path.join(CLIENT_DIR, "_internal")
|
||||
|
||||
def prompt_user(version):
|
||||
root = tk.Tk()
|
||||
root.withdraw() # Hide main window
|
||||
result = tk.messagebox.askyesno("Update Available", f"New version {version} available. Download and install?")
|
||||
root.destroy()
|
||||
return result
|
||||
|
||||
def download_and_extract(zip_url):
|
||||
print("Downloading...")
|
||||
response = requests.get(zip_url)
|
||||
response.raise_for_status()
|
||||
with zipfile.ZipFile(io.BytesIO(response.content)) as z:
|
||||
temp_dir = "_temp_extracted"
|
||||
z.extractall(temp_dir)
|
||||
top_folder = next(os.scandir(temp_dir)).path
|
||||
|
||||
# Replace _internal
|
||||
source_internal = os.path.join(top_folder, "client", "_internal")
|
||||
if os.path.exists(INTERNAL_DIR):
|
||||
shutil.rmtree(INTERNAL_DIR)
|
||||
shutil.copytree(source_internal, INTERNAL_DIR)
|
||||
|
||||
# Replace client.exe
|
||||
source_exe = os.path.join(top_folder, "client", "client.exe")
|
||||
target_exe = os.path.join(CLIENT_DIR, "client.exe")
|
||||
shutil.copy2(source_exe, target_exe)
|
||||
|
||||
shutil.rmtree(temp_dir)
|
||||
print("Update complete.")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
|
||||
if prompt_user():
|
||||
download_and_extract()
|
||||
# TODO: run main file again
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user