From 1e9379636d572dfea9335ec6bd7bcfb0f26e637d Mon Sep 17 00:00:00 2001 From: Joey Eamigh <55670930+JoeyEamigh@users.noreply.github.com> Date: Wed, 21 Jun 2023 21:24:13 -0400 Subject: [PATCH] windows-compatible modpack downloader --- client/client.py | 29 ++++++++++++++++++++++++----- venv.ps1 | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/client/client.py b/client/client.py index 3dc3881..a0d6a66 100644 --- a/client/client.py +++ b/client/client.py @@ -6,7 +6,7 @@ from typing import Any OS = sys.platform -MOD_DOWNLOADER_URL = "https://github.com/Advik-B/CMPDL/releases/download/v3.0.0/CMPDL-raw.ZipApp.zip" +MOD_DOWNLOADER_URL = "https://github.com/Joshyx/ModpackDownloader/releases/download/v1.3/ModpackDownloader-1.3.jar" MODPACK_RELEASES_URL = "https://git.233hfd.com/api/v1/repos/joey/FishPogPixelmon/releases?limit=1" @@ -57,21 +57,40 @@ def mods(): os.chdir(INSTANCE_DIR) if not os.path.exists(os.path.join(INSTANCE_DIR, "downloader.zip")): - cprint("downloader.zip not found - downloading", "yellow") + cprint("downloader.jar not found - downloading", "yellow") r = requests.get(MOD_DOWNLOADER_URL, allow_redirects=True) - open("downloader.zip", "wb").write(r.content) + open("downloader.jar", "wb").write(r.content) cprint("downloading mods. this may take a while, please wait.", "green") - subprocess.run(["python", "downloader.zip", "manifest.json"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + os.makedirs(os.path.join(INSTANCE_DIR, "mods")) + if OS != "win32": + subprocess.run(["java", "-jar", "downloader.jar", ".", "mods"]) + else: + subprocess.run( + [ + "C:\\Program Files\\AdoptOpenJDK\\jdk-11.0.11.9-hotspot\\bin\\java", + "-jar", + "downloader.jar", + ".", + "mods", + ] + ) for file in glob.glob(os.path.join(INSTANCE_DIR, ".minecraft", "mods", "*")): if os.path.basename(file) == "OptiFine_1.16.5_HD_U_G8.jar": continue os.remove(file) - for file in glob.glob(os.path.join(INSTANCE_DIR, "mods", "*")): + for file in glob.glob(os.path.join(INSTANCE_DIR, "mods", "mods", "*")): shutil.move(file, os.path.join(INSTANCE_DIR, ".minecraft", "mods", os.path.basename(file))) + os.makedirs(os.path.join(INSTANCE_DIR, ".minecraft", "resourcepacks"), exist_ok=True) + for file in glob.glob(os.path.join(INSTANCE_DIR, "mods", "resourcepacks", "*")): + if os.path.exists(os.path.join(INSTANCE_DIR, ".minecraft", "resourcepacks", os.path.basename(file))): + continue + shutil.move(file, os.path.join(INSTANCE_DIR, ".minecraft", "resourcepacks", os.path.basename(file))) + shutil.rmtree(os.path.join(INSTANCE_DIR, "mods")) cprint("mods downloaded successfully", "green") diff --git a/venv.ps1 b/venv.ps1 index e0118b1..1e382c1 100644 --- a/venv.ps1 +++ b/venv.ps1 @@ -12,7 +12,7 @@ if (-Not (Test-Path "./.venv")) { } # Activate the virtual environment -. ./.venv/bin/Activate.ps1 +. .\.venv\Scripts\Activate.ps1 # Install required packages & $python -m pip install --upgrade pip