diff options
Diffstat (limited to 'installer.py')
-rwxr-xr-x | installer.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/installer.py b/installer.py index deecd5b..6e2a758 100755 --- a/installer.py +++ b/installer.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import os import sys @@ -24,11 +25,16 @@ def install_forge(): Downloads and runs the Forge installer specified in pack.ini. """ 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]) + util.download_file(config['pack']['forge_url'], forge_path) + try: + subprocess.check_output([util.find_jre(), "-jar", forge_path]) + except RuntimeError: + if sys.platform == 'win32': + subprocess.check_output(["start", forge_path]) + else: + raise + def setup_forge(profile_id): path_to_profiles = os.path.join(util.find_minecraft_directory(), "launcher_profiles.json") @@ -59,26 +65,33 @@ def setup_forge(profile_id): "lastVersionId": forge_game_version, "type": "custom", "javaArgs": config["pack"]["java_args"], - "icon": util.generate_base64_icon(config["pack"]["icon_name"]) + "icon": util.generate_base64_icon("icon.png") } 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"]) + profile["icon"] = util.generate_base64_icon("icon.png") with open(path_to_profiles, "w") as f: json.dump(profiles, f, indent=2) def main(): + # if we're in a bundle, download the latest pack data from remote source + if hasattr(sys, "_MEIPASS"): + update_self() + 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: + # this is the first time this pack is installed pathlib.Path(config["pack"]["location"]).mkdir(parents=True, exist_ok=True) persistent_data = {"last_forge_url": "no", "profile_id": str(uuid.uuid4()).replace('-', '')} + if os.path.exists(os.path.join(util.find_minecraft_directory(), 'options.txt')): + shutil.copyfile(os.path.join(util.find_minecraft_directory(), 'options.txt'), os.path.join(config["pack"]["location"], "options.txt")) if config["pack"]["forge_url"] != persistent_data["last_forge_url"]: setup_forge(persistent_data["profile_id"]) |