Initial modpack installation implementation

This commit is contained in:
Евгений Титаренко 2023-01-10 22:55:42 +03:00
parent 1e923dacb9
commit 983d0f9e21
4 changed files with 117 additions and 52 deletions

45
mcfs.py
View file

@ -1,6 +1,9 @@
import os
from sys import platform
import shutil
import zipfile
import json
def __get_mc_dir():
directory = ""
@ -11,17 +14,18 @@ def __get_mc_dir():
appdata = os.getenv('APPDATA')
directory = appdata + r"\.minecraft"
elif platform == "darwin":
directory = "~/Library/Application Support/minecraft" #unsure
directory = "~/Library/Application Support/minecraft" # unsure
directory = os.getenv("MC_DIR", directory)
return directory
def __get_cache_dir():
directory = ""
if platform == 'win32':
appdata_local = os.getenv("LOCALAPPDATA")
directory = appdata_local + r"\mc-get"
elif platform == 'darwin':
directory = '~/Library/Caches/mc-get' #unsure
directory = '~/Library/Caches/mc-get' # unsure
elif platform == 'linux':
cache = os.getenv("HOME") + "/.cache"
directory = cache + "/mc-get"
@ -30,15 +34,40 @@ def __get_cache_dir():
directory = cache + "/mc-get"
return directory
def is_path_exist(path:str):
def get_modpack_info(filename: str):
with zipfile.ZipFile(os.path.join(cache_dir, filename)) as modpack:
with modpack.open("modrinth.index.json") as index:
return type("modpack_index", (object,), json.load(index))
def install_modpacks_override(filename: str):
with zipfile.ZipFile(os.path.join(cache_dir, filename)) as modpack:
files = filter(lambda x: x.filename.startswith("overrides/"), modpack.infolist())
for file in files:
if file.is_dir():
continue
_to_path = os.path.join(mc_dir, file.filename[len("overrides/"):])
os.makedirs(os.path.dirname(_to_path), exist_ok=True)
print(file.filename[len("overrides/"):])
with modpack.open(file) as _from, open(_to_path, 'wb') as _to:
shutil.copyfileobj(_from, _to)
def is_path_exist(path: str):
return os.path.exists(os.path.join(path))
def is_standart_dir_structure():
return not os.path.exists(os.path.join(directory, "home"))
def install(filename, subdir:str):
shutil.copy2(os.path.join(cache_dir,filename),\
os.path.join(mc_dir,subdir,filename))
def is_standard_dir_structure():
return not os.path.exists(os.path.join(mc_dir, "home"))
def install(filename, subdir: str):
_from = os.path.join(cache_dir, filename)
_to = os.path.join(mc_dir, subdir, filename)
os.makedirs(os.path.dirname(_to), exist_ok=True)
shutil.copy2(_from, _to)
mc_dir = __get_mc_dir()
cache_dir = __get_cache_dir()