|
| 1 | +# ~~~~~~ |
| 2 | +# NOTE: Do NOT execute this script if you have forked this repo, it will REVERT YOUR CHANGES to the latest release! |
| 3 | +# ~~~~~~ |
| 4 | +import multiprocessing |
| 5 | + |
| 6 | +import requests |
| 7 | +import zipfile |
| 8 | +import io |
| 9 | +import os |
| 10 | +import shutil |
| 11 | +import sys |
| 12 | + |
| 13 | +# --- CONFIGURATION --- |
| 14 | +REPO_OWNER = "Redfourk" |
| 15 | +REPO_NAME = "FileLauncher" |
| 16 | +TAG_NAME = "0.1.0-test.4" |
| 17 | + |
| 18 | + |
| 19 | +ZIP_URL = f"https://codeload.github.com/{REPO_OWNER}/{REPO_NAME}/zip/refs/tags/{TAG_NAME}" |
| 20 | +ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 21 | + |
| 22 | + |
| 23 | +def update_project(): |
| 24 | + try: |
| 25 | + print(f"Connecting to GitHub to download {TAG_NAME}...") |
| 26 | + response = requests.get(ZIP_URL, stream=True, timeout=20) |
| 27 | + response.raise_for_status() |
| 28 | + zip_data = zipfile.ZipFile(io.BytesIO(response.content)) |
| 29 | + temp_dir = os.path.join(ROOT_DIR, "_update_temp") |
| 30 | + if os.path.exists(temp_dir): |
| 31 | + shutil.rmtree(temp_dir) |
| 32 | + zip_data.extractall(temp_dir) |
| 33 | + extracted_folder = os.path.join(temp_dir, f"{REPO_NAME}-{TAG_NAME}") |
| 34 | + |
| 35 | + if not os.path.exists(extracted_folder): |
| 36 | + extracted_folder = os.path.join(temp_dir, os.listdir(temp_dir)[0]) |
| 37 | + |
| 38 | + print("Updating local project files...") |
| 39 | + for item in os.listdir(extracted_folder): |
| 40 | + source = os.path.join(extracted_folder, item) |
| 41 | + destination = os.path.join(ROOT_DIR, item) |
| 42 | + |
| 43 | + if os.path.isdir(source): |
| 44 | + if os.path.exists(destination): |
| 45 | + shutil.rmtree(destination) |
| 46 | + shutil.copytree(source, destination) |
| 47 | + else: |
| 48 | + shutil.copy2(source, destination) |
| 49 | + |
| 50 | + shutil.rmtree(temp_dir) |
| 51 | + print("\nSUCCESS: Project updated to latest version. Please restart.") |
| 52 | + sys.exit() |
| 53 | + |
| 54 | + except requests.exceptions.ConnectionError: |
| 55 | + print("ERROR: Could not connect to GitHub. Check your internet or proxy.") |
| 56 | + except Exception as e: |
| 57 | + print(f"An error occurred: {e}") |
| 58 | + |
| 59 | +if __name__ == "__main__": |
| 60 | + multiprocessing.freeze_support() |
| 61 | + update_project() |
| 62 | + |
0 commit comments