refactor: NeoForge BMCLAPI 版本列表(爱来自 bangbang93)

fix: 安装 NeoForge 整合包时的参数初始化不正确
chores: 在低版本(<=1.19)的自动安装界面将不会显示 NeoForge
This commit is contained in:
Pigeon0v0
2024-06-30 15:01:06 +08:00
parent 4dba7c969c
commit 3c44a55b37
3 changed files with 44 additions and 31 deletions
@@ -802,24 +802,33 @@
''' </summary> ''' </summary>
Public DlNeoForgeListBmclapiLoader As New LoaderTask(Of Integer, DlNeoForgeListResult)("DlNeoForgeList Bmclapi", AddressOf DlNeoForgeListBmclapiMain) Public DlNeoForgeListBmclapiLoader As New LoaderTask(Of Integer, DlNeoForgeListResult)("DlNeoForgeList Bmclapi", AddressOf DlNeoForgeListBmclapiMain)
Private Sub DlNeoForgeListBmclapiMain(Loader As LoaderTask(Of Integer, DlNeoForgeListResult)) Private Sub DlNeoForgeListBmclapiMain(Loader As LoaderTask(Of Integer, DlNeoForgeListResult))
Dim ResultLatest As String
Dim VersionsJArray As JArray
Try
ResultLatest = NetGetCodeByDownload("https://bmclapi2.bangbang93.com/neoforge/meta/api/maven/details/releases/net/neoforged/neoforge", UseBrowserUserAgent:=True, IsJson:=True)
Catch ex As Exception
If GetExceptionSummary(ex).Contains("(404)") Then
Throw New Exception("没有可用版本")
Else
Throw
End If
End Try
If ResultLatest.Length < 50 Then Throw New Exception("获取到的版本列表长度不足(" & ResultLatest & ")")
VersionsJArray = GetJson(ResultLatest)("name")
Dim Versions As New List(Of String) Dim Versions As New List(Of String)
Dim ClientVersions As JArray = DlClientListLoader.Output.Value("versions") 'BMCLAPI 不能返回所有 NeoForge 版本,获取 MC 版本列表进行遍历 Versions.Add("1.20.1")
Dim ClientReleases As New List(Of String) Try
For Each Token As String In VersionsJArray("name")
For Each Client In ClientVersions '排除快照版或远古版等特殊版本 Dim Version As String = Token.Replace("neoforge-", "")
If RegexCheck(Client("id").ToString(), "[0,9.]+") Then Dim Inherit As String = $"1.{Version.Split(".")(0)}.{Token.Split(".")(1)}"
ClientReleases.Add(Client("id").ToString()) If Inherit.EndsWith(".0") Then Inherit = Inherit.Replace(".0", "")
End If Versions.Add(Inherit)
Next Next
Versions = Versions.Distinct().ToList()
For Each Release In ClientReleases Catch ex As Exception
If Int(Release.Split(".")(1)) <= 19 Then Continue For '如果游戏版本低于 1.20 就不进行请求 Log(ex, LogLevel.Feedback)
Dim Json As String = NetGetCodeByRequestRetry("https://bmclapi2.bangbang93.com/neoforge/list/" & Release) End Try
If Not Json.Contains("[]") Then '如果这个版本不支持 NeoForge,BMCLAPI 会直接返回一个空的 Json 序列,这里直接用字符串处理了 If Not Versions.Any() Then Throw New Exception("没有可用版本")
Versions.Add(Release)
End If
Next
Loader.Output = New DlNeoForgeListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Versions} Loader.Output = New DlNeoForgeListResult With {.IsOfficial = False, .SourceName = "BMCLAPI", .Value = Versions}
End Sub End Sub
#End Region #End Region
@@ -1300,7 +1300,7 @@ Retry:
Dim DownloadInfo = If(IsNeo, DownloadNeoInfo, DownloadForgeInfo) Dim DownloadInfo = If(IsNeo, DownloadNeoInfo, DownloadForgeInfo)
If IsNeo Then '兜底,有的时候 DownloadInfo 可能是空的 If IsNeo Then '兜底,有的时候 DownloadInfo 可能是空的
If DownloadNeoInfo Is Nothing Then If DownloadNeoInfo Is Nothing Then
DownloadInfo.VersionName = Version DownloadInfo = New DlNeoForgeVersionEntry With {.VersionName = Version}
Version = Version.Replace("neoforge-", "").Replace("-beta", "").Replace("1.20.1-", "") Version = Version.Replace("neoforge-", "").Replace("-beta", "").Replace("1.20.1-", "")
DownloadInfo.VersionCode = Version DownloadInfo.VersionCode = Version
If Version.Contains("-beta") Then DownloadInfo.IsBeta = True If Version.Contains("-beta") Then DownloadInfo.IsBeta = True
@@ -372,6 +372,9 @@
LabForge.Foreground = ColorGray1 LabForge.Foreground = ColorGray1
End If End If
'NeoForge 'NeoForge
If Not SelectedMinecraftId.Contains("1.") OrElse Val(SelectedMinecraftId.Split(".")(1)) <= 19 Then
CardNeoForge.Visibility = Visibility.Collapsed
Else
Dim NeoForgeError As String = LoadNeoForgeGetError() Dim NeoForgeError As String = LoadNeoForgeGetError()
CardNeoForge.MainSwap.Visibility = If(NeoForgeError Is Nothing, Visibility.Visible, Visibility.Collapsed) CardNeoForge.MainSwap.Visibility = If(NeoForgeError Is Nothing, Visibility.Visible, Visibility.Collapsed)
If NeoForgeError IsNot Nothing Then CardNeoForge.IsSwaped = True If NeoForgeError IsNot Nothing Then CardNeoForge.IsSwaped = True
@@ -387,6 +390,7 @@
LabNeoForge.Text = SelectedNeoForge.VersionCode & If(SelectedNeoForge.IsBeta, "-beta", "") LabNeoForge.Text = SelectedNeoForge.VersionCode & If(SelectedNeoForge.IsBeta, "-beta", "")
LabNeoForge.Foreground = ColorGray1 LabNeoForge.Foreground = ColorGray1
End If End If
End If
'Fabric 'Fabric
If SelectedMinecraftId.Contains("1.") AndAlso Val(SelectedMinecraftId.Split(".")(1)) <= 13 Then If SelectedMinecraftId.Contains("1.") AndAlso Val(SelectedMinecraftId.Split(".")(1)) <= 13 Then
CardFabric.Visibility = Visibility.Collapsed CardFabric.Visibility = Visibility.Collapsed