diff options
author | Alexander Hayden <alexhayden25@gmail.com> | 2020-11-30 00:53:05 -0500 |
---|---|---|
committer | Alexander Hayden <alexhayden25@gmail.com> | 2020-11-30 00:53:05 -0500 |
commit | 5b25086399f6a08d087b43ed57a9f3068516d0a2 (patch) | |
tree | 11d019421bb26562da4afd9f6b8cdde9b79c0dd8 | |
parent | b29b1bb338e8745c24d5348de8f65f4667b9e22f (diff) | |
download | modpackman-5b25086399f6a08d087b43ed57a9f3068516d0a2.tar.gz modpackman-5b25086399f6a08d087b43ed57a9f3068516d0a2.zip |
finish automatic forge installer
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | installer.py | 80 | ||||
-rw-r--r-- | jeffrey-3-icon.png | bin | 0 -> 923 bytes | |||
-rwxr-xr-x | modpackman.py | 5 | ||||
-rw-r--r-- | pack.ini | 5 | ||||
-rw-r--r-- | util.py | 5 |
6 files changed, 85 insertions, 11 deletions
@@ -5,3 +5,4 @@ geckodriver.log __pycache__/ *.swp *.swo +*.log diff --git a/installer.py b/installer.py index 2df64a4..16e087f 100644 --- a/installer.py +++ b/installer.py @@ -1,27 +1,91 @@ import subprocess import os import requests +import tempfile +import shutil +import subprocess +import json +import uuid +import pathlib + +from modpackman import install from util import config +import util -def install_forge(java_path): +def install_forge(): """ :param java_path: path to a working Java executable Downloads and runs the Forge installer specified in pack.ini. """ - pass + with tempfile.TemporaryDirectory() as working_dir: + forge_dl = requests.get(config['pack']['forge_url'], stream=True) + forge_path = os.path.join(working_dir, "forge_installer.jar") + with open(forge_path, 'wb') as f: + shutil.copyfileobj(forge_dl.raw, f) + subprocess.check_output([util.find_jre(), "-jar", forge_path]) +def setup_forge(profile_id): + path_to_profiles = os.path.join(util.find_minecraft_directory(), "launcher_profiles.json") + # first, find current profiles so we can figure out which forge installs + with open(path_to_profiles, "r") as f: + profiles = json.load(f) + old_profile_ids = set(profiles["profiles"].keys()) + + # install forge, should add a new profile + install_forge() -def create_profile(): - """ - Automatically create a launcher profile for the modpack. - """ - pass + with open(path_to_profiles, "r") as f: + profiles = json.load(f) + difference = set(profiles["profiles"].keys()) - old_profile_ids + if difference: + forge_profile_id = next(difference) + forge_game_version = profiles["profiles"][forge_profile_id]["lastVersionId"] + del profiles["profiles"][forge_profile_id] + else: + # this will probably break soon :( + game_version, forge_version = config["pack"]["forge_url"].split("/")[-2].split('-') + forge_game_version = f"{game_version}-forge-{forge_version}" + + if profile_id not in profiles["profiles"]: + profile = { + "name": config["pack"]["name"], + "gameDir": config["pack"]["location"], + "lastVersionId": forge_game_version, + "type": "custom", + "javaArgs": config["pack"]["java_args"], + "icon": util.generate_base64_icon(config["pack"]["icon_name"]) + } + profiles["profiles"][profile_id] = profile + else: + profile = profiles["profiles"][profile_id] + profile["lastVersionId"] = forge_game_version + profile["icon"] = util.generate_base64_icon(config["pack"]["icon_name"]) + with open(path_to_profiles, "w") as f: + json.dump(profiles, f, indent=2) def main(): - pass + persistent_data_path = os.path.join(config["pack"]["location"], "modpackman.json") + if os.path.exists(persistent_data_path): + with open(persistent_data_path, "r") as f: + persistent_data = json.load(f) + else: + pathlib.Path(config["pack"]["location"]).mkdir(parents=True, exist_ok=True) + persistent_data = {"last_forge_url": "no", "profile_id": str(uuid.uuid4()).replace('-', '')} + + if config["pack"]["forge_url"] != persistent_data["last_forge_url"]: + setup_forge(persistent_data["profile_id"]) + persistent_data["last_forge_url"] = config["pack"]["forge_url"] + with open(persistent_data_path, "w") as f: + json.dump(persistent_data, f, indent=2) + + ##todo install mods + install() + + + if __name__ == '__main__': diff --git a/jeffrey-3-icon.png b/jeffrey-3-icon.png Binary files differnew file mode 100644 index 0000000..d60084b --- /dev/null +++ b/jeffrey-3-icon.png diff --git a/modpackman.py b/modpackman.py index 77b0c2c..1bd28d4 100755 --- a/modpackman.py +++ b/modpackman.py @@ -11,7 +11,10 @@ import util from util import config # Apply updates to the actual mod pack -def install(version_file, whitelist, mods_location): +def install(): + mods_location = os.path.join(config["pack"]["location"], "mods") + whitelist = config["pack"]["whitelist"] + version_file = "version.txt" pack_version = util.get_version_from_file(version_file) print("Updating pack with version " + str(pack_version) + "...") print() @@ -1,8 +1,9 @@ [pack] name = J.E.F.F.R.E.Y 3 -forge_url = forge.com +forge_url = https://files.minecraftforge.net/maven/net/minecraftforge/forge/1.16.4-35.1.7/forge-1.16.4-35.1.7-installer.jar game_version = 1.16.4 -icon_name = jeffrey-3.png +icon_name = jeffrey-3-icon.png +java_args = -Xmx6G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M [mods] # Possibly controversial mods - subject to further review @@ -8,6 +8,7 @@ import collections import urllib.parse import multiprocessing import pathlib +import base64 from configparser import ConfigParser import requests @@ -79,6 +80,10 @@ def sanitize_text(text): sanitized += replacement_map[char] return sanitized +def generate_base64_icon(filename): + with open(filename, "rb") as f: + return "data:image/png;base64," + base64.b64encode(f.read()).decode("utf8") + def read_file(fil): """ |