modpack/CLI tools/CurseForge to Packwiz-Modrinth.py

84 lines
3.5 KiB
Python
Raw Normal View History

2022-01-07 18:08:00 +00:00
import os
from zipfile import ZipFile
from pathlib import Path
import toml # pip install toml
2022-01-07 18:08:00 +00:00
user_path = os.path.expanduser("~")
2022-06-03 16:00:34 +00:00
git_path = user_path + "\\Documents\\GitHub\\fabulously-optimized\\"
2022-03-01 20:37:36 +00:00
minecraft_version = "1.18.2"
2022-06-03 16:00:34 +00:00
packwiz_path = git_path + "Packwiz\\" + minecraft_version + "\\"
2022-01-19 16:12:02 +00:00
packwiz_exe_path = "..\packwiz.exe"
2022-01-07 18:08:00 +00:00
mods_path = packwiz_path + "mods"
packwiz_manifest = "pack.toml"
2022-01-07 18:08:00 +00:00
2022-06-03 16:00:34 +00:00
cf_zip_path = ""
pack_version = ""
refresh_only = True
2022-01-19 16:12:02 +00:00
is_legacy = False
2022-03-14 16:26:33 +00:00
hydrogen = False
2022-05-23 16:11:34 +00:00
modrinth_overrides = True
2022-06-03 16:00:34 +00:00
mmc_export_modrinth_export = True
packwiz_modrinth_export = False
2022-01-07 18:08:00 +00:00
def extract_file(from_zip, from_file, to_path, from_desc, to_desc):
with ZipFile(from_zip, 'r') as zip:
if from_file in zip.namelist():
zip.extract(from_file, to_path)
print("Copied " + from_desc + " to " + to_desc)
else:
print("Skipped " + from_desc + " copying to " + to_desc + ", didn't exist")
2022-01-19 16:12:02 +00:00
mod_files = os.listdir(mods_path)
if refresh_only == False:
for item in mod_files:
os.remove( os.path.join(mods_path, item))
2022-01-07 18:08:00 +00:00
os.chdir(packwiz_path)
2022-06-03 16:00:34 +00:00
if refresh_only == True:
2022-05-24 05:04:37 +00:00
cf_zip_path = input("Please drag the CurseForge zip file here: ")[3:][:-1] # Because dragging the file adds "& " and double quotes
# Update pack.toml first
pack_version = "-".join(str(Path(cf_zip_path).with_suffix("")).split("-")[1:])
with open(packwiz_manifest, "r") as f:
pack_toml = toml.load(f)
pack_toml["version"] = pack_version
with open(packwiz_manifest, "w") as f:
toml.dump(pack_toml, f)
# Packwiz import
2022-01-19 16:12:02 +00:00
os.system(packwiz_exe_path + " curseforge import \"" + cf_zip_path + "\"")
2022-03-14 16:26:33 +00:00
if hydrogen:
2022-01-19 16:12:02 +00:00
os.system(packwiz_exe_path + " remove hydrogen")
os.system(packwiz_exe_path + " mr install hydrogen")
2022-05-23 16:11:34 +00:00
if modrinth_overrides:
2022-06-01 04:26:52 +00:00
os.system(packwiz_exe_path + " remove entityculling")
os.system(packwiz_exe_path + " mr install entityculling")
2022-01-19 16:12:02 +00:00
os.system(packwiz_exe_path + " refresh")
2022-01-07 18:08:00 +00:00
# Copy fresh manifest/modlist to git
2022-01-19 16:12:02 +00:00
if is_legacy == False and refresh_only == False:
2022-05-24 05:04:37 +00:00
extract_file(cf_zip_path, "manifest.json", git_path + "CurseForge", "CurseForge manifest.json", "Git")
extract_file(cf_zip_path, "modlist.html", git_path + "CurseForge", "CurseForge modlist.html", "Git")
2022-01-07 18:08:00 +00:00
2022-06-03 16:00:34 +00:00
# Export Modrinth pack and manifest via mmc-export method
if mmc_export_modrinth_export:
mmc_zip_root = str(Path(cf_zip_path).parents[0])
mmc_zip_path = mmc_zip_root + "\\Fabulously Optimized " + pack_version + ".zip"
modrinth_config = git_path + "Modrinth\\mmc-export.toml"
os.system("mmc-export -i \"" + mmc_zip_path + "\" -f Modrinth --modrinth-search loose -o \"" + mmc_zip_root + "\" -c \"" + modrinth_config + "\" -v " + pack_version)
if is_legacy == False:
extract_file(mmc_zip_root + "\\MR_Fabulously Optimized.mrpack", "modrinth.index.json", git_path + "\\" + "Modrinth", "Modrinth manifest", "Git")
# Export Modrinth pack and manifest via packwiz method
if packwiz_modrinth_export:
2022-05-23 16:11:34 +00:00
os.system(packwiz_exe_path + " modrinth export")
for pack in os.listdir(packwiz_path):
if pack.endswith('.mrpack'):
if is_legacy == False:
2022-06-03 16:00:34 +00:00
extract_file(packwiz_path + "\\" + pack, "modrinth.index.json", git_path + "\\" + "Modrinth", "Modrinth manifest", "Git")
os.replace(packwiz_path + "\\" + pack, os.path.expanduser("~/Desktop") + "\\" + pack)
2022-05-23 16:11:34 +00:00
print("Moved " + pack + " to desktop")
os.system(packwiz_exe_path + " refresh")