Added an install_modpack function.
This commit is contained in:
25
main.py
25
main.py
@@ -110,6 +110,30 @@ def backup_mods(modpack_dir, mods_backup_dir):
|
||||
else:
|
||||
print("No mods directory found. No backup required.")
|
||||
|
||||
def install_modpack(modpack_url, modpack_dir):
|
||||
print("Downloading modpack...")
|
||||
try:
|
||||
response = requests.get(modpack_url)
|
||||
if response.status_code == 200:
|
||||
print("Extracting modpack...")
|
||||
modpack_zip = zipfile.ZipFile(BytesIO(response.content))
|
||||
for member in modpack_zip.namelist():
|
||||
filename = os.path.basename(member)
|
||||
if not filename:
|
||||
continue
|
||||
|
||||
source = modpack_zip.open(member)
|
||||
target = open(os.path.join(modpack_dir, filename), "wb")
|
||||
|
||||
with source, target:
|
||||
shutil.copyfileobj(source, target)
|
||||
|
||||
print("Modpack installed successfully.")
|
||||
else:
|
||||
print("Failed to download modpack. Please check the URL or your internet connection.")
|
||||
except Exception as e:
|
||||
print(f"An error occurred during modpack installation: {e}")
|
||||
|
||||
# Entry point of the script.
|
||||
def main():
|
||||
try:
|
||||
@@ -117,6 +141,7 @@ def main():
|
||||
install_forge(forge_dir, forge_url)
|
||||
install_forge_libraries(forge_libraries_dir, forge_libraries_url)
|
||||
backup_mods(modpack_dir, mods_backup_dir)
|
||||
install_modpack(modpack_url, modpack_dir)
|
||||
except KeyboardInterrupt:
|
||||
print("\033[91m\nSession ended by user.\033[0m")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user