Project_Glowstone/GlowstoneDust.py

60 lines
2.3 KiB
Python

import zipfile
import json
import shutil
import sys
import logging
import minecraft_launcher_lib
from pathlib import Path
# action plan for final product:
# 1) Get a list of mod jars from a directory
# 2) Install appropriate version of minecraft if it is not already installed
# 3) Install appropriate version of minecraft forge if it is not already installed
# 4) Launch empty version of minecraft forge to generate boilerplate file structure
# 5) Exit the process after it launches successfully
# 6) For each Jar:
# a) Copy jar to directory
# b) Attempt to launch the game
# c) Record whether or not the game successfully launched/built/etc
# d) If the game failed to launch, mark the jar as disabled
# e) Continue to next jar
def get_mod_list(target_dir: Path):
for f in target_dir.glob("*.jar"):
yield f
def setup_minecraft(target_version: str, target_path: Path):
# install vanilla minecraft version if not installed
# install forge minecraft version if not installed
pass
def launch_minecraft(target_version: str, target_path: Path):
# launch minecraft forge
pass
def test_mods(target_version: str, target_path: Path, modpack_path: Path):
for mod in get_mod_list(modpack_path):
shutil.copyfile(mod, target_path)
try:
logging.info(f"Adding mod {mod.name} to instance and launching...")
launch_minecraft(target_version, target_path)
logging.info(f"Mod {mod.name} passed!")
except BaseException as e:
# if forge failed to launch, disable the mod
logging.warning(f"Minecraft failed to launch with mod {mod} added, disabling.\n"
f"Returned error was: {e}")
shutil.move(target_path / mod.name, target_path / f"{mod.name}.disabled")
finally:
logging.debug(f"Test for {mod.name} completed, moving to next mod file...")
logging.info(f"Testing completed! Any mods that caused failures were marked as .disabled in the directory.")
if __name__ == "__main__":
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())}
logging.getLogger().setLevel(logging.DEBUG)
# main(Path(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods"))