mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-16 12:31:43 +02:00
.config
.run
.workdir
Agent
Common
Phantom.Common.Data
Agent
Instance
Java
JavaRuntime.cs
TaggedJavaRuntime.cs
Minecraft
Replies
AllowedPorts.cs
Phantom.Common.Data.csproj
RamAllocationUnits.cs
Phantom.Common.Data.Tests
Phantom.Common.Logging
Phantom.Common.Messages
Docker
Server
Utils
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
PhantomPanel.sln
global.json
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using MessagePack;
|
|
|
|
namespace Phantom.Common.Data.Java;
|
|
|
|
[MessagePackObject]
|
|
public sealed record JavaRuntime(
|
|
[property: Key(0)] string MainVersion,
|
|
[property: Key(1)] string FullVersion,
|
|
[property: Key(2)] string DisplayName
|
|
) : IComparable<JavaRuntime> {
|
|
public int CompareTo(JavaRuntime? other) {
|
|
if (ReferenceEquals(this, other)) {
|
|
return 0;
|
|
}
|
|
|
|
if (ReferenceEquals(null, other)) {
|
|
return 1;
|
|
}
|
|
|
|
if (TryParseFullVersion(FullVersion, out var fullVersion) && TryParseFullVersion(other.FullVersion, out var otherFullVersion)) {
|
|
var versionComparison = -fullVersion.CompareTo(otherFullVersion);
|
|
if (versionComparison != 0) {
|
|
return versionComparison;
|
|
}
|
|
}
|
|
|
|
return string.Compare(DisplayName, other.DisplayName, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
private static bool TryParseFullVersion(string versionString, [NotNullWhen(true)] out Version? version) {
|
|
int dashIndex = versionString.IndexOf('-');
|
|
var versionSpan = dashIndex != -1 ? versionString.AsSpan(0, dashIndex) : versionString;
|
|
if (versionSpan.Contains('_')) {
|
|
versionSpan = versionSpan.ToString().Replace('_', '.');
|
|
}
|
|
|
|
return Version.TryParse(versionSpan, out version);
|
|
}
|
|
}
|