Modified info to be passed from manifest.json instead of hard coding per file

This commit is contained in:
harmacist 2021-03-05 16:28:36 -06:00
parent c954f45715
commit 45ff6e8e99
2 changed files with 61 additions and 17 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.idea/
testing_data/
*.log
# ---> Python
# Byte-compiled / optimized / DLL files

View File

@ -1,13 +1,13 @@
import platform
from pathlib import PurePath, Path
from os import getenv
import subprocess
import json
import uuid
from zipfile import ZipFile
import datetime
import logging
# Launcher/Install profiles are found in .minecraft/launcher_profiles.json
import argparse
def get_sysroot():
@ -38,16 +38,20 @@ def get_modpack_id(modpack_name, install_list):
return None
def main(modpack_path):
def main(modpack_path, manifest_path, forge_installer=None):
# Get Minecraft Install Location
sys_root = get_sysroot()
if not sys_root:
sys_root = input("Unable to locate your minecraft install - please enter it here: ")
sys_root = input("Unable to locate your minecraft install - please enter the path to it here: ")
logging.debug(f"System path set to: {sys_root}")
# Get Manifest info:
with open(manifest_path, 'r') as f:
manifest_info = json.load(f)
# Get Modpack Name from zipfile:
modpack_name = modpack_path.stem
modpack_name = manifest_info['name']
logging.debug(f"Modpack name extracted as: {modpack_name}")
# Get Minecraft Installs
@ -55,24 +59,24 @@ def main(modpack_path):
modpack_id = get_modpack_id(modpack_name, install_list) or uuid.uuid4().hex
logging.debug(f"Modpack ID extracted as: {modpack_id}")
install_path = sys_root / '.moddedminecraft' / modpack_name
install_path = sys_root / '.moddedminecraft' / modpack_name.replace(' ', '_')
logging.debug(f"Modpack install path set to: {install_path}")
if forge_installer:
install_forge(forge_installer)
else:
logging.info("Forge installer not found/specified, assuming forge is already installed...")
# Check if modpack is already installed
if modpack_id not in install_list:
logging.info(f"Modpack {modpack_name} ({modpack_id}) not found in install list - creating...")
install_list[modpack_id] = {
'created': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z',
'gameDir': str(install_path),
'icon': 'Redstone_Block',
'javaArgs': '-Xmx4G '
'-XX:+UnlockExperimentalVMOptions '
'-XX:+UseG1GC -XX:G1NewSizePercent=20 '
'-XX:G1ReservePercent=20 '
'-XX:MaxGCPauseMillis=50 '
'-XX:G1HeapRegionSize=32M',
'icon': manifest_info['icon'],
'javaArgs': manifest_info['javaArgs'],
'lastUsed': '',
'lastVersionId': '1.16.5-forge-36.0.43',
'lastVersionId': manifest_info['lastVersionId'],
'name': modpack_name,
'type': 'custom'
}
@ -91,7 +95,46 @@ def main(modpack_path):
logging.info("Validation Completed.")
def find_modpack_files(path_to_search=PurePath()):
path = Path(path_to_search)
modpack_zip = None
modpack_manifest = None
forge_installer = None
for p in path.glob("*"):
if p.is_dir():
continue
elif '.jar' in p.name.lower():
forge_installer = p
elif '.zip' in p.name.lower():
modpack_zip = p
elif '.json' in p.name.lower():
modpack_manifest = p
return modpack_zip, modpack_manifest, forge_installer
def install_forge(forge_installer_path):
logging.info(f"Forge installer found, launching...")
subprocess.call(['java', '-jar', Path(forge_installer_path).resolve()])
if __name__ == '__main__':
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
main(PurePath() / 'testing_data' / 'FusterCluck_test.zip')
parser = argparse.ArgumentParser()
parser.add_argument("--log_level", type=str, default='INFO', help='set logging level of this program', nargs='?')
parser.add_argument("--modpackpath", type=str, default=PurePath(), nargs='?')
parser.add_argument("--replace", type=bool, default=True, nargs='?', help='Overwrite contents of the mod folder')
args = parser.parse_args()
logging.basicConfig(filename='piston.log',
filemode='w',
level=getattr(logging, args.log_level.upper()),
format='[%(asctime)s] [%(levelname)s] %(message)s',
datefmt='%Y-%m-%dT%H:%M:%S')
target_dir = args.modpackpath or PurePath()
modpack_zip, modpack_manifest, forge_installer = find_modpack_files(target_dir)
main(modpack_zip, modpack_manifest, forge_installer)
logging.info("Done baking your cake - you can open your minecraft launcher now!")