Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Added shaderpacks to modpacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tygoee committed Aug 16, 2023
1 parent e4c3e24 commit bf9561b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ cython_debug/

.vscode/
src/mods/
src/resourcepacks
src/resourcepacks
src/shaderpacks
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ This is what the file structure of an .mcm file should be:
"slug": "(slug)",
"name": "(filename)"
}
],
"shaderpacks": [
{
"type": "(type)",
"slug": "(slug)",
"name": "(filename)"
}
]
}
```
Expand Down Expand Up @@ -65,6 +72,14 @@ An example file:
"name": "unique-spawn-eggs-v1-5.zip",
"media": "texture"
}
],
"shaderpacks": [
{
"type": "cf",
"slug": "complementary-shaders",
"name": "ComplementaryShaders_v4.7.2.zip",
"id": 4570482
}
]
}
```
Expand Down
8 changes: 8 additions & 0 deletions src/example-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,5 +827,13 @@
"name": "xali%27s+Bushy+Leaves+v3.4.1.zip",
"id": 4677561
}
],
"shaderpacks": [
{
"type": "cf",
"slug": "complementary-shaders",
"name": "ComplementaryShaders_v4.7.2.zip",
"id": 4570482
}
]
}
30 changes: 25 additions & 5 deletions src/install/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
Media: TypeAlias = dict[str, Any]


def prepare_media(total_size: int, install_path: str, mods: MediaList, resourcepacks: MediaList) -> int:
def prepare_media(total_size: int, install_path: str, mods: MediaList,
resourcepacks: MediaList, shaderpacks: MediaList) -> int:
"""Get the file size and check media validity while listing all media"""

def check_media_validity(media_list: MediaList, media_type: str) -> None:
Expand Down Expand Up @@ -58,26 +59,45 @@ def get_headers(media: Media, total_size: int) -> int:
if len(resourcepacks) != 0:
check_media_validity(resourcepacks, 'resourcepack')

# List the installed resourcepacks and prepare the resourcepack
# List the installed resourcepacks and prepare them
print("\nResourcepacks:")

for resourcepack in resourcepacks:
# Add the corresponding url to mod['_']
url, resourcepack['_'] = generate_url(
resourcepack, install_path, 'resourcepacks')

# Append the mod size to the total size and save it in mod['_']
# Append the resourcepack size to the total size and save it in mod['_']
total_size = get_headers(resourcepack, total_size)

# Print the mod name
# Print the resourcepack name
print(
f" {resourcepack['slug']} ({parse.unquote(resourcepack['name'])})")

if len(shaderpacks) != 0:
check_media_validity(shaderpacks, 'shaderpack')

# List the installed shaderpacks and prepare them
print("\nShaderpacks:")

for shaderpack in shaderpacks:
# Add the corresponding url to mod['_']
url, shaderpack['_'] = generate_url(
shaderpack, install_path, 'shaderpacks')

# Append the shaderpack size to the total size and save it in mod['_']
total_size = get_headers(shaderpack, total_size)

# Print the shaderpack name
print(
f" {shaderpack['slug']} ({parse.unquote(shaderpack['name'])})")

# At the end, return the total mods size
return total_size


def download_media(url: str, fname: str, size: int, skipped_files: int, outer_bar: tqdm, inner_bar: tqdm) -> int: # type: ignore
def download_media(url: str, fname: str, size: int, skipped_files: int,
outer_bar: tqdm, inner_bar: tqdm) -> int: # type: ignore
if not path.isfile(fname):
description = f"Installing {parse.unquote(path.basename(fname))}..."
if len(description) > get_terminal_size().columns:
Expand Down
32 changes: 17 additions & 15 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
Media: TypeAlias = dict[str, Any]


def download_files(total_size: int, install_path: str, mods: MediaList, resourcepacks: MediaList):
"""Download all files with a tqdm loading bar"""
if not path.isdir(path.join(install_path, 'mods')):
mkdir(path.join(install_path, 'mods'))
if not path.isdir(path.join(install_path, 'resourcepacks')):
mkdir(path.join(install_path, 'resourcepacks'))
def download_files(total_size: int, install_path: str, mods: MediaList,
resourcepacks: MediaList, shaderpacks: MediaList) -> None:
"""Download all files using a tqdm loading bar"""

for folder, media_list in {'mods': mods, 'resourcepacks': resourcepacks, 'shaderpacks': shaderpacks}.items():
if len(media_list) != 0 and not path.isdir(path.join(install_path, folder)):
mkdir(path.join(install_path, folder))

print('\033[?25l') # Hide the cursor
skipped_files = 0
Expand All @@ -28,7 +29,8 @@ def download_files(total_size: int, install_path: str, mods: MediaList, resource
) as outer_bar:
for url, fname, size in (inner_bar := tqdm(
[mod['_'] for mod in mods] +
[resourcepack['_'] for resourcepack in resourcepacks],
[resourcepack['_'] for resourcepack in resourcepacks] +
[shaderpack['_'] for shaderpack in shaderpacks],
position=0,
unit='B',
unit_scale=True,
Expand Down Expand Up @@ -62,7 +64,7 @@ def download_files(total_size: int, install_path: str, mods: MediaList, resource

print(' ' * (get_terminal_size().columns) + '\r', end='')
print(
f"Skipped {skipped_files}/{len(mods) + len(resourcepacks)} files that were already installed" if skipped_files != 0 else '')
f"Skipped {skipped_files}/{len(mods) + len(resourcepacks) + len(shaderpacks)} files that were already installed" if skipped_files != 0 else '')


def install(manifest_file: str, install_path: str = path.dirname(path.realpath(__file__)), confirm: bool = True) -> None:
Expand Down Expand Up @@ -132,14 +134,14 @@ def install(manifest_file: str, install_path: str = path.dirname(path.realpath(_
f"Mod loader: {modloader}\n"
f"Mod loader version: {modloader_version}")

total_size = 0

total_size = media.prepare_media(
total_size, install_path, manifest.get('mods', []), manifest.get('resourcepacks', []))
0, install_path, manifest.get('mods', []),
manifest.get('resourcepacks', []), manifest.get('shaderpacks', [])
)

print(
f"\n{len(manifest.get('mods', []))} mods, {len(manifest.get('resourcepacks', []))} recourcepacks, 0 shaderpacks\n" +
f"Total file size: {filesize.size(total_size, system=filesize.alternative)}") # type: ignore
f"\n{len(manifest.get('mods', []))} mods, {len(manifest.get('resourcepacks', []))} recourcepacks, {len(manifest.get('shaderpacks', []))} shaderpacks\n" +
f"Total file size: {filesize.size(total_size, system=filesize.alternative)}")

# Ask for confirmation if confirm is True and install all modpacks
if confirm == True:
Expand All @@ -150,8 +152,8 @@ def install(manifest_file: str, install_path: str = path.dirname(path.realpath(_
print("Continue (Y/n) ")

# Download all files
download_files(total_size, install_path, manifest.get(
'mods', []), manifest.get('resourcepacks', []))
download_files(total_size, install_path, manifest.get('mods', []),
manifest.get('resourcepacks', []), manifest.get('shaderpacks', []))


if __name__ == '__main__':
Expand Down

0 comments on commit bf9561b

Please sign in to comment.