def update_mod(self, params): try: update_file = self.file_pick({"multiple": False})[0] except IndexError: return mod = BcmlMod.from_json(params["mod"]) if (mod.path / "options.json").exists(): options = json.loads((mod.path / "options.json").read_text(), encoding="utf-8") else: options = {} remergers = mergers.get_mergers_for_mod(mod) rmtree(mod.path) with Pool(maxtasksperchild=1000) as pool: new_mod = install.install_mod( Path(update_file), insert_priority=mod.priority, options=options, pool=pool, ) remergers |= { m for m in mergers.get_mergers_for_mod(new_mod) if m.NAME not in {m.NAME for m in remergers} } try: install.refresh_merges() except Exception: # pylint: disable=broad-except pool.terminate() raise
def reprocess(self, params): mod = BcmlMod.from_json(params["mod"]) rmtree(mod.path / "logs") if (mod.path / "options.json").exists(): options = json.loads((mod.path / "options.json").read_text(), encoding="utf-8") else: options = {} install.generate_logs(mod.path, options) install.refresh_merges()
def remerge(self, params): try: if not util.get_installed_mods(): if util.get_master_modpack_dir().exists(): rmtree(util.get_master_modpack_dir()) install.link_master_mod() return if params["name"] == "all": install.refresh_merges() else: [ m() for m in mergers.get_mergers() if m().friendly_name == params["name"] ][0].perform_merge() except Exception as err: # pylint: disable=broad-except raise Exception( f"There was an error merging your mods. {str(err)}\n" "Note that this could leave your game in an unplayable state.")
def install_mod(self, params: dict): util.vprint(params) with Pool(maxtasksperchild=1000) as pool: selects = (params["selects"] if "selects" in params and params["selects"] else {}) mods = [ install.install_mod( Path(m), options=params["options"], selects=selects.get(m, None), pool=pool, ) for m in params["mods"] ] util.vprint(f"Installed {len(mods)} mods") print(f"Installed {len(mods)} mods") try: install.refresh_merges() print("Install complete") except Exception: # pylint: disable=broad-except pool.terminate() raise
def apply_queue(self, params): mods = [] for move_mod in params["moves"]: mod = BcmlMod.from_json(move_mod["mod"]) mods.append(mod) mod.change_priority(move_mod["priority"]) with Pool(maxtasksperchild=500) as pool: for i in params["installs"]: print(i) mods.append( install.install_mod( Path(i["path"].replace("QUEUE", "")), options=i["options"], insert_priority=i["priority"], pool=pool, )) try: install.refresh_merges() except Exception: # pylint: disable=broad-except pool.terminate() raise install.refresh_master_export()
def convert_old_mods(source: Path = None): mod_dir = util.get_modpack_dir() old_path = source or util.get_cemu_dir() / "graphicPacks" / "BCML" print("Copying old mods...") shutil.rmtree(mod_dir, ignore_errors=True) shutil.copytree(old_path, mod_dir) print("Converting old mods...") for i, mod in enumerate( sorted({ d for d in mod_dir.glob("*") if d.is_dir() and d.name != "9999_BCML" })): print(f"Converting {mod.name[4:]}") try: convert_old_mod(mod, True) except Exception as err: shutil.rmtree(mod) install.refresh_merges() raise RuntimeError( f"BCML was unable to convert {mod.name[4:]}. Error: {str(err)}. Your old " f"mods have not been modified. {i} mod(s) were successfully imported." ) from err shutil.rmtree(old_path, ignore_errors=True)