mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 06:51:36 +01:00
wip: self updater
This commit is contained in:
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
|
||||||
@@ -320,6 +320,8 @@ def update_button_positions(event=None):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# run updater #
|
||||||
|
|
||||||
pgw = pgwrapper.ProgressBarWrapper()
|
pgw = pgwrapper.ProgressBarWrapper()
|
||||||
pgw.new(app)
|
pgw.new(app)
|
||||||
|
|
||||||
|
|||||||
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