2022-01-07 18:08:00 +00:00
|
|
|
import os
|
|
|
|
from zipfile import ZipFile
|
2022-01-19 19:18:27 +00:00
|
|
|
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-08-08 10:40:09 +00:00
|
|
|
minecraft_version = "1.19.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"
|
2022-01-19 19:18:27 +00:00
|
|
|
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 = ""
|
|
|
|
|
2022-06-03 16:11:56 +00:00
|
|
|
refresh_only = False
|
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:11:56 +00:00
|
|
|
if refresh_only == False:
|
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
|
2022-01-19 19:18:27 +00:00
|
|
|
|
|
|
|
# Update pack.toml first
|
2022-03-02 16:47:13 +00:00
|
|
|
pack_version = "-".join(str(Path(cf_zip_path).with_suffix("")).split("-")[1:])
|
2022-01-19 19:18:27 +00:00
|
|
|
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"
|
2022-07-03 08:01:31 +00:00
|
|
|
os.system("mmc-export -i \"" + mmc_zip_path + "\" -f Modrinth --modrinth-search loose -o \"" + mmc_zip_root + "\" -c \"" + modrinth_config + "\" -v " + pack_version + " --scheme \"{abbr}_{name}_{version}\"")
|
2022-06-03 16:00:34 +00:00
|
|
|
if is_legacy == False:
|
2022-07-03 08:01:31 +00:00
|
|
|
extract_file(mmc_zip_root + "\\MR_Fabulously Optimized_" + pack_version + ".mrpack", "modrinth.index.json", git_path + "\\" + "Modrinth", "Modrinth manifest", "Git")
|
2022-06-03 16:00:34 +00:00
|
|
|
|
|
|
|
# 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")
|