Minor updates / tweaks
This commit is contained in:
parent
33cbf3b4a4
commit
2ca4783a6e
15 changed files with 35 additions and 264 deletions
|
|
@ -1,12 +0,0 @@
|
||||||
@echo off
|
|
||||||
|
|
||||||
:loop
|
|
||||||
|
|
||||||
@echo Processing file: %1
|
|
||||||
python.exe .\main.py %1
|
|
||||||
@echo "Done!"
|
|
||||||
|
|
||||||
shift
|
|
||||||
if not "%~1"=="" goto loop
|
|
||||||
|
|
||||||
@REM pause
|
|
||||||
|
|
@ -1,187 +0,0 @@
|
||||||
"""@author Jose Stovall | github.com/oitsjustjose"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import sys
|
|
||||||
import zipfile
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import toml
|
|
||||||
|
|
||||||
THIS_DIR = Path(__file__).absolute().parent
|
|
||||||
CLEANUP_CONF_PATH = THIS_DIR.joinpath("..").joinpath("configuration.json").resolve()
|
|
||||||
MMC_EXPORT_CONFIG_PATH = THIS_DIR.joinpath("config.toml").resolve()
|
|
||||||
TROUBLEMAKERS_PATH = THIS_DIR.joinpath("troublemakers").resolve()
|
|
||||||
WORKING_FOLDER: Path = Path(".").resolve() # Temp, gets resolved from sys.argv in main()
|
|
||||||
|
|
||||||
# Temporary variables that aren't actually persistent really
|
|
||||||
__TMP_PACK_UNZIPPED_PATH = THIS_DIR.joinpath("activepack").resolve()
|
|
||||||
__TMP_PACK_ZIP_PATH = THIS_DIR.joinpath("activepack.zip").resolve()
|
|
||||||
__TMP_RESPACK_DIR = __TMP_PACK_UNZIPPED_PATH.joinpath("minecraft").joinpath("resourcepacks").resolve()
|
|
||||||
|
|
||||||
|
|
||||||
def print(obj):
|
|
||||||
"""override"""
|
|
||||||
# log_nm_base = sys.argv[1].split("\\")[-1]
|
|
||||||
|
|
||||||
log_nm_base = Path()
|
|
||||||
|
|
||||||
with open(f"./{log_nm_base}.log", "a+", encoding="utf-8") as log_handle:
|
|
||||||
log_handle.write(f"{str(obj)}\n")
|
|
||||||
|
|
||||||
|
|
||||||
def _clean_pack():
|
|
||||||
"""
|
|
||||||
Removes client-only configs/files
|
|
||||||
"""
|
|
||||||
with open(CLEANUP_CONF_PATH, "r", encoding="utf-8") as handle:
|
|
||||||
config = json.loads(handle.read())
|
|
||||||
|
|
||||||
for to_del in config["remove"]:
|
|
||||||
fpath = __TMP_PACK_UNZIPPED_PATH.joinpath("minecraft").joinpath(to_del)
|
|
||||||
|
|
||||||
if not fpath.exists():
|
|
||||||
continue
|
|
||||||
|
|
||||||
if fpath.is_dir():
|
|
||||||
shutil.rmtree(fpath)
|
|
||||||
print(f"Removed directory {fpath}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
fpath.unlink()
|
|
||||||
print(f"Removed file {fpath}")
|
|
||||||
|
|
||||||
|
|
||||||
def _get_modpack_outnames(join: bool = False) -> List[str]:
|
|
||||||
"""
|
|
||||||
Gets the MR_{packname}.mrpack and CF_{packname}.zip names based off of the config.toml contents
|
|
||||||
Args: join (bool) [False]: Whether to join them to the current dir or not
|
|
||||||
Returns: Tuple[str, str]: The MR_ and CF_ paths (in that order)
|
|
||||||
"""
|
|
||||||
with open(MMC_EXPORT_CONFIG_PATH, "r", encoding="utf-8") as handle:
|
|
||||||
name = toml.loads(handle.read())["name"]
|
|
||||||
if join:
|
|
||||||
return [
|
|
||||||
str(THIS_DIR.joinpath(f"MR_{name}.mrpack")),
|
|
||||||
str(THIS_DIR.joinpath(f"CF_{name}.zip")),
|
|
||||||
]
|
|
||||||
return [f"MR_{name}.mrpack", f"CF_{name}.zip"]
|
|
||||||
|
|
||||||
|
|
||||||
def __cleanup() -> None:
|
|
||||||
"""Cleans up output files"""
|
|
||||||
os.unlink(MMC_EXPORT_CONFIG_PATH)
|
|
||||||
os.unlink(__TMP_PACK_ZIP_PATH)
|
|
||||||
shutil.rmtree(__TMP_PACK_UNZIPPED_PATH)
|
|
||||||
shutil.rmtree(TROUBLEMAKERS_PATH)
|
|
||||||
for file in os.listdir(THIS_DIR):
|
|
||||||
if file.startswith("CF_") or file.startswith("MR_"):
|
|
||||||
THIS_DIR.joinpath(file).unlink()
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""
|
|
||||||
The main run function.
|
|
||||||
Args: None
|
|
||||||
Returns: None
|
|
||||||
Process Flow:
|
|
||||||
1. Move file to this dir
|
|
||||||
2. Unzip it, then:
|
|
||||||
1. Clean up the client mods
|
|
||||||
2. Grab the config.toml
|
|
||||||
3. Find any exceptive files that are going to be a PITA and remove them (a. la. Witchery in the RP's dir)
|
|
||||||
3. Re-zip
|
|
||||||
4. mmc-export
|
|
||||||
5. Move files from step 3 into output files
|
|
||||||
6. Move output folders back to originating dir
|
|
||||||
"""
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
print("Missing 2nd parameter File")
|
|
||||||
return
|
|
||||||
|
|
||||||
INPUT_FILE_PATH = Path(sys.argv[1]).resolve().parent
|
|
||||||
if not TROUBLEMAKERS_PATH.exists():
|
|
||||||
TROUBLEMAKERS_PATH.mkdir()
|
|
||||||
|
|
||||||
# STEP 1: copy the modpack locally
|
|
||||||
shutil.copy(INPUT_FILE_PATH.parent, __TMP_PACK_ZIP_PATH)
|
|
||||||
print("STEP 1: SUCCESS")
|
|
||||||
|
|
||||||
# STEP 2: unzip the pack
|
|
||||||
shutil.unpack_archive(__TMP_PACK_ZIP_PATH, __TMP_PACK_UNZIPPED_PATH, "zip")
|
|
||||||
print("STEP 2: SUCCESS")
|
|
||||||
|
|
||||||
# STEP 2.1: clean up client mods
|
|
||||||
_clean_pack()
|
|
||||||
print("STEP 2.1: SUCCESS")
|
|
||||||
|
|
||||||
# STEP 2.2: grab the config.toml file
|
|
||||||
config_toml_path = __TMP_PACK_UNZIPPED_PATH.joinpath("config.toml")
|
|
||||||
if config_toml_path.exists():
|
|
||||||
shutil.move(config_toml_path, MMC_EXPORT_CONFIG_PATH)
|
|
||||||
print("STEP 2.2: SUCCESS")
|
|
||||||
|
|
||||||
# STEP 2.3: grab PITA resourcepacks files like Witchery's 1.7.10 jar
|
|
||||||
if __TMP_RESPACK_DIR.exists() and __TMP_RESPACK_DIR.is_dir():
|
|
||||||
for respack_path in __TMP_RESPACK_DIR.iterdir():
|
|
||||||
if not respack_path.is_dir() and not respack_path.name.endswith(".zip"):
|
|
||||||
shutil.move(respack_path, TROUBLEMAKERS_PATH.joinpath(respack_path.name))
|
|
||||||
print(f"STEP 2.3: Potential Troublemaker Found & Relocated: {respack_path.name}")
|
|
||||||
else:
|
|
||||||
print("No resourcepacks dir - skipping")
|
|
||||||
|
|
||||||
# STEP 3: re-zip & cleanup
|
|
||||||
shutil.make_archive(str(__TMP_PACK_ZIP_PATH.with_suffix("")), "zip", __TMP_PACK_UNZIPPED_PATH)
|
|
||||||
shutil.rmtree(__TMP_PACK_UNZIPPED_PATH)
|
|
||||||
print("STEP 3: SUCCESS")
|
|
||||||
|
|
||||||
# ---- ANY FURTHER REFERENCES TO PACK_UNZIPPED_PATH ARE BAD!! ---- #
|
|
||||||
|
|
||||||
# STEP 4: MMC-EXPORT
|
|
||||||
print("MMC-Exporter is running, please wait")
|
|
||||||
status = os.system(
|
|
||||||
" ".join(
|
|
||||||
f"""
|
|
||||||
mmc-export.exe
|
|
||||||
-i "{__TMP_PACK_ZIP_PATH}"
|
|
||||||
-f Modrinth CurseForge
|
|
||||||
-c "{MMC_EXPORT_CONFIG_PATH}"
|
|
||||||
-o "{THIS_DIR}"
|
|
||||||
""".split()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if status != 0:
|
|
||||||
print("Failed to convert MMC pack to Curse and/or Modrinth. See above log.")
|
|
||||||
return
|
|
||||||
|
|
||||||
print("STEP 4: SUCCESS")
|
|
||||||
|
|
||||||
# STEP 5: Move Troublemakers back to inside each zip
|
|
||||||
output_files = _get_modpack_outnames(join=True)
|
|
||||||
for fname in output_files:
|
|
||||||
with zipfile.ZipFile(THIS_DIR.joinpath(fname), "a") as zipf:
|
|
||||||
for file in TROUBLEMAKERS_PATH.iterdir():
|
|
||||||
troublemaker_path = TROUBLEMAKERS_PATH.joinpath(file)
|
|
||||||
zipf.write(troublemaker_path, f"overrides/resourcepacks/{file}")
|
|
||||||
print("STEP 5: SUCCESS")
|
|
||||||
|
|
||||||
# STEP 6: Move finished pack files back to OG dir
|
|
||||||
output_files = _get_modpack_outnames(join=False)
|
|
||||||
for fname in output_files + ["bundled_links.md"]:
|
|
||||||
shutil.move(THIS_DIR.joinpath(fname), INPUT_FILE_PATH.parent.joinpath(fname))
|
|
||||||
|
|
||||||
print("STEP 6: SUCCESS")
|
|
||||||
|
|
||||||
__cleanup()
|
|
||||||
print("DONE")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except Exception as e:
|
|
||||||
__cleanup()
|
|
||||||
print(e)
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
@echo off
|
|
||||||
|
|
||||||
:loop
|
|
||||||
|
|
||||||
@echo Processing file: %1
|
|
||||||
python.exe .\main.py %1
|
|
||||||
@echo "Done!"
|
|
||||||
|
|
||||||
shift
|
|
||||||
if not "%~1"=="" goto loop
|
|
||||||
|
|
||||||
@REM pause
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
@REM Sets up the Python dependency one time
|
|
||||||
pip install git+https://github.com/tanaydin/gql-query-builder.git@patch-2
|
|
||||||
pip install -U mmc-export
|
|
||||||
|
|
@ -4,16 +4,17 @@ import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List
|
from pathlib import Path
|
||||||
|
|
||||||
THIS_DIR = "\\".join(os.path.realpath(__file__).split("\\")[:-1])
|
THIS_DIR = Path(__file__).absolute().parent
|
||||||
IS_MODRINTH = sys.argv[1].endswith(".mrpack")
|
INPUT_FILE: Path = Path(sys.argv[1]).resolve() # Temp, gets resolved from sys.argv in main()
|
||||||
|
IS_MODRINTH = INPUT_FILE.suffix == ".mrpack"
|
||||||
|
|
||||||
CONFIG_PATH = os.path.join(THIS_DIR, "..", "configuration.json")
|
CONFIG_PATH = THIS_DIR.joinpath("configuration.json").resolve()
|
||||||
PACK_UNZIP_PATH = os.path.join(THIS_DIR, "activepack")
|
|
||||||
PACK_ZIP_PATH = f"{PACK_UNZIP_PATH}.{'mrpack' if IS_MODRINTH else 'zip'}"
|
PACK_UNZIP_PATH = THIS_DIR.joinpath("activepack").resolve()
|
||||||
|
PACK_ZIP_PATH = PACK_UNZIP_PATH.with_suffix(".mrpack" if IS_MODRINTH else ".zip").resolve()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
@ -32,10 +33,10 @@ def print(obj) -> None:
|
||||||
def __cleanup() -> None:
|
def __cleanup() -> None:
|
||||||
"""File and dir cleanup for when the program exits"""
|
"""File and dir cleanup for when the program exits"""
|
||||||
# remove the copied zip file
|
# remove the copied zip file
|
||||||
if os.path.exists(PACK_ZIP_PATH):
|
if PACK_ZIP_PATH.exists():
|
||||||
os.unlink(PACK_ZIP_PATH)
|
PACK_ZIP_PATH.unlink()
|
||||||
# remove any unzipped files
|
# remove any unzipped files
|
||||||
if os.path.exists(PACK_UNZIP_PATH):
|
if PACK_UNZIP_PATH.exists():
|
||||||
shutil.rmtree(PACK_UNZIP_PATH)
|
shutil.rmtree(PACK_UNZIP_PATH)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,31 +45,18 @@ def __get_pack_info() -> ModpackInfo:
|
||||||
Gets the modpack info based on the currently unzipped pack
|
Gets the modpack info based on the currently unzipped pack
|
||||||
Returns None in the event of any failures
|
Returns None in the event of any failures
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(PACK_UNZIP_PATH):
|
if not PACK_UNZIP_PATH.exists():
|
||||||
print(
|
raise Exception(f"[__get_pack_info]: Failed to get Modpack Info: {PACK_UNZIP_PATH} does not exist!")
|
||||||
f"[__get_pack_info]: Failed to get Modpack Info: {PACK_UNZIP_PATH} does not exist!"
|
|
||||||
)
|
|
||||||
return None
|
|
||||||
|
|
||||||
manifest_path: str = None
|
|
||||||
|
|
||||||
if IS_MODRINTH:
|
if IS_MODRINTH:
|
||||||
manifest_path = os.path.join(PACK_UNZIP_PATH, "modrinth.index.json")
|
manifest_path = PACK_UNZIP_PATH.joinpath("modrinth.index.json")
|
||||||
else:
|
else:
|
||||||
manifest_path = os.path.join(PACK_UNZIP_PATH, "manifest.json")
|
manifest_path = PACK_UNZIP_PATH.joinpath("manifest.json")
|
||||||
|
|
||||||
if not manifest_path:
|
|
||||||
print(
|
|
||||||
"[__get_pack_info]: Failed to get Modpack Info: could not find a valid manifest path!"
|
|
||||||
)
|
|
||||||
return None
|
|
||||||
|
|
||||||
with open(manifest_path, "r") as handle:
|
with open(manifest_path, "r") as handle:
|
||||||
manifest = json.loads(handle.read())
|
manifest = json.loads(handle.read())
|
||||||
|
|
||||||
return ModpackInfo(
|
return ModpackInfo(manifest["name"], manifest["versionId" if IS_MODRINTH else "version"])
|
||||||
manifest["name"], manifest["versionId" if IS_MODRINTH else "version"]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def __patch_neo_curse() -> None:
|
def __patch_neo_curse() -> None:
|
||||||
|
|
@ -76,9 +64,9 @@ def __patch_neo_curse() -> None:
|
||||||
Fixes an issue with CurseForge exports from Prism that makes them incompatible
|
Fixes an issue with CurseForge exports from Prism that makes them incompatible
|
||||||
with the CurseForge launcher because CurseForge is fucking stupid
|
with the CurseForge launcher because CurseForge is fucking stupid
|
||||||
"""
|
"""
|
||||||
manifest_path = os.path.join(PACK_UNZIP_PATH, "manifest.json")
|
manifest_path = PACK_UNZIP_PATH.joinpath("manifest.json")
|
||||||
|
|
||||||
if not os.path.exists(manifest_path):
|
if not manifest_path.exists():
|
||||||
print(f"[__patch_neo_curse]: Failed to find manifest at {manifest_path}")
|
print(f"[__patch_neo_curse]: Failed to find manifest at {manifest_path}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -95,9 +83,7 @@ def __patch_neo_curse() -> None:
|
||||||
|
|
||||||
mc_version = manifest["minecraft"]["version"]
|
mc_version = manifest["minecraft"]["version"]
|
||||||
if mc_version not in ["1.20.1"]:
|
if mc_version not in ["1.20.1"]:
|
||||||
print(
|
print(f"[__patch_neo_curse]: Minecraft {mc_version} does not need NeoForge cleanup (or if it does, clean up this script!)")
|
||||||
f"[__patch_neo_curse]: Minecraft {mc_version} does not need NeoForge cleanup (or if it does, clean up this script!)"
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
for modloader in manifest["minecraft"]["modLoaders"]:
|
for modloader in manifest["minecraft"]["modLoaders"]:
|
||||||
|
|
@ -137,7 +123,7 @@ def main() -> None:
|
||||||
print("Unarchived pack successfully!")
|
print("Unarchived pack successfully!")
|
||||||
|
|
||||||
# Read in the config if it exists - if it doesn't, early exit
|
# Read in the config if it exists - if it doesn't, early exit
|
||||||
if not os.path.exists(CONFIG_PATH):
|
if not CONFIG_PATH.exists():
|
||||||
print(f"Failed to find configuration at {CONFIG_PATH}")
|
print(f"Failed to find configuration at {CONFIG_PATH}")
|
||||||
__cleanup()
|
__cleanup()
|
||||||
return
|
return
|
||||||
|
|
@ -147,16 +133,17 @@ def main() -> None:
|
||||||
|
|
||||||
# Prepend the "overrides/" path, remove all files necessary
|
# Prepend the "overrides/" path, remove all files necessary
|
||||||
for target in [f"overrides/{x}" for x in config]:
|
for target in [f"overrides/{x}" for x in config]:
|
||||||
rm_path = os.path.join(PACK_UNZIP_PATH, target)
|
rm_path = PACK_UNZIP_PATH.joinpath(target)
|
||||||
if not os.path.exists(rm_path):
|
if not rm_path.exists():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if os.path.isdir(rm_path):
|
if rm_path.is_dir():
|
||||||
shutil.rmtree(rm_path)
|
shutil.rmtree(rm_path)
|
||||||
print(f"Removed dir {rm_path}")
|
print(f"Removed dir {rm_path}")
|
||||||
else:
|
continue
|
||||||
os.unlink(rm_path)
|
|
||||||
print(f"Removed file {rm_path}")
|
rm_path.unlink
|
||||||
|
print(f"Removed file {rm_path}")
|
||||||
|
|
||||||
# Fix CurseForge packs being pissed about NeoForge :V
|
# Fix CurseForge packs being pissed about NeoForge :V
|
||||||
if not IS_MODRINTH:
|
if not IS_MODRINTH:
|
||||||
|
|
@ -164,25 +151,20 @@ def main() -> None:
|
||||||
|
|
||||||
# Zip up the pack & cleanup the old working directory
|
# Zip up the pack & cleanup the old working directory
|
||||||
info = __get_pack_info()
|
info = __get_pack_info()
|
||||||
shutil.make_archive(
|
shutil.make_archive(str(THIS_DIR.joinpath(f"{info.name} {info.version}")), "zip", PACK_UNZIP_PATH)
|
||||||
os.path.join(THIS_DIR, f"{info.name} {info.version}"), "zip", PACK_UNZIP_PATH
|
|
||||||
)
|
|
||||||
shutil.rmtree(PACK_UNZIP_PATH)
|
shutil.rmtree(PACK_UNZIP_PATH)
|
||||||
if IS_MODRINTH:
|
if IS_MODRINTH:
|
||||||
os.rename(
|
os.rename(
|
||||||
os.path.join(THIS_DIR, f"{info.name} {info.version}.zip"),
|
THIS_DIR.joinpath(f"{info.name} {info.version}.zip"),
|
||||||
os.path.join(THIS_DIR, f"{info.name} {info.version}.mrpack"),
|
THIS_DIR.joinpath(f"{info.name} {info.version}.mrpack"),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Rename .zip to .mrpack if it was a modrinth pack
|
# Rename .zip to .mrpack if it was a modrinth pack
|
||||||
file_name = f"{info.name} {info.version}.{'mrpack' if IS_MODRINTH else 'zip'}"
|
file_name = f"{info.name} {info.version}.{'mrpack' if IS_MODRINTH else 'zip'}"
|
||||||
|
|
||||||
# Move the file back to where it should've started from
|
# Move the file back to where it should've started from
|
||||||
og_dirname = "\\".join(sys.argv[1].split("\\")[:-1])
|
shutil.move(THIS_DIR.joinpath(file_name), INPUT_FILE.parent.joinpath(file_name))
|
||||||
shutil.move(os.path.join(THIS_DIR, file_name), os.path.join(og_dirname, file_name))
|
print(f"Successfully processed & moved/replaced {'Modrinth' if IS_MODRINTH else 'CurseForge'} modpack")
|
||||||
print(
|
|
||||||
f"Successfully processed & moved/replaced {'Modrinth' if IS_MODRINTH else 'CurseForge'} modpack"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
3
windows/modpack-finalizers/requirements.txt
Normal file
3
windows/modpack-finalizers/requirements.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
gql-query-builder @ git+https://github.com/tanaydin/gql-query-builder.git@patch-2
|
||||||
|
mmc-export==2.7.4
|
||||||
|
toml==0.10.2
|
||||||
Loading…
Reference in a new issue