-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87b0bfe
commit 4bff382
Showing
4 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from metautil import * | ||
import jsonobject | ||
|
||
# barebones semver-like parser | ||
def isFabricVerStable(ver): | ||
s = ver.split("+") | ||
return ("-" not in s[0]) | ||
|
||
class FabricInstallerArguments(JsonObject): | ||
client = ListProperty(StringProperty) | ||
common = ListProperty(StringProperty) | ||
server = ListProperty(StringProperty) | ||
|
||
class FabricInstallerLaunchwrapper(JsonObject): | ||
tweakers = ObjectProperty(FabricInstallerArguments, required=True) | ||
|
||
class FabricInstallerLibraries(JsonObject): | ||
client = ListProperty(MultiMCLibrary) | ||
common = ListProperty(MultiMCLibrary) | ||
server = ListProperty(MultiMCLibrary) | ||
|
||
class FabricInstallerDataV1(JsonObject): | ||
version = IntegerProperty(required=True) | ||
libraries = ObjectProperty(FabricInstallerLibraries, required=True) | ||
mainClass = jsonobject.DefaultProperty() | ||
arguments = ObjectProperty(FabricInstallerArguments, required=False) | ||
launchwrapper = ObjectProperty(FabricInstallerLaunchwrapper, required=False) | ||
|
||
class FabricJarInfo(JsonObject): | ||
releaseTime = ISOTimestampProperty() | ||
size = IntegerProperty() | ||
sha256 = StringProperty() | ||
sha1 = StringProperty() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/python3 | ||
from fabricutil import * | ||
from jsonobject import * | ||
from datetime import datetime | ||
from pprint import pprint | ||
import os, copy | ||
|
||
# turn loader versions into packages | ||
loaderRecommended = [] | ||
loaderVersions = [] | ||
intermediaryRecommended = [] | ||
intermediaryVersions = [] | ||
|
||
def mkdirs(path): | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
|
||
mkdirs("multimc/net.fabricmc.fabric-loader") | ||
mkdirs("multimc/net.fabricmc.intermediary") | ||
|
||
def loadJarInfo(mavenKey): | ||
with open("upstream/fabric/jars/" + mavenKey.replace(":", ".") + ".json", 'r', encoding='utf-8') as jarInfoFile: | ||
return FabricJarInfo(json.load(jarInfoFile)) | ||
|
||
def processLoaderVersion(loaderVersion, it, loaderData): | ||
verStable = isFabricVerStable(loaderVersion) | ||
if (len(loaderRecommended) < 1) and verStable: | ||
loaderRecommended.append(loaderVersion) | ||
versionJarInfo = loadJarInfo(it["maven"]) | ||
version = MultiMCVersionFile(name="Fabric Loader", uid="net.fabricmc.fabric-loader", version=loaderVersion) | ||
version.releaseTime = versionJarInfo.releaseTime | ||
version.requires = [] | ||
version.order = 10 | ||
if verStable: | ||
version.type = "release" | ||
else: | ||
version.type = "snapshot" | ||
if isinstance(loaderData.mainClass, dict): | ||
version.mainClass = loaderData.mainClass["client"] | ||
else: | ||
version.mainClass = loaderData.mainClass | ||
version.libraries = [] | ||
version.libraries.extend(loaderData.libraries.common) | ||
version.libraries.extend(loaderData.libraries.client) | ||
loaderLib = MultiMCLibrary(name=GradleSpecifier(it["maven"]), url="https://maven.fabricmc.net") | ||
version.libraries.append(loaderLib) | ||
loaderVersions.append(version) | ||
|
||
def processIntermediaryVersion(it): | ||
intermediaryRecommended.append(it["version"]) | ||
versionJarInfo = loadJarInfo(it["maven"]) | ||
version = MultiMCVersionFile(name="Intermediary Mappings", uid="net.fabricmc.intermediary", version=it["version"]) | ||
version.releaseTime = versionJarInfo.releaseTime | ||
version.requires = [DependencyEntry(uid='net.minecraft', equals=it["version"])] | ||
version.order = 10 | ||
version.type = "release" | ||
version.libraries = [] | ||
mappingLib = MultiMCLibrary(name=GradleSpecifier(it["maven"]), url="https://maven.fabricmc.net") | ||
version.libraries.append(mappingLib) | ||
intermediaryVersions.append(version) | ||
|
||
with open("upstream/fabric/meta-v2/loader.json", 'r', encoding='utf-8') as loaderVersionIndexFile: | ||
loaderVersionIndex = json.load(loaderVersionIndexFile) | ||
for it in loaderVersionIndex: | ||
version = it["version"] | ||
with open("upstream/fabric/loader-installer-json/" + version + ".json", 'r', encoding='utf-8') as loaderVersionFile: | ||
ldata = json.load(loaderVersionFile) | ||
ldata = FabricInstallerDataV1(ldata) | ||
processLoaderVersion(version, it, ldata) | ||
|
||
with open("upstream/fabric/meta-v2/intermediary.json", 'r', encoding='utf-8') as intermediaryVersionIndexFile: | ||
intermediaryVersionIndex = json.load(intermediaryVersionIndexFile) | ||
for it in intermediaryVersionIndex: | ||
processIntermediaryVersion(it) | ||
|
||
for version in loaderVersions: | ||
outFilepath = "multimc/net.fabricmc.fabric-loader/%s.json" % version.version | ||
with open(outFilepath, 'w') as outfile: | ||
json.dump(version.to_json(), outfile, sort_keys=True, indent=4) | ||
|
||
sharedData = MultiMCSharedPackageData(uid = 'net.fabricmc.fabric-loader', name = 'Fabric Loader') | ||
sharedData.recommended = loaderRecommended | ||
sharedData.description = "Fabric Loader is a tool to load Fabric-compatible mods in game environments." | ||
sharedData.projectUrl = "https://fabricmc.net" | ||
sharedData.authors = ["Fabric Developers"] | ||
sharedData.write() | ||
|
||
for version in intermediaryVersions: | ||
outFilepath = "multimc/net.fabricmc.intermediary/%s.json" % version.version | ||
with open(outFilepath, 'w') as outfile: | ||
json.dump(version.to_json(), outfile, sort_keys=True, indent=4) | ||
|
||
sharedData = MultiMCSharedPackageData(uid = 'net.fabricmc.intermediary', name = 'Intermediary Mappings') | ||
sharedData.recommended = intermediaryRecommended | ||
sharedData.description = "Intermediary mappings allow using Fabric Loader with mods for Minecraft in a more compatible manner." | ||
sharedData.projectUrl = "https://fabricmc.net" | ||
sharedData.authors = ["Fabric Developers"] | ||
sharedData.write() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/python3 | ||
import os, requests | ||
from cachecontrol import CacheControl | ||
import datetime | ||
import hashlib, json | ||
import zipfile | ||
from fabricutil import * | ||
|
||
from cachecontrol.caches import FileCache | ||
|
||
forever_cache = FileCache('http_cache', forever=True) | ||
sess = CacheControl(requests.Session(), forever_cache) | ||
|
||
def mkdirs(path): | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
|
||
def filehash(filename, hashtype, blocksize=65536): | ||
hash = hashtype() | ||
with open(filename, "rb") as f: | ||
for block in iter(lambda: f.read(blocksize), b""): | ||
hash.update(block) | ||
return hash.hexdigest() | ||
|
||
def get_maven_url(mavenKey, server, ext): | ||
mavenParts = mavenKey.split(":", 3) | ||
mavenVerUrl = server + mavenParts[0].replace(".", "/") + "/" + mavenParts[1] + "/" + mavenParts[2] + "/" | ||
mavenUrl = mavenVerUrl + mavenParts[1] + "-" + mavenParts[2] + ext | ||
return mavenUrl | ||
|
||
def get_json_file(path, url): | ||
with open(path, 'w', encoding='utf-8') as f: | ||
r = sess.get(url) | ||
r.raise_for_status() | ||
version_json = r.json() | ||
json.dump(version_json, f, sort_keys=True, indent=4) | ||
return version_json | ||
|
||
def get_binary_file(path, url): | ||
with open(path, 'w', encoding='utf-8') as f: | ||
r = sess.get(url) | ||
r.raise_for_status() | ||
with open(path, 'wb') as f: | ||
for chunk in r.iter_content(chunk_size=128): | ||
f.write(chunk) | ||
|
||
def compute_jar_file(path, url): | ||
jarPath = path + ".jar" | ||
get_binary_file(jarPath, url) | ||
tstamp = datetime.datetime.fromtimestamp(0) | ||
with zipfile.ZipFile(jarPath, 'r') as jar: | ||
allinfo = jar.infolist() | ||
for info in allinfo: | ||
tstampNew = datetime.datetime(*info.date_time) | ||
if tstampNew > tstamp: | ||
tstamp = tstampNew | ||
data = FabricJarInfo() | ||
data.releaseTime = tstamp | ||
data.sha1 = filehash(jarPath, hashlib.sha1) | ||
data.sha256 = filehash(jarPath, hashlib.sha256) | ||
data.size = os.path.getsize(jarPath) | ||
with open(path + ".json", 'w') as outfile: | ||
json.dump(data.to_json(), outfile, sort_keys=True, indent=4) | ||
|
||
mkdirs("upstream/fabric/meta-v2") | ||
mkdirs("upstream/fabric/loader-installer-json") | ||
mkdirs("upstream/fabric/jars") | ||
|
||
# get the version list for each component we are interested in | ||
for component in ["intermediary", "loader"]: | ||
index = get_json_file("upstream/fabric/meta-v2/" + component + ".json", "https://meta.fabricmc.net/v2/versions/" + component) | ||
for it in index: | ||
jarMavenUrl = get_maven_url(it["maven"], "https://maven.fabricmc.net/", ".jar") | ||
compute_jar_file("upstream/fabric/jars/" + it["maven"].replace(":", "."), jarMavenUrl) | ||
|
||
# for each loader, download installer JSON file from maven | ||
with open("upstream/fabric/meta-v2/loader.json", 'r', encoding='utf-8') as loaderVersionIndexFile: | ||
loaderVersionIndex = json.load(loaderVersionIndexFile) | ||
for it in loaderVersionIndex: | ||
mavenUrl = get_maven_url(it["maven"], "https://maven.fabricmc.net/", ".json") | ||
get_json_file("upstream/fabric/loader-installer-json/" + it["version"] + ".json", mavenUrl) |