Compare commits

..

No commits in common. "94c58befd8da6af65557ee292884266500b9b390" and "2e33439b6c2399dcaa3e92dcf630fda93c618e48" have entirely different histories.

2 changed files with 43 additions and 44 deletions

2
.gitignore vendored
View File

@ -1,6 +1,4 @@
venv venv
.idea .idea
logs
*.jar *.jar
*.log

View File

@ -1,59 +1,60 @@
import zipfile import zipfile
import json import json
import shutil
import sys import sys
import logging import logging
import minecraft_launcher_lib
from pathlib import Path from pathlib import Path
# action plan for final product: class MinecraftMod:
# 1) Get a list of mod jars from a directory def __init__(self, fileName, filePath, modid, parentMods=None):
# 2) Install appropriate version of minecraft if it is not already installed self.parentMods = parentMods or []
# 3) Install appropriate version of minecraft forge if it is not already installed self.fileName = fileName
# 4) Launch empty version of minecraft forge to generate boilerplate file structure self.filePath = filePath
# 5) Exit the process after it launches successfully self.modid = modid
# 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): def get_mod_info(target_file: Path):
# install vanilla minecraft version if not installed with zipfile.ZipFile(target_file) as z:
# install forge minecraft version if not installed info_files = [f for f in z.filelist if not f.is_dir() and '.info' in f.filename.lower()]
pass rtn_json = json.loads(z.read(info_files[0]))[0]
rtn_json['path'] = target_file
return MinecraftMod(
fileName=z.filename,
filePath=z.filename,
modid=rtn_json['modid'],
parentMods=rtn_json.get('dependencies', [])
)
def launch_minecraft(target_version: str, target_path: Path): def get_modpack_info(target_dir: Path):
# launch minecraft forge for f in target_dir.glob('*.jar'):
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: try:
logging.info(f"Adding mod {mod.name} to instance and launching...") yield get_mod_info(f)
launch_minecraft(target_version, target_path) except (KeyError, IndexError) as e:
logging.info(f"Mod {mod.name} passed!") logging.warning(f'There is no .info in the file {f.name}!')
logging.debug(f"{e}")
except json.decoder.JSONDecodeError as e:
logging.warning(f"The file {f.name} has a corrupted or malformed .info file - skipping!")
except BaseException as e: except BaseException as e:
# if forge failed to launch, disable the mod logging.fatal(f"While parsing file {f.name}, encountered the following unhandled error: {e}")
logging.warning(f"Minecraft failed to launch with mod {mod} added, disabling.\n" raise e
f"Returned error was: {e}")
shutil.move(target_path / mod.name, target_path / f"{mod.name}.disabled")
finally: def main(directory=Path('.')):
logging.debug(f"Test for {mod.name} completed, moving to next mod file...") modpack_info = list(get_modpack_info(directory))
logging.info(f"Testing completed! Any mods that caused failures were marked as .disabled in the directory.") root_mods = [mp for mp in modpack_info if not mp.parentMods]
dependant_mods = [mp for mp in modpack_info if mp.parentMods]
mod_tree = []
for root_mod in root_mods:
mod_tree.append({
root_mod.modid: [mod.modid for mod in dependant_mods if root_mod.modid in mod.parentMods]
})
print(json.dumps(mod_tree, indent=4))
if __name__ == "__main__": if __name__ == "__main__":
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())} 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) logging.getLogger().setLevel(logging.DEBUG)
# main(Path(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods")) main(Path(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods"))