From 3bc44acc3c3ca550e2c06af870349e0ee0739518 Mon Sep 17 00:00:00 2001 From: Fl1tzi Date: Wed, 17 May 2023 00:11:28 +0200 Subject: [PATCH] remove cli tools --- CLI tools/CurseForge to MultiMC-Git.py | 55 ------- CLI tools/CurseForge to Packwiz-Modrinth.py | 159 -------------------- CLI tools/MultiMC to Git.py | 46 ------ CLI tools/README.md | 1 - CLI tools/Update version.py | 26 ---- 5 files changed, 287 deletions(-) delete mode 100644 CLI tools/CurseForge to MultiMC-Git.py delete mode 100644 CLI tools/CurseForge to Packwiz-Modrinth.py delete mode 100644 CLI tools/MultiMC to Git.py delete mode 100644 CLI tools/README.md delete mode 100644 CLI tools/Update version.py diff --git a/CLI tools/CurseForge to MultiMC-Git.py b/CLI tools/CurseForge to MultiMC-Git.py deleted file mode 100644 index 86b4726..0000000 --- a/CLI tools/CurseForge to MultiMC-Git.py +++ /dev/null @@ -1,55 +0,0 @@ -import os, shutil - -user_path = os.path.expanduser("~") -cf_path = user_path + "/curseforge/minecraft/Instances/Fabulously Optimized/" -mmc_path = user_path + "/Documents/MultiMC/instances/Fabulously Optimized/minecraft/" -git_path = user_path + "/Documents/GitHub/fabulously-optimized/" -minecraft_version = "1.19.4" -packwiz_path = git_path + "Packwiz/" + minecraft_version - -# Functions - -def remove_dir(path, description): - if os.path.isdir(path): - shutil.rmtree(path) - print("Deleted " + description) - else: - print("Skipped " + description + " deletion, didn't exist") - -def remove_file(path, description): - if os.path.isfile(path): - os.remove(path) - print("Deleted " + description) - else: - print("Skipped " + description + " deletion, didn't exist") - -def copy_dir(from_path, to_path, from_desc, to_desc): - if os.path.isdir(from_path): - shutil.copytree(from_path, to_path, dirs_exist_ok=True) - print("Copied " + from_desc + " to " + to_desc) - else: - print("Skipped " + from_desc + " copying to " + to_desc + ", didn't exist") - -def copy_file(from_path, to_path, from_desc, to_desc): - if os.path.isfile(from_path): - shutil.copy2(from_path, to_path) - print("Copied " + from_desc + " to " + to_desc) - else: - print("Skipped " + from_desc + " copying to " + to_desc + ", didn't exist") - -# CurseForge to MultiMC - -remove_dir(mmc_path + "config/", "MultiMC configs") -remove_file(mmc_path + "options.txt", "MultiMC options.txt") -remove_dir(mmc_path + "mods/", "MultiMC mods") -remove_dir(mmc_path + "resourcepacks/", "MultiMC resourcepacks") -copy_dir(cf_path + "config/", mmc_path + "config/", "CurseForge configs", "MultiMC") -copy_dir(cf_path + "mods/", mmc_path + "mods/", "CurseForge mods", "MultiMC") -copy_dir(cf_path + "resourcepacks/", mmc_path + "resourcepacks/", "CurseForge resource packs", "MultiMC") - -# CurseForge to Git - -# Manifest and json copying moved to "CurseForge to Packwiz.py" to make sure they are always newest -remove_dir(packwiz_path + "/config/", "Packwiz configs in Git") -copy_dir(cf_path + "config/", packwiz_path + "/config/", "CurseForge configs", "Git (Packwiz)") -copy_dir(cf_path + "resourcepacks/", packwiz_path + "/resourcepacks/", "CurseForge resource packs", "Git (Packwiz)") diff --git a/CLI tools/CurseForge to Packwiz-Modrinth.py b/CLI tools/CurseForge to Packwiz-Modrinth.py deleted file mode 100644 index 77b0a61..0000000 --- a/CLI tools/CurseForge to Packwiz-Modrinth.py +++ /dev/null @@ -1,159 +0,0 @@ -from json import loads as parse_json -from zipfile import ZipFile -from io import BytesIO - -import os -from shutil import unpack_archive -from pathlib import Path -import toml # pip install toml - -user_path = os.path.expanduser("~") -git_path = user_path + "\\Documents\\GitHub\\fabulously-optimized\\" -minecraft_version = "1.19.4" -packwiz_path = git_path + "Packwiz\\" + minecraft_version + "\\" -packwiz_exe_path = "..\packwiz.exe" -mods_path = packwiz_path + "mods" -packwiz_manifest = "pack.toml" - -cf_zip_path = "" -pack_version = "" - -refresh_only = False -is_legacy = False -hydrogen = False -modrinth_overrides = True -mmc_export_packwiz_export = True -mmc_export_modrinth_export = True -packwiz_modrinth_export = False - -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") - -def remove_from_archive(file_path: str, archive_path: str) -> None: - - files = [] - - with ZipFile(archive_path) as archive: - for zipinfo in archive.infolist(): - if zipinfo.filename != file_path: - files.append((zipinfo.filename, archive.read(zipinfo.filename))) - - with ZipFile(archive_path, "w") as archive: - for filename, content in files: archive.writestr(filename, content) - -def read_mod_meta(file_handle: BytesIO) -> dict: - - with ZipFile(file_handle) as archive: - data = archive.read("fabric.mod.json") - return parse_json(data, strict=False) - -def remove_mod_from_archive(mod_name: str, archive_path: str) -> None: - - with ZipFile(archive_path) as archive: - - for zipinfo in archive.infolist(): - - name = zipinfo.filename - - if not name.endswith(".jar"): continue - - with archive.open(name) as mod_file: - mod_meta = read_mod_meta(mod_file) - - if mod_meta["name"] == mod_name: - remove_from_archive(name, archive_path) - return - -def main() -> int: - - mod_files = os.listdir(mods_path) - if not refresh_only: - for item in mod_files: - os.remove( os.path.join(mods_path, item)) - - os.chdir(packwiz_path) - if not refresh_only: - cf_zip_path = input("Please drag the CurseForge zip file here: ")[3:][:-1] # Because dragging the file adds "& " and double quotes - pack_version = "-".join(str(Path(cf_zip_path).with_suffix("")).split("-")[1:]) - - if not mmc_export_packwiz_export and not refresh_only: - # Update pack.toml first - 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 - os.system(packwiz_exe_path + " curseforge import \"" + cf_zip_path + "\"") - if hydrogen: - os.system(packwiz_exe_path + " remove hydrogen") - os.system(packwiz_exe_path + " mr install hydrogen") - if modrinth_overrides: - os.system(packwiz_exe_path + " remove entityculling") - os.system(packwiz_exe_path + " mr install entityculling") - - elif refresh_only: - os.system(packwiz_exe_path + " refresh") - - # Copy fresh manifest/modlist to git - if not is_legacy and not refresh_only: - 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") - - # Export packwiz pack via mmc-export method - if mmc_export_packwiz_export and not refresh_only: - mmc_zip_root = str(Path(cf_zip_path).parents[0]) - mmc_zip_path = mmc_zip_root + "\\Fabulously Optimized " + pack_version + ".zip" - packwiz_config = git_path + "Packwiz\\mmc-export.toml" - - cmd = f'mmc-export -i "{mmc_zip_path}" -f packwiz --modrinth-search loose -o "{mmc_zip_root}" -c "{packwiz_config}" -v {pack_version} --provider-priority Modrinth CurseForge Other --scheme mmc_export_packwiz_output' - os.system(cmd) - - packwiz_zip_path = Path(mmc_zip_root) / "mmc_export_packwiz_output.zip" - packwiz_out_path = Path(git_path) / "Packwiz" / minecraft_version - packwiz_out_path.mkdir(parents=True, exist_ok=True) - unpack_archive(packwiz_zip_path, packwiz_out_path) - - os.remove(packwiz_zip_path) - - # Export Modrinth pack and manifest via mmc-export method - if mmc_export_modrinth_export and not refresh_only: - 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" - - cmd = f'mmc-export -i "{mmc_zip_path}" -f Modrinth --modrinth-search loose -o "{mmc_zip_root}" -c "{modrinth_config}" -v {pack_version} --scheme {"{name}-{version}"}' - os.system(cmd) - - if is_legacy == False: - extract_file(mmc_zip_root + "\\Fabulously Optimized-" + pack_version + ".mrpack", "modrinth.index.json", git_path + "\\" + "Modrinth", "Modrinth manifest", "Git") - - # Export Modrinth pack and manifest via packwiz method - if packwiz_modrinth_export: - os.system(packwiz_exe_path + " modrinth export") - for pack in os.listdir(packwiz_path): - if pack.endswith('.mrpack'): - if is_legacy == False: - extract_file(packwiz_path + "\\" + pack, "modrinth.index.json", git_path + "\\" + "Modrinth", "Modrinth manifest", "Git") - os.replace(packwiz_path + "\\" + pack, os.path.expanduser("~/Desktop") + "\\" + pack) - print("Moved " + pack + " to desktop") - os.system(packwiz_exe_path + " refresh") - - if not refresh_only: - mmc_zip_root = str(Path(cf_zip_path).parents[0]) - mmc_zip_path = mmc_zip_root + "\\Fabulously Optimized " + pack_version + ".zip" - remove_mod_from_archive("Sodium", mmc_zip_path) - - return 0 - -if __name__ == "__main__": - try: main() - except KeyboardInterrupt: - print("Operation aborted by user.") - exit(-1) diff --git a/CLI tools/MultiMC to Git.py b/CLI tools/MultiMC to Git.py deleted file mode 100644 index f23ac86..0000000 --- a/CLI tools/MultiMC to Git.py +++ /dev/null @@ -1,46 +0,0 @@ -import os, shutil, re, zipfile - -user_path = os.path.expanduser("~") -mmc_path = user_path + "/Documents/MultiMC/instances/Fabulously Optimized/" -git_path = user_path + "/Documents/GitHub/fabulously-optimized/" -output_path = user_path + "/Desktop/" - -# Functions - -def copy_file(from_path, to_path, from_desc, to_desc): - if os.path.isfile(from_path): - shutil.copy2(from_path, to_path) - print("Copied " + from_desc + " to " + to_desc) - else: - print("Skipped " + from_desc + " copying to " + to_desc + ", didn't exist") - -def copy_to_archive(from_path, to_path, archive_path): - - files = [] - - with zipfile.ZipFile(archive_path) as archive: - for zipinfo in archive.infolist(): - if zipinfo.filename != to_path: - files.append((zipinfo.filename, archive.read(zipinfo.filename))) - - with zipfile.ZipFile(archive_path, "w") as archive: - for filename, content in files: - archive.writestr(filename, content) - archive.write(from_path, to_path) - -# MultiMC to Git - -version = "0.0.0" -pattern = re.compile(r"\d+\.\d+\.\d+-?\w*\.?\d*") - -with open(mmc_path + "instance.cfg") as file: - if match := pattern.search(file.read()): - version = match.group() - -with open(git_path + "/MultiMC/Fabulously Optimized x.y.z/instance.cfg", "r+") as file: - data = pattern.sub(version, file.read()) - file.seek(0); file.truncate(); file.write(data) - -copy_to_archive(git_path + "/MultiMC/Fabulously Optimized x.y.z/instance.cfg", f"Fabulously Optimized {version}/instance.cfg", output_path + f"Fabulously Optimized {version}.zip") -copy_file(mmc_path + "mmc-pack.json", git_path + "MultiMC/Fabulously Optimized x.y.z/mmc-pack.json", "MultiMC mmc-pack.json", "Git") -copy_file(mmc_path + "pack.png", git_path + "MultiMC/Fabulously Optimized x.y.z/pack.png", "MultiMC pack.png", "Git") \ No newline at end of file diff --git a/CLI tools/README.md b/CLI tools/README.md deleted file mode 100644 index ae17f56..0000000 --- a/CLI tools/README.md +++ /dev/null @@ -1 +0,0 @@ -These files are for the maintainer(s) of Fabulously Optimized, used to copy files faster across folders. Feel free to improve them by making a PR. diff --git a/CLI tools/Update version.py b/CLI tools/Update version.py deleted file mode 100644 index f19a291..0000000 --- a/CLI tools/Update version.py +++ /dev/null @@ -1,26 +0,0 @@ -import os, json - -user_path = os.path.expanduser("~") -cf_path = user_path + "/curseforge/minecraft/Instances/Fabulously Optimized/" -title_screen_path = cf_path + "config/isxander-main-menu-credits.json" -warning_path = cf_path + "config/fabric_loader_dependencies.json" - -def load_json(path): - return json.load(open(path)) - -def save_file(path, obj): - with open(path, "w") as f: - json.dump(obj, f, separators=(',', ':')) - -title_screen_obj = load_json(title_screen_path) -existing_version = title_screen_obj["main_menu"]["bottom_right"][0]["text"] - -print("Current version: " + existing_version) -new_version = input("Enter new version: Fabulously Optimized ") - -title_screen_obj["main_menu"]["bottom_right"][0]["text"] = "Fabulously Optimized " + new_version -save_file(title_screen_path, title_screen_obj) - -warning_file_obj = load_json(warning_path) -warning_file_obj["overrides"]["minecraft"]["+recommends"]["Fabulously Optimized"] = ">" + new_version -save_file(warning_path, warning_file_obj) \ No newline at end of file