generateLiteloader.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import os
  2. from datetime import datetime
  3. from typing import List, Tuple, Dict, Optional
  4. from meta.common import ensure_component_dir, polymc_path, upstream_path
  5. from meta.common.liteloader import LITELOADER_COMPONENT, VERSIONS_FILE
  6. from meta.common.mojang import MINECRAFT_COMPONENT
  7. from meta.model import MetaVersion, GradleSpecifier, Library, MetaPackage, Dependency
  8. from meta.model.liteloader import LiteloaderIndex, LiteloaderArtefact
  9. PMC_DIR = polymc_path()
  10. UPSTREAM_DIR = upstream_path()
  11. ensure_component_dir(LITELOADER_COMPONENT)
  12. def process_artefacts(mc_version: str, artefacts: Dict[str, LiteloaderArtefact], is_snapshot: bool) \
  13. -> Tuple[List[MetaVersion], Optional[MetaVersion]]:
  14. versions: List[MetaVersion] = []
  15. lookup: Dict[str, MetaVersion] = {}
  16. latest_version = None
  17. latest = None
  18. for x, artefact in artefacts.items():
  19. if x == 'latest':
  20. latest_version = artefact.version
  21. continue
  22. v = MetaVersion(
  23. name="LiteLoader",
  24. uid=LITELOADER_COMPONENT,
  25. version=artefact.version,
  26. requires=[Dependency(uid=MINECRAFT_COMPONENT, equals=mc_version)],
  27. release_time=datetime.utcfromtimestamp(int(artefact.timestamp)),
  28. additional_tweakers=[artefact.tweakClass],
  29. main_class="net.minecraft.launchwrapper.Launch",
  30. order=10,
  31. libraries=artefact.libraries,
  32. type="release")
  33. if is_snapshot:
  34. v.type = "snapshot"
  35. # hack to make broken liteloader versions work
  36. for lib in v.libraries:
  37. if lib.name == GradleSpecifier("org.ow2.asm", "asm-all", "5.0.3"):
  38. lib.url = "https://repo.maven.apache.org/maven2/"
  39. if lib.name == GradleSpecifier("org.ow2.asm", "asm-all", "5.2"):
  40. lib.url = "http://repo.liteloader.com/"
  41. liteloader_lib = Library(
  42. name=GradleSpecifier("com.mumfrey", "liteloader", v.version),
  43. url="http://dl.liteloader.com/versions/"
  44. )
  45. if is_snapshot:
  46. liteloader_lib.mmcHint = "always-stale"
  47. v.libraries.append(liteloader_lib)
  48. versions.append(v)
  49. lookup[v.version] = v
  50. if latest_version:
  51. latest = lookup[latest_version]
  52. return versions, latest
  53. def process_versions(index: LiteloaderIndex) -> Tuple[List[MetaVersion], List[str]]:
  54. all_versions: List[MetaVersion] = []
  55. recommended: List[str] = []
  56. for mcVersion, versionObject in index.versions.items():
  57. # ignore this for now. It should be a jar mod or something.
  58. if mcVersion == "1.5.2":
  59. continue
  60. latest_release = None
  61. if versionObject.artefacts:
  62. versions, latest_release = process_artefacts(mcVersion, versionObject.artefacts.liteloader, False)
  63. all_versions.extend(versions)
  64. if versionObject.snapshots:
  65. versions, latest_snapshot = process_artefacts(mcVersion, versionObject.snapshots.liteloader, True)
  66. all_versions.extend(versions)
  67. if latest_release:
  68. recommended.append(latest_release.version)
  69. recommended.sort()
  70. all_versions.sort(key=lambda x: x.release_time, reverse=True)
  71. return all_versions, recommended
  72. def main():
  73. index = LiteloaderIndex.parse_file(os.path.join(UPSTREAM_DIR, VERSIONS_FILE))
  74. all_versions, recommended = process_versions(index)
  75. for version in all_versions:
  76. version.write(os.path.join(PMC_DIR, LITELOADER_COMPONENT, f"{version.version}.json"))
  77. package = MetaPackage(uid=LITELOADER_COMPONENT,
  78. name='LiteLoader',
  79. description=index.meta.description,
  80. project_url=index.meta.url,
  81. authors=[index.meta.authors],
  82. recommended=recommended)
  83. package.write(os.path.join(PMC_DIR, LITELOADER_COMPONENT, "package.json"))
  84. if __name__ == '__main__':
  85. main()