Added an install_forge_libraries function.
This commit is contained in:
28
main.py
28
main.py
@@ -66,7 +66,32 @@ def install_forge(forge_dir, forge_url):
|
||||
print("Forge is already installed.")
|
||||
|
||||
# Installs forge files and places them in the correct version folder.
|
||||
|
||||
def install_forge_libraries(forge_libraries_dir, forge_libraries_url):
|
||||
print("Checking for existing Forge libraries installation...")
|
||||
if not Path(forge_libraries_dir).exists():
|
||||
print("Forge libraries not found, beginning download and installation...")
|
||||
os.makedirs(forge_libraries_dir)
|
||||
try:
|
||||
print("Downloading Forge libraries...")
|
||||
response = requests.get(forge_libraries_url)
|
||||
if response.status_code == 200:
|
||||
with zipfile.ZipFile(BytesIO(response.content)) as z:
|
||||
print("Extracting Forge libraries...")
|
||||
common_prefix = os.path.commonprefix(z.namelist())
|
||||
for file_info in z.infolist():
|
||||
target_path = os.path.join(forge_libraries_dir, file_info.filename[len(common_prefix):])
|
||||
if file_info.filename.endswith('/'):
|
||||
os.makedirs(target_path, exist_ok=True)
|
||||
else:
|
||||
with z.open(file_info) as source_file, open(target_path, 'wb') as dest_file:
|
||||
shutil.copyfileobj(source_file, dest_file)
|
||||
print("Forge libraries installed successfully.")
|
||||
else:
|
||||
print("Error downloading Forge libraries. Please check the URL or your internet connection.")
|
||||
except Exception as e:
|
||||
print(f"An error occurred during Forge libraries installation: {e}")
|
||||
else:
|
||||
print("Forge libraries are already installed.")
|
||||
|
||||
# Backups the mods from the mods folder to the backup folder.
|
||||
def backup_mods(modpack_dir, mods_backup_dir):
|
||||
@@ -90,6 +115,7 @@ def main():
|
||||
try:
|
||||
check_minecraft_installation(minecraft_dir)
|
||||
install_forge(forge_dir, forge_url)
|
||||
install_forge_libraries(forge_libraries_dir, forge_libraries_url)
|
||||
backup_mods(modpack_dir, mods_backup_dir)
|
||||
except KeyboardInterrupt:
|
||||
print("\033[91m\nSession ended by user.\033[0m")
|
||||
|
||||
Reference in New Issue
Block a user