From a47f0a0dd1dd43f90a1a86fa6b67ae551c13a844 Mon Sep 17 00:00:00 2001 From: Alexander Hayden Date: Sat, 19 Dec 2020 19:16:41 -0500 Subject: installer downloads updates & write readme --- util.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'util.py') diff --git a/util.py b/util.py index 0167bbc..d76eb76 100644 --- a/util.py +++ b/util.py @@ -9,7 +9,7 @@ import urllib.parse import multiprocessing import pathlib import base64 -from configparser import ConfigParser +from configparser import RawConfigParser import requests @@ -19,7 +19,7 @@ def load_config(): Load configuarion from pack and local configuration files Fill in reasonable defaults where applicable. """ - config_p = ConfigParser() + config_p = RawConfigParser() config_p.read(["pack.ini", "local-config.ini"]) config = config_p._sections config["pack"]["sanitized_name"] = sanitize_text(config["pack"]["name"]) @@ -44,8 +44,21 @@ def update_self(): in order to update to the latest version. Will overwrite any existing pack.ini and other config files, so be careful! """ + global config + + base_url = config["pack"]["pack_base_url"].strip("/") + "/" + download_file(base_url + "pack.ini", "pack.ini") + download_file(base_url + "pack-lock.ini", "pack-lock.ini") + download_file(base_url + "icon.png", "icon.png") + + pack_lock = RawConfigParser() + pack_lock.read(["pack-lock.ini"]) + for path in pack_lock["global"]["config_files"].split(","): + if not path: + continue + download_file(f"{base_url}config/{path}", os.path.join("config", path)) - raise NotImplementedError() + config = load_config() def find_minecraft_directory(): @@ -78,6 +91,14 @@ def find_jre(): return "C:\\Program Files (x86)\\Minecraft Launcher\\runtime\\jre-x64\\java.exe" raise RuntimeError("Unable to detect an installed JRE. Please install Java in order to use modpackman.") +def download_file(url, destination): + """ + given a url, performs a requests request to get the remote object + and write it to destination + """ + with open(destination, "wb") as f: + dl = requests.get(url, stream=True) + shutil.copyfileobj(dl.raw, f) # take a string and only keep filename-friendly parts def sanitize_text(text): -- cgit v1.2.3