Modified info to be passed from manifest.json instead of hard coding per file
This commit is contained in:
parent
c954f45715
commit
45ff6e8e99
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
.idea/
|
.idea/
|
||||||
testing_data/
|
testing_data/
|
||||||
|
*.log
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
|
77
piston.py
77
piston.py
@ -1,13 +1,13 @@
|
|||||||
import platform
|
import platform
|
||||||
from pathlib import PurePath, Path
|
from pathlib import PurePath, Path
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
import subprocess
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import argparse
|
||||||
# Launcher/Install profiles are found in .minecraft/launcher_profiles.json
|
|
||||||
|
|
||||||
|
|
||||||
def get_sysroot():
|
def get_sysroot():
|
||||||
@ -38,16 +38,20 @@ def get_modpack_id(modpack_name, install_list):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def main(modpack_path):
|
def main(modpack_path, manifest_path, forge_installer=None):
|
||||||
# Get Minecraft Install Location
|
# Get Minecraft Install Location
|
||||||
sys_root = get_sysroot()
|
sys_root = get_sysroot()
|
||||||
if not sys_root:
|
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}")
|
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:
|
# Get Modpack Name from zipfile:
|
||||||
modpack_name = modpack_path.stem
|
modpack_name = manifest_info['name']
|
||||||
logging.debug(f"Modpack name extracted as: {modpack_name}")
|
logging.debug(f"Modpack name extracted as: {modpack_name}")
|
||||||
|
|
||||||
# Get Minecraft Installs
|
# Get Minecraft Installs
|
||||||
@ -55,24 +59,24 @@ def main(modpack_path):
|
|||||||
modpack_id = get_modpack_id(modpack_name, install_list) or uuid.uuid4().hex
|
modpack_id = get_modpack_id(modpack_name, install_list) or uuid.uuid4().hex
|
||||||
logging.debug(f"Modpack ID extracted as: {modpack_id}")
|
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}")
|
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
|
# Check if modpack is already installed
|
||||||
if modpack_id not in install_list:
|
if modpack_id not in install_list:
|
||||||
logging.info(f"Modpack {modpack_name} ({modpack_id}) not found in install list - creating...")
|
logging.info(f"Modpack {modpack_name} ({modpack_id}) not found in install list - creating...")
|
||||||
install_list[modpack_id] = {
|
install_list[modpack_id] = {
|
||||||
'created': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z',
|
'created': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z',
|
||||||
'gameDir': str(install_path),
|
'gameDir': str(install_path),
|
||||||
'icon': 'Redstone_Block',
|
'icon': manifest_info['icon'],
|
||||||
'javaArgs': '-Xmx4G '
|
'javaArgs': manifest_info['javaArgs'],
|
||||||
'-XX:+UnlockExperimentalVMOptions '
|
|
||||||
'-XX:+UseG1GC -XX:G1NewSizePercent=20 '
|
|
||||||
'-XX:G1ReservePercent=20 '
|
|
||||||
'-XX:MaxGCPauseMillis=50 '
|
|
||||||
'-XX:G1HeapRegionSize=32M',
|
|
||||||
'lastUsed': '',
|
'lastUsed': '',
|
||||||
'lastVersionId': '1.16.5-forge-36.0.43',
|
'lastVersionId': manifest_info['lastVersionId'],
|
||||||
'name': modpack_name,
|
'name': modpack_name,
|
||||||
'type': 'custom'
|
'type': 'custom'
|
||||||
}
|
}
|
||||||
@ -91,7 +95,46 @@ def main(modpack_path):
|
|||||||
logging.info("Validation Completed.")
|
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__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig()
|
parser = argparse.ArgumentParser()
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
parser.add_argument("--log_level", type=str, default='INFO', help='set logging level of this program', nargs='?')
|
||||||
main(PurePath() / 'testing_data' / 'FusterCluck_test.zip')
|
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!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user