Initial commit
This commit is contained in:
commit
1a427e102a
4 changed files with 136 additions and 0 deletions
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
.idea/
|
||||
*.user
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
/.vs/
|
10
EPLMetadataGenerator.csproj
Normal file
10
EPLMetadataGenerator.csproj
Normal file
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
16
EPLMetadataGenerator.sln
Normal file
16
EPLMetadataGenerator.sln
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EPLMetadataGenerator", "EPLMetadataGenerator.csproj", "{91C078A4-FA5F-4A15-A8D4-1A68E04EE264}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{91C078A4-FA5F-4A15-A8D4-1A68E04EE264}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{91C078A4-FA5F-4A15-A8D4-1A68E04EE264}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{91C078A4-FA5F-4A15-A8D4-1A68E04EE264}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{91C078A4-FA5F-4A15-A8D4-1A68E04EE264}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
102
Program.cs
Normal file
102
Program.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Xml;
|
||||
|
||||
const string mavenMetadataUrl = "https://maven.ely.by/releases/by/ely/authlib/maven-metadata.xml";
|
||||
const string authlibInjectorUrl =
|
||||
"https://github.com/yushijinhun/authlib-injector/releases/download/v1.2.5/authlib-injector-1.2.5.jar";
|
||||
|
||||
var client = new HttpClient();
|
||||
var metadataXml = await client.GetStringAsync(mavenMetadataUrl);
|
||||
|
||||
var document = new XmlDocument();
|
||||
document.LoadXml(metadataXml);
|
||||
|
||||
var versioning = document["metadata"]!["versioning"];
|
||||
var versions = versioning!["versions"]!.GetElementsByTagName("version");
|
||||
|
||||
var versionsDict = new Dictionary<string, string>();
|
||||
foreach (var versionObject in versions)
|
||||
{
|
||||
var versionElement = versionObject as XmlElement;
|
||||
var fullVersion = versionElement!.InnerText;
|
||||
var authlibVersion = fullVersion.Split('-').First();
|
||||
if (versionsDict.TryGetValue(authlibVersion, out var existing))
|
||||
{
|
||||
var newElyPatchNumber = Convert.ToInt32(fullVersion.Split('.').Last());
|
||||
var existingElyPatchNumber = Convert.ToInt32(existing.Split('.').Last());
|
||||
if (newElyPatchNumber > existingElyPatchNumber)
|
||||
{
|
||||
versionsDict.Remove(authlibVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
versionsDict.Add(authlibVersion, fullVersion);
|
||||
}
|
||||
|
||||
versionsDict = versionsDict.OrderByDescending(kvp =>
|
||||
{
|
||||
var versionNumbers = kvp.Key.Split('.');
|
||||
var score = 0;
|
||||
if (versionNumbers.Length > 0)
|
||||
{
|
||||
score += 1_000_000 * Convert.ToInt32(versionNumbers[0]);
|
||||
}
|
||||
if (versionNumbers.Length > 1)
|
||||
{
|
||||
score += 1_000 * Convert.ToInt32(versionNumbers[1]);
|
||||
}
|
||||
if (versionNumbers.Length > 2)
|
||||
{
|
||||
score += Convert.ToInt32(versionNumbers[2]);
|
||||
}
|
||||
|
||||
return score;
|
||||
}).ToDictionary();
|
||||
|
||||
var overrides = new JsonObject();
|
||||
foreach (var version in versionsDict)
|
||||
{
|
||||
// TODO: replace with GitHub repo
|
||||
var downloadUrl = $"https://llaun.ch/repo/libraries/by/ely/authlib/{version.Value}/authlib-{version.Value}.jar";
|
||||
byte[] result;
|
||||
try
|
||||
{
|
||||
result = await client.GetByteArrayAsync(downloadUrl);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
if (e.StatusCode != HttpStatusCode.NotFound) throw;
|
||||
continue;
|
||||
}
|
||||
|
||||
var sha1 = Convert.ToHexStringLower(SHA1.HashData(result));
|
||||
var size = result.Length;
|
||||
overrides[version.Key] = new JsonObject
|
||||
{
|
||||
["url"] = downloadUrl,
|
||||
["sha1"] = sha1,
|
||||
["size"] = size
|
||||
};
|
||||
}
|
||||
|
||||
var root = new JsonObject
|
||||
{
|
||||
["overrides"] = new JsonObject
|
||||
{
|
||||
["com.mojang:authlib"] = overrides
|
||||
},
|
||||
["extras"] = new JsonObject
|
||||
{
|
||||
["authlib-injector"] = authlibInjectorUrl
|
||||
}
|
||||
};
|
||||
|
||||
await using var output = File.Create("epl_metadata.json");
|
||||
await JsonSerializer.SerializeAsync(output, root, new JsonSerializerOptions { WriteIndented = true });
|
Loading…
Reference in a new issue