diff options
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -7,6 +7,7 @@ import re import collections import urllib.parse import multiprocessing +import pathlib from configparser import ConfigParser import requests @@ -29,9 +30,16 @@ def load_config(): config["pack"]["game_version"] = game_version_from_string(config["pack"]["game_version"]) - #TODO generate a default pack location if "location" not in config["pack"]: - config["pack"]["location"] = f"/tmp/{config['pack']['sanitized_name']}" + if sys.platform == "linux": + config["pack"]["location"] = os.path.join(os.path.expanduser('~'), ".minecraft", config['pack']['sanitized_name']) + elif sys.platform == "win32": + config["pack"]["location"] = os.path.join(os.environ["APPDATA"], ".minecraft", config['pack']['sanitized_name']) + elif sys.platform == "darwin": + config["pack"]["location"] = os.path.join(os.path.expanduser('~'), "Library", "Application Support", "minecraft", config['pack']['sanitized_name']) + else: + raise RuntimeError(f"Unsupported operating system `{sys.platform}`. Please define a location for the pack in your `local-config.ini` file") + # return the whole config file, pack configuration and modlist return config @@ -80,10 +88,14 @@ def game_version_from_string(string): # Apply updates to the actual mod pack -def install(version_file, whitelist, pack_location): +def install(version_file, whitelist, mods_location): pack_version = get_version_from_file(version_file) print("Updating pack with version " + str(pack_version) + "...") print() + + # create the mods folder if it doesn't already exist + pathlib.Path(mods_location).mkdir(parents=True, exist_ok=True) + # (fname, checksum, url) mods = read_file(version_file) names = [mod[0] for mod in mods] @@ -92,7 +104,7 @@ def install(version_file, whitelist, pack_location): i = 0 for mod in mods: - mod_path = os.path.join(pack_location, mod[0]) + mod_path = os.path.join(mods_location, mod[0]) i += 1 if os.path.exists(mod_path) and os.path.isfile(mod_path) and \ hashlib.sha1(open(mod_path, 'rb').read()).hexdigest() == mod[1]: @@ -107,9 +119,9 @@ def install(version_file, whitelist, pack_location): print() print("Removing old mods...") - for jar in os.listdir(pack_location): + for jar in os.listdir(mods_location): if jar not in names and os.path.splitext(jar)[1] == ".jar": - os.remove(os.path.join(pack_location, jar)) + os.remove(os.path.join(mods_location, jar)) print("Removing '{jar}'".format(jar=jar)) print() |