diff options
author | Dylan Jones <dylanjones2011@gmail.com> | 2020-12-19 20:19:56 -0500 |
---|---|---|
committer | Dylan Jones <dylanjones2011@gmail.com> | 2020-12-19 20:19:56 -0500 |
commit | ed471e62c880dd8effbf9f536681e800b1d7e32c (patch) | |
tree | f84b161adaef291c1b9c3dcd60c26aba1589f3b5 | |
parent | a47f0a0dd1dd43f90a1a86fa6b67ae551c13a844 (diff) | |
download | modpackman-ed471e62c880dd8effbf9f536681e800b1d7e32c.tar.gz modpackman-ed471e62c880dd8effbf9f536681e800b1d7e32c.zip |
Fix auto downloader
-rwxr-xr-x | installer.py | 2 | ||||
-rw-r--r-- | util.py | 32 |
2 files changed, 20 insertions, 14 deletions
diff --git a/installer.py b/installer.py index 6e2a758..05384ed 100755 --- a/installer.py +++ b/installer.py @@ -80,7 +80,7 @@ def setup_forge(profile_id): def main(): # if we're in a bundle, download the latest pack data from remote source if hasattr(sys, "_MEIPASS"): - update_self() + util.update_self() persistent_data_path = os.path.join(config["pack"]["location"], "modpackman.json") if os.path.exists(persistent_data_path): @@ -47,9 +47,9 @@ def update_self(): 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") + download_text_file(base_url + "pack.ini?inline=false", "pack.ini") + download_text_file(base_url + "pack-lock.ini?inline=false", "pack-lock.ini") + download_file(base_url + "icon.png?inline=false", "icon.png") pack_lock = RawConfigParser() pack_lock.read(["pack-lock.ini"]) @@ -91,14 +91,25 @@ 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 + Given a url, performs a requests request to get the remote object + and write it to destination. + Note that this only works on binary files. """ with open(destination, "wb") as f: - dl = requests.get(url, stream=True) - shutil.copyfileobj(dl.raw, f) + with requests.get(url, stream=True) as dl: + shutil.copyfileobj(dl.raw, f) + +def download_text_file(url, destination): + """ + Given the URL to a text file, download it to the file named + by `destination`. Note that this only works for text files, not binary files. + """ + with open(destination, "w") as f: + f.write(requests.get(url).text) + # take a string and only keep filename-friendly parts def sanitize_text(text): @@ -111,6 +122,7 @@ 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") @@ -132,12 +144,6 @@ def read_file(fil): return strings -def get_version_from_file(fil): - with open(fil) as f: - for line in f: - if line.strip().split()[0] == "#VERSION": - return int(line.strip().split()[1]) - return 0 def game_version_from_string(string): if string is not None: |