aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Hayden <alexhayden25@gmail.com>2020-11-28 02:11:49 -0500
committerAlexander Hayden <alexhayden25@gmail.com>2020-11-28 02:11:49 -0500
commitf3fafd67f085265a02881ca01474e2b4555495c2 (patch)
tree6ffcf13b9653f826acee6a43caea8ec0ae409684
parent82202fea4f29698dddbc3d588e34e4adce26f2f8 (diff)
downloadmodpackman-f3fafd67f085265a02881ca01474e2b4555495c2.tar.gz
modpackman-f3fafd67f085265a02881ca01474e2b4555495c2.zip
add path generation
-rwxr-xr-xmodpackman.py2
-rw-r--r--util.py24
-rw-r--r--whitelist.txt1
3 files changed, 19 insertions, 8 deletions
diff --git a/modpackman.py b/modpackman.py
index 6e23792..55ebea6 100755
--- a/modpackman.py
+++ b/modpackman.py
@@ -30,7 +30,7 @@ if __name__ == "__main__":
# run the command
if args.command == "install":
- util.install("version.txt", pack["whitelist"], pack['location'])
+ util.install("version.txt", pack["whitelist"], os.path.join(pack['location'], 'mods'))
elif args.command == "apply_updates":
util.apply_updates(mods, "version.txt", pack["game_version"])
elif args.command == "check_updates":
diff --git a/util.py b/util.py
index ed63631..3e9e918 100644
--- a/util.py
+++ b/util.py
@@ -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()
diff --git a/whitelist.txt b/whitelist.txt
deleted file mode 100644
index 76c8d1f..0000000
--- a/whitelist.txt
+++ /dev/null
@@ -1 +0,0 @@
-# file names in here are NOT removed from mods folder during 'install'