forked from PrismLauncher/meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateNeoForge.py
182 lines (150 loc) · 5.72 KB
/
generateNeoForge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from copy import deepcopy
import os
import re
import sys
from operator import attrgetter
from typing import Collection
from meta.common import ensure_component_dir, launcher_path, upstream_path, static_path
from meta.common.neoforge import (
NEOFORGE_COMPONENT,
INSTALLER_MANIFEST_DIR,
VERSION_MANIFEST_DIR,
DERIVED_INDEX_FILE,
INSTALLER_INFO_DIR,
)
from meta.common.forge import FORGEWRAPPER_LIBRARY
from meta.common.mojang import MINECRAFT_COMPONENT
from meta.model import (
MetaVersion,
Dependency,
Library,
GradleSpecifier,
MojangLibraryDownloads,
MojangArtifact,
MetaPackage,
)
from meta.model.neoforge import (
NeoForgeVersion,
NeoForgeInstallerProfileV2,
InstallerInfo,
DerivedNeoForgeIndex,
)
from meta.model.mojang import MojangVersion
LAUNCHER_DIR = launcher_path()
UPSTREAM_DIR = upstream_path()
STATIC_DIR = static_path()
ensure_component_dir(NEOFORGE_COMPONENT)
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def version_from_build_system_installer(
installer: MojangVersion,
profile: NeoForgeInstallerProfileV2,
version: NeoForgeVersion,
) -> MetaVersion:
v = MetaVersion(name="NeoForge", version=version.rawVersion, uid=NEOFORGE_COMPONENT)
v.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=version.mc_version_sane)]
v.main_class = "io.github.zekerzhayard.forgewrapper.installer.Main"
# FIXME: Add the size and hash here
v.maven_files = []
# load the locally cached installer file info and use it to add the installer entry in the json
info = InstallerInfo.parse_file(
os.path.join(UPSTREAM_DIR, INSTALLER_INFO_DIR, f"{version.long_version}.json")
)
installer_lib = Library(
name=GradleSpecifier(
"net.neoforged", version.artifact, version.long_version, "installer"
)
)
installer_lib.downloads = MojangLibraryDownloads()
installer_lib.downloads.artifact = MojangArtifact(
url="https://maven.neoforged.net/%s" % (installer_lib.name.path()),
sha1=info.sha1hash,
size=info.size,
)
v.maven_files.append(installer_lib)
for forge_lib in profile.libraries:
if forge_lib.name.is_log4j():
continue
v.maven_files.append(forge_lib)
v.libraries = []
v.libraries.append(FORGEWRAPPER_LIBRARY)
for forge_lib in installer.libraries:
if forge_lib.name.is_log4j():
continue
v.libraries.append(forge_lib)
v.release_time = installer.release_time
v.order = 5
mc_args = (
"--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} "
"--assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} "
"--accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}"
)
for arg in installer.arguments.game:
mc_args += f" {arg}"
v.minecraft_arguments = mc_args
return v
def main():
# load the locally cached version list
remote_versions = DerivedNeoForgeIndex.parse_file(
os.path.join(UPSTREAM_DIR, DERIVED_INDEX_FILE)
)
recommended_versions = []
for key, entry in remote_versions.versions.items():
if entry.mc_version is None:
eprint("Skipping %s with invalid MC version" % key)
continue
version = NeoForgeVersion(entry)
if version.url() is None:
eprint("Skipping %s with no valid files" % key)
continue
eprint("Processing Forge %s" % version.rawVersion)
version_elements = version.rawVersion.split(".")
if len(version_elements) < 1:
eprint("Skipping version %s with not enough version elements" % key)
continue
major_version_str = version_elements[0]
if not major_version_str.isnumeric():
eprint(
"Skipping version %s with non-numeric major version %s"
% (key, major_version_str)
)
continue
if entry.recommended:
recommended_versions.append(version.rawVersion)
# If we do not have the corresponding Minecraft version, we ignore it
if not os.path.isfile(
os.path.join(
LAUNCHER_DIR, MINECRAFT_COMPONENT, f"{version.mc_version_sane}.json"
)
):
eprint(
"Skipping %s with no corresponding Minecraft version %s"
% (key, version.mc_version_sane)
)
continue
# Path for new-style build system based installers
installer_version_filepath = os.path.join(
UPSTREAM_DIR, VERSION_MANIFEST_DIR, f"{version.long_version}.json"
)
profile_filepath = os.path.join(
UPSTREAM_DIR, INSTALLER_MANIFEST_DIR, f"{version.long_version}.json"
)
eprint(installer_version_filepath)
assert os.path.isfile(
installer_version_filepath
), f"version {installer_version_filepath} does not have installer version manifest"
installer = MojangVersion.parse_file(installer_version_filepath)
profile = NeoForgeInstallerProfileV2.parse_file(profile_filepath)
v = version_from_build_system_installer(installer, profile, version)
v.write(os.path.join(LAUNCHER_DIR, NEOFORGE_COMPONENT, f"{v.version}.json"))
recommended_versions.sort()
print("Recommended versions:", recommended_versions)
package = MetaPackage(
uid=NEOFORGE_COMPONENT,
name="NeoForge",
project_url="https://neoforged.net",
)
package.recommended = recommended_versions
package.write(os.path.join(LAUNCHER_DIR, NEOFORGE_COMPONENT, "package.json"))
if __name__ == "__main__":
main()