def update(self):
"""Removes unused old versions of mods from the cache folder."""
all_mods = set([(m.name, m.required_version) for mp in self.mod_manager.modpacks for m in mp.contents])
mods = {}
for cmod in self.mods:
if not cmod.name in mods:
mods[cmod.name] = []
# keep the version list sorted
bisect.insort(mods[cmod.name], parse_version(cmod.version))
for name, versions in mods.items():
newest = "{}.{}.{}".format(*versions[0])
all_versions = {"{}.{}.{}".format(*v) for v in versions}
candidates = {v for n, v in all_mods if n == name and v}
# preserve all mods that are a part of avalable modpack
preserve = {v for v in all_versions if v in candidates}
# preserve newest version of each mod
preserve.add(newest)
for version in (all_versions - preserve):
# NOTE: Far too lazy to figure out what the actual issue is, so I'll assume the CachedMod constructor wants a filename
# cmod = CachedMod(name, version)
cmod = CachedMod(name + "_" + version + ".zip")
assert os.path.exists(cmod.path)
os.remove(cmod.path)
评论列表
文章目录